Search in sources :

Example 36 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project scout.rt by eclipse.

the class WsseUsernameTokenMethod method readWsseCredentials.

/**
 * Method invoked to extract the WSSE-credentials from the {@link SOAPHeader}.
 *
 * @return {@link Entry} with username as key and password as value, or <code>null</code> if not found.
 */
protected Entry<String, String> readWsseCredentials(final SOAPMessageContext messageContext) {
    SOAPHeader header;
    try {
        header = messageContext.getMessage().getSOAPPart().getEnvelope().getHeader();
    } catch (final SOAPException e) {
        throw new WebServiceException("Failed to read SOAP envelope", e);
    }
    if (header == null) {
        throw new WebServiceException("Missing WSSE-security header");
    }
    final Iterator iterator = header.getChildElements(new QName(NAME_SPACE_URI, WS_SEC, WSSE));
    while (iterator.hasNext()) {
        final SOAPElement security = (SOAPElement) iterator.next();
        final Iterator iteratorUserToken = security.getChildElements(new QName(NAME_SPACE_URI, USERNAME_TOKEN, WSSE));
        while (iteratorUserToken.hasNext()) {
            final SOAPElement userTokenElement = (SOAPElement) iteratorUserToken.next();
            final Iterator iteratorUsername = userTokenElement.getChildElements(new QName(NAME_SPACE_URI, USERNAME, WSSE));
            final Iterator iteratorPassword = userTokenElement.getChildElements(new QName(NAME_SPACE_URI, PASSWORD, WSSE));
            if (iteratorUsername.hasNext() && iteratorPassword.hasNext()) {
                final SOAPElement usernameElement = (SOAPElement) iteratorUsername.next();
                final SOAPElement passwordElement = (SOAPElement) iteratorPassword.next();
                if (usernameElement != null && passwordElement != null) {
                    return new SimpleEntry<>(usernameElement.getValue(), passwordElement.getValue());
                }
            }
        }
    }
    return null;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) SimpleEntry(java.util.AbstractMap.SimpleEntry) SOAPException(javax.xml.soap.SOAPException) Iterator(java.util.Iterator) SOAPElement(javax.xml.soap.SOAPElement) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 37 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.

the class ProviderMessageTestCase method testProviderDispatch.

@Test
@RunAsClient
public void testProviderDispatch() throws Exception {
    Dispatch<SOAPMessage> dispatch = createDispatch("ProviderEndpoint");
    SOAPMessage reqMsg = getRequestMessage();
    SOAPMessage resMsg = dispatch.invoke(reqMsg);
    SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
    SOAPHeader soapHeader = resEnv.getHeader();
    if (soapHeader != null)
        soapHeader.detachNode();
    assertEquals(DOMUtils.parse(msgString), resEnv);
}
Also used : SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 38 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.

the class ProviderPayloadTestCase method testProviderMessage.

@Test
@RunAsClient
public void testProviderMessage() throws Exception {
    String reqEnvStr = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>" + "  <env:Body>" + reqString + "</env:Body>" + "</env:Envelope>";
    MessageFactory msgFactory = MessageFactory.newInstance();
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage reqMsg = msgFactory.createMessage(null, new ByteArrayInputStream(reqEnvStr.getBytes()));
    URL epURL = baseURL;
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
    SOAPHeader soapHeader = resEnv.getHeader();
    if (soapHeader != null)
        soapHeader.detachNode();
    Node responseBody = DOMUtils.getFirstChildElement(resEnv.getBody());
    assertEquals("wrong namespace: " + responseBody.getNamespaceURI(), "http://org.jboss.ws/provider", responseBody.getNamespaceURI());
    assertEquals("wrong localPart: " + responseBody.getLocalName(), "somePayload", responseBody.getLocalName());
    String responseString = DOMUtils.getTextContent(responseBody);
    assertEquals("wrong content: " + responseString, "Hello:Inbound:LogicalSourceHandler:Outbound:LogicalSourceHandler", responseString);
}
Also used : MessageFactory(javax.xml.soap.MessageFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(org.w3c.dom.Node) SOAPConnection(javax.xml.soap.SOAPConnection) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) SOAPHeader(javax.xml.soap.SOAPHeader) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 39 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.

the class LogHandler method handleInbound.

@Override
protected boolean handleInbound(SOAPMessageContext msgContext) {
    log.info("handleInbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = getFailsafeSOAPHeader(soapMessage);
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("LogHandlerInbound", "ns1", "http://somens");
        SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|LogIn");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPFactory(javax.xml.soap.SOAPFactory) Name(javax.xml.soap.Name) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 40 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project jbossws-cxf by jbossws.

the class LogHandler method handleOutbound.

@Override
protected boolean handleOutbound(SOAPMessageContext msgContext) {
    log.info("handleOutbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = getFailsafeSOAPHeader(soapMessage);
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("LogHandlerOutbound", "ns1", "http://somens");
        SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
        she.setValue("true");
        SOAPBodyElement soapBodyElement = (SOAPBodyElement) soapBody.getChildElements().next();
        SOAPElement soapElement = (SOAPElement) soapBodyElement.getChildElements().next();
        String value = soapElement.getValue();
        soapElement.setValue(value + "|LogOut");
    } catch (SOAPException e) {
        throw new WebServiceException(e);
    }
    return true;
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPBody(javax.xml.soap.SOAPBody) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPHeader(javax.xml.soap.SOAPHeader) SOAPFactory(javax.xml.soap.SOAPFactory) Name(javax.xml.soap.Name) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

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