Search in sources :

Example 16 with SOAPHeader

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

the class WsseUsernameTokenAuthenticationHandler method handleMessage.

@Override
public final boolean handleMessage(final SOAPMessageContext messageContext) {
    if (MessageContexts.isInboundMessage(messageContext)) {
        return true;
    }
    SOAPEnvelope envelope;
    SOAPHeader header;
    try {
        envelope = messageContext.getMessage().getSOAPPart().getEnvelope();
        header = envelope.getHeader();
        if (header == null) {
            header = envelope.addHeader();
        }
        final SOAPElement security = header.addChildElement(WS_SEC, WSSE, NAME_SPACE_URI);
        final SOAPElement userToken = security.addChildElement(USERNAME_TOKEN, WSSE);
        userToken.addChildElement(USERNAME, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_USERNAME)));
        userToken.addChildElement(PASSWORD, WSSE).addTextNode(StringUtility.valueOf(messageContext.get(InvocationContext.PROP_PASSWORD)));
        return true;
    } catch (final SOAPException e) {
        throw new WebServiceException("Failed to set SOAP header for WsseUsernameTokenAuthentication", e);
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPEnvelope(javax.xml.soap.SOAPEnvelope) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 17 with SOAPHeader

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

the class RoutingHandler method handleOutbound.

@Override
protected boolean handleOutbound(SOAPMessageContext msgContext) {
    log.info("handleOutbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = soapMessage.getSOAPHeader();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("RoutingHandlerOutbound", "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 + "|RoutOut");
    } 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 18 with SOAPHeader

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

the class AuthorizationHandler method handleOutbound.

@Override
protected boolean handleOutbound(SOAPMessageContext msgContext) {
    log.info("handleOutbound");
    try {
        SOAPMessage soapMessage = msgContext.getMessage();
        SOAPHeader soapHeader = soapMessage.getSOAPHeader();
        SOAPBody soapBody = soapMessage.getSOAPBody();
        SOAPFactory soapFactory = SOAPFactory.newInstance();
        Name headerName = soapFactory.createName("AuthorizationHandlerOutbound", "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 + "|AuthOut");
    } 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 19 with SOAPHeader

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

the class ProviderMessageTestCase method testProviderMessage.

@Test
@RunAsClient
public void testProviderMessage() throws Exception {
    SOAPMessage reqMsg = getRequestMessage();
    SOAPEnvelope reqEnv = reqMsg.getSOAPPart().getEnvelope();
    URL epURL = baseURL;
    SOAPConnection con = SOAPConnectionFactory.newInstance().createConnection();
    SOAPMessage resMsg = con.call(reqMsg, epURL);
    SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope();
    SOAPHeader soapHeader = resEnv.getHeader();
    if (soapHeader != null)
        soapHeader.detachNode();
    assertEquals(reqEnv, resEnv);
}
Also used : 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 20 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project Java-OCA-OCPP by ChargeTimeEU.

the class SOAPSyncHelper method getHeaderValue.

public static String getHeaderValue(SOAPMessage message, String tagName) {
    String value = null;
    try {
        SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();
        NodeList elements = header.getElementsByTagNameNS("*", tagName);
        if (elements.getLength() > 0) {
            value = elements.item(0).getChildNodes().item(0).getTextContent();
        }
    } catch (SOAPException e) {
        logger.warn("getHeaderValue() failed", e);
    }
    return value;
}
Also used : NodeList(org.w3c.dom.NodeList) SOAPException(javax.xml.soap.SOAPException) 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