Search in sources :

Example 6 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project camel by apache.

the class TesterBean method processSOAP.

public SOAPMessage processSOAP(Exchange exchange) {
    // Since the Camel-CXF endpoint uses a list to store the parameters
    // and bean component uses the bodyAs expression to get the value
    // we'll need to deal with the parameters ourself
    SOAPMessage soapMessage = (SOAPMessage) exchange.getIn().getBody(List.class).get(0);
    if (soapMessage == null) {
        System.out.println("Incoming null message detected...");
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", "null");
    }
    try {
        SOAPPart sp = soapMessage.getSOAPPart();
        SOAPEnvelope se = sp.getEnvelope();
        SOAPBody sb = se.getBody();
        String requestText = sb.getFirstChild().getTextContent();
        System.out.println(requestText);
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", requestText);
    } catch (Exception e) {
        e.printStackTrace();
        return createDefaultSoapMessage("Greetings from Apache Camel!!!!", e.getClass().getName());
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) SOAPPart(javax.xml.soap.SOAPPart) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException)

Example 7 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project camel by apache.

the class TesterBean method createDefaultSoapMessage.

public static SOAPMessage createDefaultSoapMessage(String responseMessage, String requestMessage) {
    try {
        SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
        SOAPBody body = soapMessage.getSOAPPart().getEnvelope().getBody();
        QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse", "ns1");
        SOAPBodyElement payload = body.addBodyElement(payloadName);
        SOAPElement message = payload.addChildElement("responseType");
        message.addTextNode(responseMessage + " Request was  " + requestMessage);
        return soapMessage;
    } catch (SOAPException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 8 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project camel by apache.

the class CXFMessageProcessor method process.

public void process(Exchange exchange) throws Exception {
    // just print out the request message
    Message in = exchange.getIn();
    String request = in.getBody(String.class);
    // just make sure the request is greetme
    assertTrue("It should be GreetMe request.", request.indexOf("<greetMe") > 0);
    InputStream is = new ByteArrayInputStream(RESPONSE.getBytes());
    SOAPMessage message = MessageFactory.newInstance().createMessage(null, is);
    exchange.getOut().setBody(message);
}
Also used : Message(org.apache.camel.Message) SOAPMessage(javax.xml.soap.SOAPMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 9 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project camel by apache.

the class SpringWebserviceConsumer method populateExchangeWithBreadcrumbFromMessageContext.

private void populateExchangeWithBreadcrumbFromMessageContext(MessageContext messageContext, Exchange exchange) {
    SaajSoapMessage saajSoap = (SaajSoapMessage) messageContext.getRequest();
    SOAPMessage soapMessageRequest = null;
    if (saajSoap != null) {
        soapMessageRequest = saajSoap.getSaajMessage();
        if (soapMessageRequest != null) {
            MimeHeaders mimeHeaders = soapMessageRequest.getMimeHeaders();
            if (mimeHeaders != null) {
                String[] breadcrumbIdHeaderValues = mimeHeaders.getHeader(Exchange.BREADCRUMB_ID);
                // may be required to implement
                if (breadcrumbIdHeaderValues != null && breadcrumbIdHeaderValues.length >= 1) {
                    exchange.getIn().setHeader(Exchange.BREADCRUMB_ID, breadcrumbIdHeaderValues[0]);
                }
            }
        }
    }
}
Also used : SaajSoapMessage(org.springframework.ws.soap.saaj.SaajSoapMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 10 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project midpoint by Evolveum.

the class WsFaultListener method faultOccurred.

@Override
public boolean faultOccurred(Exception exception, String description, Message message) {
    LOGGER.trace("Handling fault: {}: {} - {}", new Object[] { exception, description, message, exception });
    Object audited = message.getContextualProperty(SecurityHelper.CONTEXTUAL_PROPERTY_AUDITED_NAME);
    if (audited != null && ((Boolean) audited)) {
        return true;
    }
    if (exception instanceof PasswordCallbackException) {
        return true;
    }
    if (exception.getCause() instanceof PasswordCallbackException) {
        return true;
    }
    if (exception.getCause() != null && exception.getCause().getCause() instanceof PasswordCallbackException) {
        return true;
    }
    try {
        String auditMessage = exception.getMessage();
        if (exception.getClass() != null) {
            // Exception cause has much better message because CXF masks real messages in the SOAP faults.
            auditMessage = exception.getCause().getMessage();
        }
        SOAPMessage saajSoapMessage = message.getContent(SOAPMessage.class);
        String username = securityHelper.getUsernameFromMessage(saajSoapMessage);
        ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
        securityHelper.auditLoginFailure(username, null, connEnv, auditMessage);
    } catch (WSSecurityException e) {
        // Ignore
        LOGGER.trace("Exception getting username from soap message (probably safe to ignore)", e);
    } catch (Exception e) {
        LOGGER.error("Error auditing SOAP fault: " + e.getMessage(), e);
    // but otherwise ignore it
    }
    return true;
}
Also used : WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) SOAPMessage(javax.xml.soap.SOAPMessage) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment)

Aggregations

SOAPMessage (javax.xml.soap.SOAPMessage)111 SOAPException (javax.xml.soap.SOAPException)61 Element (org.w3c.dom.Element)31 SOAPBody (javax.xml.soap.SOAPBody)30 IOException (java.io.IOException)28 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)25 SOAPElement (javax.xml.soap.SOAPElement)21 MessageFactory (javax.xml.soap.MessageFactory)19 SOAPPart (javax.xml.soap.SOAPPart)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 ServletException (javax.servlet.ServletException)13 QName (javax.xml.namespace.QName)13 MimeHeaders (javax.xml.soap.MimeHeaders)12 SessionException (com.sun.identity.plugin.session.SessionException)11 OutputStream (java.io.OutputStream)11 NodeList (org.w3c.dom.NodeList)11 SPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement)10 List (java.util.List)10 StreamSource (javax.xml.transform.stream.StreamSource)10