IT Process Automation

Expand all | Collapse all

Receiving and processing SOAP requests from external applications

Jump to Best Answer
  • 1.  Receiving and processing SOAP requests from external applications

    Posted 01-13-2016 10:27 AM

    I found an excellent tutorial within PAM for how to use an Invoke_SOAP_Method operator to:

     

    • Make a SOAP call to an external application
    • Process the data received from the SOAP response

     

    However, I'm looking for a similar tutorial (doesn't have to be video) of how to do the opposite.

     

    That is, I want to use PAM to:

     

    1. Receive a SOAP call from an external application
    2. Do a bunch of other data processing in PAM ( <-- I know how to do this part ) and then...
    3. Format and return the SOAP response to the original caller

     

    Where can I find some very specific examples of how to do (1) and (3) in PAM?



  • 2.  Re: Receiving and processing SOAP requests from external applications

    Posted 01-13-2016 02:49 PM

    You need to use the REST or SOAP webService of PAM.

     

    I'M currently trying to use them. I do not understand everything yet, but here is some infos so you can get yourself started.

     

    WSDL : http(s)://pamServer:port/itpam/soap?wsdl

    Service : http(s)://pamServer:port/itpam/soap

     

    You need to use :

    - executeProcess to start a Process

    - executeStartRequest to start a Start Request Form

     

     

    I suggest that you install SoapUI to become familiar with the webService, it's also very usefull to try new webService, before trying to use them in PAM.



  • 3.  Re: Receiving and processing SOAP requests from external applications
    Best Answer

    Posted 01-22-2016 12:40 PM

    Hi,

     

    I have just posted a document on how to do this via .NET, however you could take most of the SOAP code that I have attached, and use it from almost anywhere (For example, I have also used it from PowerShell)

    .NET API for some basic CAPA functions

     

    Thanks,

    Ian



  • 4.  Re: Receiving and processing SOAP requests from external applications

    Posted 02-10-2016 04:37 PM

    I'm following up on my original post to give others (who may be looking) the answer of how to do this using Java.

     

    Many thanks to both pier-olivier.tremblay and IanRich for their assistance.

     

    Code follows.  Approximately 100 lines.  3 methods.

     

    import java.io.ByteArrayInputStream;
    import java.io.InputStream;
    
    import javax.xml.soap.MessageFactory;
    import javax.xml.soap.MimeHeaders;
    import javax.xml.soap.SOAPConnection;
    import javax.xml.soap.SOAPConnectionFactory;
    import javax.xml.soap.SOAPConstants;
    import javax.xml.soap.SOAPMessage;
    import javax.xml.transform.Source;
    import javax.xml.transform.Transformer;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.stream.StreamResult;
    
    /**
     * @author I shamelessly stole most of this code from user 'acdcjunior' on https://stackoverflow.com/questions/19291283/soap-request-to-webservice-with-java
     */
    public class CallPAMProcess
    {
        /**
         * Main Entry Point
         * @param args
         */
        public static void main( String[] args )
        {
            try
            {
                // Create SOAP Connection
                SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
                SOAPConnection soapConnection = soapConnectionFactory.createConnection();
    
                // Send SOAP Message to PAM Server
                String url = "http://<your PAM server>:8080/itpam/soap";
                SOAPMessage soapResponse =
                    soapConnection.call( executeProcess( "<procLocationOnPAM>", "<yourLogin>", "<yourPassword>" ), url );
    
                // View the SOAP Response (see method, below)
                printSOAPResponse( soapResponse );
    
                // Optionally, you can parse the SOAP Response (in this example, the Process Runtime ID)
                String runtimeID = soapResponse.getSOAPBody().getElementsByTagName( "ROID" ).item( 0 ).getTextContent();
                System.out.println( "\n\n" + runtimeID );
    
                soapConnection.close();
            }
            catch ( Exception e )
            {
                System.err.println( "Error occurred while sending SOAP Request to Server" );
                e.printStackTrace();
            }
        }
    
        /**
         * Formats a SOAP message to send to PAM
         * @param _procName
         * @param _usr
         * @param _pass
         * @return
         * @throws Exception
         */
        public static SOAPMessage executeProcess(String _procName, String _usr, String _pass)
            throws Exception
        {
            // This (verbatum) comes from Web Services API Reference document
            String formattedSOAPMsg = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\n"
                + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n"
                + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" 
                + "<SOAP-ENV:Header/>\n"
                + "<SOAP-ENV:Body>\n" 
                + "<tns:executeProcess xmlns:tns=\"http://www.ca.com/itpam\">\n" 
                + "<tns:flow>\n"
                + "<tns:name>" + _procName + "</tns:name>\n" 
                + "<tns:action>start</tns:action>\n" 
                + "<tns:auth>\n"
                + "<tns:user>" + _usr + "</tns:user>\n" 
                + "<tns:password>" + _pass + "</tns:password>\n" 
                + "</tns:auth>\n"
                + "</tns:flow>\n" 
                + "</tns:executeProcess>\n" 
                + "</SOAP-ENV:Body>\n"
                + "</SOAP-ENV:Envelope>";
                
            // Convert String to SOAP object (note that PAM is stuck at v1.1 for SOAP)
            InputStream is = new ByteArrayInputStream( formattedSOAPMsg.getBytes() );
            SOAPMessage msg =
                MessageFactory.newInstance( SOAPConstants.SOAP_1_1_PROTOCOL ).createMessage( new MimeHeaders(), is );
    
            // Add headers to SOAP object (won't work without this--even if everything else is correct)
            MimeHeaders headers = msg.getMimeHeaders();
            headers.addHeader( "SOAPAction", "ExecuteC2OFlow" );   // ( <-- Note: this is a naming error on CA's end )
            msg.saveChanges();
    
            // Print the request message (for debug)
            System.out.print( "Request SOAP Message = " );
            msg.writeTo( System.out );
            System.out.println();
    
            return msg;
        };
    
        /**
         * Method used to print the SOAP Response
         * @param soapResponse
         * @throws Exception
         */
        private static void printSOAPResponse( SOAPMessage soapResponse )
            throws Exception
        {
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            Source sourceContent = soapResponse.getSOAPPart().getContent();
            System.out.print( "\nResponse SOAP Message = " );
            StreamResult result = new StreamResult( System.out );
            transformer.transform( sourceContent, result );
        }
    }