Java Code Examples for org.apache.cxf.binding.soap.SoapMessage#getVersion()

The following examples show how to use org.apache.cxf.binding.soap.SoapMessage#getVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderVerifier.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void addPartialResponseHeader(SoapMessage message) {
    try {
        // add piggybacked wsa:From header to partial response
        List<Header> header = message.getHeaders();
        Document doc = DOMUtils.getEmptyDocument();
        SoapVersion ver = message.getVersion();
        Element hdr = doc.createElementNS(ver.getHeader().getNamespaceURI(),
            ver.getHeader().getLocalPart());
        hdr.setPrefix(ver.getHeader().getPrefix());

        marshallFrom("urn:piggyback_responder", hdr, getMarshaller());
        Element elem = DOMUtils.getFirstElement(hdr);
        while (elem != null) {
            Header holder = new Header(
                    new QName(elem.getNamespaceURI(), elem.getLocalName()),
                    elem, null);
            header.add(holder);

            elem = DOMUtils.getNextElement(elem);
        }

    } catch (Exception e) {
        verificationCache.put("SOAP header addition failed: " + e);
        e.printStackTrace();
    }
}
 
Example 2
Source File: MustUnderstandInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(SoapMessage soapMessage) throws Fault {
    SoapVersion soapVersion = soapMessage.getVersion();
    Set<QName> notFound = new HashSet<>();
    List<Header> heads = soapMessage.getHeaders();

    for (Header header : heads) {
        if (header instanceof SoapHeader
            && ((SoapHeader)header).isMustUnderstand()
            && header.getDirection() == Header.Direction.DIRECTION_IN
            && !knownHeaders.contains(header.getName())
            && (StringUtils.isEmpty(((SoapHeader)header).getActor())
                || soapVersion.getUltimateReceiverRole()
                    .equals(((SoapHeader)header).getActor()))) {

            notFound.add(header.getName());
        }
    }


    if (!notFound.isEmpty()) {
        soapMessage.remove(UNKNOWNS);
        throw new SoapFault(new Message("MUST_UNDERSTAND", BUNDLE, notFound),
                        soapVersion.getMustUnderstand());
    }
}
 
Example 3
Source File: SoapOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    try {
        XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
        if (xtw != null) {
            // Write body end
            xtw.writeEndElement();
            // Write Envelope end element
            xtw.writeEndElement();
            xtw.writeEndDocument();

            xtw.flush();
        }
    } catch (XMLStreamException e) {
        if (e.getCause() instanceof EOFException) {
            //Nothing we can do about this, some clients will close the connection early if
            //they fully parse everything they need
        } else {
            SoapVersion soapVersion = message.getVersion();
            throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e,
                                soapVersion.getSender());
        }
    }
}
 
Example 4
Source File: SoapPreProtocolOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
}
 
Example 5
Source File: Soap12FaultOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    Fault f = (Fault) message.getContent(Exception.class);
    message.put(org.apache.cxf.message.Message.RESPONSE_CODE, f.getStatusCode());
    if (message.getVersion() == Soap11.getInstance()) {
        message.getInterceptorChain().add(Soap11FaultOutInterceptorInternal.INSTANCE);
    } else {
        message.getInterceptorChain().add(Soap12FaultOutInterceptorInternal.INSTANCE);
    }
}
 
Example 6
Source File: SAAJOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public synchronized MessageFactory getFactory(SoapMessage message) throws SOAPException {
    if (message.getVersion() instanceof Soap11) {
        if (factory11 == null) {
            factory11 = SAAJFactoryResolver.createMessageFactory(message.getVersion());
        }
        return factory11;
    }
    if (message.getVersion() instanceof Soap12) {
        if (factory12 == null) {
            factory12 = SAAJFactoryResolver.createMessageFactory(message.getVersion());
        }
        return factory12;
    }
    return SAAJFactoryResolver.createMessageFactory(null);
}
 
Example 7
Source File: SAAJInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public synchronized MessageFactory getFactory(SoapMessage message) throws SOAPException {
    if (message.getVersion() instanceof Soap11) {
        if (factory11 == null) {
            factory11 = SAAJFactoryResolver.createMessageFactory(message.getVersion());
        }
        return factory11;
    }
    if (message.getVersion() instanceof Soap12) {
        if (factory12 == null) {
            factory12 = SAAJFactoryResolver.createMessageFactory(message.getVersion());
        }
        return factory12;
    }
    return SAAJFactoryResolver.createMessageFactory(null);
}
 
Example 8
Source File: MustUnderstandInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: SoapActionInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static boolean isActionMatch(SoapMessage message, BindingOperationInfo boi, String action) {
    SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
    if (soi == null) {
        return false;
    }
    boolean allowNoMatchingToDefault = MessageUtils.getContextualBoolean(message,
                                                                ALLOW_NON_MATCHING_TO_DEFAULT,
                                                                false);
    return action.equals(soi.getAction())
           || (allowNoMatchingToDefault && StringUtils.isEmpty(soi.getAction())
           || (message.getVersion() instanceof Soap12) && StringUtils.isEmpty(soi.getAction()));
}
 
Example 10
Source File: Soap11FaultOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    Fault f = (Fault) message.getContent(Exception.class);
    message.put(org.apache.cxf.message.Message.RESPONSE_CODE, f.getStatusCode());
    if (message.getVersion() == Soap11.getInstance()) {
        message.getInterceptorChain().add(Soap11FaultOutInterceptorInternal.INSTANCE);
    } else {
        message.getInterceptorChain().add(Soap12FaultOutInterceptorInternal.INSTANCE);
    }
}
 
Example 11
Source File: Soap12FaultInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void handleMessage(SoapMessage message) throws Fault {
    if (message.getVersion() == Soap11.getInstance()) {
        new Soap11FaultInInterceptor().handleMessage(message);
        return;
    }
    XMLStreamReader reader = message.getContent(XMLStreamReader.class);
    message.setContent(Exception.class, unmarshalFault(message, reader));
}
 
Example 12
Source File: ResponseSoapPayloadConverter.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
protected void convertMessage(Message in) {
    try {
        // get SOAP QNames from CxfPayload headers
        final SoapMessage soapMessage = in.getHeader("CamelCxfMessage", SoapMessage.class);
        final SoapVersion soapVersion = soapMessage.getVersion();

        // get CxfPayload body
        final CxfPayload<?> cxfPayload = in.getMandatoryBody(CxfPayload.class);
        final List<?> headers = cxfPayload.getHeaders();
        final List<Source> body = cxfPayload.getBodySources();

        final OutputStream outputStream = newOutputStream(in, cxfPayload);
        final XMLStreamWriter writer = newXmlStreamWriter(outputStream);

        // serialize headers and body into an envelope
        writeStartEnvelopeAndHeaders(soapVersion, headers, writer);
        if (body != null && !body.isEmpty()) {
            writeBody(writer, body, soapVersion);
        }
        writer.writeEndDocument();

        final InputStream inputStream = getInputStream(outputStream, writer);

        // set the input stream as the Camel message body
        in.setBody(inputStream);

    } catch (InvalidPayloadException | XMLStreamException | IOException e) {
        throw new RuntimeCamelException("Error parsing CXF Payload: " + e.getMessage(), e);
    }
}
 
Example 13
Source File: SoapPreProtocolOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setSoapAction(SoapMessage message) {
    BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();

    // The soap action is set on the wrapped operation.
    if (boi != null && boi.isUnwrapped()) {
        boi = boi.getWrappedOperation();
    }

    String action = getSoapAction(message, boi);

    if (message.getVersion() instanceof Soap11) {
        Map<String, List<String>> tempReqHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        Map<String, List<String>> reqHeaders
                = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
        if (reqHeaders != null) {
            tempReqHeaders.putAll(reqHeaders);
        }
        if (!tempReqHeaders.containsKey(SoapBindingConstants.SOAP_ACTION)) {
            tempReqHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList(action));
        }
        message.put(Message.PROTOCOL_HEADERS, tempReqHeaders);
    } else if (message.getVersion() instanceof Soap12 && !"\"\"".equals(action)) {
        String ct = (String) message.get(Message.CONTENT_TYPE);

        if (ct.indexOf("action=\"") == -1) {
            ct = new StringBuilder().append(ct)
                .append("; action=").append(action).toString();
            message.put(Message.CONTENT_TYPE, ct);
        }
    }
}
 
Example 14
Source File: AbstractFaultSoapPayloadConverter.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public void process(Exchange exchange) {
    final Exception exception = (Exception) exchange.getProperty(Exchange.EXCEPTION_CAUGHT);
    if (exception instanceof SoapFault) {

        SoapFault soapFault = (SoapFault) exception;
        final Message in = exchange.getIn();

        // get SOAP QNames from CxfPayload headers
        final SoapMessage soapMessage = in.getHeader("CamelCxfMessage", SoapMessage.class);
        final SoapVersion soapVersion = soapMessage.getVersion();

        try {

            // get CxfPayload body
            final CxfPayload<?> cxfPayload = in.getMandatoryBody(CxfPayload.class);

            final OutputStream outputStream = newOutputStream(in, cxfPayload);
            final XMLStreamWriter writer = newXmlStreamWriter(outputStream);

            handleFault(writer, soapFault, soapVersion);
            writer.writeEndDocument();

            final InputStream inputStream = getInputStream(outputStream, writer);

            // set the input stream as the Camel message body
            in.setBody(inputStream);

        } catch (InvalidPayloadException | XMLStreamException | IOException e) {
            throw new RuntimeCamelException("Error parsing CXF Payload: " + e.getMessage(), e);
        }
    }
}
 
Example 15
Source File: FragmentDialect.java    From cxf with Apache License 2.0 4 votes vote down vote up
private SoapVersion getSoapVersion() {
    WrappedMessageContext wmc = (WrappedMessageContext) context.getMessageContext();
    SoapMessage message = (SoapMessage) wmc.getWrappedMessage();
    return message.getVersion();
}
 
Example 16
Source File: SoapActionInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public static String getSoapAction(Message m) {
    if (!(m instanceof SoapMessage)) {
        return null;
    }
    SoapMessage message = (SoapMessage)m;
    if (message.getVersion() instanceof Soap11) {
        Map<String, List<String>> headers
            = CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));
        if (headers != null) {
            List<String> sa = headers.get(SoapBindingConstants.SOAP_ACTION);
            if (sa != null && !sa.isEmpty()) {
                String action = sa.get(0);
                if (action.startsWith("\"") || action.startsWith("\'")) {
                    action = action.substring(1, action.length() - 1);
                }
                return action;
            }
        }
    } else if (message.getVersion() instanceof Soap12) {
        String ct = (String) message.get(Message.CONTENT_TYPE);

        if (ct == null) {
            return null;
        }

        int start = ct.indexOf("action=");
        if (start == -1 && ct.indexOf("multipart/related") == 0 && ct.indexOf("start-info") == -1) {
            // the action property may not be found at the package's content-type for non-mtom multipart message
            // but skip searching if the start-info property is set
            List<String> cts = CastUtils.cast((List<?>)(((Map<?, ?>)
                message.get(AttachmentDeserializer.ATTACHMENT_PART_HEADERS)).get(Message.CONTENT_TYPE)));
            if (cts != null && !cts.isEmpty()) {
                ct = cts.get(0);
                start = ct.indexOf("action=");
            }
        }
        if (start != -1) {
            int end;
            char c = ct.charAt(start + 7);
            // handle the extraction robustly
            if (c == '\"') {
                start += 8;
                end = ct.indexOf('\"', start);
            } else if (c == '\\' && ct.charAt(start + 8) == '\"') {
                start += 9;
                end = ct.indexOf('\\', start);
            } else {
                start += 7;
                end = ct.indexOf(';', start);
                if (end == -1) {
                    end = ct.length();
                }
            }
            return ct.substring(start, end);
        }
    }

    // Return the Soap Action for the JMS Case
    if (message.containsKey(SoapJMSInInterceptor.JMS_SOAP_ACTION_VALUE)) {
        return (String)message.get(SoapJMSInInterceptor.JMS_SOAP_ACTION_VALUE);
    }

    return null;
}
 
Example 17
Source File: XSLTResourceTransformer.java    From cxf with Apache License 2.0 4 votes vote down vote up
private SoapVersion getSoapVersion() {
    WrappedMessageContext wmc = (WrappedMessageContext) context.getMessageContext();
    SoapMessage message = (SoapMessage) wmc.getWrappedMessage();
    return message.getVersion();
}
 
Example 18
Source File: XSDResourceValidator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private SoapVersion getSoapVersion() {
    WrappedMessageContext wmc = (WrappedMessageContext) context.getMessageContext();
    SoapMessage message = (SoapMessage) wmc.getWrappedMessage();
    return message.getVersion();
}
 
Example 19
Source File: XSDResourceTypeIdentifier.java    From cxf with Apache License 2.0 4 votes vote down vote up
private SoapVersion getSoapVersion() {
    WrappedMessageContext wmc = (WrappedMessageContext) context.getMessageContext();
    SoapMessage message = (SoapMessage) wmc.getWrappedMessage();
    return message.getVersion();
}
 
Example 20
Source File: MemoryResourceManager.java    From cxf with Apache License 2.0 4 votes vote down vote up
private SoapVersion getSoapVersion() {
    WrappedMessageContext wmc = (WrappedMessageContext) context.getMessageContext();
    SoapMessage message = (SoapMessage) wmc.getWrappedMessage();
    return message.getVersion();
}