0

I am calling a web service (jsp page) that returns some data to me. I would like to have a timeout because sometimes it really takes a long time to respond. What is the proper way to achieve that? How can I set both a request timeout and response timeout? Could these be achieved with the session.setMaxInactiveInterval()?

My jsp page looks like this `public JSONObject performLogic(JSONObject state, Map additionalParams) throws Exception {

String callingSystem = state.getString("caller");
String  cli = state.getString("cli");
String taxnumber = state.getString("taxnumber");

PosDataReaderService posService = new PosDataReaderService();
PosDataReader pos = posService.getPosDataReaderSoapPort();

OrderDataRequest orderDataRequest = new OrderDataRequest();
orderDataRequest.setTaxNumber(taxnumber);
Caller caller = new Caller();
caller.setCallingSystem(callingSystem);
OrderDataResponse orderDataResponse = pos.getOrderData(orderDataRequest, caller);

JSONObject result = new JSONObject();

result.put("var_ws_passportstatuscode", orderDataResponse.getPasportStatusCode());

return result;

};`

Chris
  • 35
  • 5
  • This sets how long the session will last after user stop doing anything. (e.g. to effectively log the user out after a certain amount of time if they left the site without clicking logout.) Has nothing to do with the kind of timeout you want. – developerwjk Mar 12 '14 at 19:58
  • And where are you wanting to timeout, in the webservice or in the client calling the webservice? – developerwjk Mar 12 '14 at 20:10
  • Thank you for your response developerwjk. I believe that a timeout from the web service would be ok because it will send the appropriate message to the client. Here is my scenario. I am calling a jsp page in which I need to provide a timeout to exit the call of the page. I have provided the page code – Chris Mar 13 '14 at 17:40

1 Answers1

0

The answer to your question is here How to timeout a thread You use an java.util.concurrent.ExecutorService and create a Task class that implements java.util.concurrent.Callable and put the code you want to interrupt in there, etc.

I have attempted to port that solution to JSP myself, but ran into an error I'm asking a question on https://stackoverflow.com/questions/22388069/error-porting-thread-timeout-solution-to-jsp

But I would say probably you have to make a servlet and use the solution in a servlet. It seems that JSP will not allow you to override a superclass method inside a class you define in JSP. It would be better to use a servlet anyway.

Community
  • 1
  • 1
developerwjk
  • 8,619
  • 2
  • 17
  • 33