Search in sources :

Example 61 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project tomee by apache.

the class EjbRpcProvider method processMessage.

public void processMessage(MessageContext msgContext, SOAPEnvelope reqEnv, SOAPEnvelope resEnv, Object obj) throws Exception {
    RPCElement body = getBody(reqEnv, msgContext);
    OperationDesc operation = getOperationDesc(msgContext, body);
    AxisRpcInterceptor interceptor = new AxisRpcInterceptor(operation, msgContext);
    SOAPMessage message = msgContext.getMessage();
    try {
        message.getSOAPPart().getEnvelope();
        msgContext.setProperty(org.apache.axis.SOAPPart.ALLOW_FORM_OPTIMIZATION, Boolean.FALSE);
        RpcContainer container = (RpcContainer) ejbDeployment.getContainer();
        Object[] arguments = { msgContext, interceptor };
        Class callInterface = ejbDeployment.getServiceEndpointInterface();
        Object result = container.invoke(ejbDeployment.getDeploymentID(), InterfaceType.SERVICE_ENDPOINT, callInterface, operation.getMethod(), arguments, null);
        interceptor.createResult(result);
    } catch (ApplicationException e) {
        interceptor.createExceptionResult(e.getCause());
    } catch (Throwable throwable) {
        throw new AxisFault("Web Service EJB Invocation failed: method " + operation.getMethod(), throwable);
    }
}
Also used : AxisFault(org.apache.axis.AxisFault) RpcContainer(org.apache.openejb.RpcContainer) ApplicationException(org.apache.openejb.ApplicationException) RPCElement(org.apache.axis.message.RPCElement) OperationDesc(org.apache.axis.description.OperationDesc) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 62 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project ddf by codice.

the class GuestInterceptor method internalHandleMessage.

private void internalHandleMessage(SoapMessage message, SOAPMessage soapMessage) throws Fault {
    //Check if security header exists; if not, execute GuestInterceptor logic
    String actor = (String) getOption(WSHandlerConstants.ACTOR);
    if (actor == null) {
        actor = (String) message.getContextualProperty(SecurityConstants.ACTOR);
    }
    Element existingSecurityHeader = null;
    try {
        LOGGER.debug("Checking for security header.");
        existingSecurityHeader = WSSecurityUtil.getSecurityHeader(soapMessage.getSOAPPart(), actor);
    } catch (WSSecurityException e1) {
        LOGGER.debug("Issue with getting security header", e1);
    }
    if (existingSecurityHeader != null) {
        LOGGER.debug("SOAP message contains security header, no action taken by the GuestInterceptor.");
        return;
    }
    LOGGER.debug("Current request has no security header, continuing with GuestInterceptor");
    AssertionInfoMap assertionInfoMap = message.get(AssertionInfoMap.class);
    boolean hasAddressingAssertion = assertionInfoMap.entrySet().stream().flatMap(p -> p.getValue().stream()).filter(info -> MetadataConstants.ADDRESSING_ASSERTION_QNAME.equals(info.getAssertion().getName())).findFirst().isPresent();
    if (hasAddressingAssertion) {
        createAddressing(message, soapMessage);
    }
    LOGGER.debug("Creating guest security token.");
    HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
    SecurityToken securityToken = createSecurityToken(request.getRemoteAddr());
    message.put(SecurityConstants.TOKEN, securityToken);
    if (!MessageUtils.isRequestor(message)) {
        try {
            message.put(Message.REQUESTOR_ROLE, true);
            policyBasedWss4jOutInterceptor.handleMessage(message);
        } finally {
            message.remove(Message.REQUESTOR_ROLE);
        }
    } else {
        policyBasedWss4jOutInterceptor.handleMessage(message);
    }
}
Also used : WSSecurityUtil(org.apache.wss4j.dom.util.WSSecurityUtil) StringUtils(org.apache.commons.lang.StringUtils) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) MetadataConstants(org.apache.cxf.ws.addressing.policy.MetadataConstants) SOAPException(javax.xml.soap.SOAPException) STSClientConfiguration(ddf.security.sts.client.configuration.STSClientConfiguration) LoggerFactory(org.slf4j.LoggerFactory) XMLUtils(org.codice.ddf.platform.util.XMLUtils) SoapBindingConstants(org.apache.cxf.binding.soap.SoapBindingConstants) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) SOAPElement(javax.xml.soap.SOAPElement) HttpServletRequest(javax.servlet.http.HttpServletRequest) WSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Fault(org.apache.cxf.interceptor.Fault) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) PolicyBasedWSS4JInInterceptor(org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JInInterceptor) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) EncryptionService(ddf.security.encryption.EncryptionService) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) Phase(org.apache.cxf.phase.Phase) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) PolicyBasedWSS4JOutInterceptor(org.apache.cxf.ws.security.wss4j.PolicyBasedWSS4JOutInterceptor) SecurityAssertion(ddf.security.assertion.SecurityAssertion) Logger(org.slf4j.Logger) Security(org.codice.ddf.security.common.Security) Message(org.apache.cxf.message.Message) WSHandlerConstants(org.apache.wss4j.dom.handler.WSHandlerConstants) Set(java.util.Set) Subject(ddf.security.Subject) UUID(java.util.UUID) SecurityConstants(org.apache.cxf.ws.security.SecurityConstants) TimeUnit(java.util.concurrent.TimeUnit) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) Element(org.w3c.dom.Element) MessageUtils(org.apache.cxf.message.MessageUtils) AbstractWSS4JInterceptor(org.apache.cxf.ws.security.wss4j.AbstractWSS4JInterceptor) CacheBuilder(com.google.common.cache.CacheBuilder) SOAPMessage(javax.xml.soap.SOAPMessage) Cache(com.google.common.cache.Cache) SecurityManager(ddf.security.service.SecurityManager) SOAPFactory(javax.xml.soap.SOAPFactory) HttpServletRequest(javax.servlet.http.HttpServletRequest) SecurityToken(org.apache.cxf.ws.security.tokenstore.SecurityToken) SOAPElement(javax.xml.soap.SOAPElement) Element(org.w3c.dom.Element) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 63 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project camel by apache.

the class Client method invoke.

public String invoke() throws Exception {
    // Service Qname as defined in the WSDL.
    QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
    // Port QName as defined in the WSDL.
    QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapOverHttpRouter");
    // Create a dynamic Service instance
    Service service = Service.create(serviceName);
    // Add a port to the Service
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
    // Create a dispatch instance
    Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    // Use Dispatch as BindingProvider
    BindingProvider bp = dispatch;
    MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
    // Create SOAPMessage Request
    SOAPMessage request = factory.createMessage();
    // Request Body
    SOAPBody body = request.getSOAPBody();
    // Compose the soap:Body payload
    QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMe", "ns1");
    SOAPBodyElement payload = body.addBodyElement(payloadName);
    SOAPElement message = payload.addChildElement("requestType");
    message.addTextNode("Hello Camel!!");
    System.out.println("Send out the request: Hello Camel!!");
    // Invoke the endpoint synchronously
    // Invoke endpoint operation and read response
    SOAPMessage reply = dispatch.invoke(request);
    // process the reply
    body = reply.getSOAPBody();
    QName responseName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse");
    SOAPElement bodyElement = (SOAPElement) body.getChildElements(responseName).next();
    String responseMessageText = bodyElement.getTextContent();
    System.out.println("Get the response: " + responseMessageText);
    return responseMessageText;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 64 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project tomcat by apache.

the class SignCode method downloadSignedFiles.

private void downloadSignedFiles(List<File> filesToSign, String id) throws SOAPException, IOException {
    log("Downloading signed files. The signing set ID is: " + id);
    SOAPMessage message = SOAP_MSG_FACTORY.createMessage();
    SOAPBody body = populateEnvelope(message, NS);
    SOAPElement getSigningSetDetails = body.addChildElement("getSigningSetDetails", NS);
    SOAPElement getSigningSetDetailsRequest = getSigningSetDetails.addChildElement("getSigningSetDetailsRequest", NS);
    addCredentials(getSigningSetDetailsRequest, this.userName, this.password, this.partnerCode);
    SOAPElement signingSetID = getSigningSetDetailsRequest.addChildElement("signingSetID", NS);
    signingSetID.addTextNode(id);
    SOAPElement returnApplication = getSigningSetDetailsRequest.addChildElement("returnApplication", NS);
    returnApplication.addTextNode("true");
    // Send the message
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();
    log("Requesting signed files from server and waiting for response");
    SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);
    log("Processing response");
    SOAPElement responseBody = response.getSOAPBody();
    // Check for success
    // Extract the signed file(s) from the ZIP
    NodeList bodyNodes = responseBody.getChildNodes();
    NodeList getSigningSetDetailsResponseNodes = bodyNodes.item(0).getChildNodes();
    NodeList returnNodes = getSigningSetDetailsResponseNodes.item(0).getChildNodes();
    String result = null;
    String data = null;
    for (int i = 0; i < returnNodes.getLength(); i++) {
        Node returnNode = returnNodes.item(i);
        if (returnNode.getLocalName().equals("result")) {
            result = returnNode.getChildNodes().item(0).getTextContent();
        } else if (returnNode.getLocalName().equals("signingSet")) {
            data = returnNode.getChildNodes().item(1).getTextContent();
        }
    }
    if (!"0".equals(result)) {
        throw new BuildException("Download failed. Result code was: " + result);
    }
    extractFilesFromApplicationString(data, filesToSign);
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) SOAPBody(javax.xml.soap.SOAPBody) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) BuildException(org.apache.tools.ant.BuildException) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 65 with SOAPMessage

use of javax.xml.soap.SOAPMessage in project tomcat by apache.

the class SignCode method makeSigningRequest.

private String makeSigningRequest(List<File> filesToSign) throws SOAPException, IOException {
    log("Constructing the code signing request");
    SOAPMessage message = SOAP_MSG_FACTORY.createMessage();
    SOAPBody body = populateEnvelope(message, NS);
    SOAPElement requestSigning = body.addChildElement("requestSigning", NS);
    SOAPElement requestSigningRequest = requestSigning.addChildElement("requestSigningRequest", NS);
    addCredentials(requestSigningRequest, this.userName, this.password, this.partnerCode);
    SOAPElement applicationName = requestSigningRequest.addChildElement("applicationName", NS);
    applicationName.addTextNode(this.applicationName);
    SOAPElement applicationVersion = requestSigningRequest.addChildElement("applicationVersion", NS);
    applicationVersion.addTextNode(this.applicationVersion);
    SOAPElement signingServiceName = requestSigningRequest.addChildElement("signingServiceName", NS);
    signingServiceName.addTextNode(this.signingService);
    List<String> fileNames = getFileNames(filesToSign);
    SOAPElement commaDelimitedFileNames = requestSigningRequest.addChildElement("commaDelimitedFileNames", NS);
    commaDelimitedFileNames.addTextNode(listToString(fileNames));
    SOAPElement application = requestSigningRequest.addChildElement("application", NS);
    application.addTextNode(getApplicationString(fileNames, filesToSign));
    // Send the message
    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = soapConnectionFactory.createConnection();
    log("Sending singing request to server and waiting for response");
    SOAPMessage response = connection.call(message, SIGNING_SERVICE_URL);
    log("Processing response");
    SOAPElement responseBody = response.getSOAPBody();
    // Should come back signed
    NodeList bodyNodes = responseBody.getChildNodes();
    NodeList requestSigningResponseNodes = bodyNodes.item(0).getChildNodes();
    NodeList returnNodes = requestSigningResponseNodes.item(0).getChildNodes();
    String signingSetID = null;
    String signingSetStatus = null;
    for (int i = 0; i < returnNodes.getLength(); i++) {
        Node returnNode = returnNodes.item(i);
        if (returnNode.getLocalName().equals("signingSetID")) {
            signingSetID = returnNode.getTextContent();
        } else if (returnNode.getLocalName().equals("signingSetStatus")) {
            signingSetStatus = returnNode.getTextContent();
        }
    }
    if (!signingService.contains("TEST") && !"SIGNED".equals(signingSetStatus) || signingService.contains("TEST") && !"INITIALIZED".equals(signingSetStatus)) {
        throw new BuildException("Signing failed. Status was: " + signingSetStatus);
    }
    return signingSetID;
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) SOAPBody(javax.xml.soap.SOAPBody) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) SOAPElement(javax.xml.soap.SOAPElement) SOAPConnection(javax.xml.soap.SOAPConnection) BuildException(org.apache.tools.ant.BuildException) SOAPMessage(javax.xml.soap.SOAPMessage)

Aggregations

SOAPMessage (javax.xml.soap.SOAPMessage)111 SOAPException (javax.xml.soap.SOAPException)61 Element (org.w3c.dom.Element)31 SOAPBody (javax.xml.soap.SOAPBody)30 IOException (java.io.IOException)28 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)25 SOAPElement (javax.xml.soap.SOAPElement)21 MessageFactory (javax.xml.soap.MessageFactory)19 SOAPPart (javax.xml.soap.SOAPPart)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 InputStream (java.io.InputStream)13 ServletException (javax.servlet.ServletException)13 QName (javax.xml.namespace.QName)13 MimeHeaders (javax.xml.soap.MimeHeaders)12 SessionException (com.sun.identity.plugin.session.SessionException)11 OutputStream (java.io.OutputStream)11 NodeList (org.w3c.dom.NodeList)11 SPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement)10 List (java.util.List)10 StreamSource (javax.xml.transform.stream.StreamSource)10