Search in sources :

Example 1 with JaxWsClientEndpointImpl

use of org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl in project cxf by apache.

the class DispatchImpl method calculateOpName.

@SuppressWarnings("unchecked")
private QName calculateOpName(Holder<T> holder, QName opName, boolean hasOpName) throws XMLStreamException {
    boolean findDispatchOp = Boolean.TRUE.equals(getRequestContext().get("find.dispatch.operation"));
    // if the addressing feature is enabled, set findDispatchOp to true
    if (!findDispatchOp) {
        // the feature list to be searched is the endpoint and the bus's lists
        List<Feature> endpointFeatures = ((JaxWsClientEndpointImpl) client.getEndpoint()).getFeatures();
        List<Feature> allFeatures;
        if (client.getBus().getFeatures() != null) {
            allFeatures = new ArrayList<>(endpointFeatures.size() + client.getBus().getFeatures().size());
            allFeatures.addAll(endpointFeatures);
            allFeatures.addAll(client.getBus().getFeatures());
        } else {
            allFeatures = endpointFeatures;
        }
        for (Feature feature : allFeatures) {
            if (feature instanceof WSAddressingFeature) {
                findDispatchOp = true;
            }
        }
    }
    Source createdSource = null;
    Map<String, QName> payloadOPMap = createPayloadEleOpNameMap(client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
    if (findDispatchOp && !payloadOPMap.isEmpty()) {
        QName payloadElementName = null;
        if (holder.value instanceof javax.xml.transform.Source) {
            XMLStreamReader reader = null;
            try {
                reader = StaxUtils.createXMLStreamReader((javax.xml.transform.Source) holder.value);
                Document document = StaxUtils.read(reader);
                createdSource = new StaxSource(StaxUtils.createXMLStreamReader(document));
                payloadElementName = getPayloadElementName(document.getDocumentElement());
            } catch (Exception e) {
            // ignore, we are trying to get the operation name
            } finally {
                StaxUtils.close(reader);
            }
        }
        if (holder.value instanceof SOAPMessage) {
            payloadElementName = getPayloadElementName((SOAPMessage) holder.value);
        }
        if (this.context != null) {
            payloadElementName = getPayloadElementName(holder.value);
        }
        if (payloadElementName != null) {
            if (hasOpName) {
                // Verify the payload element against the given operation name.
                // This allows graceful handling of non-standard WSDL definitions
                // where different operations have the same payload element.
                QName expectedElementName = payloadOPMap.get(opName.toString());
                if (expectedElementName == null || !expectedElementName.toString().equals(payloadElementName.toString())) {
                    // Verification of the provided operation name failed.
                    // Resolve the operation name from the payload element.
                    hasOpName = false;
                    payloadOPMap = createPayloadEleOpNameMap(client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
                }
            }
            QName dispatchedOpName = null;
            if (!hasOpName) {
                dispatchedOpName = payloadOPMap.get(payloadElementName.toString());
            }
            if (null != dispatchedOpName) {
                BindingOperationInfo dbop = client.getEndpoint().getBinding().getBindingInfo().getOperation(dispatchedOpName);
                if (dbop != null) {
                    opName = dispatchedOpName;
                }
            }
        }
    }
    if (createdSource != null) {
        holder.value = (T) createdSource;
    }
    return opName;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) JaxWsClientEndpointImpl(org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) Feature(org.apache.cxf.feature.Feature) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) SOAPMessage(javax.xml.soap.SOAPMessage) StaxSource(org.apache.cxf.staxutils.StaxSource) Source(javax.xml.transform.Source) DataSource(javax.activation.DataSource) HTTPException(javax.xml.ws.http.HTTPException) SOAPException(javax.xml.soap.SOAPException) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) StaxSource(org.apache.cxf.staxutils.StaxSource)

Example 2 with JaxWsClientEndpointImpl

use of org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl in project cxf by apache.

the class ServiceImpl method getJaxwsEndpoint.

private JaxWsClientEndpointImpl getJaxwsEndpoint(QName portName, AbstractServiceFactoryBean sf, WebServiceFeature... features) {
    Service service = sf.getService();
    EndpointInfo ei = null;
    if (portName == null) {
        ei = service.getServiceInfos().get(0).getEndpoints().iterator().next();
    } else {
        ei = service.getEndpointInfo(portName);
        if (ei == null) {
            PortInfoImpl portInfo = getPortInfo(portName);
            if (null != portInfo) {
                try {
                    ei = createEndpointInfo(sf, portName, portInfo);
                } catch (BusException e) {
                    throw new WebServiceException(e);
                }
            }
        }
    }
    if (ei == null) {
        Message msg = new Message("INVALID_PORT", BUNDLE, portName);
        throw new WebServiceException(msg.toString());
    }
    // When the dispatch is created from EPR, the EPR's address will be set in portInfo
    PortInfoImpl portInfo = getPortInfo(portName);
    if (portInfo != null && portInfo.getAddress() != null && !portInfo.getAddress().equals(ei.getAddress())) {
        ei.setAddress(portInfo.getAddress());
    }
    try {
        return new JaxWsClientEndpointImpl(bus, service, ei, this, getAllFeatures(features));
    } catch (EndpointException e) {
        throw new WebServiceException(e);
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message) JaxWsClientEndpointImpl(org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl) EndpointException(org.apache.cxf.endpoint.EndpointException) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) BusException(org.apache.cxf.BusException)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)2 JaxWsClientEndpointImpl (org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl)2 IOException (java.io.IOException)1 DataSource (javax.activation.DataSource)1 WebService (javax.jws.WebService)1 QName (javax.xml.namespace.QName)1 SOAPException (javax.xml.soap.SOAPException)1 SOAPMessage (javax.xml.soap.SOAPMessage)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamReader (javax.xml.stream.XMLStreamReader)1 Source (javax.xml.transform.Source)1 HTTPException (javax.xml.ws.http.HTTPException)1 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)1 BusException (org.apache.cxf.BusException)1 Message (org.apache.cxf.common.i18n.Message)1 EndpointException (org.apache.cxf.endpoint.EndpointException)1 Feature (org.apache.cxf.feature.Feature)1 PortInfoImpl (org.apache.cxf.jaxws.handler.PortInfoImpl)1 Service (org.apache.cxf.service.Service)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1