Java Code Examples for java.net.SecureCacheResponse

The following are top voted examples for showing how to use java.net.SecureCacheResponse. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: GitHub   File: ResponseCacheTest.java   View source code 6 votes vote down vote up
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) throws IOException {
  final CacheResponse response = delegate.get(uri, requestMethod, requestHeaders);
  if (response instanceof SecureCacheResponse) {
    return new CacheResponse() {
      @Override public InputStream getBody() throws IOException {
        return response.getBody();
      }

      @Override public Map<String, List<String>> getHeaders() throws IOException {
        return response.getHeaders();
      }
    };
  }
  return response;
}
 
Example 2
Project: GitHub   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpGet() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .get()
          .build();
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(null)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertNull(javaCacheResponse.getBody());
}
 
Example 3
Project: GitHub   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpPost() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .post(createRequestBody("RequestBody"))
          .build();
  ResponseBody responseBody = createResponseBody("ResponseBody");
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(responseBody)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertEquals("ResponseBody", readAll(javaCacheResponse.getBody()));
}
 
Example 4
Project: GitHub   File: ResponseCacheTest.java   View source code 6 votes vote down vote up
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) throws IOException {
  final CacheResponse response = delegate.get(uri, requestMethod, requestHeaders);
  if (response instanceof SecureCacheResponse) {
    return new CacheResponse() {
      @Override public InputStream getBody() throws IOException {
        return response.getBody();
      }

      @Override public Map<String, List<String>> getHeaders() throws IOException {
        return response.getHeaders();
      }
    };
  }
  return response;
}
 
Example 5
Project: GitHub   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpGet() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .get()
          .build();
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(null)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertNull(javaCacheResponse.getBody());
}
 
Example 6
Project: GitHub   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpPost() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .post(createRequestBody("RequestBody"))
          .build();
  ResponseBody responseBody = createResponseBody("ResponseBody");
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(responseBody)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertEquals("ResponseBody", readAll(javaCacheResponse.getBody()));
}
 
Example 7
Project: OpenJSharp   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the
 * server, or null if the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates() {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalCertificates ());
    }
}
 
Example 8
Project: OpenJSharp   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's certificate chain, or throws
 * SSLPeerUnverified Exception if
 * the server did not authenticate.
 */
public java.security.cert.Certificate[] getServerCertificates()
        throws SSLPeerUnverifiedException {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getServerCertificates ());
    }
}
 
Example 9
Project: jdk8u-jdk   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the
 * server, or null if the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates() {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalCertificates ());
    }
}
 
Example 10
Project: jdk8u-jdk   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's certificate chain, or throws
 * SSLPeerUnverified Exception if
 * the server did not authenticate.
 */
public java.security.cert.Certificate[] getServerCertificates()
        throws SSLPeerUnverifiedException {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getServerCertificates ());
    }
}
 
Example 11
Project: openjdk-jdk10   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the
 * server, or null if the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates() {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalCertificates ());
    }
}
 
Example 12
Project: openjdk-jdk10   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's certificate chain, or throws
 * SSLPeerUnverified Exception if
 * the server did not authenticate.
 */
public java.security.cert.Certificate[] getServerCertificates()
        throws SSLPeerUnverifiedException {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l =
                ((SecureCacheResponse)cachedResponse)
                        .getServerCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getServerCertificates ());
    }
}
 
Example 13
Project: silvertunnel-ng   File: HttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the cipher suite in use on this connection.
 */
public String getCipherSuite()
{
	if (cachedResponse != null)
	{
		return ((SecureCacheResponse) cachedResponse).getCipherSuite();
	}
	if (http == null)
	{
		throw new IllegalStateException("connection not yet open");
	}
	else
	{
		return ((HttpsClient) http).getCipherSuite();
	}
}
 
Example 14
Project: silvertunnel-ng   File: HttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the server, or null if
 * the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates()
{
	if (cachedResponse != null)
	{
		final List<java.security.cert.Certificate> l = ((SecureCacheResponse) cachedResponse)
				.getLocalCertificateChain();
		if (l == null)
		{
			return null;
		}
		else
		{
			return (java.security.cert.Certificate[]) l.toArray();
		}
	}
	if (http == null)
	{
		throw new IllegalStateException("connection not yet open");
	}
	else
	{
		return (((HttpsClient) http).getLocalCertificates());
	}
}
 
Example 15
Project: silvertunnel-ng   File: HttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's principal, or throws SSLPeerUnverifiedException if
 * the server did not authenticate.
 */
Principal getPeerPrincipal() throws SSLPeerUnverifiedException
{
	if (cachedResponse != null)
	{
		return ((SecureCacheResponse) cachedResponse).getPeerPrincipal();
	}

	if (http == null)
	{
		throw new IllegalStateException("connection not yet open");
	}
	else
	{
		return (((HttpsClient) http).getPeerPrincipal());
	}
}
 
Example 16
Project: silvertunnel-ng   File: HttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the principal the client sent to the server, or null if the
 * client did not authenticate.
 */
Principal getLocalPrincipal()
{
	if (cachedResponse != null)
	{
		return ((SecureCacheResponse) cachedResponse).getLocalPrincipal();
	}

	if (http == null)
	{
		throw new IllegalStateException("connection not yet open");
	}
	else
	{
		return (((HttpsClient) http).getLocalPrincipal());
	}
}
 
Example 17
Project: openjdk9   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the
 * server, or null if the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates() {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalCertificates ());
    }
}
 
Example 18
Project: openjdk9   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's certificate chain, or throws
 * SSLPeerUnverified Exception if
 * the server did not authenticate.
 */
public java.security.cert.Certificate[] getServerCertificates()
        throws SSLPeerUnverifiedException {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l =
                ((SecureCacheResponse)cachedResponse)
                        .getServerCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getServerCertificates ());
    }
}
 
Example 19
Project: PriorityOkHttp   File: ResponseCacheTest.java   View source code 6 votes vote down vote up
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) throws IOException {
  final CacheResponse response = delegate.get(uri, requestMethod, requestHeaders);
  if (response instanceof SecureCacheResponse) {
    return new CacheResponse() {
      @Override public InputStream getBody() throws IOException {
        return response.getBody();
      }

      @Override public Map<String, List<String>> getHeaders() throws IOException {
        return response.getHeaders();
      }
    };
  }
  return response;
}
 
Example 20
Project: PriorityOkHttp   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpGet() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .get()
          .build();
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(null)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertNull(javaCacheResponse.getBody());
}
 
Example 21
Project: PriorityOkHttp   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpPost() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .post(createRequestBody("RequestBody"))
          .build();
  ResponseBody responseBody = createResponseBody("ResponseBody");
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(responseBody)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertEquals("ResponseBody", readAll(javaCacheResponse.getBody()));
}
 
Example 22
Project: Okhttp   File: ResponseCacheTest.java   View source code 6 votes vote down vote up
@Override public CacheResponse get(URI uri, String requestMethod,
    Map<String, List<String>> requestHeaders) throws IOException {
  final CacheResponse response = delegate.get(uri, requestMethod, requestHeaders);
  if (response instanceof SecureCacheResponse) {
    return new CacheResponse() {
      @Override public InputStream getBody() throws IOException {
        return response.getBody();
      }

      @Override public Map<String, List<String>> getHeaders() throws IOException {
        return response.getHeaders();
      }
    };
  }
  return response;
}
 
Example 23
Project: Okhttp   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpGet() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .get()
          .build();
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(null)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertNull(javaCacheResponse.getBody());
}
 
Example 24
Project: Okhttp   File: JavaApiConverterTest.java   View source code 6 votes vote down vote up
@Test public void createJavaCacheResponse_httpPost() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("http://insecure/request")
          .post(createRequestBody("RequestBody"))
          .build();
  ResponseBody responseBody = createResponseBody("ResponseBody");
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(responseBody)
      .build();
  CacheResponse javaCacheResponse = JavaApiConverter.createJavaCacheResponse(okResponse);
  assertFalse(javaCacheResponse instanceof SecureCacheResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertEquals("ResponseBody", readAll(javaCacheResponse.getBody()));
}
 
Example 25
Project: jdk8u_jdk   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the
 * server, or null if the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates() {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalCertificates ());
    }
}
 
Example 26
Project: jdk8u_jdk   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's certificate chain, or throws
 * SSLPeerUnverified Exception if
 * the server did not authenticate.
 */
public java.security.cert.Certificate[] getServerCertificates()
        throws SSLPeerUnverifiedException {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getServerCertificates ());
    }
}
 
Example 27
Project: lookaside_java-1.8.0-openjdk   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the
 * server, or null if the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates() {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalCertificates ());
    }
}
 
Example 28
Project: lookaside_java-1.8.0-openjdk   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's certificate chain, or throws
 * SSLPeerUnverified Exception if
 * the server did not authenticate.
 */
public java.security.cert.Certificate[] getServerCertificates()
        throws SSLPeerUnverifiedException {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getServerCertificates ());
    }
}
 
Example 29
Project: silvertunnel-monteux   File: HttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the server, or null if
 * the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates()
{
	if (cachedResponse != null)
	{
		final List<java.security.cert.Certificate> l = ((SecureCacheResponse) cachedResponse)
				.getLocalCertificateChain();
		if (l == null)
		{
			return null;
		}
		else
		{
			return (java.security.cert.Certificate[]) l.toArray();
		}
	}
	if (http == null)
	{
		throw new IllegalStateException("connection not yet open");
	}
	else
	{
		return (((HttpsClient) http).getLocalCertificates());
	}
}
 
Example 30
Project: jdk8u-dev-jdk   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the certificate chain the client sent to the
 * server, or null if the client did not authenticate.
 */
public java.security.cert.Certificate[] getLocalCertificates() {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getLocalCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalCertificates ());
    }
}
 
Example 31
Project: silvertunnel-monteux   File: HttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the principal the client sent to the server, or null if the
 * client did not authenticate.
 */
Principal getLocalPrincipal()
{
	if (cachedResponse != null)
	{
		return ((SecureCacheResponse) cachedResponse).getLocalPrincipal();
	}

	if (http == null)
	{
		throw new IllegalStateException("connection not yet open");
	}
	else
	{
		return (((HttpsClient) http).getLocalPrincipal());
	}
}
 
Example 32
Project: infobip-open-jdk-8   File: AbstractDelegateHttpsURLConnection.java   View source code 6 votes vote down vote up
/**
 * Returns the server's certificate chain, or throws
 * SSLPeerUnverified Exception if
 * the server did not authenticate.
 */
public java.security.cert.Certificate[] getServerCertificates()
        throws SSLPeerUnverifiedException {
    if (cachedResponse != null) {
        List<java.security.cert.Certificate> l = ((SecureCacheResponse)cachedResponse).getServerCertificateChain();
        if (l == null) {
            return null;
        } else {
            return l.toArray(new java.security.cert.Certificate[0]);
        }
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getServerCertificates ());
    }
}
 
Example 33
Project: GitHub   File: JavaApiConverterTest.java   View source code 5 votes vote down vote up
@Test public void createJavaCacheResponse_httpsPost() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("https://secure/request")
          .post(createRequestBody("RequestBody"))
          .build();
  ResponseBody responseBody = createResponseBody("ResponseBody");
  Handshake handshake = Handshake.get(null, CipherSuite.TLS_RSA_WITH_NULL_MD5,
      Arrays.<Certificate>asList(SERVER_CERT), Arrays.<Certificate>asList(LOCAL_CERT));
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(responseBody)
      .handshake(handshake)
      .build();
  SecureCacheResponse javaCacheResponse =
      (SecureCacheResponse) JavaApiConverter.createJavaCacheResponse(okResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertEquals("ResponseBody", readAll(javaCacheResponse.getBody()));
  assertEquals(handshake.cipherSuite().javaName(), javaCacheResponse.getCipherSuite());
  assertEquals(handshake.localCertificates(), javaCacheResponse.getLocalCertificateChain());
  assertEquals(handshake.peerCertificates(), javaCacheResponse.getServerCertificateChain());
  assertEquals(handshake.localPrincipal(), javaCacheResponse.getLocalPrincipal());
  assertEquals(handshake.peerPrincipal(), javaCacheResponse.getPeerPrincipal());
}
 
Example 34
Project: GitHub   File: JavaApiConverterTest.java   View source code 5 votes vote down vote up
@Test public void createJavaCacheResponse_httpsPost() throws Exception {
  Request okRequest =
      createArbitraryOkRequest().newBuilder()
          .url("https://secure/request")
          .post(createRequestBody("RequestBody"))
          .build();
  ResponseBody responseBody = createResponseBody("ResponseBody");
  Handshake handshake = Handshake.get(TlsVersion.SSL_3_0, CipherSuite.TLS_RSA_WITH_NULL_MD5,
      Arrays.<Certificate>asList(SERVER_CERT), Arrays.<Certificate>asList(LOCAL_CERT));
  Response okResponse = createArbitraryOkResponse(okRequest).newBuilder()
      .protocol(Protocol.HTTP_1_1)
      .code(200)
      .message("Fantastic")
      .addHeader("key1", "value1_1")
      .addHeader("key2", "value2")
      .addHeader("key1", "value1_2")
      .body(responseBody)
      .handshake(handshake)
      .build();
  SecureCacheResponse javaCacheResponse =
      (SecureCacheResponse) JavaApiConverter.createJavaCacheResponse(okResponse);
  Map<String, List<String>> javaHeaders = javaCacheResponse.getHeaders();
  assertEquals(Arrays.asList("value1_1", "value1_2"), javaHeaders.get("key1"));
  assertEquals(Arrays.asList("HTTP/1.1 200 Fantastic"), javaHeaders.get(null));
  assertEquals("ResponseBody", readAll(javaCacheResponse.getBody()));
  assertEquals(handshake.cipherSuite().javaName(), javaCacheResponse.getCipherSuite());
  assertEquals(handshake.localCertificates(), javaCacheResponse.getLocalCertificateChain());
  assertEquals(handshake.peerCertificates(), javaCacheResponse.getServerCertificateChain());
  assertEquals(handshake.localPrincipal(), javaCacheResponse.getLocalPrincipal());
  assertEquals(handshake.peerPrincipal(), javaCacheResponse.getPeerPrincipal());
}
 
Example 35
Project: OpenJSharp   File: AbstractDelegateHttpsURLConnection.java   View source code 5 votes vote down vote up
/**
 * Returns the cipher suite in use on this connection.
 */
public String getCipherSuite () {
    if (cachedResponse != null) {
        return ((SecureCacheResponse)cachedResponse).getCipherSuite();
    }
    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
       return ((HttpsClient)http).getCipherSuite ();
    }
}
 
Example 36
Project: OpenJSharp   File: AbstractDelegateHttpsURLConnection.java   View source code 5 votes vote down vote up
/**
 * Returns the server's principal, or throws SSLPeerUnverifiedException
 * if the server did not authenticate.
 */
Principal getPeerPrincipal()
        throws SSLPeerUnverifiedException
{
    if (cachedResponse != null) {
        return ((SecureCacheResponse)cachedResponse).getPeerPrincipal();
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getPeerPrincipal());
    }
}
 
Example 37
Project: OpenJSharp   File: AbstractDelegateHttpsURLConnection.java   View source code 5 votes vote down vote up
/**
 * Returns the principal the client sent to the
 * server, or null if the client did not authenticate.
 */
Principal getLocalPrincipal()
{
    if (cachedResponse != null) {
        return ((SecureCacheResponse)cachedResponse).getLocalPrincipal();
    }

    if (http == null) {
        throw new IllegalStateException("connection not yet open");
    } else {
        return (((HttpsClient)http).getLocalPrincipal());
    }
}
 
Example 38
Project: LoRaWAN-Smart-Parking   File: HttpsURLConnectionImpl.java   View source code 5 votes vote down vote up
@Override public String getCipherSuite() {
  SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
  if (cacheResponse != null) {
    return cacheResponse.getCipherSuite();
  }
  SSLSocket sslSocket = getSslSocket();
  if (sslSocket != null) {
    return sslSocket.getSession().getCipherSuite();
  }
  return null;
}
 
Example 39
Project: LoRaWAN-Smart-Parking   File: HttpsURLConnectionImpl.java   View source code 5 votes vote down vote up
@Override public Certificate[] getLocalCertificates() {
  SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
  if (cacheResponse != null) {
    List<Certificate> result = cacheResponse.getLocalCertificateChain();
    return result != null ? result.toArray(new Certificate[result.size()]) : null;
  }
  SSLSocket sslSocket = getSslSocket();
  if (sslSocket != null) {
    return sslSocket.getSession().getLocalCertificates();
  }
  return null;
}
 
Example 40
Project: LoRaWAN-Smart-Parking   File: HttpsURLConnectionImpl.java   View source code 5 votes vote down vote up
@Override public Certificate[] getServerCertificates() throws SSLPeerUnverifiedException {
  SecureCacheResponse cacheResponse = delegate.getSecureCacheResponse();
  if (cacheResponse != null) {
    List<Certificate> result = cacheResponse.getServerCertificateChain();
    return result != null ? result.toArray(new Certificate[result.size()]) : null;
  }
  SSLSocket sslSocket = getSslSocket();
  if (sslSocket != null) {
    return sslSocket.getSession().getPeerCertificates();
  }
  return null;
}