use of org.apache.cxf.jaxrs.impl.HttpServletResponseFilter in project cxf by apache.
the class JAXRSUtilsTest method testSingletonContextFields.
@SuppressWarnings("unchecked")
@Test
public void testSingletonContextFields() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
cri.setResourceProvider(new SingletonResourceProvider(c));
Message m = createMessage();
m.put(Message.PROTOCOL_HEADERS, new HashMap<String, List<String>>());
ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
HttpServletRequest httpRequest = EasyMock.createNiceMock(HttpServletRequest.class);
m.put(AbstractHTTPDestination.HTTP_REQUEST, httpRequest);
HttpServletResponse httpResponse = EasyMock.createMock(HttpServletResponse.class);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
InjectionUtils.injectContextFields(c, cri, m);
InjectionUtils.injectContextMethods(c, cri, m);
assertSame(ThreadLocalUriInfo.class, c.getUriInfo2().getClass());
assertSame(UriInfoImpl.class, ((ThreadLocalProxy<UriInfo>) c.getUriInfo2()).get().getClass());
assertSame(HttpHeadersImpl.class, ((ThreadLocalProxy<HttpHeaders>) c.getHeaders()).get().getClass());
assertSame(RequestImpl.class, ((ThreadLocalProxy<Request>) c.getRequest()).get().getClass());
assertSame(ResourceInfoImpl.class, ((ThreadLocalProxy<ResourceInfo>) c.getResourceInfo()).get().getClass());
assertSame(SecurityContextImpl.class, ((ThreadLocalProxy<SecurityContext>) c.getSecurityContext()).get().getClass());
assertSame(ProvidersImpl.class, ((ThreadLocalProxy<Providers>) c.getBodyWorkers()).get().getClass());
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getThreadLocalServletContext()).get());
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getServletContext()).get());
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getSuperServletContext()).get());
HttpServletRequest currentReq = ((ThreadLocalProxy<HttpServletRequest>) c.getServletRequest()).get();
assertSame(httpRequest, ((HttpServletRequestFilter) currentReq).getRequest());
HttpServletResponseFilter filter = (HttpServletResponseFilter) ((ThreadLocalProxy<HttpServletResponse>) c.getServletResponse()).get();
assertSame(httpResponse, filter.getResponse());
}
use of org.apache.cxf.jaxrs.impl.HttpServletResponseFilter in project cxf by apache.
the class MessageContextImplTest method testHttpResponse.
@Test
public void testHttpResponse() {
Message m = createMessage();
MessageContext mc = new MessageContextImpl(m);
HttpServletResponse request = EasyMock.createMock(HttpServletResponse.class);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, request);
HttpServletResponseFilter filter = (HttpServletResponseFilter) mc.getHttpServletResponse();
assertSame(request.getClass(), filter.getResponse().getClass());
filter = (HttpServletResponseFilter) mc.getContext(HttpServletResponse.class);
assertSame(request.getClass(), filter.getResponse().getClass());
}
use of org.apache.cxf.jaxrs.impl.HttpServletResponseFilter in project cxf by apache.
the class JAXRSUtilsTest method testSingletonHttpResourceFields.
@SuppressWarnings("unchecked")
@Test
public void testSingletonHttpResourceFields() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
Customer c = new Customer();
cri.setResourceProvider(new SingletonResourceProvider(c));
Message m = createMessage();
ServletContext servletContextMock = EasyMock.createNiceMock(ServletContext.class);
m.put(AbstractHTTPDestination.HTTP_CONTEXT, servletContextMock);
HttpServletRequest httpRequest = EasyMock.createNiceMock(HttpServletRequest.class);
m.put(AbstractHTTPDestination.HTTP_REQUEST, httpRequest);
HttpServletResponse httpResponse = EasyMock.createMock(HttpServletResponse.class);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, httpResponse);
InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
InjectionUtils.injectContextFields(c, cri, m);
assertSame(servletContextMock, ((ThreadLocalProxy<ServletContext>) c.getServletContextResource()).get());
HttpServletRequest currentReq = ((ThreadLocalProxy<HttpServletRequest>) c.getServletRequestResource()).get();
assertSame(httpRequest, ((HttpServletRequestFilter) currentReq).getRequest());
HttpServletResponseFilter filter = (HttpServletResponseFilter) ((ThreadLocalProxy<HttpServletResponse>) c.getServletResponseResource()).get();
assertSame(httpResponse, filter.getResponse());
}
use of org.apache.cxf.jaxrs.impl.HttpServletResponseFilter in project cxf by apache.
the class JAXRSUtilsTest method testServletContextParameters.
@Test
public void testServletContextParameters() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("testServletParams", new Class[] { HttpServletRequest.class, HttpServletResponse.class, ServletContext.class, ServletConfig.class }), cri);
ori.setHttpMethod("GET");
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
HttpServletResponse response = new HttpServletResponseFilter(EasyMock.createMock(HttpServletResponse.class), null);
ServletContext context = EasyMock.createMock(ServletContext.class);
ServletConfig config = EasyMock.createMock(ServletConfig.class);
EasyMock.replay(request);
EasyMock.replay(context);
EasyMock.replay(config);
Message m = createMessage();
m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
m.put(AbstractHTTPDestination.HTTP_CONFIG, config);
List<Object> params = JAXRSUtils.processParameters(ori, new MetadataMap<String, String>(), m);
assertEquals("4 parameters expected", 4, params.size());
assertSame(request.getClass(), ((HttpServletRequestFilter) params.get(0)).getRequest().getClass());
assertSame(response.getClass(), params.get(1).getClass());
assertSame(context.getClass(), params.get(2).getClass());
assertSame(config.getClass(), params.get(3).getClass());
}
use of org.apache.cxf.jaxrs.impl.HttpServletResponseFilter in project cxf by apache.
the class JAXRSUtilsTest method testServletResourceFields.
@Test
public void testServletResourceFields() throws Exception {
ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
cri.setResourceProvider(new PerRequestResourceProvider(Customer.class));
OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethod("postConstruct", new Class[] {}), cri);
Customer c = new Customer();
// Creating mocks for the servlet request, response and context
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
ServletContext context = EasyMock.createMock(ServletContext.class);
EasyMock.replay(request);
EasyMock.replay(response);
EasyMock.replay(context);
Message m = createMessage();
m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
m.put(AbstractHTTPDestination.HTTP_CONTEXT, context);
InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
assertSame(request.getClass(), ((HttpServletRequestFilter) c.getServletRequestResource()).getRequest().getClass());
HttpServletResponseFilter filter = (HttpServletResponseFilter) c.getServletResponseResource();
assertSame(response.getClass(), filter.getResponse().getClass());
assertSame(context.getClass(), c.getServletContextResource().getClass());
assertNotNull(c.getServletRequest());
assertNotNull(c.getServletResponse());
assertNotNull(c.getServletContext());
assertNotNull(c.getServletRequestResource());
assertNotNull(c.getServletResponseResource());
assertNotNull(c.getServletContextResource());
assertSame(request.getClass(), ((HttpServletRequestFilter) c.getServletRequestResource()).getRequest().getClass());
filter = (HttpServletResponseFilter) c.getServletResponse();
assertSame(response.getClass(), filter.getResponse().getClass());
assertSame(context.getClass(), c.getServletContext().getClass());
}
Aggregations