Search in sources :

Example 36 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class EncoderDecoder method getDataBinding.

/**
 * Get the databinding used for the header objects
 * @return databinding
 */
protected DataBinding getDataBinding() throws JAXBException {
    DataBinding result = databinding;
    if (result == null) {
        synchronized (this) {
            result = databinding;
            if (result == null) {
                result = new JAXBDataBinding(getContext());
                databinding = result;
            }
        }
    }
    return result;
}
Also used : DataBinding(org.apache.cxf.databinding.DataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 37 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class DispatchImpl method getPayloadElementName.

private QName getPayloadElementName(Object object) {
    JAXBDataBinding dataBinding = new JAXBDataBinding();
    dataBinding.setContext(context);
    DataWriter<XMLStreamWriter> dbwriter = dataBinding.createWriter(XMLStreamWriter.class);
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter resultWriter = StaxUtils.createXMLStreamWriter(stringWriter);
    DepthXMLStreamReader reader = null;
    try {
        dbwriter.write(object, resultWriter);
        resultWriter.flush();
        if (!StringUtils.isEmpty(stringWriter.toString())) {
            ByteArrayInputStream binput = new ByteArrayInputStream(stringWriter.getBuffer().toString().getBytes());
            XMLStreamReader xmlreader = StaxUtils.createXMLStreamReader(binput);
            reader = new DepthXMLStreamReader(xmlreader);
            StaxUtils.skipToStartOfElement(reader);
            return reader.getName();
        }
    } catch (XMLStreamException e) {
    // ignore
    } finally {
        try {
            StaxUtils.close(reader);
        } catch (XMLStreamException e) {
        // ignore
        }
        StaxUtils.close(resultWriter);
    }
    return null;
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) ByteArrayInputStream(java.io.ByteArrayInputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader)

Example 38 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class ServiceImpl method createDispatch.

public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
    // using this instead of JaxWsClientFactoryBean so that handlers are configured
    JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
    // Initialize Features.
    configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
    final AbstractServiceFactoryBean sf;
    try {
        DataBinding db;
        if (context != null) {
            db = new JAXBDataBinding(context);
        } else {
            db = new SourceDataBinding(type);
        }
        sf = createDispatchService(db);
    } catch (ServiceConstructionException e) {
        throw new WebServiceException(e);
    }
    JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
    // if the client factory has properties specified, then set those into the endpoint
    if (clientFac.getProperties() != null) {
        endpoint.putAll(clientFac.getProperties());
    }
    // add all the client factory features onto the endpoint feature list
    endpoint.getFeatures().addAll(clientFac.getFeatures());
    // if the client factory has a bus specified (other than the thread default),
    // then use that for the client.  Otherwise use the bus from this service.
    Bus clientBus = getBus();
    if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
        clientBus = clientFac.getBus();
    }
    @SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
    // CXF-3956
    hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
    endpoint.getJaxwsBinding().setHandlerChain(hc);
    // create the client object, then initialize the endpoint features against it
    Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
    for (Feature af : endpoint.getFeatures()) {
        af.initialize(client, clientBus);
    }
    // CXF-2822
    initIntercepors(client, clientFac);
    if (executor != null) {
        client.getEndpoint().setExecutor(executor);
    }
    // then try to get it from the wsdl
    if (!StringUtils.isEmpty(clientFac.getAddress())) {
        client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
    } else {
        // Set the the EPR's address in EndpointInfo
        PortInfoImpl portInfo = portInfos.get(portName);
        if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
            client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
        }
    }
    Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
    configureObject(disp);
    return disp;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ClientImpl(org.apache.cxf.endpoint.ClientImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature) WebServiceFeature(javax.xml.ws.WebServiceFeature) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) DataBinding(org.apache.cxf.databinding.DataBinding) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Example 39 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class SimpleDocLitWrappedImpl method echoWithHeader.

public String echoWithHeader(String what) {
    List<Header> headers = new ArrayList<>();
    Header dummyHeader;
    try {
        dummyHeader = new Header(new QName("uri:org.apache.cxf", "dummy"), "decapitated", new JAXBDataBinding(String.class));
    } catch (JAXBException e) {
        throw new RuntimeException(e);
    }
    headers.add(dummyHeader);
    context.getMessageContext().put(Header.HEADER_LIST, headers);
    return what;
}
Also used : Header(org.apache.cxf.headers.Header) QName(javax.xml.namespace.QName) JAXBException(javax.xml.bind.JAXBException) ArrayList(java.util.ArrayList) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding)

Example 40 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project cxf by apache.

the class SerializationTest method testDeserialization.

@Test
public void testDeserialization() throws Exception {
    setupClientAndRhino("simple-dlwu-proxy-factory");
    testUtilities.readResourceIntoRhino("/deserializationTests.js");
    DataBinding dataBinding = new JAXBDataBinding(TestBean1.class, TestBean2.class);
    assertNotNull(dataBinding);
    TestBean1 bean = new TestBean1();
    bean.stringItem = "bean1>stringItem";
    bean.doubleItem = -1.0;
    String serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeTestBean3_1", serialized);
    bean = new TestBean1();
    bean.stringItem = null;
    bean.intItem = 21;
    bean.longItem = 200000001;
    bean.optionalIntItem = 456123;
    bean.optionalIntArrayItem = new int[4];
    bean.optionalIntArrayItem[0] = 3;
    bean.optionalIntArrayItem[1] = 1;
    bean.optionalIntArrayItem[2] = 4;
    bean.optionalIntArrayItem[3] = 1;
    bean.doubleItem = -1.0;
    serialized = serializeObject(dataBinding, bean);
    testUtilities.rhinoCallInContext("deserializeTestBean3_2", serialized);
}
Also used : TestBean1(org.apache.cxf.javascript.fortest.TestBean1) DataBinding(org.apache.cxf.databinding.DataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) AbstractCXFSpringTest(org.apache.cxf.test.AbstractCXFSpringTest) Test(org.junit.Test)

Aggregations

JAXBDataBinding (org.apache.cxf.jaxb.JAXBDataBinding)51 QName (javax.xml.namespace.QName)24 Test (org.junit.Test)18 JAXBException (javax.xml.bind.JAXBException)15 Header (org.apache.cxf.headers.Header)15 XMLStreamReader (javax.xml.stream.XMLStreamReader)12 ArrayList (java.util.ArrayList)10 DataBinding (org.apache.cxf.databinding.DataBinding)9 ByteArrayInputStream (java.io.ByteArrayInputStream)7 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)7 DepthXMLStreamReader (org.apache.cxf.staxutils.DepthXMLStreamReader)7 Service (org.apache.cxf.service.Service)6 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)6 JAXBContext (javax.xml.bind.JAXBContext)5 Bus (org.apache.cxf.Bus)5 URL (java.net.URL)4 OutofBandHeader (org.apache.cxf.outofband.header.OutofBandHeader)4 HashMap (java.util.HashMap)3 List (java.util.List)3 MessageContext (javax.xml.ws.handler.MessageContext)3