Forum Discussion

sanbie's avatar
Senior Member
2 years ago

How to Synchronise OnRequest and Dispatch Script

I have Mockservice which is running - With OnRequest Script that takes the mockRequest and builds the mockResponse XML and its saved to a context Variable.

Then Dispatch Script uses that variables and sends the response XML. This works when there are less number of Requests coming in. But when simultaneous Request come sup in the same millisecond , before Request1 completes the OnRequest Script REquest2 arrives and hence I am unable to synchronize ONRequest and Dispatch Script i tried using sunchronised keyword by locking the context, but that did not work. Not sure if I am doing anything wrong here -



OnRequest Script

context.lock = new Object()
MyCode to manipulate Input XML and create Response XML

context.getMockService().properties["FinalResponseXML"].value = textResponseXML




Dispatch Script


def requestPath = mockRequest.getPath()
if( requestPath.contains("/ABCD") )
return "Response 1"




No RepliesBe the first to reply