use of org.openclinica.ns.response.v31.Response in project okhttp by square.
the class JavaApiConverterTest method createOkResponseForCacheGet_secure.
@Test
public void createOkResponseForCacheGet_secure() throws Exception {
final String statusLine = "HTTP/1.1 200 Fantastic";
final Principal localPrincipal = LOCAL_CERT.getSubjectX500Principal();
final List<Certificate> localCertificates = Arrays.<Certificate>asList(LOCAL_CERT);
final Principal serverPrincipal = SERVER_CERT.getSubjectX500Principal();
final List<Certificate> serverCertificates = Arrays.<Certificate>asList(SERVER_CERT);
URI uri = new URI("https://foo/bar");
Request request = new Request.Builder().url(uri.toURL()).build();
SecureCacheResponse cacheResponse = new SecureCacheResponse() {
@Override
public Map<String, List<String>> getHeaders() throws IOException {
Map<String, List<String>> headers = new LinkedHashMap<>();
headers.put(null, Collections.singletonList(statusLine));
headers.put("xyzzy", Arrays.asList("bar", "baz"));
return headers;
}
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream("HelloWorld".getBytes(StandardCharsets.UTF_8));
}
@Override
public String getCipherSuite() {
return "SSL_RSA_WITH_NULL_MD5";
}
@Override
public List<Certificate> getLocalCertificateChain() {
return localCertificates;
}
@Override
public List<Certificate> getServerCertificateChain() throws SSLPeerUnverifiedException {
return serverCertificates;
}
@Override
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
return serverPrincipal;
}
@Override
public Principal getLocalPrincipal() {
return localPrincipal;
}
};
Response response = JavaApiConverter.createOkResponseForCacheGet(request, cacheResponse);
Request cacheRequest = response.request();
assertEquals(request.url(), cacheRequest.url());
assertEquals(request.method(), cacheRequest.method());
assertEquals(0, request.headers().size());
assertEquals(Protocol.HTTP_1_1, response.protocol());
assertEquals(200, response.code());
assertEquals("Fantastic", response.message());
Headers okResponseHeaders = response.headers();
assertEquals("baz", okResponseHeaders.get("xyzzy"));
assertEquals("HelloWorld", response.body().string());
Handshake handshake = response.handshake();
assertNotNull(handshake);
assertNotNullAndEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5, handshake.cipherSuite());
assertEquals(localPrincipal, handshake.localPrincipal());
assertEquals(serverPrincipal, handshake.peerPrincipal());
assertEquals(serverCertificates, handshake.peerCertificates());
assertEquals(localCertificates, handshake.localCertificates());
}
use of org.openclinica.ns.response.v31.Response in project okhttp by square.
the class JavaApiConverterTest method createJavaCacheResponse_httpGet.
@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());
}
use of org.openclinica.ns.response.v31.Response in project okhttp by square.
the class JavaApiConverterTest method createJavaUrlConnection_https_extraHttpsMethods.
@Test
public void createJavaUrlConnection_https_extraHttpsMethods() throws Exception {
Request okRequest = createArbitraryOkRequest().newBuilder().get().url("https://secure/request").build();
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().handshake(handshake).build();
HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) JavaApiConverter.createJavaUrlConnectionForCachePut(okResponse);
assertEquals("SSL_RSA_WITH_NULL_MD5", httpsUrlConnection.getCipherSuite());
assertEquals(SERVER_CERT.getSubjectX500Principal(), httpsUrlConnection.getPeerPrincipal());
assertArrayEquals(new Certificate[] { LOCAL_CERT }, httpsUrlConnection.getLocalCertificates());
assertArrayEquals(new Certificate[] { SERVER_CERT }, httpsUrlConnection.getServerCertificates());
assertEquals(LOCAL_CERT.getSubjectX500Principal(), httpsUrlConnection.getLocalPrincipal());
}
use of org.openclinica.ns.response.v31.Response in project okhttp by square.
the class JavaApiConverterTest method createJavaUrlConnection_requestChangesForbidden.
@Test
public void createJavaUrlConnection_requestChangesForbidden() throws Exception {
Response okResponse = createArbitraryOkResponse();
HttpURLConnection httpUrlConnection = JavaApiConverter.createJavaUrlConnectionForCachePut(okResponse);
// request.
try {
httpUrlConnection.setRequestProperty("key", "value");
fail();
} catch (UnsupportedOperationException expected) {
}
try {
httpUrlConnection.setFixedLengthStreamingMode(1234);
fail();
} catch (UnsupportedOperationException expected) {
}
try {
httpUrlConnection.setRequestMethod("PUT");
fail();
} catch (UnsupportedOperationException expected) {
}
try {
httpUrlConnection.getHeaderFields().put("key", Collections.singletonList("value"));
fail();
} catch (UnsupportedOperationException expected) {
}
try {
httpUrlConnection.getOutputStream();
fail();
} catch (UnsupportedOperationException expected) {
}
}
use of org.openclinica.ns.response.v31.Response in project okhttp by square.
the class JavaApiConverterTest method createOkResponseForCacheGet.
@Test
public void createOkResponseForCacheGet() throws Exception {
final String statusLine = "HTTP/1.1 200 Fantastic";
URI uri = new URI("http://foo/bar");
Request request = new Request.Builder().url(uri.toURL()).build();
CacheResponse cacheResponse = new CacheResponse() {
@Override
public Map<String, List<String>> getHeaders() throws IOException {
Map<String, List<String>> headers = new LinkedHashMap<>();
headers.put(null, Collections.singletonList(statusLine));
headers.put("xyzzy", Arrays.asList("bar", "baz"));
return headers;
}
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream("HelloWorld".getBytes(StandardCharsets.UTF_8));
}
};
Response response = JavaApiConverter.createOkResponseForCacheGet(request, cacheResponse);
Request cacheRequest = response.request();
assertEquals(request.url(), cacheRequest.url());
assertEquals(request.method(), cacheRequest.method());
assertEquals(0, request.headers().size());
assertEquals(Protocol.HTTP_1_1, response.protocol());
assertEquals(200, response.code());
assertEquals("Fantastic", response.message());
Headers okResponseHeaders = response.headers();
assertEquals("baz", okResponseHeaders.get("xyzzy"));
assertEquals("HelloWorld", response.body().string());
assertNull(response.handshake());
}
Aggregations