Forum Discussion

horvathv's avatar
horvathv
New Contributor
13 years ago

scripting - call a service automatically

Hi experts,

I would like to call a service automatically if an other service receives a request.
So my scenario:
1. service A (one way service) receives a request
2. a script starts working automatically when the service A has received the request
3. service B is called by script

How could I do that in soapUI?

I found similar codes but how could I select the project of service B from the project of service A?

def project = mockResponse.mockOperation.mockService.project
def request = project.interfaces["NewWebServicePortBinding"].operations["sum"].getRequestByName("Request 2")
request.requestContent = mockRequest.requestContent
request.submit( new com.eviware.soapui.impl.wsdl.WsdlSubmitContext( request ), false )


Where should I have to put the script at service A?

Thanks,
Viktor
  • horvathv's avatar
    horvathv
    New Contributor
    I managed to write a script which works well (I get the WSA messageID and relatesTo fields from the recevied request and put these values into the the SOAP header of the request of an other service and call it):

    // get the messageID and RelatesTo from the request that received into the mock services
    def reqReceived = mockResult.mockResponse.mockResult.mockRequest
    def holderReqReceived = new com.eviware.soapui.support.XmlHolder( reqReceived.requestContent )
    holderReqReceived.namespaces["env"] = "http://schemas.xmlsoap.org/soap/envelope/"
    holderReqReceived.namespaces["wsa"] = "http://www.w3.org/2005/08/addressing"
    def messageID = holderReqReceived.getNodeValue("/env:Envelope/env:Header/wsa:MessageID")
    def relatesTo = holderReqReceived.getNodeValue("/env:Envelope/env:Header/wsa:RelatesTo")
    log.info "### messageID:$messageID / relatesTo:$relatesTo"

    // set the messageID
    def projectSend = mockResult.mockResponse.mockOperation.mockService.project.workspace.projects['MYBPELPROJECT']
    def reqSend = projectSend.interfaces["BPELBinding"].operations["OPERATION"].getRequestByName("Auto Request 1")
    def holderReqSend = new com.eviware.soapui.support.XmlHolder( reqSend.requestContent )
    holderReqSend.namespaces["soapenv"] = "http://schemas.xmlsoap.org/soap/envelope/"
    holderReqSend.namespaces["wsa"] = "http://www.w3.org/2005/08/addressing"
    holderReqSend["/soapenv:Envelope/soapenv:Header/wsa:MessageID"] = messageID
    holderReqSend["/soapenv:Envelope/soapenv:Header/wsa:RelatesTo"] = relatesTo
    holderReqSend.updateProperty()
    reqSend.setRequestContent(holderReqSend.getPrettyXml())

    sleep(1000)
    log.info "### I am going to call the service"
    reqSend.submit(new com.eviware.soapui.impl.wsdl.WsdlSubmitContext( ), false)


    I had to put this code to the AfterRequest Script of the mock service.
  • horvathv's avatar
    horvathv
    New Contributor
    Alright, Thanks! Luckily the code is working fine for me!
    V.