Search in sources :

Example 46 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 47 with JAXBDataBinding

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

the class JaxWsServerFactoryBeanTest method testJaxbExtraClass.

@Test
public void testJaxbExtraClass() {
    JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
    sf.setBus(getBus());
    sf.setAddress("http://localhost:9000/test");
    sf.setServiceClass(Hello.class);
    sf.setStart(false);
    Map<String, Object> props = sf.getProperties();
    if (props == null) {
        props = new HashMap<>();
    }
    props.put("jaxb.additionalContextClasses", new Class[] { DescriptionType.class, DisplayNameType.class });
    sf.setProperties(props);
    Server server = sf.create();
    assertNotNull(server);
    Class<?>[] extraClass = ((JAXBDataBinding) sf.getServiceFactory().getDataBinding()).getExtraClass();
    assertEquals(extraClass.length, 2);
    assertEquals(extraClass[0], DescriptionType.class);
    assertEquals(extraClass[1], DisplayNameType.class);
}
Also used : Server(org.apache.cxf.endpoint.Server) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) Test(org.junit.Test)

Example 48 with JAXBDataBinding

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

the class WSDiscoveryClient method addAddressing.

private void addAddressing(BindingProvider p, boolean addSeq, String action) {
    AddressingProperties addrProperties = new AddressingProperties();
    if (action != null) {
        AttributedURIType act = new AttributedURIType();
        act.setValue(action);
        addrProperties.setAction(act);
    }
    if (adHoc) {
        EndpointReferenceType to = new EndpointReferenceType();
        addrProperties.exposeAs(version.getAddressingNamespace());
        AttributedURIType epr = new AttributedURIType();
        epr.setValue(version.getToAddress());
        to.setAddress(epr);
        addrProperties.setTo(to);
        if (addSeq) {
            AppSequenceType s = new AppSequenceType();
            s.setInstanceId(instanceId);
            s.setMessageNumber(msgId.getAndIncrement());
            JAXBElement<AppSequenceType> seq = new ObjectFactory().createAppSequence(s);
            Header h = new Header(seq.getName(), seq, new JAXBDataBinding(getJAXBContext()));
            List<Header> headers = new ArrayList<>();
            headers.add(h);
            p.getRequestContext().put(Header.HEADER_LIST, headers);
        }
    } else {
        addrProperties.exposeAs(version.getAddressingNamespace());
    }
    p.getRequestContext().put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES, addrProperties);
}
Also used : EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) ObjectFactory(org.apache.cxf.ws.discovery.wsdl.ObjectFactory) Header(org.apache.cxf.headers.Header) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) ArrayList(java.util.ArrayList) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) AppSequenceType(org.apache.cxf.ws.discovery.wsdl.AppSequenceType)

Example 49 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project tesb-rt-se by Talend.

the class FlowIdSoapCodec method writeFlowId.

/**
 * Write flow id to message.
 *
 * @param message the message
 * @param flowId the flow id
 */
public static void writeFlowId(Message message, String flowId) {
    if (!(message instanceof SoapMessage)) {
        return;
    }
    SoapMessage soapMessage = (SoapMessage) message;
    Header hdFlowId = soapMessage.getHeader(FLOW_ID_QNAME);
    if (hdFlowId != null) {
        LOG.warning("FlowId already existing in soap header, need not to write FlowId header.");
        return;
    }
    try {
        soapMessage.getHeaders().add(new Header(FLOW_ID_QNAME, flowId, new JAXBDataBinding(String.class)));
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Stored flowId '" + flowId + "' in soap header: " + FLOW_ID_QNAME);
        }
    } catch (JAXBException e) {
        LOG.log(Level.SEVERE, "Couldn't create flowId header.", e);
    }
}
Also used : Header(org.apache.cxf.headers.Header) JAXBException(javax.xml.bind.JAXBException) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 50 with JAXBDataBinding

use of org.apache.cxf.jaxb.JAXBDataBinding in project tesb-rt-se by Talend.

the class CorrelationIdSoapCodec method writeCorrelationId.

/**
 * Write correlation id to message.
 *
 * @param message the message
 * @param correlationId the correlation id
 */
public static void writeCorrelationId(Message message, String correlationId) {
    if (!(message instanceof SoapMessage)) {
        return;
    }
    SoapMessage soapMessage = (SoapMessage) message;
    Header hdCorrelationId = soapMessage.getHeader(CORRELATION_ID_QNAME);
    if (hdCorrelationId != null) {
        LOG.warning("CorrelationId already existing in soap header, need not to write CorrelationId header.");
        return;
    }
    if ((soapMessage.getContent(javax.xml.stream.XMLStreamWriter.class) != null) && (soapMessage.getContent(javax.xml.stream.XMLStreamWriter.class) instanceof SAAJStreamWriter) && (((SAAJStreamWriter) soapMessage.getContent(javax.xml.stream.XMLStreamWriter.class)).getDocument().getElementsByTagNameNS("http://www.talend.com/esb/sam/correlationId/v1", "correlationId").getLength() > 0)) {
        LOG.warning("CorrelationId already existing in soap header, need not to write CorrelationId header.");
        return;
    }
    try {
        soapMessage.getHeaders().add(new Header(CORRELATION_ID_QNAME, correlationId, new JAXBDataBinding(String.class)));
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("Stored correlationId '" + correlationId + "' in soap header: " + CORRELATION_ID_QNAME);
        }
    } catch (JAXBException e) {
        LOG.log(Level.SEVERE, "Couldn't create correlationId header.", e);
    }
}
Also used : Header(org.apache.cxf.headers.Header) JAXBException(javax.xml.bind.JAXBException) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SAAJStreamWriter(org.apache.cxf.binding.soap.saaj.SAAJStreamWriter)

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