Search in sources :

Example 6 with SOAPConnection

use of javax.xml.soap.SOAPConnection 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 7 with SOAPConnection

use of javax.xml.soap.SOAPConnection 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)

Example 8 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project quickstarts by jboss-switchyard.

the class SoapAttachmentClient method sendMessage.

public static SOAPMessage sendMessage(String switchyard_web_service) throws Exception {
    SOAPConnectionFactory conFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = conFactory.createConnection();
    MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage msg = msgFactory.createMessage();
    SOAPBodyElement bodyElement = msg.getSOAPBody().addBodyElement(new QName("urn:switchyard-quickstart:soap-attachment:1.0", "echoImage"));
    bodyElement.addTextNode("cid:switchyard.png");
    AttachmentPart ap = msg.createAttachmentPart();
    URL imageUrl = Classes.getResource("switchyard.png");
    ap.setDataHandler(new DataHandler(new URLDataSource(imageUrl)));
    ap.setContentId("switchyard.png");
    msg.addAttachmentPart(ap);
    return connection.call(msg, new URL(switchyard_web_service));
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory) URLDataSource(javax.activation.URLDataSource) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPConnection(javax.xml.soap.SOAPConnection) AttachmentPart(javax.xml.soap.AttachmentPart) DataHandler(javax.activation.DataHandler) SOAPMessage(javax.xml.soap.SOAPMessage) URL(java.net.URL) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Example 9 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project OpenAM by OpenRock.

the class FSSOAPService method sendTerminationMessage.

/*
     * Method to send the passed SOAPMessage to the SOAPEndpoint URL
     * that is passed. The SOAP Message will then be sent across to the remote
     * provider in order to perform federation termination.
     * @param msg the <code>FSFederationTerminationNotification</code> 
     *  SOAPMesage to be sent
     * @param soapEndPoint the SOAPEndpoint URL of remote provider
     * @return boolean true if successful else false
     */
public boolean sendTerminationMessage(SOAPMessage msg, String soapEndPoint) {
    try {
        FSUtils.debug.message("started in func sendTerminationMessage");
        if (soapEndPoint == null) {
            FSUtils.debug.error("createSOAPReceiverURL Error!");
            String[] data = { FSUtils.bundle.getString("failCreateURLEndpoint") };
            LogUtil.error(Level.INFO, LogUtil.FAILED_SOAP_URL_END_POINT_CREATION, data);
            return false;
        }
        // Send the message to the provider using the connection.
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        msg.writeTo(output);
        if (FSUtils.debug.messageEnabled()) {
            String xmlString = output.toString(IFSConstants.DEFAULT_ENCODING);
            FSUtils.debug.message("SENDING message: \n " + xmlString);
            FSUtils.debug.message("URLEndpoint :" + soapEndPoint);
        }
        SOAPConnection con = scf.createConnection();
        SOAPMessage reply = con.call(msg, soapEndPoint);
        FSUtils.debug.message("SOAP CALL COMPLETED");
        return true;
    } catch (Exception e) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("In catch of sendTerminationMessage", e);
        }
        return false;
    }
}
Also used : SOAPConnection(javax.xml.soap.SOAPConnection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPException(javax.xml.soap.SOAPException) FSException(com.sun.identity.federation.common.FSException) IOException(java.io.IOException)

Aggregations

SOAPConnection (javax.xml.soap.SOAPConnection)9 SOAPMessage (javax.xml.soap.SOAPMessage)9 SOAPException (javax.xml.soap.SOAPException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 SOAPConnectionFactory (javax.xml.soap.SOAPConnectionFactory)3 FSException (com.sun.identity.federation.common.FSException)2 KeyProvider (com.sun.identity.saml.xmlsig.KeyProvider)2 Issuer (com.sun.identity.saml2.assertion.Issuer)2 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)2 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)2 Artifact (com.sun.identity.saml2.protocol.Artifact)2 ArtifactResolve (com.sun.identity.saml2.protocol.ArtifactResolve)2 ArtifactResponse (com.sun.identity.saml2.protocol.ArtifactResponse)2 Response (com.sun.identity.saml2.protocol.Response)2 Date (java.util.Date)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 SOAPBody (javax.xml.soap.SOAPBody)2 SOAPElement (javax.xml.soap.SOAPElement)2 BuildException (org.apache.tools.ant.BuildException)2