use of javax.ws.rs.client.Client in project jersey by jersey.
the class JdkHttpsServerTest method testHttpsServerNoSslContextDelayedStart.
/**
* Test, that {@link HttpsServer} can be manually started even with (empty) SSLContext, but will throw an exception
* on request.
* @throws Exception
*/
@Test(expected = IOException.class)
public void testHttpsServerNoSslContextDelayedStart() throws Throwable {
server = JdkHttpServerFactory.createHttpServer(httpsUri, rc, null, false);
assertThat(server, instanceOf(HttpsServer.class));
server.start();
final Client client = ClientBuilder.newBuilder().newClient();
try {
client.target(httpsUri).path("testHttps").request().get(String.class);
} catch (final ProcessingException e) {
throw e.getCause();
}
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HelloWorldTest method testConfigurationUpdate.
@Test
public void testConfigurationUpdate() {
Client client1 = client();
client1.register(CustomLoggingFilter.class).property("foo", "bar");
Client client = ClientBuilder.newClient(client1.getConfiguration());
CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
String s = target().path(ROOT_PATH).request().get(String.class);
assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
assertEquals(1, CustomLoggingFilter.preFilterCalled);
assertEquals(1, CustomLoggingFilter.postFilterCalled);
client.close();
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class ExceptionTest method test500StatusCode.
@Test
public void test500StatusCode() {
startServer(ExceptionResource.class);
Client client = ClientBuilder.newClient();
WebTarget r = client.target(getUri().path("500").build());
assertEquals(500, r.request().get(Response.class).getStatus());
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class ExceptionTest method test400StatusCode.
@Test
public void test400StatusCode() {
startServer(ExceptionResource.class);
Client client = ClientBuilder.newClient();
WebTarget r = client.target(getUri().path("400").build());
assertEquals(400, r.request().get(Response.class).getStatus());
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HttpAuthenticationFilter method repeatRequest.
/**
* Repeat the {@code request} with provided {@code newAuthorizationHeader}
* and update the {@code response} with newest response data.
*
* @param request Request context.
* @param response Response context (will be updated with the new response data).
* @param newAuthorizationHeader {@code Authorization} header that should be added to the new request.
* @return {@code true} is the authentication was successful ({@code true} if 401 response code was not returned;
* {@code false} otherwise).
*/
static boolean repeatRequest(ClientRequestContext request, ClientResponseContext response, String newAuthorizationHeader) {
Client client = request.getClient();
String method = request.getMethod();
MediaType mediaType = request.getMediaType();
URI lUri = request.getUri();
WebTarget resourceTarget = client.target(lUri);
Invocation.Builder builder = resourceTarget.request(mediaType);
MultivaluedMap<String, Object> newHeaders = new MultivaluedHashMap<String, Object>();
for (Map.Entry<String, List<Object>> entry : request.getHeaders().entrySet()) {
if (HttpHeaders.AUTHORIZATION.equals(entry.getKey())) {
continue;
}
newHeaders.put(entry.getKey(), entry.getValue());
}
newHeaders.add(HttpHeaders.AUTHORIZATION, newAuthorizationHeader);
builder.headers(newHeaders);
builder.property(REQUEST_PROPERTY_FILTER_REUSED, "true");
Invocation invocation;
if (request.getEntity() == null) {
invocation = builder.build(method);
} else {
invocation = builder.build(method, Entity.entity(request.getEntity(), request.getMediaType()));
}
Response nextResponse = invocation.invoke();
if (nextResponse.hasEntity()) {
response.setEntityStream(nextResponse.readEntity(InputStream.class));
}
MultivaluedMap<String, String> headers = response.getHeaders();
headers.clear();
headers.putAll(nextResponse.getStringHeaders());
response.setStatus(nextResponse.getStatus());
return response.getStatus() != Response.Status.UNAUTHORIZED.getStatusCode();
}
Aggregations