use of javax.ws.rs.client.Client in project jersey by jersey.
the class JerseyInvocationTest method buildInvocationWithHeaders.
private JerseyInvocation buildInvocationWithHeaders(final MultivaluedMap<String, Object> headers) {
final Client c = ClientBuilder.newClient();
final Invocation.Builder builder = c.target("http://localhost:8080/mypath").request();
return (JerseyInvocation) builder.header("unexpected-header", "unexpected-header").headers(headers).buildGet();
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class JerseyInvocationTest method overrideHttpMethodBasedComplianceCheckTest.
/**
* Checks that presence of request entity fo HTTP DELETE method does not fail in Jersey.
* Instead, the request is propagated up to HttpURLConnection, where it fails with
* {@code ProtocolException}.
* <p/>
* See also JERSEY-1711.
*
* @see #overrideHttpMethodBasedComplianceCheckNegativeTest()
*/
@Test
public void overrideHttpMethodBasedComplianceCheckTest() {
final Client c1 = ClientBuilder.newClient().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
try {
c1.target("http://localhost:8080/myPath").request().method("DELETE", Entity.text("body"));
fail("ProcessingException expected.");
} catch (final ProcessingException ex) {
assertThat(ex.getCause().getClass(), anyOf(CoreMatchers.<Class<?>>equalTo(ProtocolException.class), CoreMatchers.<Class<?>>equalTo(ConnectException.class)));
}
final Client c2 = ClientBuilder.newClient();
try {
c2.target("http://localhost:8080/myPath").request().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true).method("DELETE", Entity.text("body"));
fail("ProcessingException expected.");
} catch (final ProcessingException ex) {
assertThat(ex.getCause().getClass(), anyOf(CoreMatchers.<Class<?>>equalTo(ProtocolException.class), CoreMatchers.<Class<?>>equalTo(ConnectException.class)));
}
final Client c3 = ClientBuilder.newClient().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, false);
try {
c3.target("http://localhost:8080/myPath").request().property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true).method("DELETE", Entity.text("body"));
fail("ProcessingException expected.");
} catch (final ProcessingException ex) {
assertThat(ex.getCause().getClass(), anyOf(CoreMatchers.<Class<?>>equalTo(ProtocolException.class), CoreMatchers.<Class<?>>equalTo(ConnectException.class)));
}
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class ClientProviderInstanceInjectionTest method test.
/**
* Tests that instance of a feature or other provider will not be injected on the client-side.
*/
@Test
public void test() {
final Client client = ClientBuilder.newBuilder().register(new MyFilterFeature()).register(new MyInjecteeBinder()).build();
final Response response = client.target("http://foo.bar").request().get();
assertEquals(200, response.getStatus());
assertEquals("null,null", response.readEntity(String.class));
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class CsrfProtectionFilterTest method setUp.
@Before
public void setUp() {
Client client = ClientBuilder.newClient(new ClientConfig(CsrfProtectionFilter.class).connectorProvider(new TestConnector()));
invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class EncodingFilterTest method testContentEncodingViaFeature.
@Test
public void testContentEncodingViaFeature() {
Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new TestConnector()).register(new EncodingFeature("gzip", GZipEncoder.class, DeflateEncoder.class)));
Invocation.Builder invBuilder = client.target(UriBuilder.fromUri("/").build()).request();
Response r = invBuilder.post(Entity.entity("Hello world", MediaType.TEXT_PLAIN_TYPE));
assertEquals("deflate,gzip,x-gzip", r.getHeaderString(ACCEPT_ENCODING));
assertEquals("gzip", r.getHeaderString(CONTENT_ENCODING));
}
Aggregations