Layer 7 API Management

Expand all | Collapse all

CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

Jump to Best Answer
  • 1.  CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-22-2018 05:30 AM

    Hi all,

     

    There is an installation of CA API Gateway 8.3 where I need to schedule a SOAP method to be invoked daily.

    This method requires a basic authentication.

     

    Which kind of approach could you suggest, since this version of CA API Gateway doesn’t include any scheduler?

     

    Many thanks, Roberto



  • 2.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-22-2018 06:43 AM

    You could use any scheduling program and trigger a webservice call.

    A very basic solution would be to setup a crontab entry and trigger curl.



  • 3.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily
    Best Answer

    Posted 02-22-2018 07:56 AM

    I had a similar issue, where the execution should be trigger by an external scheduler. Let's assume that

    • The usage of a script, in a secured folder, is permitted (where the exit code is expected by the scheduler)
    • The usage of a script permits the access to a sensitive information (and this is why is preferred to have it in a secured folder

    you can set up a powershell like I did in the following way:

     

    #####################   START Settings   #####################
    [System.String] $soap_url = "https://soap:8443/webservicemethod"
    [System.String] $soap_userid = "username"
    [System.String] $soap_password = "password"
    #####################    END Settings    #####################
    [System.String] $soap_credential_base64 = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $soap_userid, $soap_password)))
    try {
        # Preparing the request
        $soap_web_request = [System.Net.WebRequest]::Create($soap_url)
        $soap_web_request.Headers.Add("Authorization", "Basic $soap_credential_base64")
        $soap_web_request.Headers.Add("SOAPAction", "soap method")
        $soap_web_request.ContentType = "text/xml;charset=UTF-8"
        $soap_web_request.Accept = "text/xml"
        $soap_web_request.Method = "POST"
        $soap_request_message = [System.Xml.XmlDocument] @"
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" >
       <soapenv:Header/>
       <soapenv:Body>
       </soapenv:Body>
    </soapenv:Envelope>
    "@

        $soap_web_request_stream = $soap_web_request.GetRequestStream()
        $soap_request_message.Save($soap_web_request_stream)
        $soap_web_request_stream.Close()
        $soap_web_response = $soap_web_request.GetResponse()
        $soap_web_response_stream = [System.IO.StreamReader] $soap_web_response.GetResponseStream()
        $soap_response_message = [System.Xml.XmlDocument] $soap_web_response_stream.ReadToEnd()
        $soap_web_response_stream.Close()
       
        # Parsing the SOAP response and lookup for the XmlNode interested value
        [System.Xml.XmlNamespaceManager] $soap_response_namespace_manager = $soap_response_message.NameTable
        $soap_response_namespace_manager.AddNamespace("soapenv", "http://schemas.xmlsoap.org/soap/envelope/")
       
        $response_info_node = $soap_response_message.SelectSingleNode("xpathexpression", $soap_response_namespace_manager)
        exit 0
    } catch [System.Management.Automation.MethodInvocationException] {
        $method_invocation_error_message = $_.Exception.Message
       
        Write-Host "[MethodInvocationException] $method_invocation_error_message" -Foreground "red"
        exit 1
    }


  • 4.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-22-2018 05:09 PM

    Dear ronro03 ,

    I would recommend you to think of upgrade the gateway to latest version, not just for the scheduled tasks feature, version 8.3 is a bit old.

    If you cannot upgrade the gateway soon, I would recommend the solution from RemcoDekker .

     

    You may create a /scheduledtask service on gateway, in this service you build the soap request with Authorization header, and route it to the down stream server:

    -- you can use a new context variable for your soap request

    -- you can use Manage Transport Properties/Headers Assertion - CA API Gateway - 9.3 - CA Technologies Documentation to add Authorization header (for basic authentication, the header is Authorization: Basic <base64 encoded username:password>) to your soap request context variable (right click on the assertion to "Select Target Message")

    -- in the route via http assertion you specify the soap request context variable as the "Request Source"

    -- then you create a cron job on gateway server to use curl to trigger the task,

    for example, if you want to send soap request at 11pm every day, you may

    crontab -e

    0 23 * * * curl http://localhost:8080/scheduledtask

     

    (compare to torlu03 's solution, we build and send the soap request in a gateway service)

     

    Regards,

    Mark



  • 5.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-23-2018 02:34 AM

    I think also ronro03 should decide which method to adopt based on the objective of this scheduling. Using the cronjob, in my view, should be limited only for administrative purposes or something related to the management of CA API gateway itself. Any other business needs that must be driven by external factor should be scheduled outside (not necessary who accesses to the policy manager is the same person that can access to the appliance :-) ).



  • 6.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-23-2018 04:43 AM

    Hi All,

     

     

    The customer finally choose to schedule this externally and demand the execution to another team. 

     

    Thanks all for the feedback.



  • 7.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-25-2018 05:03 PM

    Dear ronro03 , torlu03 ,

    Using external scheduler is not a problem, but your (torlu03 's) solution doesn't require gateway -- since you bypass the gateway, you won't have any (security) benefit from gateway.

    So, the question is not where to build the soap request, the question is, would you intend to use gateway to protect your backend server? Or would you allow direct connection to the backend server without gateway?

     

    Regards,

    Mark



  • 8.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-26-2018 03:04 AM

    Hi Mark,

    regarding my case, the scenario is a web services exposed by CA API Gateway, invoked live by a web page and invoked scheduled by a batch. There is not direct comunication with backend, because it is protected by farewall and secured by CA API gateway. What I simply did is to allow a scheduler to consume a web services already in place (without open any change request for scheduling a crontab and create a new policy for this).

    I do not know if the scenario of ronro03 is the same :-)

     

    Thanks, bye

    Luca



  • 9.  Re: CA API Gateway 8.3 - schedule a SOAP method to be invoked daily

    Posted 02-26-2018 04:59 PM

    Yes, that makes sense.