Search in sources :

Example 51 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project jdk8u_jdk by JetBrains.

the class SaajEmptyNamespaceTest method testAddElementToNullNsQName.

/*
     * Test that adding element with explicitly empty namespace URI set via QName
     * shall put the element into global namespace.
     */
@Test
public void testAddElementToNullNsQName() throws Exception {
    // Create empty SOAP message
    SOAPMessage msg = createSoapMessage();
    SOAPBody body = msg.getSOAPPart().getEnvelope().getBody();
    // Add elements
    SOAPElement parentExplicitNS = body.addChildElement("content", "", TEST_NS);
    parentExplicitNS.addNamespaceDeclaration("", TEST_NS);
    SOAPElement childGlobalNS = parentExplicitNS.addChildElement(new QName(null, "global-child"));
    childGlobalNS.addNamespaceDeclaration("", "");
    SOAPElement grandChildGlobalNS = childGlobalNS.addChildElement("global-grand-child");
    SOAPElement childDefaultNS = parentExplicitNS.addChildElement("default-child");
    // Check namespace URIs
    Assert.assertNull(childGlobalNS.getNamespaceURI());
    Assert.assertNull(grandChildGlobalNS.getNamespaceURI());
    Assert.assertEquals(childDefaultNS.getNamespaceURI(), TEST_NS);
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) Test(org.testng.annotations.Test)

Example 52 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project wildfly by wildfly.

the class WSHandler method log.

private void log(SOAPMessageContext smc) {
    if (!LOGGER.isTraceEnabled()) {
        return;
    }
    boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (outboundProperty) {
        LOGGER.trace("Outgoing message:");
    } else {
        LOGGER.trace("Incoming message:");
    }
    LOGGER.trace("-----------");
    SOAPMessage message = smc.getMessage();
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        message.writeTo(baos);
        LOGGER.trace(baos.toString());
        LOGGER.trace("");
    } catch (Exception e) {
        LOGGER.error("Exception in handler: " + e);
    }
    LOGGER.trace("-----------");
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 53 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project wildfly by wildfly.

the class ReliableCheckHandler method handleContext.

private synchronized void handleContext(SOAPMessageContext smc) {
    Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    SOAPMessage message = smc.getMessage();
    if (outboundProperty.booleanValue()) {
        log.debug("Outgoing message:");
    } else {
        log.debug("Incoming message:");
    }
    log.debug("-----------");
    try {
        JBossLoggingOutputStream os = new JBossLoggingOutputStream(log, Level.DEBUG);
        message.writeTo(os);
        os.flush();
        log.debug("");
    } catch (Exception e) {
        log.debug("Exception in handler: " + e);
    }
    log.debug("-----------");
    SOAPElement firstBodyElement;
    try {
        switch(status % 4) {
            case 0:
                @SuppressWarnings("unchecked") Iterator<SOAPElement> it = (Iterator<SOAPElement>) message.getSOAPBody().getChildElements();
                if (it.hasNext()) {
                    firstBodyElement = it.next();
                    final QName createSequenceQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "CreateSequence");
                    if (!createSequenceQName.equals(firstBodyElement.getElementQName())) {
                        throw new WebServiceException("CreateSequence in soap body was expected, but it contains '" + firstBodyElement.getElementQName() + "'");
                    }
                    status++;
                } else {
                    //we could get multiple acknowledments
                    verifySequenceAcknowledgement(message);
                }
                break;
            case 1:
                firstBodyElement = (SOAPElement) message.getSOAPBody().getChildElements().next();
                final QName createSequenceResponseQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "CreateSequenceResponse");
                if (!createSequenceResponseQName.equals(firstBodyElement.getElementQName())) {
                    throw new WebServiceException("CreateSequenceResponse in soap body was expected, but it contains '" + firstBodyElement.getElementQName() + "'");
                }
                status++;
                break;
            case 2:
                Iterator headerElements = message.getSOAPHeader().getChildElements();
                boolean found = false;
                final QName sequenceQName = new QName("http://schemas.xmlsoap.org/ws/2005/02/rm", "Sequence");
                while (headerElements.hasNext()) {
                    SOAPElement soapElement = (SOAPElement) headerElements.next();
                    if (sequenceQName.equals(soapElement.getElementQName())) {
                        found = true;
                    }
                }
                if (!found) {
                    throw new WebServiceException("wsrm:Sequence is not present in soap header");
                }
                status++;
                break;
            case 3:
                if (verifySequenceAcknowledgement(message)) {
                    status++;
                }
                break;
        }
    } catch (SOAPException ex) {
        throw new WebServiceException(ex.getMessage(), ex);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) Iterator(java.util.Iterator) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException)

Example 54 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project wildfly by wildfly.

the class TestHandler method ensureInjectionsAndInitialization.

private boolean ensureInjectionsAndInitialization(MessageContext msgContext, String direction) {
    if (!this.correctState) {
        throw new WebServiceException("Unfunctional injections");
    }
    try {
        SOAPMessage soapMessage = ((SOAPMessageContext) msgContext).getMessage();
        SOAPElement soapElement = (SOAPElement) soapMessage.getSOAPBody().getChildElements().next();
        soapElement = (SOAPElement) soapElement.getChildElements().next();
        String oldValue = soapElement.getValue();
        String newValue = oldValue + ":" + direction + ":TestHandler";
        soapElement.setValue(newValue);
        log.debug("oldValue: " + oldValue);
        log.debug("newValue: " + newValue);
        return true;
    } catch (SOAPException ex) {
        throw new WebServiceException(ex);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 55 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project nhin-d by DirectProject.

the class RepositorySOAPHandler method handleMessage.

/**
     * This method handles the incoming and outgoing SOAP-Message. It's an
     * excellent point to manipulate the SOAP.
     * 
     * @param SOAPMessageContext
     *            The SOAPMessageContext object.
     * 
     * @return true if successful handling, false otherwise.
     */
@Override
public boolean handleMessage(SOAPMessageContext context) {
    //Inquire incoming or outgoing message.
    boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    try {
        if (outbound) {
            getHeaderData();
            SOAPMessage msg = ((SOAPMessageContext) context).getMessage();
            // dumpSOAPMessage(msg);
            SOAPPart sp = msg.getSOAPPart();
            // edit Envelope
            SOAPEnvelope env = sp.getEnvelope();
            SOAPHeader sh = env.addHeader();
            @SuppressWarnings("unused") SOAPBody sb = env.getBody();
            if (action != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "Action");
                SOAPHeaderElement saction = sh.addHeaderElement(qname);
                boolean must = true;
                saction.setMustUnderstand(must);
                saction.setValue(action);
            }
            if (relatesTo != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "RelatesTo");
                SOAPHeaderElement relates = sh.addHeaderElement(qname);
                relates.setValue(relatesTo);
            }
            if (from != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "From");
                QName child = new QName("http://www.w3.org/2005/08/addressing", "Address");
                SOAPHeaderElement efrom = sh.addHeaderElement(qname);
                SOAPElement address = efrom.addChildElement(child);
                address.setValue(from);
            }
            if (messageId != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "MessageID");
                SOAPHeaderElement message = sh.addHeaderElement(qname);
                message.setValue(messageId);
            }
            if (to != null) {
                QName qname = new QName("http://www.w3.org/2005/08/addressing", "To");
                SOAPHeaderElement sto = sh.addHeaderElement(qname);
                sto.setValue(to);
            }
        } else {
        //should not be any inbound
        }
    } catch (Exception e) {
        LOGGER.error("Error handling SOAP message", e);
        return false;
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) QName(javax.xml.namespace.QName) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) SOAPBody(javax.xml.soap.SOAPBody) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPPart(javax.xml.soap.SOAPPart) SOAPElement(javax.xml.soap.SOAPElement) SOAPHeader(javax.xml.soap.SOAPHeader)

Aggregations

SOAPMessage (javax.xml.soap.SOAPMessage)219 SOAPException (javax.xml.soap.SOAPException)87 SOAPBody (javax.xml.soap.SOAPBody)47 Test (org.junit.Test)46 InputStream (java.io.InputStream)45 QName (javax.xml.namespace.QName)45 Element (org.w3c.dom.Element)44 IOException (java.io.IOException)40 MessageFactory (javax.xml.soap.MessageFactory)40 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)30 SOAPElement (javax.xml.soap.SOAPElement)28 ByteArrayInputStream (java.io.ByteArrayInputStream)26 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)25 XMLStreamReader (javax.xml.stream.XMLStreamReader)25 Node (org.w3c.dom.Node)24 Document (org.w3c.dom.Document)22 URL (java.net.URL)21 SOAPPart (javax.xml.soap.SOAPPart)21 Exchange (org.apache.cxf.message.Exchange)19 MessageImpl (org.apache.cxf.message.MessageImpl)19