Search in sources :

Example 61 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf 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));
    }
}
Also used : SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) ClassResourceInfo(org.apache.cxf.jaxrs.model.ClassResourceInfo) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 62 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class BookServer20 method createServer.

@Override
protected Server createServer(Bus bus) throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookStore.class);
    List<Object> providers = new ArrayList<>();
    providers.add(new PreMatchContainerRequestFilter2());
    providers.add(new PreMatchContainerRequestFilter());
    providers.add(new PostMatchContainerResponseFilter());
    providers.add((Feature) context -> {
        context.register(new PostMatchContainerResponseFilter3());
        return true;
    });
    providers.add(new PostMatchContainerResponseFilter2());
    providers.add(new CustomReaderBoundInterceptor());
    providers.add(new CustomReaderInterceptor());
    providers.add(new CustomWriterInterceptor());
    providers.add(new CustomDynamicFeature());
    providers.add(new PostMatchContainerRequestFilter());
    providers.add(new FaultyContainerRequestFilter());
    providers.add(new PreMatchReplaceStreamOrAddress());
    providers.add(new ServerTestFeature());
    providers.add(new JacksonJaxbJsonProvider());
    providers.add(new IOExceptionMapper());
    providers.add(new GregorianCalendarMessageBodyWriter());
    sf.setApplication(new Application());
    sf.setProviders(providers);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    return sf.create();
}
Also used : Arrays(java.util.Arrays) Provider(javax.ws.rs.ext.Provider) StringUtils(org.apache.cxf.common.util.StringUtils) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Application(javax.ws.rs.core.Application) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) ContainerResponseFilter(javax.ws.rs.container.ContainerResponseFilter) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) MediaType(javax.ws.rs.core.MediaType) ByteArrayInputStream(java.io.ByteArrayInputStream) ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) Map(java.util.Map) URI(java.net.URI) Method(java.lang.reflect.Method) Server(org.apache.cxf.endpoint.Server) Context(javax.ws.rs.core.Context) GregorianCalendar(java.util.GregorianCalendar) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) Collectors(java.util.stream.Collectors) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) PreMatching(javax.ws.rs.container.PreMatching) Priority(javax.annotation.Priority) DynamicFeature(javax.ws.rs.container.DynamicFeature) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) Response(javax.ws.rs.core.Response) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) Bus(org.apache.cxf.Bus) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Feature(javax.ws.rs.core.Feature) SimpleDateFormat(java.text.SimpleDateFormat) ReaderInterceptorContext(javax.ws.rs.ext.ReaderInterceptorContext) HashMap(java.util.HashMap) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) FeatureContext(javax.ws.rs.core.FeatureContext) ResourceInfo(javax.ws.rs.container.ResourceInfo) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) AbstractServerTestServerBase(org.apache.cxf.testutil.common.AbstractServerTestServerBase) OutputStream(java.io.OutputStream) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOUtils(org.apache.cxf.helpers.IOUtils) IOException(java.io.IOException) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) NameBinding(javax.ws.rs.NameBinding) InjectionUtils(org.apache.cxf.jaxrs.utils.InjectionUtils) InputStream(java.io.InputStream) RetentionPolicy(java.lang.annotation.RetentionPolicy) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) Application(javax.ws.rs.core.Application)

Example 63 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class BookServerSub method createServer.

@Override
protected Server createServer(Bus bus) throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setStaticSubresourceResolution(true);
    sf.setResourceClasses(BookStoreSubObject.class);
    sf.setResourceProvider(BookStoreSubObject.class, new SingletonResourceProvider(new BookStoreSubObject(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    return sf.create();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 64 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class BookCxfContinuationServlet3Server method serverFactory.

private JAXRSServerFactoryBean serverFactory(Bus bus) {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(bus);
    sf.setResourceClasses(BookCxfContinuationStore.class);
    sf.setResourceProvider(BookCxfContinuationStore.class, new SingletonResourceProvider(new BookCxfContinuationStore()));
    sf.setAddress("/");
    return sf;
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Example 65 with SingletonResourceProvider

use of org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider in project cxf by apache.

the class BookCxfContinuationServer method createServer.

@Override
protected Server createServer(Bus bus) throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(BookCxfContinuationStore.class);
    sf.setResourceProvider(BookCxfContinuationStore.class, new SingletonResourceProvider(new BookCxfContinuationStore()));
    sf.setAddress("http://localhost:" + PORT + "/");
    return sf.create();
}
Also used : JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)

Aggregations

SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)84 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)63 Bus (org.apache.cxf.Bus)17 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)15 ArrayList (java.util.ArrayList)14 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)14 ResourceProvider (org.apache.cxf.jaxrs.lifecycle.ResourceProvider)9 HashMap (java.util.HashMap)7 Before (org.junit.Before)7 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)5 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)5 Map (java.util.Map)4 ReactiveIOCustomizer (org.apache.cxf.jaxrs.rx3.server.ReactiveIOCustomizer)4 DetectorResource (org.apache.tika.server.resource.DetectorResource)4 MetadataResource (org.apache.tika.server.resource.MetadataResource)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Feature (org.apache.cxf.feature.Feature)3 ReactiveIOCustomizer (org.apache.cxf.jaxrs.rx2.server.ReactiveIOCustomizer)3 Message (org.apache.cxf.message.Message)3