use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class MethodSelectingRouter method createHeadEnrichedRouter.
private Router createHeadEnrichedRouter() {
return new Router() {
@Override
public Continuation apply(final RequestProcessingContext context) {
final ContainerRequest request = context.request();
if (HttpMethod.HEAD.equals(request.getMethod())) {
request.setMethodWithoutException(HttpMethod.GET);
context.push(new Function<ContainerResponse, ContainerResponse>() {
@Override
public ContainerResponse apply(final ContainerResponse responseContext) {
responseContext.getRequestContext().setMethodWithoutException(HttpMethod.HEAD);
return responseContext;
}
});
}
return Continuation.of(context, getMethodRouter(context));
}
};
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class JsonWithPaddingInterceptor method getCallbackName.
/**
* Returns a JavaScript callback name to wrap the JSON entity into. The callback name is determined from the {@link JSONP}
* annotation.
*
* @param jsonp {@link JSONP} annotation to determine the callback name from.
* @return a JavaScript callback name.
*/
private String getCallbackName(final JSONP jsonp) {
String callback = jsonp.callback();
if (!"".equals(jsonp.queryParam())) {
final ContainerRequest containerRequest = containerRequestProvider.get();
final UriInfo uriInfo = containerRequest.getUriInfo();
final MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters();
final List<String> queryParameter = queryParameters.get(jsonp.queryParam());
callback = (queryParameter != null && !queryParameter.isEmpty()) ? queryParameter.get(0) : callback;
}
return callback;
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class ContextBasedInjectionTest method testAsyncApp.
@Test
public void testAsyncApp() throws InterruptedException, ExecutionException {
ContainerRequest req = RequestContextBuilder.from(BASE_URI, URI.create(BASE_URI.getPath() + uriSuffix), "GET").build();
Future<ContainerResponse> res = app.apply(req);
assertEquals(expectedResponse, res.get().getEntity());
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class MixedResourceConfigurationTest method testPutGet.
@Test
public void testPutGet() throws Exception {
final ResourceConfig resourceConfig = new ResourceConfig(NameResource.class);
final Resource.Builder resourceBuilder = Resource.builder("/name");
resourceBuilder.addMethod("PUT").handledBy(new Inflector<ContainerRequestContext, Response>() {
@Override
public Response apply(ContainerRequestContext request) {
name = ((ContainerRequest) request).readEntity(String.class);
return Response.ok().build();
}
});
resourceConfig.registerResources(resourceBuilder.build());
final ApplicationHandler application = new ApplicationHandler(resourceConfig);
final ContainerResponse response = application.apply(RequestContextBuilder.from("/name", "PUT").entity("Gaga").type(MediaType.TEXT_PLAIN).build()).get();
assertEquals(200, response.getStatus());
assertEquals("Gaga", application.apply(RequestContextBuilder.from("/name", "GET").accept(MediaType.TEXT_PLAIN).build()).get().getEntity());
}
use of org.glassfish.jersey.server.ContainerRequest in project jersey by jersey.
the class OptionsTest method testRequestNoType.
@Test
public void testRequestNoType() throws ExecutionException, InterruptedException {
ApplicationHandler application = new ApplicationHandler(new ResourceConfig(WadlResource.class));
final ContainerRequest request = RequestContextBuilder.from("/resource", "OPTIONS").build();
final ContainerResponse response = application.apply(request).get();
Assert.assertEquals(200, response.getStatus());
final MediaType type = response.getMediaType();
Assert.assertTrue(type.equals(MediaTypes.WADL_TYPE) || type.equals(MediaType.TEXT_HTML_TYPE) || type.equals(MediaType.TEXT_PLAIN));
}
Aggregations