Search in sources :

Example 1 with SoapVersion

use of org.apache.cxf.binding.soap.SoapVersion in project camel by apache.

the class SoapMessageHeaderFilter method filter.

public void filter(Direction direction, List<Header> headers) {
    // Treat both in and out direction the same
    if (headers == null) {
        return;
    }
    Iterator<Header> iterator = headers.iterator();
    while (iterator.hasNext()) {
        Header header = iterator.next();
        LOG.trace("Processing header: {}", header);
        if (!(header instanceof SoapHeader)) {
            LOG.trace("Skipped header: {} since it is not a SoapHeader", header);
            continue;
        }
        SoapHeader soapHeader = SoapHeader.class.cast(header);
        for (Iterator<SoapVersion> itv = SoapVersionFactory.getInstance().getVersions(); itv.hasNext(); ) {
            SoapVersion version = itv.next();
            if (soapHeader.getActor() != null && soapHeader.getActor().equals(version.getNextRole())) {
                // dropping headers if actor/role equals to {ns}/role|actor/next
                // cxf SoapHeader needs to have soap:header@relay attribute, 
                // then we can check for it here as well
                LOG.trace("Filtered header: {}", header);
                iterator.remove();
                break;
            }
        }
    }
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Header(org.apache.cxf.headers.Header) SoapHeader(org.apache.cxf.binding.soap.SoapHeader)

Example 2 with SoapVersion

use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.

the class MustUnderstandInterceptor method handleMessage.

public void handleMessage(SoapMessage soapMessage) {
    Set<QName> paramHeaders = HeaderUtil.getHeaderQNameInOperationParam(soapMessage);
    if (soapMessage.getHeaders().isEmpty() && paramHeaders.isEmpty()) {
        return;
    }
    SoapVersion soapVersion = soapMessage.getVersion();
    Set<Header> mustUnderstandHeaders = new HashSet<>();
    Set<URI> serviceRoles = new HashSet<>();
    Set<QName> notUnderstandHeaders = new HashSet<>();
    Set<Header> ultimateReceiverHeaders = new HashSet<>();
    Set<QName> mustUnderstandQNames = new HashSet<>();
    initServiceSideInfo(mustUnderstandQNames, soapMessage, serviceRoles, paramHeaders);
    buildMustUnderstandHeaders(mustUnderstandHeaders, soapMessage, serviceRoles, ultimateReceiverHeaders);
    checkUnderstand(mustUnderstandHeaders, mustUnderstandQNames, notUnderstandHeaders);
    if (!notUnderstandHeaders.isEmpty()) {
        if (!isRequestor(soapMessage)) {
            soapMessage.put(MustUnderstandInterceptor.UNKNOWNS, notUnderstandHeaders);
            soapMessage.getInterceptorChain().add(ending);
        } else {
            throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notUnderstandHeaders), soapVersion.getMustUnderstand());
        }
    }
    if (!ultimateReceiverHeaders.isEmpty() && !isRequestor(soapMessage)) {
        checkUltimateReceiverHeaders(ultimateReceiverHeaders, mustUnderstandQNames, soapMessage);
    }
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) SoapFault(org.apache.cxf.binding.soap.SoapFault) SoapHeader(org.apache.cxf.binding.soap.SoapHeader) Header(org.apache.cxf.headers.Header) Message(org.apache.cxf.common.i18n.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) QName(javax.xml.namespace.QName) URI(java.net.URI) HashSet(java.util.HashSet)

Example 3 with SoapVersion

use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.

the class SoapHeaderInterceptor method handleMessage.

public void handleMessage(Message m) throws Fault {
    SoapMessage message = (SoapMessage) m;
    SoapVersion soapVersion = message.getVersion();
    Exchange exchange = message.getExchange();
    MessageContentsList parameters = MessageContentsList.getContentsList(message);
    if (null == parameters) {
        parameters = new MessageContentsList();
    }
    BindingOperationInfo bop = exchange.getBindingOperationInfo();
    if (null == bop) {
        return;
    }
    if (bop.isUnwrapped()) {
        bop = bop.getWrappedOperation();
    }
    boolean client = isRequestor(message);
    BindingMessageInfo bmi = client ? bop.getOutput() : bop.getInput();
    if (bmi == null) {
        // one way operation.
        return;
    }
    List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
    if (headers == null || headers.isEmpty()) {
        return;
    }
    boolean supportsNode = this.supportsDataReader(message, Node.class);
    Service service = ServiceModelUtil.getService(message.getExchange());
    for (SoapHeaderInfo header : headers) {
        MessagePartInfo mpi = header.getPart();
        try {
            if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.IN, message)) {
                Schema schema = EndpointReferenceUtils.getSchema(service.getServiceInfos().get(0), message.getExchange().getBus());
                validateHeader(message, mpi, schema);
            }
        } catch (Fault f) {
            if (!isRequestor(message)) {
                f.setFaultCode(Fault.FAULT_CODE_CLIENT);
            }
            throw f;
        }
        if (mpi.getTypeClass() != null) {
            Header param = findHeader(message, mpi);
            Object object = null;
            if (param != null) {
                message.getHeaders().remove(param);
                if (param.getDataBinding() == null) {
                    Node source = (Node) param.getObject();
                    if (source instanceof Element) {
                        // need to remove these attributes as they
                        // would cause validation failures
                        Element el = (Element) source;
                        el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameMustUnderstand());
                        el.removeAttributeNS(soapVersion.getNamespace(), soapVersion.getAttrNameRole());
                    }
                    if (supportsNode) {
                        object = getNodeDataReader(message).read(mpi, source);
                    } else {
                        W3CDOMStreamReader reader = new W3CDOMStreamReader((Element) source);
                        try {
                            // advance into the first tag
                            reader.nextTag();
                        } catch (XMLStreamException e) {
                        // ignore
                        }
                        object = getDataReader(message, XMLStreamReader.class).read(mpi, reader);
                    }
                } else {
                    object = param.getObject();
                }
            }
            parameters.put(mpi, object);
        }
    }
    if (!parameters.isEmpty()) {
        message.setContent(List.class, parameters);
    }
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageContentsList(org.apache.cxf.message.MessageContentsList) SoapHeaderInfo(org.apache.cxf.binding.soap.model.SoapHeaderInfo) Schema(javax.xml.validation.Schema) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) Service(org.apache.cxf.service.Service) Fault(org.apache.cxf.interceptor.Fault) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SoapVersion(org.apache.cxf.binding.soap.SoapVersion) Exchange(org.apache.cxf.message.Exchange) BindingMessageInfo(org.apache.cxf.service.model.BindingMessageInfo) Header(org.apache.cxf.headers.Header) XMLStreamException(javax.xml.stream.XMLStreamException) W3CDOMStreamReader(org.apache.cxf.staxutils.W3CDOMStreamReader)

Example 4 with SoapVersion

use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.

the class SoapPreProtocolOutInterceptor method ensureVersion.

/**
 * Ensure the SOAP version is set for this message.
 *
 * @param message the current message
 */
private void ensureVersion(SoapMessage message) {
    SoapVersion soapVersion = message.getVersion();
    if (soapVersion == null && message.getExchange().getInMessage() instanceof SoapMessage) {
        soapVersion = ((SoapMessage) message.getExchange().getInMessage()).getVersion();
        message.setVersion(soapVersion);
    }
    if (soapVersion == null) {
        soapVersion = Soap11.getInstance();
        message.setVersion(soapVersion);
    }
    message.put(Message.CONTENT_TYPE, soapVersion.getContentType());
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 5 with SoapVersion

use of org.apache.cxf.binding.soap.SoapVersion in project cxf by apache.

the class EndpointSelectionInterceptor method selectEndpoint.

protected Endpoint selectEndpoint(Message message, Set<Endpoint> eps) {
    SoapVersion sv = ((SoapMessage) message).getVersion();
    for (Endpoint e : eps) {
        EndpointInfo ei = e.getEndpointInfo();
        BindingInfo binding = ei.getBinding();
        if (binding instanceof SoapBindingInfo && ((SoapBindingInfo) binding).getSoapVersion().equals(sv)) {
            return e;
        }
    }
    return null;
}
Also used : SoapVersion(org.apache.cxf.binding.soap.SoapVersion) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) BindingInfo(org.apache.cxf.service.model.BindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Aggregations

SoapVersion (org.apache.cxf.binding.soap.SoapVersion)26 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)15 QName (javax.xml.namespace.QName)12 Element (org.w3c.dom.Element)11 SoapFault (org.apache.cxf.binding.soap.SoapFault)10 Header (org.apache.cxf.headers.Header)7 Fault (org.apache.cxf.interceptor.Fault)7 SOAPMessage (javax.xml.soap.SOAPMessage)6 XMLStreamException (javax.xml.stream.XMLStreamException)6 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 XMLStreamReader (javax.xml.stream.XMLStreamReader)5 SoapHeader (org.apache.cxf.binding.soap.SoapHeader)5 Message (org.apache.cxf.common.i18n.Message)5 Exchange (org.apache.cxf.message.Exchange)5 Node (org.w3c.dom.Node)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)4 SOAPElement (javax.xml.soap.SOAPElement)4 SOAPException (javax.xml.soap.SOAPException)4