Search in sources :

Example 1 with SOAPConnectionFactory

use of javax.xml.soap.SOAPConnectionFactory in project tdi-studio-se by Talend.

the class SOAPUtil method init.

private void init() throws SOAPException {
    SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
    connection = soapConnFactory.createConnection();
}
Also used : SOAPConnectionFactory(javax.xml.soap.SOAPConnectionFactory)

Example 2 with SOAPConnectionFactory

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

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

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

Aggregations

SOAPConnectionFactory (javax.xml.soap.SOAPConnectionFactory)4 SOAPConnection (javax.xml.soap.SOAPConnection)3 SOAPMessage (javax.xml.soap.SOAPMessage)3 SOAPBody (javax.xml.soap.SOAPBody)2 SOAPElement (javax.xml.soap.SOAPElement)2 BuildException (org.apache.tools.ant.BuildException)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 URL (java.net.URL)1 DataHandler (javax.activation.DataHandler)1 URLDataSource (javax.activation.URLDataSource)1 QName (javax.xml.namespace.QName)1 AttachmentPart (javax.xml.soap.AttachmentPart)1 MessageFactory (javax.xml.soap.MessageFactory)1 SOAPBodyElement (javax.xml.soap.SOAPBodyElement)1