use of org.apache.cxf.jaxrs.impl.HttpServletRequestFilter 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.HttpServletRequestFilter 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());
}
use of org.apache.cxf.jaxrs.impl.HttpServletRequestFilter in project cxf by apache.
the class HttpUtils method createServletResourceValue.
public static <T> T createServletResourceValue(Message m, Class<T> clazz) {
Object value = null;
if (clazz == HttpServletRequest.class) {
HttpServletRequest request = (HttpServletRequest) m.get(AbstractHTTPDestination.HTTP_REQUEST);
value = request != null ? new HttpServletRequestFilter(request, m) : null;
} else if (clazz == HttpServletResponse.class) {
HttpServletResponse response = (HttpServletResponse) m.get(AbstractHTTPDestination.HTTP_RESPONSE);
value = response != null ? new HttpServletResponseFilter(response, m) : null;
} else if (clazz == ServletContext.class) {
value = m.get(AbstractHTTPDestination.HTTP_CONTEXT);
} else if (clazz == ServletConfig.class) {
value = m.get(AbstractHTTPDestination.HTTP_CONFIG);
}
return clazz.cast(value);
}
use of org.apache.cxf.jaxrs.impl.HttpServletRequestFilter in project cxf by apache.
the class MessageContextImplTest method testHttpRequest.
@Test
public void testHttpRequest() {
Message m = createMessage();
MessageContext mc = new MessageContextImpl(m);
HttpServletRequest request = EasyMock.createMock(HttpServletRequest.class);
m.put(AbstractHTTPDestination.HTTP_REQUEST, request);
assertSame(request.getClass(), ((HttpServletRequestFilter) mc.getHttpServletRequest()).getRequest().getClass());
assertSame(request.getClass(), ((HttpServletRequestFilter) mc.getContext(HttpServletRequest.class)).getRequest().getClass());
}
Aggregations