Search in sources :

Example 16 with SOAPConnection

use of javax.xml.soap.SOAPConnection in project jaffa-framework by jaffa-projects.

the class WebServiceInvoker method invoke.

/**
 *  Marshals the inout arguments into a SOAPMessage
 * and invokes the WebService.
 * @param arguments the arguments for the WebService.
 * @return the reply from the WebService.
 * @throws SOAPException if any SOAP error occurs.
 * @throws SOAPFaultException if any SOAPFault occurs.
 * @throws JAXBException if any XML (un)marshalling error occurs.
 */
public Object invoke(Object... arguments) throws SOAPException, SOAPFaultException, JAXBException {
    SOAPConnection connection = null;
    try {
        // Create a connection
        connection = SOAPConnectionFactory.newInstance().createConnection();
        // Create the SOAPMessage
        SOAPMessage message = createSOAPMessage(arguments);
        // Invoke the WebService
        SOAPMessage response = invoke(connection, message);
        // Unmarshal the response
        return unmarshalResponse(response);
    } finally {
        // Always close the connection
        if (connection != null) {
            connection.close();
        }
    }
}
Also used : SOAPConnection(javax.xml.soap.SOAPConnection) SOAPMessage(javax.xml.soap.SOAPMessage)

Example 17 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 18 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 19 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)

Example 20 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)

Aggregations

SOAPConnection (javax.xml.soap.SOAPConnection)28 SOAPMessage (javax.xml.soap.SOAPMessage)28 URL (java.net.URL)16 MessageFactory (javax.xml.soap.MessageFactory)13 Test (org.junit.Test)12 SOAPConnectionFactory (javax.xml.soap.SOAPConnectionFactory)11 SOAPElement (javax.xml.soap.SOAPElement)11 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)11 JBossWSTest (org.jboss.wsf.test.JBossWSTest)11 QName (javax.xml.namespace.QName)10 SOAPException (javax.xml.soap.SOAPException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IOException (java.io.IOException)5 SOAPEnvelope (javax.xml.soap.SOAPEnvelope)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 AttachmentPart (javax.xml.soap.AttachmentPart)4 SOAPBody (javax.xml.soap.SOAPBody)4 SOAPFactory (javax.xml.soap.SOAPFactory)3 Node (org.w3c.dom.Node)3 FSException (com.sun.identity.federation.common.FSException)2