use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class ManagedBeanWebAppTest method testExceptionMapper.
/**
* Test exceptions are properly mapped.
*/
@Test
public void testExceptionMapper() {
WebTarget singletonTarget = target().path("managedbean/singleton/exception");
WebTarget perRequestTarget = target().path("managedbean/per-request/exception");
_testExceptionOutput(singletonTarget, "singleton");
_testExceptionOutput(perRequestTarget, "per-request");
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class VariantsTest method testGetLanguageEn.
@Test
public void testGetLanguageEn() throws IOException {
WebTarget rp = target("/lvr");
Response r = rp.request().header("Accept-Language", "en").get();
assertEquals("en", r.readEntity(String.class));
assertEquals("en", r.getLanguage().toString());
String vary = r.getHeaderString("Vary");
assertNotNull(vary);
assertTrue(!contains(vary, "Accept"));
assertTrue(contains(vary, "Accept-Language"));
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class ClientTest method testContextHeaders.
@Test
public // Inspired by JERSEY-1502
void testContextHeaders() {
final WebTarget target = target().path("headers").path("content");
Invocation.Builder ib;
Invocation i;
Response r;
String reqHeaders;
ib = target.request("*/*");
ib.header("custom-header", "custom-value");
ib.header("content-encoding", "deflate");
i = ib.build("POST", Entity.entity("aaa", MediaType.WILDCARD_TYPE));
r = i.invoke();
reqHeaders = r.readEntity(String.class).toLowerCase();
for (final String expected : new String[] { "custom-header:[custom-value]", "custom-header:custom-value" }) {
assertTrue(String.format("Request headers do not contain expected '%s' entry:\n%s", expected, reqHeaders), reqHeaders.contains(expected));
}
final String unexpected = "content-encoding";
assertFalse(String.format("Request headers contains unexpected '%s' entry:\n%s", unexpected, reqHeaders), reqHeaders.contains(unexpected));
ib = target.request("*/*");
i = ib.build("POST", Entity.entity("aaa", Variant.mediaTypes(MediaType.WILDCARD_TYPE).encodings("deflate").build().get(0)));
r = i.invoke();
final String expected = "content-encoding:[deflate]";
reqHeaders = r.readEntity(String.class).toLowerCase();
assertTrue(String.format("Request headers do not contain expected '%s' entry:\n%s", expected, reqHeaders), reqHeaders.contains(expected));
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class InterceptorCustomTest method testMoreInterceptorsAndFilter.
@Test
public void testMoreInterceptorsAndFilter() throws IOException {
WebTarget target = target().path("test");
Response response = target.request().put(Entity.entity(ENTITY, MediaType.TEXT_PLAIN_TYPE));
String str = response.readEntity(String.class);
assertEquals(ENTITY + FROM_RESOURCE, str);
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class InterceptorGzipTest method testGzipInterceptorOnlyOnServer.
@Test
public void testGzipInterceptorOnlyOnServer() throws IOException {
client().register(GZIPWriterTestInterceptor.class);
WebTarget target = target().path("test");
String entity = "hello, this is text entity";
Response response = target.request().put(Entity.entity(entity, MediaType.TEXT_PLAIN_TYPE));
InputStream is = response.readEntity(InputStream.class);
GZIPInputStream gzipIs = new GZIPInputStream(is);
BufferedReader br = new BufferedReader(new InputStreamReader(gzipIs));
String str = br.readLine();
assertEquals(entity + FROM_RESOURCE, str);
}
Aggregations