Search in sources :

Example 31 with JacksonJaxbJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project cxf by apache.

the class JAXRS20ClientServerBookTest method testPostGetCollectionGenericEntityAndTypeJson.

@Test
public void testPostGetCollectionGenericEntityAndTypeJson() throws Exception {
    String endpointAddress = "http://localhost:" + PORT + "/bookstore/collections";
    WebClient wc = WebClient.create(endpointAddress, Collections.singletonList(new JacksonJaxbJsonProvider()));
    doTestPostGetCollectionGenericEntityAndType(wc, MediaType.APPLICATION_JSON_TYPE);
}
Also used : JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 32 with JacksonJaxbJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider 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 33 with JacksonJaxbJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project cxf by apache.

the class JAXRSMultipartLocalTransportTest method testBookAsMultipleInputStreams.

@Test
public void testBookAsMultipleInputStreams() throws Exception {
    final MultipartStore store = JAXRSClientFactory.create(ENDPOINT_ADDRESS, MultipartStore.class, Collections.singletonList(new JacksonJaxbJsonProvider()));
    final byte[] books1 = generateBooks(40000).getBytes(StandardCharsets.UTF_8);
    final byte[] books2 = generateBooks(2000).getBytes(StandardCharsets.UTF_8);
    final List<Book> books = store.addBookJsonTypeFromStreams(new ByteArrayInputStream(books1), new ByteArrayInputStream(books2));
    assertThat(books.size(), equalTo(42000));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) Test(org.junit.Test)

Example 34 with JacksonJaxbJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project incubator-pulsar by apache.

the class WebServer method addRestResources.

public void addRestResources(String basePath, String javaPackages, String attribute, Object attributeValue) {
    JacksonJaxbJsonProvider provider = new JacksonJaxbJsonProvider();
    provider.setMapper(ObjectMapperFactory.create());
    ResourceConfig config = new ResourceConfig();
    config.packages("jersey.config.server.provider.packages", javaPackages);
    config.register(provider);
    ServletHolder servletHolder = new ServletHolder(new ServletContainer(config));
    servletHolder.setAsyncSupported(true);
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(basePath);
    context.addServlet(servletHolder, "/*");
    context.setAttribute(attribute, attributeValue);
    handlers.add(context);
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 35 with JacksonJaxbJsonProvider

use of com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider in project fabric8 by fabric8io.

the class WebClients method createProviders.

public static List<Object> createProviders() {
    List<Object> providers = new ArrayList<Object>();
    Annotations[] annotationsToUse = JacksonJaxbJsonProvider.DEFAULT_ANNOTATIONS;
    ObjectMapper objectMapper = createObjectMapper();
    providers.add(new JacksonJaxbJsonProvider(objectMapper, annotationsToUse));
    providers.add(new ExceptionResponseMapper());
    return providers;
}
Also used : Annotations(com.fasterxml.jackson.jaxrs.cfg.Annotations) ArrayList(java.util.ArrayList) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) JsonHelper.createObjectMapper(io.fabric8.utils.jaxrs.JsonHelper.createObjectMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)35 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 URI (java.net.URI)3 Response (javax.ws.rs.core.Response)3 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)2 Provides (com.google.inject.Provides)2 Singleton (com.google.inject.Singleton)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Annotation (java.lang.annotation.Annotation)2 ElementType (java.lang.annotation.ElementType)2 Retention (java.lang.annotation.Retention)2 RetentionPolicy (java.lang.annotation.RetentionPolicy)2 Target (java.lang.annotation.Target)2 Method (java.lang.reflect.Method)2 Type (java.lang.reflect.Type)2