Search in sources :

Example 41 with SOAPHeader

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

the class RoutingHandler method handleInbound.

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

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

the class AuthorizationHandler method handleInbound.

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

use of javax.xml.soap.SOAPHeader in project cloudstack by apache.

the class VcenterSessionHandler method handleMessage.

@Override
public boolean handleMessage(SOAPMessageContext smc) {
    if (isOutgoingMessage(smc)) {
        try {
            SOAPHeader header = getSOAPHeader(smc);
            SOAPElement vcsessionHeader = header.addChildElement(new javax.xml.namespace.QName("#", "vcSessionCookie"));
            vcsessionHeader.setValue(vcSessionCookie);
        } catch (DOMException e) {
            s_logger.debug(e);
            throw new CloudRuntimeException(e);
        } catch (SOAPException e) {
            s_logger.debug(e);
            throw new CloudRuntimeException(e);
        }
    }
    return true;
}
Also used : DOMException(org.w3c.dom.DOMException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) QName(javax.xml.namespace.QName) SOAPHeader(javax.xml.soap.SOAPHeader)

Example 44 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project keycloak by keycloak.

the class SAMLServletAdapterTest method testSuccessfulEcpFlow.

@Test
public void testSuccessfulEcpFlow() throws Exception {
    Response authnRequestResponse = AdminClientUtil.createResteasyClient().target(ecpSPPage.toString()).request().header("Accept", "text/html; application/vnd.paos+xml").header("PAOS", "ver='urn:liberty:paos:2003-08' ;'urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp'").get();
    SOAPMessage authnRequestMessage = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(authnRequestResponse.readEntity(byte[].class)));
    // printDocument(authnRequestMessage.getSOAPPart().getContent(), System.out);
    Iterator<javax.xml.soap.Node> it = authnRequestMessage.getSOAPHeader().<SOAPHeaderElement>getChildElements(new QName("urn:oasis:names:tc:SAML:2.0:profiles:SSO:ecp", "Request"));
    SOAPHeaderElement ecpRequestHeader = (SOAPHeaderElement) it.next();
    NodeList idpList = ecpRequestHeader.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "IDPList");
    Assert.assertThat("No IDPList returned from Service Provider", idpList.getLength(), is(1));
    NodeList idpEntries = idpList.item(0).getChildNodes();
    Assert.assertThat("No IDPEntry returned from Service Provider", idpEntries.getLength(), is(1));
    String singleSignOnService = null;
    for (int i = 0; i < idpEntries.getLength(); i++) {
        Node item = idpEntries.item(i);
        NamedNodeMap attributes = item.getAttributes();
        Node location = attributes.getNamedItem("Loc");
        singleSignOnService = location.getNodeValue();
    }
    Assert.assertThat("Could not obtain SSO Service URL", singleSignOnService, notNullValue());
    Document authenticationRequest = authnRequestMessage.getSOAPBody().getFirstChild().getOwnerDocument();
    String username = "pedroigor";
    String password = "password";
    String pair = username + ":" + password;
    String authHeader = "Basic " + Base64.encodeBytes(pair.getBytes());
    Response authenticationResponse = AdminClientUtil.createResteasyClient().target(singleSignOnService).request().header(HttpHeaders.AUTHORIZATION, authHeader).post(Entity.entity(DocumentUtil.asString(authenticationRequest), "text/xml"));
    Assert.assertThat(authenticationResponse.getStatus(), is(OK.getStatusCode()));
    SOAPMessage responseMessage = MessageFactory.newInstance().createMessage(null, new ByteArrayInputStream(authenticationResponse.readEntity(byte[].class)));
    // printDocument(responseMessage.getSOAPPart().getContent(), System.out);
    SOAPHeader responseMessageHeaders = responseMessage.getSOAPHeader();
    NodeList ecpResponse = responseMessageHeaders.getElementsByTagNameNS(JBossSAMLURIConstants.ECP_PROFILE.get(), JBossSAMLConstants.RESPONSE__ECP.get());
    Assert.assertThat("No ECP Response", ecpResponse.getLength(), is(1));
    Node samlResponse = responseMessage.getSOAPBody().getFirstChild();
    Assert.assertThat(samlResponse, notNullValue());
    ResponseType responseType = (ResponseType) SAMLParser.getInstance().parse(samlResponse);
    StatusCodeType statusCode = responseType.getStatus().getStatusCode();
    Assert.assertThat(statusCode.getValue().toString(), is(JBossSAMLURIConstants.STATUS_SUCCESS.get()));
    Assert.assertThat(responseType.getDestination(), is(ecpSPPage.toString()));
    Assert.assertThat(responseType.getSignature(), notNullValue());
    Assert.assertThat(responseType.getAssertions().size(), is(1));
    SOAPMessage samlResponseRequest = MessageFactory.newInstance().createMessage();
    samlResponseRequest.getSOAPBody().addDocument(responseMessage.getSOAPBody().extractContentAsDocument());
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    samlResponseRequest.writeTo(os);
    Response serviceProviderFinalResponse = AdminClientUtil.createResteasyClient().target(responseType.getDestination()).request().post(Entity.entity(os.toByteArray(), "application/vnd.paos+xml"));
    Map<String, NewCookie> cookies = serviceProviderFinalResponse.getCookies();
    Invocation.Builder resourceRequest = AdminClientUtil.createResteasyClient().target(responseType.getDestination()).request();
    for (NewCookie cookie : cookies.values()) {
        resourceRequest.cookie(cookie);
    }
    Response resourceResponse = resourceRequest.get();
    Assert.assertThat(resourceResponse.readEntity(String.class), containsString("pedroigor"));
}
Also used : SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) NamedNodeMap(org.w3c.dom.NamedNodeMap) Invocation(javax.ws.rs.client.Invocation) QName(javax.xml.namespace.QName) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Document(org.w3c.dom.Document) SOAPMessage(javax.xml.soap.SOAPMessage) ResponseType(org.keycloak.dom.saml.v2.protocol.ResponseType) StatusResponseType(org.keycloak.dom.saml.v2.protocol.StatusResponseType) Response(javax.ws.rs.core.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) StatusCodeType(org.keycloak.dom.saml.v2.protocol.StatusCodeType) SOAPHeader(javax.xml.soap.SOAPHeader) NewCookie(javax.ws.rs.core.NewCookie) AbstractSamlTest(org.keycloak.testsuite.saml.AbstractSamlTest) Test(org.junit.Test)

Example 45 with SOAPHeader

use of javax.xml.soap.SOAPHeader in project googleads-java-lib by googleads.

the class JaxWsSoapContextHandler method handleMessage.

/**
 * Captures pertinent information from SOAP messages exchanged by the SOAP
 * service this handler is attached to. Also responsible for placing custom
 * (implicit) SOAP headers on outgoing messages.
 *
 * @see SOAPHandler#handleMessage(MessageContext)
 * @param context the context of the SOAP message passing through this handler
 * @return whether this SOAP interaction should continue
 */
@Override
public boolean handleMessage(SOAPMessageContext context) {
    if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
        // Outbound message (request), so reset the last request and response builders.
        lastRequestInfo = new RequestInfo.Builder();
        lastResponseInfo = new ResponseInfo.Builder();
        SOAPMessage soapMessage = context.getMessage();
        try {
            SOAPHeader soapHeader = soapMessage.getSOAPHeader();
            if (soapHeader == null) {
                soapHeader = soapMessage.getSOAPPart().getEnvelope().addHeader();
            }
            for (SOAPElement header : soapHeaders) {
                soapHeader.addChildElement(header);
            }
        } catch (SOAPException e) {
            throw new ServiceException("Error setting SOAP headers on outbound message.", e);
        }
        captureServiceAndOperationNames(context);
    }
    captureSoapXml(context);
    return true;
}
Also used : ResponseInfo(com.google.api.ads.common.lib.client.ResponseInfo) ServiceException(com.google.api.ads.common.lib.exception.ServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) RequestInfo(com.google.api.ads.common.lib.client.RequestInfo) 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