Search in sources :

Example 1 with Soap11

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

the class SoapActionInInterceptor method getSoapAction.

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 null;
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) Soap11(org.apache.cxf.binding.soap.Soap11) List(java.util.List) Map(java.util.Map) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 2 with Soap11

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

the class SoapPreProtocolOutInterceptor method setSoapAction.

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, List<String>>(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);
        }
    }
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Soap11(org.apache.cxf.binding.soap.Soap11) List(java.util.List) TreeMap(java.util.TreeMap)

Example 3 with Soap11

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

the class SAAJFactoryResolver method createMessageFactory.

public static MessageFactory createMessageFactory(SoapVersion version) throws SOAPException {
    MessageFactory messageFactory;
    String messageFactoryClassName = SystemPropertyAction.getPropertyOrNull(MESSAGE_FACTORY_KEY);
    if (messageFactoryClassName != null) {
        messageFactory = newInstanceCxfSAAJFactory(messageFactoryClassName, MessageFactory.class);
    } else if (version instanceof Soap11) {
        try {
            messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        } catch (Throwable t) {
            messageFactory = MessageFactory.newInstance();
        }
    } else if (version instanceof Soap12) {
        try {
            messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        } catch (Throwable t) {
            messageFactory = MessageFactory.newInstance();
        }
    } else {
        messageFactory = MessageFactory.newInstance();
    }
    return messageFactory;
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) MessageFactory(javax.xml.soap.MessageFactory) Soap11(org.apache.cxf.binding.soap.Soap11)

Example 4 with Soap11

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

the class SoapActionInInterceptorTest method setUpMessage.

private SoapMessage setUpMessage(String contentType, SoapVersion version, String prop) {
    SoapMessage message = control.createMock(SoapMessage.class);
    Map<String, List<String>> headers = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    Map<String, List<String>> partHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    if (version instanceof Soap11 && prop != null) {
        headers.put("SOAPAction", Collections.singletonList(prop));
    } else if (version instanceof Soap12 && prop != null) {
        partHeaders.put(Message.CONTENT_TYPE, Collections.singletonList("application/soap+xml; action=\"" + prop + "\""));
    }
    EasyMock.expect(message.getVersion()).andReturn(version).anyTimes();
    EasyMock.expect(message.get(Message.CONTENT_TYPE)).andReturn(contentType).anyTimes();
    EasyMock.expect(message.get(Message.PROTOCOL_HEADERS)).andReturn(headers).anyTimes();
    EasyMock.expect(message.get(AttachmentDeserializer.ATTACHMENT_PART_HEADERS)).andReturn(partHeaders).anyTimes();
    return message;
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) Soap11(org.apache.cxf.binding.soap.Soap11) List(java.util.List) TreeMap(java.util.TreeMap) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 5 with Soap11

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

the class SAAJFactoryResolver method createSOAPFactory.

public static SOAPFactory createSOAPFactory(SoapVersion version) throws SOAPException {
    SOAPFactory soapFactory;
    String soapFactoryClassName = SystemPropertyAction.getPropertyOrNull(SOAP_FACTORY_KEY);
    if (soapFactoryClassName != null) {
        soapFactory = newInstanceCxfSAAJFactory(soapFactoryClassName, SOAPFactory.class);
    } else if (version instanceof Soap11) {
        try {
            soapFactory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
        } catch (Throwable t) {
            soapFactory = SOAPFactory.newInstance();
        }
    } else if (version instanceof Soap12) {
        try {
            soapFactory = SOAPFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
        } catch (Throwable t) {
            soapFactory = SOAPFactory.newInstance();
        }
    } else {
        soapFactory = SOAPFactory.newInstance();
    }
    return soapFactory;
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) Soap11(org.apache.cxf.binding.soap.Soap11) SOAPFactory(javax.xml.soap.SOAPFactory)

Aggregations

Soap11 (org.apache.cxf.binding.soap.Soap11)5 Soap12 (org.apache.cxf.binding.soap.Soap12)5 List (java.util.List)3 TreeMap (java.util.TreeMap)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)2 Map (java.util.Map)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPFactory (javax.xml.soap.SOAPFactory)1 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)1