use of javax.ws.rs.core.Response in project jersey by jersey.
the class TerminalClientRequestFilter method filter.
@Override
public void filter(final ClientRequestContext requestContext) throws IOException {
// Obtain entity - from request or create new.
final ByteArrayInputStream entity = new ByteArrayInputStream(requestContext.hasEntity() ? requestContext.getEntity().toString().getBytes() : "NO-ENTITY".getBytes());
final int responseStatus = requestContext.getHeaders().getFirst("Response-Status") != null ? (int) requestContext.getHeaders().getFirst("Response-Status") : 200;
Response.ResponseBuilder response = Response.status(responseStatus).entity(entity).type("text/plain").header("Test-Thread", Thread.currentThread().getName()).header("Test-Uri", requestContext.getUri().toString()).header("Test-Method", requestContext.getMethod());
// Request headers -> Response headers (<header> -> Test-Header-<header>)
for (final MultivaluedMap.Entry<String, List<String>> entry : requestContext.getStringHeaders().entrySet()) {
response = response.header("Test-Header-" + entry.getKey(), entry.getValue());
}
// Request properties -> Response headers (<header> -> Test-Property-<header>)
for (final String property : requestContext.getPropertyNames()) {
response = response.header("Test-Property-" + property, requestContext.getProperty(property));
}
requestContext.abortWith(response.build());
}
use of javax.ws.rs.core.Response in project jersey by jersey.
the class ModelEntityOnListTest method myBeanAndPut.
@Test
public void myBeanAndPut() {
WebTarget target = target("empty/mybean");
MyBean mb = new MyBean();
mb.setValue("Hello");
MyBean ah = new MyBean();
ah.setValue("Ahoy");
GenericEntity<List<MyBean>> ge = new GenericEntity<List<MyBean>>(Arrays.asList(mb, ah)) {
};
final Response response = target.request().post(Entity.entity(ge, MediaType.APPLICATION_JSON_TYPE));
assertEquals(200, response.getStatus());
assertEquals("PASSED", response.readEntity(String.class));
}
use of javax.ws.rs.core.Response in project jersey by jersey.
the class EventListenerTest method testSimpleProcessing.
@Test
public void testSimpleProcessing() {
final Response response = target().path("resource").request().get();
assertEquals(200, response.getStatus());
assertEquals("get", response.readEntity(String.class));
int i = 1;
System.out.println(response.getHeaders());
assertEquals("[" + i++ + "]", response.getHeaderString("R.REQ_FILTERS_START.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.REQ_FILTERS_FINISHED.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.RESOURCE_METHOD_START.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.RESOURCE_METHOD_FINISHED.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.RESP_FILTERS_START.order"));
assertEquals("[" + i + "]", response.getHeaderString("R.RESP_FILTERS_FINISHED.order"));
}
use of javax.ws.rs.core.Response in project jersey by jersey.
the class EventListenerTest method testException.
@Test
public void testException() {
final Response response = target().path("resource/locator/exception").request().get();
assertEquals(200, response.getStatus());
assertEquals("mapped", response.readEntity(String.class));
assertEquals("[org.glassfish.jersey.tests.e2e.server.monitoring.EventListenerTest$MyMappableException: test-error]", response.getHeaderString("R.EXCEPTION_MAPPER_FOUND.exception"));
}
use of javax.ws.rs.core.Response in project jersey by jersey.
the class EventListenerTest method testLocatorProcessing.
@Test
public void testLocatorProcessing() {
final Response response = target().path("resource/locator").request().get();
assertEquals(200, response.getStatus());
assertEquals("sub", response.readEntity(String.class));
int i = 1;
System.out.println(response.getHeaders());
assertEquals("[" + i++ + "]", response.getHeaderString("R.MATCHED_LOCATOR.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.MATCHED_SUB_RESOURCE.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.REQ_FILTERS_START.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.REQ_FILTERS_FINISHED.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.RESOURCE_METHOD_START.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.RESOURCE_METHOD_FINISHED.order"));
assertEquals("[" + i++ + "]", response.getHeaderString("R.RESP_FILTERS_START.order"));
assertEquals("[" + i + "]", response.getHeaderString("R.RESP_FILTERS_FINISHED.order"));
}
Aggregations