use of org.glassfish.jersey.internal.MapPropertiesDelegate in project jersey by jersey.
the class ContainerRequestTest method testAcceptableMediaTypes.
@Test
public void testAcceptableMediaTypes() throws URISyntaxException {
ContainerRequest r = new ContainerRequest(URI.create("http://example.org/app"), URI.create("http://example.org/app/resource"), "GET", SECURITY_CONTEXT, new MapPropertiesDelegate());
r.header(HttpHeaders.ACCEPT, "application/xml, text/plain");
r.header(HttpHeaders.ACCEPT, "application/json");
assertEquals(r.getAcceptableMediaTypes().size(), 3);
assertTrue(r.getAcceptableMediaTypes().contains(MediaType.APPLICATION_XML_TYPE));
assertTrue(r.getAcceptableMediaTypes().contains(MediaType.TEXT_PLAIN_TYPE));
assertTrue(r.getAcceptableMediaTypes().contains(MediaType.APPLICATION_JSON_TYPE));
}
use of org.glassfish.jersey.internal.MapPropertiesDelegate in project jersey by jersey.
the class ContainerRequestTest method testPreconditionsNoneMatch.
@Test
public void testPreconditionsNoneMatch() {
ContainerRequest r = new ContainerRequest(URI.create("http://example.org/app"), URI.create("http://example.org/app/resource"), "GET", SECURITY_CONTEXT, new MapPropertiesDelegate());
r.header(HttpHeaders.IF_NONE_MATCH, "\"686897696a7c876b7e\"");
assertEquals(r.evaluatePreconditions(new EntityTag("686897696a7c876b7e")).build().getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
assertNull(r.evaluatePreconditions(new EntityTag("000000000000000000")));
}
use of org.glassfish.jersey.internal.MapPropertiesDelegate in project jersey by jersey.
the class ContainerRequestTest method testPreconditionsModified.
@Test
public void testPreconditionsModified() throws ParseException {
ContainerRequest r = new ContainerRequest(URI.create("http://example.org/app"), URI.create("http://example.org/app/resource"), "GET", SECURITY_CONTEXT, new MapPropertiesDelegate());
r.header(HttpHeaders.IF_MODIFIED_SINCE, "Sat, 29 Oct 2011 19:43:31 GMT");
SimpleDateFormat f = new SimpleDateFormat("E, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
Date date = f.parse("Sat, 29 Oct 2011 19:43:31 GMT");
assertEquals(r.evaluatePreconditions(date).build().getStatus(), Response.Status.NOT_MODIFIED.getStatusCode());
date = f.parse("Sat, 30 Oct 2011 19:43:31 GMT");
assertNull(r.evaluatePreconditions(date));
}
use of org.glassfish.jersey.internal.MapPropertiesDelegate in project jersey by jersey.
the class ContainerRequestTest method testAcceptableLanguages.
@Test
public void testAcceptableLanguages() throws URISyntaxException {
ContainerRequest r = new ContainerRequest(URI.create("http://example.org/app"), URI.create("http://example.org/app/resource"), "GET", SECURITY_CONTEXT, new MapPropertiesDelegate());
r.header(HttpHeaders.ACCEPT_LANGUAGE, "en-gb;q=0.8, en;q=0.7");
r.header(HttpHeaders.ACCEPT_LANGUAGE, "de");
assertEquals(r.getAcceptableLanguages().size(), 3);
assertTrue(r.getAcceptableLanguages().contains(Locale.UK));
assertTrue(r.getAcceptableLanguages().contains(Locale.ENGLISH));
assertTrue(r.getAcceptableLanguages().contains(Locale.GERMAN));
}
use of org.glassfish.jersey.internal.MapPropertiesDelegate in project jersey by jersey.
the class JdkHttpHandlerContainer method handle.
@Override
public void handle(final HttpExchange exchange) throws IOException {
/**
* This is a URI that contains the path, query and fragment components.
*/
URI exchangeUri = exchange.getRequestURI();
/**
* The base path specified by the HTTP context of the HTTP handler. It
* is in decoded form.
*/
String decodedBasePath = exchange.getHttpContext().getPath();
// Ensure that the base path ends with a '/'
if (!decodedBasePath.endsWith("/")) {
if (decodedBasePath.equals(exchangeUri.getPath())) {
/**
* This is an edge case where the request path does not end in a
* '/' and is equal to the context path of the HTTP handler.
* Both the request path and base path need to end in a '/'
* Currently the request path is modified.
*
* TODO support redirection in accordance with resource configuration feature.
*/
exchangeUri = UriBuilder.fromUri(exchangeUri).path("/").build();
}
decodedBasePath += "/";
}
/*
* The following is madness, there is no easy way to get the complete
* URI of the HTTP request!!
*
* TODO this is missing the user information component, how can this be obtained?
*/
final boolean isSecure = exchange instanceof HttpsExchange;
final String scheme = isSecure ? "https" : "http";
final URI baseUri = getBaseUri(exchange, decodedBasePath, scheme);
final URI requestUri = getRequestUri(exchange, baseUri);
final ResponseWriter responseWriter = new ResponseWriter(exchange);
final ContainerRequest requestContext = new ContainerRequest(baseUri, requestUri, exchange.getRequestMethod(), getSecurityContext(exchange.getPrincipal(), isSecure), new MapPropertiesDelegate());
requestContext.setEntityStream(exchange.getRequestBody());
requestContext.getHeaders().putAll(exchange.getRequestHeaders());
requestContext.setWriter(responseWriter);
try {
appHandler.handle(requestContext);
} finally {
// if the response was not committed yet by the JerseyApplication
// then commit it and log warning
responseWriter.closeAndLogWarning();
}
}
Aggregations