org.apache.cxf.binding.soap.SoapVersion Java Examples

The following examples show how to use org.apache.cxf.binding.soap.SoapVersion. 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: 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 #2
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 #3
Source File: RequestCustomizer.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
public void customize(final ComponentProxyComponent component, final Map<String, Object> options) {

    // read version without removing it from options, it's removed in proxy component
    SoapVersion soapVersion = Soap11.getInstance();
    final Object value = options.get(ComponentProperties.SOAP_VERSION);
    if (value != null) {
        final double versionNumber = Double.parseDouble(value.toString());
        final Iterator<SoapVersion> versions = SoapVersionFactory.getInstance().getVersions();

        while (versions.hasNext()) {
            final SoapVersion version = versions.next();
            if (version.getVersion() == versionNumber) {
                soapVersion = version;
                break;
            }
        }
    }

    Processors.addBeforeProducer(component, new RequestSoapPayloadConverter(soapVersion));
}
 
Example #4
Source File: SoapCxfProxyComponent.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@Override
protected void enrichOptions(Map<String, Object> options) {
    // read and remove soap version property
    this.soapVersion = Soap11.getInstance();
    final Object value = options.remove(ComponentProperties.SOAP_VERSION);
    if (value != null) {
        final double versionNumber = Double.parseDouble(value.toString());
        final Iterator<SoapVersion> versions = SoapVersionFactory.getInstance().getVersions();

        while (versions.hasNext()) {
            final SoapVersion version = versions.next();
            if (version.getVersion() == versionNumber) {
                soapVersion = version;
                break;
            }
        }
    }

    // read and remove exceptionMessageCauseEnabled
    final Object causeEnabled = options.remove(ComponentProperties.EXCEPTION_MESSAGE_CAUSE_ENABLED);
    if (causeEnabled != null) {
        exceptionMessageCauseEnabled = Boolean.TRUE.equals(Boolean.parseBoolean(causeEnabled.toString()));
    }
}
 
Example #5
Source File: ReadHeadersInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
public static SoapVersion readVersion(XMLStreamReader xmlReader, SoapMessage message) {
    String ns = xmlReader.getNamespaceURI();
    String lcname = xmlReader.getLocalName();
    if (ns == null || "".equals(ns)) {
        throw new SoapFault(new Message("NO_NAMESPACE", LOG, lcname),
                            Soap11.getInstance().getVersionMismatch());
    }

    SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
    if (soapVersion == null) {
        throw new SoapFault(new Message("INVALID_VERSION", LOG, ns, lcname),
                            Soap11.getInstance().getVersionMismatch());
    }

    if (!"Envelope".equals(lcname)) {
        throw new SoapFault(new Message("INVALID_ENVELOPE", LOG, lcname),
                            soapVersion.getSender());
    }
    message.setVersion(soapVersion);
    return soapVersion;
}
 
Example #6
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 #7
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 #8
Source File: SoapActionInInterceptorTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private SoapMessage setUpMessage(String contentType, SoapVersion version, String prop) {
    SoapMessage message = control.createMock(SoapMessage.class);
    Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    Map<String, List<String>> partHeaders = new TreeMap<>(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;
}
 
Example #9
Source File: SoapOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
public SOAPHeaderWriter(XMLStreamWriter writer,
                        SoapHeader header,
                        SoapVersion version,
                        String pfx) {
    super(writer);
    soapHeader = header;
    soapVersion = version;
    soapPrefix = pfx;
}
 
Example #10
Source File: EndpointSelectionInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #11
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 #12
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private String getAction(SoapMessage msg, SoapVersion version) {
    String action = (String)getOption(WSHandlerConstants.ACTION);
    if (action == null) {
        action = (String)msg.get(WSHandlerConstants.ACTION);
    }
    if (action == null) {
        LOG.warning("No security action was defined!");
        throw new SoapFault("No security action was defined!", version.getReceiver());
    }
    return action;
}
 
Example #13
Source File: RMEndpointTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateEndpoint() throws NoSuchMethodException, EndpointException {
    Method m = RMEndpoint.class.getDeclaredMethod("getUsingAddressing", new Class[] {EndpointInfo.class});
    Service as = control.createMock(Service.class);
    EndpointInfo aei = new EndpointInfo();
    ae = new EndpointImpl(null, as, aei);
    rme = EasyMock.createMockBuilder(RMEndpoint.class).withConstructor(manager, ae)
        .addMockedMethod(m).createMock(control);
    rme.setAplicationEndpoint(ae);
    rme.setManager(manager);
    SoapBindingInfo bi = control.createMock(SoapBindingInfo.class);
    aei.setBinding(bi);
    SoapVersion sv = Soap11.getInstance();
    EasyMock.expect(bi.getSoapVersion()).andReturn(sv);
    String ns = "http://schemas.xmlsoap.org/wsdl/soap/";
    EasyMock.expect(bi.getBindingId()).andReturn(ns);
    aei.setTransportId(ns);
    String addr = "addr";
    aei.setAddress(addr);
    Object ua = new Object();
    EasyMock.expect(rme.getUsingAddressing(aei)).andReturn(ua);
    control.replay();
    rme.createServices();
    rme.createEndpoints(null);
    Endpoint e = rme.getEndpoint(ProtocolVariation.RM10WSA200408);
    WrappedEndpoint we = (WrappedEndpoint)e;
    assertSame(ae, we.getWrappedEndpoint());
    Service s = rme.getService(ProtocolVariation.RM10WSA200408);
    assertEquals(1, s.getEndpoints().size());
    assertSame(e, s.getEndpoints().get(RM10Constants.PORT_NAME));
}
 
Example #14
Source File: MAPCodecTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private SoapMessage setUpMessage(boolean requestor, boolean outbound, boolean invalidMAP,
                                 boolean preExistingSOAPAction, Boolean generateRelatesTo,
                                 String exposeAs) throws Exception {
    SoapMessage message = new SoapMessage(new MessageImpl());
    setUpOutbound(message, outbound);
    expectRelatesTo = generateRelatesTo != null ? generateRelatesTo
        : (requestor && !outbound) || (!requestor && outbound);
    message.put(REQUESTOR_ROLE, Boolean.valueOf(requestor));
    String mapProperty = getMAPProperty(requestor, outbound);
    AddressingProperties maps = getMAPs(requestor, outbound, exposeAs);
    final Element header = control.createMock(Element.class);
    codec.setHeaderFactory(new MAPCodec.HeaderFactory() {
        public Element getHeader(SoapVersion version) {
            return header;
        }
    });
    List<Header> headers = message.getHeaders();
    JAXBContext jaxbContext = control.createMock(JAXBContext.class);
    ContextJAXBUtils.setJAXBContext(jaxbContext);
    Names200408.setJAXBContext(jaxbContext);
    Names200403.setJAXBContext(jaxbContext);
    if (outbound) {
        setUpEncode(requestor, message, header, maps, mapProperty, invalidMAP, preExistingSOAPAction);
    } else {
        setUpDecode(message, headers, maps, mapProperty, requestor);
    }
    control.replay();
    return message;
}
 
Example #15
Source File: MAPCodec.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected HeaderFactory getHeaderFactory() {
    if (headerFactory == null) {
        headerFactory = new HeaderFactory() {
            public Element getHeader(SoapVersion soapversion) {
                Document doc = DOMUtils.getEmptyDocument();
                return doc.createElementNS(soapversion.getHeader().getNamespaceURI(),
                        soapversion.getHeader().getLocalPart());
            }
        };
    }
    return headerFactory;
}
 
Example #16
Source File: WSS4JInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private String getAction(SoapMessage msg, SoapVersion version) {
    String action = (String)getOption(ConfigurationConstants.ACTION);
    if (action == null) {
        action = (String)msg.get(ConfigurationConstants.ACTION);
    }
    if (action == null && !ignoreActions) {
        LOG.warning("No security action was defined!");
        throw new SoapFault("No security action was defined!", version.getReceiver());
    }
    return action;
}
 
Example #17
Source File: SOAPHandlerInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Object[] prepareSOAPHeader() throws Exception {
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
    SoapVersion soapVersion = Soap11.getInstance();
    Element envElement = doc.createElementNS(soapVersion.getEnvelope().getNamespaceURI(),
                                             soapVersion.getEnvelope().getLocalPart());

    Element headerElement = doc.createElementNS(soapVersion.getNamespace(),
                                                soapVersion.getHeader().getLocalPart());

    Element bodyElement = doc.createElementNS(soapVersion.getBody().getNamespaceURI(),
                                              soapVersion.getBody().getLocalPart());

    Element childElement = doc.createElementNS("http://apache.org/hello_world_rpclit/types",
                                               "ns2:header1");
    Attr attr =
        childElement.getOwnerDocument().createAttributeNS(soapVersion.getNamespace(),
                                                              "SOAP-ENV:mustUnderstand");
    attr.setValue("true");
    childElement.setAttributeNodeNS(attr);

    headerElement.appendChild(childElement);
    envElement.appendChild(headerElement);
    envElement.appendChild(bodyElement);
    doc.appendChild(envElement);

    return new Object[] {doc, headerElement};
}
 
Example #18
Source File: SOAPHandlerInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private XMLStreamReader preparemXMLStreamReader(String resouceName) throws Exception {
    InputStream is = this.getClass().getResourceAsStream(resouceName);
    XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(is);

    // skip until soap body
    if (xmlReader.nextTag() == XMLStreamConstants.START_ELEMENT) {
        String ns = xmlReader.getNamespaceURI();
        SoapVersion soapVersion = SoapVersionFactory.getInstance().getSoapVersion(ns);
        // message.setVersion(soapVersion);

        QName qn = xmlReader.getName();
        while (!qn.equals(soapVersion.getBody()) && !qn.equals(soapVersion.getHeader())) {
            while (xmlReader.nextTag() != XMLStreamConstants.START_ELEMENT) {
                // nothing to do
            }
            qn = xmlReader.getName();
        }
        if (qn.equals(soapVersion.getHeader())) {
            XMLStreamReader filteredReader = new PartialXMLStreamReader(xmlReader, soapVersion.getBody());

            StaxUtils.read(filteredReader);
        }
        // advance just past body.
        xmlReader.next();

        while (xmlReader.isWhiteSpace()) {
            xmlReader.next();
        }
    }
    return xmlReader;
}
 
Example #19
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private String getAction(SoapMessage msg, SoapVersion version) {
    String action = (String)getOption(WSHandlerConstants.ACTION);
    if (action == null) {
        action = (String)msg.get(WSHandlerConstants.ACTION);
    }
    if (action == null) {
        LOG.warning("No security action was defined!");
        throw new SoapFault("No security action was defined!", version.getReceiver());
    }
    return action;
}
 
Example #20
Source File: ResponseSoapPayloadConverter.java    From syndesis with Apache License 2.0 5 votes vote down vote up
protected static void writeHeaders(XMLStreamWriter writer, List<?> headers, SoapVersion soapVersion) throws XMLStreamException {
    writer.writeStartElement(SOAP_PREFIX,  soapVersion.getHeader().getLocalPart(), soapVersion.getNamespace());
    writePartSources(writer, headers.stream()
        .map(h -> h instanceof Source ? (Source) h : new DOMSource((Node)h))
        .collect(Collectors.toList()));
    writer.writeEndElement();
}
 
Example #21
Source File: ResponseSoapPayloadConverter.java    From syndesis with Apache License 2.0 5 votes vote down vote up
protected static void writeStartEnvelopeAndHeaders(SoapVersion soapVersion, List<?> headers, XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument();
    writer.writeStartElement(SOAP_PREFIX,  soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace());
    if (headers != null && !headers.isEmpty()) {
        writeHeaders(writer, headers, soapVersion);
    }
}
 
Example #22
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 #23
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 #24
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private String getAction(SoapMessage msg, SoapVersion version) {
    String action = (String)getOption(WSHandlerConstants.ACTION);
    if (action == null) {
        action = (String)msg.get(WSHandlerConstants.ACTION);
    }
    if (action == null) {
        LOG.warning("No security action was defined!");
        throw new SoapFault("No security action was defined!", version.getReceiver());
    }
    return action;
}
 
Example #25
Source File: WSS4JInInterceptor.java    From steady with Apache License 2.0 5 votes vote down vote up
private String getAction(SoapMessage msg, SoapVersion version) {
    String action = (String)getOption(WSHandlerConstants.ACTION);
    if (action == null) {
        action = (String)msg.get(WSHandlerConstants.ACTION);
    }
    if (action == null) {
        LOG.warning("No security action was defined!");
        throw new SoapFault("No security action was defined!", version.getReceiver());
    }
    return action;
}
 
Example #26
Source File: SoapBindingInfo.java    From cxf with Apache License 2.0 4 votes vote down vote up
public SoapBindingInfo(ServiceInfo serv, String n, SoapVersion soapVersion) {
    super(serv, n);

    this.soapVersion = soapVersion;
}
 
Example #27
Source File: ReadHeadersInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
public ReadHeadersInterceptor(Bus b, SoapVersion v) {
    super(Phase.READ);
    version = v;
    bus = b;
}
 
Example #28
Source File: ReadHeadersInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
HeadersProcessor(SoapVersion version) {
    this.header = version.getHeader().getLocalPart();
    this.ns = version.getEnvelope().getNamespaceURI();
    this.envelope = version.getEnvelope().getLocalPart();
    this.body = version.getBody().getLocalPart();
}
 
Example #29
Source File: WSS4JOutInterceptor.java    From steady with Apache License 2.0 4 votes vote down vote up
private void configureActions(SoapMessage mc, boolean doDebug,
        SoapVersion version, WSSConfig config) {
    
    final Map<Integer, Object> actionMap = CastUtils.cast(
        (Map<?, ?>)getProperty(mc, WSS4J_ACTION_MAP));
    if (actionMap != null) {
        for (Map.Entry<Integer, Object> entry : actionMap.entrySet()) {
            Class<?> removedAction = null;
            
            // Be defensive here since the cast above is slightly risky
            // with the handler config options not being strongly typed.
            try {
                if (entry.getValue() instanceof Class<?>) {
                    removedAction = config.setAction(
                            entry.getKey().intValue(), 
                            (Class<?>)entry.getValue());
                } else if (entry.getValue() instanceof Action) {
                    removedAction = config.setAction(
                            entry.getKey().intValue(), 
                            (Action)entry.getValue());
                } else {
                    throw new SoapFault(new Message("BAD_ACTION", LOG), version
                            .getReceiver());
                }
            } catch (ClassCastException e) {
                throw new SoapFault(new Message("BAD_ACTION", LOG), version
                        .getReceiver());
            }
            
            if (doDebug) {
                if (removedAction != null) {
                    LOG.fine("Replaced Action: " + removedAction.getName()
                            + " with Action: " + entry.getValue()
                            + " for ID: " + entry.getKey());
                } else {
                    LOG.fine("Added Action: " + entry.getValue()
                            + " with ID: " + entry.getKey());
                }
            }
        }
    }
}
 
Example #30
Source File: WSS4JOutInterceptor.java    From steady with Apache License 2.0 4 votes vote down vote up
private void configureActions(SoapMessage mc, boolean doDebug,
        SoapVersion version, WSSConfig config) {
    
    final Map<Integer, Object> actionMap = CastUtils.cast(
        (Map<?, ?>)getProperty(mc, WSS4J_ACTION_MAP));
    if (actionMap != null) {
        for (Map.Entry<Integer, Object> entry : actionMap.entrySet()) {
            Class<?> removedAction = null;
            
            // Be defensive here since the cast above is slightly risky
            // with the handler config options not being strongly typed.
            try {
                if (entry.getValue() instanceof Class<?>) {
                    removedAction = config.setAction(
                            entry.getKey().intValue(), 
                            (Class<?>)entry.getValue());
                } else if (entry.getValue() instanceof Action) {
                    removedAction = config.setAction(
                            entry.getKey().intValue(), 
                            (Action)entry.getValue());
                } else {
                    throw new SoapFault(new Message("BAD_ACTION", LOG), version
                            .getReceiver());
                }
            } catch (ClassCastException e) {
                throw new SoapFault(new Message("BAD_ACTION", LOG), version
                        .getReceiver());
            }
            
            if (doDebug) {
                if (removedAction != null) {
                    LOG.fine("Replaced Action: " + removedAction.getName()
                            + " with Action: " + entry.getValue()
                            + " for ID: " + entry.getKey());
                } else {
                    LOG.fine("Added Action: " + entry.getValue()
                            + " with ID: " + entry.getKey());
                }
            }
        }
    }
}