Search in sources :

Example 11 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 12 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)

Aggregations

SOAPHeader (javax.xml.soap.SOAPHeader)12 SOAPException (javax.xml.soap.SOAPException)9 SOAPBody (javax.xml.soap.SOAPBody)5 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)5 SOAPMessage (javax.xml.soap.SOAPMessage)5 SOAPPart (javax.xml.soap.SOAPPart)5 SOAPHeaderElement (javax.xml.soap.SOAPHeaderElement)4 NodeList (org.w3c.dom.NodeList)4 QName (javax.xml.namespace.QName)3 MessageFactory (javax.xml.soap.MessageFactory)3 BinarySecurityToken (com.sun.identity.liberty.ws.common.wsse.BinarySecurityToken)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MimeHeaders (javax.xml.soap.MimeHeaders)2 SOAPElement (javax.xml.soap.SOAPElement)2 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)2 Element (org.w3c.dom.Element)2 Node (org.w3c.dom.Node)2