use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.
the class RxJava2FlowableServer method createFactoryBean.
private JAXRSServerFactoryBean createFactoryBean(Bus bus, boolean useStreamingSubscriber, String relAddress) {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.getProperties(true).put("useStreamingSubscriber", useStreamingSubscriber);
sf.setProvider(new JacksonJsonProvider());
new ReactiveIOCustomizer().customize(sf);
sf.getOutInterceptors().add(new LoggingOutInterceptor());
sf.setResourceClasses(RxJava2FlowableService.class);
sf.setResourceProvider(RxJava2FlowableService.class, new SingletonResourceProvider(new RxJava2FlowableService(), true));
sf.setAddress("http://localhost:" + PORT + relAddress);
return sf;
}
use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project tomee by apache.
the class JAXRSInInterceptor method setExchangeProperties.
private void setExchangeProperties(Message message, Exchange exchange, OperationResourceInfo ori, MultivaluedMap<String, String> values, int numberOfResources) {
final ClassResourceInfo cri = ori.getClassResourceInfo();
exchange.put(OperationResourceInfo.class, ori);
exchange.put(JAXRSUtils.ROOT_RESOURCE_CLASS, cri);
message.put(RESOURCE_METHOD, ori.getMethodToInvoke());
message.put(URITemplate.TEMPLATE_PARAMETERS, values);
message.put(URITemplate.URI_TEMPLATE, JAXRSUtils.getUriTemplate(message, cri, ori));
String plainOperationName = ori.getMethodToInvoke().getName();
if (numberOfResources > 1) {
plainOperationName = cri.getServiceClass().getSimpleName() + "#" + plainOperationName;
}
exchange.put(RESOURCE_OPERATION_NAME, plainOperationName);
if (ori.isOneway() || PropertyUtils.isTrue(HttpUtils.getProtocolHeader(message, Message.ONE_WAY_REQUEST, null))) {
exchange.setOneWay(true);
}
ResourceProvider rp = cri.getResourceProvider();
if (rp instanceof SingletonResourceProvider) {
// cri.isSingleton is not guaranteed to indicate we have a 'pure' singleton
exchange.put(Message.SERVICE_OBJECT, rp.getInstance(message));
}
}
use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider 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.lifecycle.SingletonResourceProvider 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());
}
use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.
the class JAXRSServiceFactoryBean method setResourceClassesFromBeans.
public void setResourceClassesFromBeans(List<Object> beans) {
for (Object bean : beans) {
Class<?> realClass = ClassHelper.getRealClass(getBus(), bean);
ClassResourceInfo cri = getCreatedFromModel(realClass);
if (cri != null) {
if (!InjectionUtils.isConcreteClass(cri.getServiceClass())) {
cri = new ClassResourceInfo(cri);
classResourceInfos.add(cri);
}
cri.setResourceClass(bean.getClass());
cri.setResourceProvider(new SingletonResourceProvider(bean));
continue;
}
cri = ResourceUtils.createClassResourceInfo(bean.getClass(), realClass, true, enableStatic, getBus());
if (cri != null) {
classResourceInfos.add(cri);
cri.setResourceProvider(new SingletonResourceProvider(bean));
}
}
}
Aggregations