Search in sources :

Example 16 with Customer

use of org.apache.cxf.jaxrs.Customer in project cxf by apache.

the class JAXRSUtilsTest method testContextAnnotationOnMethod.

@SuppressWarnings("unchecked")
@Test
public void testContextAnnotationOnMethod() throws Exception {
    ClassResourceInfo cri = new ClassResourceInfo(Customer.class, true);
    Customer c = new Customer();
    cri.setResourceProvider(new SingletonResourceProvider(c));
    InjectionUtils.injectContextProxies(cri, cri.getResourceProvider().getInstance(null));
    OperationResourceInfo ori = new OperationResourceInfo(Customer.class.getMethods()[0], cri);
    Message message = createMessage();
    InjectionUtils.injectContextMethods(c, ori.getClassResourceInfo(), message);
    assertNotNull(c.getUriInfo());
    assertSame(ThreadLocalUriInfo.class, c.getUriInfo().getClass());
    assertSame(UriInfoImpl.class, ((ThreadLocalProxy<UriInfo>) c.getUriInfo()).get().getClass());
    assertSame(ThreadLocalServletConfig.class, c.getSuperServletConfig().getClass());
    assertSame(ThreadLocalHttpServletRequest.class, c.getHttpServletRequest().getClass());
}
Also used : ThreadLocalProxy(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy) Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Test(org.junit.Test)

Example 17 with Customer

use of org.apache.cxf.jaxrs.Customer 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());
}
Also used : ThreadLocalHttpServletRequest(org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) ThreadLocalProxy(org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy) Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) ServletContext(javax.servlet.ServletContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) HttpServletResponseFilter(org.apache.cxf.jaxrs.impl.HttpServletResponseFilter) Test(org.junit.Test)

Example 18 with Customer

use of org.apache.cxf.jaxrs.Customer in project cxf by apache.

the class JAXRSUtilsTest method testContextResolverFields.

@Test
public void testContextResolverFields() 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);
    Message m = createMessage();
    HttpServletResponse response = EasyMock.createMock(HttpServletResponse.class);
    m.put(AbstractHTTPDestination.HTTP_RESPONSE, response);
    Customer c = new Customer();
    ContextResolver<JAXBContext> cr = new JAXBContextProvider();
    ProviderFactory.getInstance(m).registerUserProvider(cr);
    m.put(Message.BASE_PATH, "/");
    InjectionUtils.injectContextFields(c, ori.getClassResourceInfo(), m);
    assertSame(cr.getClass(), c.getContextResolver().getClass());
}
Also used : Message(org.apache.cxf.message.Message) Customer(org.apache.cxf.jaxrs.Customer) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) HttpServletResponse(javax.servlet.http.HttpServletResponse) OperationResourceInfo(org.apache.cxf.jaxrs.model.OperationResourceInfo) JAXBContext(javax.xml.bind.JAXBContext) JAXBContextProvider(org.apache.cxf.jaxrs.JAXBContextProvider) PerRequestResourceProvider(org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider) Test(org.junit.Test)

Aggregations

Customer (org.apache.cxf.jaxrs.Customer)18 Test (org.junit.Test)17 Message (org.apache.cxf.message.Message)13 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)11 OperationResourceInfo (org.apache.cxf.jaxrs.model.OperationResourceInfo)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 ThreadLocalProxy (org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy)5 CustomerParameterHandler (org.apache.cxf.jaxrs.CustomerParameterHandler)4 MessageImpl (org.apache.cxf.message.MessageImpl)4 ServletContext (javax.servlet.ServletContext)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ParamConverterProvider (javax.ws.rs.ext.ParamConverterProvider)3 Server (org.apache.cxf.endpoint.Server)3 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)3 PriorityCustomerParameterHandler (org.apache.cxf.jaxrs.PriorityCustomerParameterHandler)3 HttpServletResponseFilter (org.apache.cxf.jaxrs.impl.HttpServletResponseFilter)3 ThreadLocalHttpServletRequest (org.apache.cxf.jaxrs.impl.tl.ThreadLocalHttpServletRequest)3 PerRequestResourceProvider (org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider)3 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)3 ArrayList (java.util.ArrayList)2