Search in sources :

Example 1 with JAXBElementProvider

use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project ddf by codice.

the class WfsSource method initProviders.

private List<? extends Object> initProviders() {
    // We need to tell the JAXBElementProvider to marshal the GetFeatureType
    // class as an element because it is missing the @XmlRootElement Annotation
    JAXBElementProvider<GetFeatureType> provider = new JAXBElementProvider<GetFeatureType>();
    Map<String, String> jaxbClassMap = new HashMap<String, String>();
    // Ensure a namespace is used when the GetFeature request is generated
    String expandedName = new QName(Wfs10Constants.WFS_NAMESPACE, Wfs10Constants.GET_FEATURE).toString();
    jaxbClassMap.put(GetFeatureType.class.getName(), expandedName);
    provider.setJaxbElementClassMap(jaxbClassMap);
    provider.setMarshallAsJaxbElement(true);
    featureCollectionReader = new FeatureCollectionMessageBodyReaderWfs10();
    return Arrays.asList(provider, new WfsResponseExceptionMapper(), new XmlSchemaMessageBodyReaderWfs10(), featureCollectionReader);
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) XmlSchemaMessageBodyReaderWfs10(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.source.reader.XmlSchemaMessageBodyReaderWfs10) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) FeatureCollectionMessageBodyReaderWfs10(org.codice.ddf.spatial.ogc.wfs.v1_0_0.catalog.source.reader.FeatureCollectionMessageBodyReaderWfs10) GetFeatureType(ogc.schema.opengis.wfs.v_1_0_0.GetFeatureType)

Example 2 with JAXBElementProvider

use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project cxf by apache.

the class BookServer method run.

protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    bus.setProperty(ExceptionMapper.class.getName(), new BusMapperExceptionMapper());
    setBus(bus);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(bus);
    sf.setResourceClasses(BookStore.class, SimpleBookStore.class, BookStorePerRequest.class);
    List<Object> providers = new ArrayList<>();
    // default lifecycle is per-request, change it to singleton
    BinaryDataProvider<Object> p = new BinaryDataProvider<Object>();
    p.setProduceMediaTypes(Collections.singletonList("application/bar"));
    p.setEnableBuffering(true);
    p.setReportByteArraySize(true);
    providers.add(p);
    providers.add(new BookStore.PrimitiveIntArrayReaderWriter());
    providers.add(new BookStore.PrimitiveDoubleArrayReaderWriter());
    providers.add(new BookStore.StringArrayBodyReaderWriter());
    providers.add(new BookStore.StringListBodyReaderWriter());
    providers.add(new StreamingResponseProvider<Object>());
    providers.add(new ContentTypeModifyingMBW());
    JAXBElementProvider<?> jaxbProvider = new JAXBElementProvider<Object>();
    Map<String, String> jaxbElementClassMap = new HashMap<>();
    jaxbElementClassMap.put(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement");
    jaxbProvider.setJaxbElementClassMap(jaxbElementClassMap);
    providers.add(jaxbProvider);
    providers.add(new FormatResponseHandler());
    providers.add(new GenericHandlerWriter());
    providers.add(new FaultyRequestHandler());
    providers.add(new SearchContextProvider());
    providers.add(new QueryContextProvider());
    providers.add(new BlockingRequestFilter());
    providers.add(new FaultyResponseFilter());
    providers.add(new BlockedExceptionMapper());
    providers.add(new ParamConverterImpl());
    sf.setProviders(providers);
    List<Interceptor<? extends Message>> inInts = new ArrayList<Interceptor<? extends Message>>();
    inInts.add(new CustomInFaultyInterceptor());
    inInts.add(new LoggingInInterceptor());
    sf.setInInterceptors(inInts);
    List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<? extends Message>>();
    outInts.add(new CustomOutInterceptor());
    outInts.add(new LoggingOutInterceptor());
    sf.setOutInterceptors(outInts);
    List<Interceptor<? extends Message>> outFaultInts = new ArrayList<Interceptor<? extends Message>>();
    outFaultInts.add(new CustomOutFaultInterceptor());
    sf.setOutFaultInterceptors(outFaultInts);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    sf.getProperties(true).put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", true);
    sf.getProperties().put("search.visitor", new SQLPrinterVisitor<SearchBean>("books"));
    sf.getProperties().put("org.apache.cxf.http.header.split", true);
    sf.getProperties().put("default.content.type", "*/*");
    sf.getProperties().putAll(properties);
    server = sf.create();
    BusFactory.setDefaultBus(null);
    BusFactory.setThreadDefaultBus(null);
}
Also used : Message(org.apache.cxf.message.Message) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) ResponseExceptionMapper(org.apache.cxf.jaxrs.client.ResponseExceptionMapper) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) AbstractPhaseInterceptor(org.apache.cxf.phase.AbstractPhaseInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) Bus(org.apache.cxf.Bus) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) SearchBean(org.apache.cxf.jaxrs.ext.search.SearchBean) BinaryDataProvider(org.apache.cxf.jaxrs.provider.BinaryDataProvider) SearchContextProvider(org.apache.cxf.jaxrs.ext.search.SearchContextProvider) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) QueryContextProvider(org.apache.cxf.jaxrs.ext.search.QueryContextProvider)

Example 3 with JAXBElementProvider

use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project tesb-rt-se by Talend.

the class RESTClient method createJAXRSProviders.

/**
 * Creates a custom JAX-RS JAXBElementProvider which can handle
 * generated JAXB clasess with no XmlRootElement annotation
 * @return providers
 */
private List<Object> createJAXRSProviders() {
    JAXBElementProvider provider = new JAXBElementProvider();
    provider.setUnmarshallAsJaxbElement(true);
    provider.setMarshallAsJaxbElement(true);
    List<Object> providers = new ArrayList<Object>();
    providers.add(provider);
    return providers;
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) ArrayList(java.util.ArrayList)

Example 4 with JAXBElementProvider

use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project tesb-rt-se by Talend.

the class CustomerServiceClient method useCustomerServiceRest.

public void useCustomerServiceRest(String[] args) throws Exception {
    JAXBElementProvider provider = new JAXBElementProvider();
    provider.setUnmarshallAsJaxbElement(true);
    provider.setMarshallAsJaxbElement(true);
    List<Object> providers = new ArrayList<Object>();
    providers.add(provider);
    providers.add(new ResponseExceptionMapper<NoSuchCustomerException>() {

        @Override
        public NoSuchCustomerException fromResponse(Response r) {
            return new NoSuchCustomerException();
        }
    });
    CustomerService customerService = JAXRSClientFactory.createFromModel("http://localhost:" + port + "/services/jaxrs", CustomerService.class, "classpath:/data/model/CustomerService-jaxrs.xml", providers, null);
    System.out.println("Using RESTful CustomerService");
    Customer customer = createCustomer("Smith");
    customerService.updateCustomer(customer);
    customer = customerService.getCustomerByName("Smith");
    printCustomerDetails(customer);
    customer = customerService.getCustomerByName("Barry");
    if (customer != null) {
        throw new RuntimeException("Barry should not be found");
    }
    System.out.println("Status : " + WebClient.client(customerService).getResponse().getStatus());
    try {
        customerService.getCustomerByName("John");
        throw new RuntimeException("Exception is expected");
    } catch (NoSuchCustomerException ex) {
        System.out.println("NoSuchCustomerException : John");
    }
}
Also used : Response(javax.ws.rs.core.Response) JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) CustomerService(org.example.customers.CustomerService) Customer(org.example.customers.Customer) ArrayList(java.util.ArrayList) NoSuchCustomerException(org.example.customers.NoSuchCustomerException)

Example 5 with JAXBElementProvider

use of org.apache.cxf.jaxrs.provider.JAXBElementProvider in project jbpm by kiegroup.

the class RestWorkItemHandlerTest method initialize.

@SuppressWarnings({ "rawtypes" })
@BeforeClass
public static void initialize() throws Exception {
    SimpleRESTApplication application = new SimpleRESTApplication();
    RuntimeDelegate delegate = RuntimeDelegate.getInstance();
    JAXRSServerFactoryBean bean = delegate.createEndpoint(application, JAXRSServerFactoryBean.class);
    bean.setProvider(new JAXBElementProvider());
    bean.setAddress("http://localhost:9998" + bean.getAddress());
    server = bean.create();
    server.start();
}
Also used : JAXBElementProvider(org.apache.cxf.jaxrs.provider.JAXBElementProvider) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) RuntimeDelegate(javax.ws.rs.ext.RuntimeDelegate) BeforeClass(org.junit.BeforeClass)

Aggregations

JAXBElementProvider (org.apache.cxf.jaxrs.provider.JAXBElementProvider)30 Test (org.junit.Test)9 HashMap (java.util.HashMap)8 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)6 WebClient (org.apache.cxf.jaxrs.client.WebClient)6 ArrayList (java.util.ArrayList)5 Unmarshaller (javax.xml.bind.Unmarshaller)5 XMLStreamException (javax.xml.stream.XMLStreamException)5 InputStream (java.io.InputStream)4 StringReader (java.io.StringReader)4 JAXBException (javax.xml.bind.JAXBException)4 QName (javax.xml.namespace.QName)4 XMLInputFactory (javax.xml.stream.XMLInputFactory)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 IOException (java.io.IOException)3 Response (javax.ws.rs.core.Response)3 RuntimeDelegate (javax.ws.rs.ext.RuntimeDelegate)3 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)3 Type (java.lang.reflect.Type)2 TypeVariable (java.lang.reflect.TypeVariable)2