Search in sources :

Example 26 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project OpenAM by OpenRock.

the class MessageProcessor method addCorrelationHeader.

/**
     * Adds the correlation header.
     * @param msg SOAP Message that needs to be added with Correlation header. 
     * @param req Message Request, if present adds the correlation header 
     *             reference.
     * @return SOAPHeader SOAP Header with Correlation header.
     * @throws SOAPBindingException if there is an error.
     */
private SOAPHeader addCorrelationHeader(SOAPMessage msg, Message req) throws SOAPBindingException {
    try {
        SOAPHeader header = msg.getSOAPPart().getEnvelope().getHeader();
        if (header == null) {
            header = msg.getSOAPPart().getEnvelope().addHeader();
        }
        CorrelationHeader cHeader = new CorrelationHeader();
        correlationId = cHeader.getId();
        if (req != null) {
            cHeader.setRefToMessageID(req.getCorrelationHeader().getMessageID());
        }
        cHeader.addToParent(header);
        return header;
    } catch (Exception ex) {
        Utils.debug.error("MessageProcessor.addCorrealtionHeader: " + "Could not add correlation header", ex);
        throw new SOAPBindingException(Utils.bundle.getString("cannotAddCorrelationHeader"));
    }
}
Also used : SOAPHeader(javax.xml.soap.SOAPHeader) SOAPException(javax.xml.soap.SOAPException)

Example 27 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project tdi-studio-se by Talend.

the class SOAPUtil method invokeSOAP.

public void invokeSOAP(String version, String destination, String soapAction, String soapMessage) throws SOAPException, TransformerException, ParserConfigurationException, FileNotFoundException, UnsupportedEncodingException {
    MessageFactory messageFactory = null;
    if (version.equals(SOAP12)) {
        messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    } else {
        messageFactory = MessageFactory.newInstance();
    }
    SOAPMessage message = messageFactory.createMessage();
    MimeHeaders mimeHeaders = message.getMimeHeaders();
    mimeHeaders.setHeader("SOAPAction", soapAction);
    if (basicAuth) {
        addBasicAuthHeader(mimeHeaders, username, password);
    }
    // Create objects for the message parts
    SOAPPart soapPart = message.getSOAPPart();
    String encoding = getEncoding(soapMessage);
    ByteArrayInputStream stream = new ByteArrayInputStream(soapMessage.getBytes(encoding));
    StreamSource preppedMsgSrc = new StreamSource(stream);
    soapPart.setContent(preppedMsgSrc);
    // InputStream stream = new FileInputStream(new File("d://soap.txt"));
    // StreamSource preppedMsgSrc = new StreamSource(stream);
    // soapPart.setContent(preppedMsgSrc);
    message.saveChanges();
    // Send the message
    SOAPMessage reply = connection.call(message, destination);
    SOAPPart reSoapPart = reply.getSOAPPart();
    if (reSoapPart != null && reSoapPart instanceof SOAPPartImpl) {
        ((SOAPPartImpl) reSoapPart).setSourceCharsetEncoding(encoding);
    }
    SOAPEnvelope reEnvelope = reSoapPart.getEnvelope();
    SOAPHeader reHeader = reEnvelope.getHeader();
    if (reHeader != null) {
        setReHeaderMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reHeader)));
    }
    SOAPBody reBody = reEnvelope.getBody();
    if (reBody.getFault() != null) {
        hasFault = true;
        setReFaultMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
        setReBodyMessage(null);
    } else {
        hasFault = false;
        if (reBody.getChildNodes().getLength() < 1) {
            setReBodyMessage(null);
        } else if (reBody.getChildNodes().getLength() == 1 && reBody.getChildNodes().item(0) instanceof javax.xml.soap.Text) {
            setReBodyMessage(null);
        } else {
            setReBodyMessage(Doc2StringWithoutDeclare(extractContentAsDocument(reBody)));
        }
        setReFaultMessage(null);
    }
}
Also used : SOAPPartImpl(com.sun.xml.messaging.saaj.soap.SOAPPartImpl) MessageFactory(javax.xml.soap.MessageFactory) StreamSource(javax.xml.transform.stream.StreamSource) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) MimeHeaders(javax.xml.soap.MimeHeaders) SOAPBody(javax.xml.soap.SOAPBody) ByteArrayInputStream(java.io.ByteArrayInputStream) SOAPPart(javax.xml.soap.SOAPPart) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 28 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project narayana by jbosstm.

the class InstanceIdentifierHandler method handleMessageOutbound.

/**
 * check for an arjuna context attached to the message context and, if found, install its identifier as the value
 * of a soap message header element
 * @param context
 * @return
 * @throws ProtocolException
 */
protected boolean handleMessageOutbound(SOAPMessageContext context) throws ProtocolException {
    try {
        ArjunaContext arjunaContext = ArjunaContext.getCurrentContext(context);
        if (arjunaContext != null) {
            InstanceIdentifier instanceIdentifier = arjunaContext.getInstanceIdentifier();
            // insert a header into the current message containing the instance identifier as a text element
            final SOAPMessage soapMessage = context.getMessage();
            final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
            SOAPHeader soapHeader = soapEnvelope.getHeader();
            if (soapHeader == null) {
                soapHeader = soapEnvelope.addHeader();
            }
            final SOAPHeaderElement headerElement = soapHeader.addHeaderElement(ArjunaConstants.WSARJ_ELEMENT_INSTANCE_IDENTIFIER_QNAME);
            headerElement.setValue(instanceIdentifier.getInstanceIdentifier());
            headerElement.setMustUnderstand(true);
        }
    } catch (Exception se) {
        throw new ProtocolException(se);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) ProtocolException(javax.xml.ws.ProtocolException) InstanceIdentifier(com.arjuna.webservices11.wsarj.InstanceIdentifier) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) ArjunaContext(com.arjuna.webservices11.wsarj.ArjunaContext) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) ProtocolException(javax.xml.ws.ProtocolException)

Example 29 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project narayana by jbosstm.

the class JaxBaseHeaderContextProcessor method handleOutboundMessage.

/**
 * Handle the request.
 *
 * @param soapMessage The current message context.
 * @param mustUnderstand Value of MustUnderstand attribute.
 * @return whether the message was handled
 */
public boolean handleOutboundMessage(final SOAPMessage soapMessage, boolean mustUnderstand) {
    if (soapMessage == null) {
        return true;
    }
    try {
        /*
             * There should either be an Atomic Transaction *or* a Business Activity
             * associated with the thread.
             */
        final TransactionManager transactionManager = TransactionManagerFactory.transactionManager();
        final com.arjuna.mw.wst11.BusinessActivityManager businessActivityManager = BusinessActivityManagerFactory.businessActivityManager();
        final Context atContext;
        if (transactionManager != null) {
            final TxContextImple txContext = (TxContextImple) transactionManager.currentTransaction();
            atContext = (txContext == null ? null : txContext.context());
        } else {
            atContext = null;
        }
        final Context baContext;
        if (businessActivityManager != null) {
            final com.arjuna.mwlabs.wst11.ba.context.TxContextImple txContext = (com.arjuna.mwlabs.wst11.ba.context.TxContextImple) businessActivityManager.currentTransaction();
            baContext = (txContext == null ? null : txContext.context());
        } else {
            baContext = null;
        }
        final CoordinationContextType coordinationContext;
        if (baContext != null) {
            coordinationContext = baContext.getCoordinationContext();
        } else if (atContext != null) {
            coordinationContext = atContext.getCoordinationContext();
        } else {
            coordinationContext = null;
        }
        if (coordinationContext != null) {
            final SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
            SOAPHeader header = env.getHeader();
            if (header == null) {
                header = env.addHeader();
            }
            final Name name = env.createName(CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT, CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
            final SOAPHeaderElement headerElement = header.addHeaderElement(name);
            headerElement.addNamespaceDeclaration(CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
            headerElement.setMustUnderstand(mustUnderstand);
            CoordinationContextHelper.serialise(coordinationContext, headerElement);
        }
    } catch (final Throwable th) {
        wstxLogger.i18NLogger.warn_mw_wst11_client_JaxHC11P_1("com.arjuna.mw.wst11.client.JaxBaseHeaderContextProcessor.handleRequest()", th);
    }
    return true;
}
Also used : TxContext(com.arjuna.mw.wst.TxContext) Context(com.arjuna.mw.wsc11.context.Context) SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) TxContextImple(com.arjuna.mwlabs.wst11.at.context.TxContextImple) Name(javax.xml.soap.Name) TransactionManager(com.arjuna.mw.wst11.TransactionManager) CoordinationContextType(org.oasis_open.docs.ws_tx.wscoor._2006._06.CoordinationContextType) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 30 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project narayana by jbosstm.

the class AbstractJTAOverWSATHandler method getHeaderElement.

/**
 * Extracts and returns SOAP header element from the SOAP message context based on <code>uri</code> and <code>name</code>.
 *
 * @param soapMessageContext
 * @param uri
 * @param name
 * @return SOAP header element if such element existed and <code>null</code> if not.
 */
private SOAPHeaderElement getHeaderElement(final SOAPMessageContext soapMessageContext, final String uri, final String name) {
    SOAPHeaderElement soapHeaderElement = null;
    try {
        final SOAPMessage soapMessage = soapMessageContext.getMessage();
        final SOAPEnvelope soapEnvelope = soapMessage.getSOAPPart().getEnvelope();
        final SOAPHeader soapHeader = soapEnvelope.getHeader();
        if (soapHeader != null) {
            soapHeaderElement = getHeaderElement(soapHeader, uri, name);
        }
    } catch (SOAPException e) {
    }
    return soapHeaderElement;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPException(javax.xml.soap.SOAPException) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader)

Aggregations

SOAPHeader (javax.xml.soap.SOAPHeader)49 SOAPException (javax.xml.soap.SOAPException)30 SOAPMessage (javax.xml.soap.SOAPMessage)29 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)22 SOAPElement (javax.xml.soap.SOAPElement)18 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)17 QName (javax.xml.namespace.QName)13 SOAPBody (javax.xml.soap.SOAPBody)13 Name (javax.xml.soap.Name)10 WebServiceException (javax.xml.ws.WebServiceException)9 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)8 ArrayList (java.util.ArrayList)7 SOAPPart (javax.xml.soap.SOAPPart)7 Test (org.junit.Test)7 Element (org.w3c.dom.Element)7 IOException (java.io.IOException)6 SOAPFactory (javax.xml.soap.SOAPFactory)6 NodeList (org.w3c.dom.NodeList)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4