Chris
Chris

Reputation: 45

jsp request/response timeout implementation

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;

};`

Upvotes: 0

Views: 723

Answers (1)

developerwjk
developerwjk

Reputation: 8659

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.

Upvotes: 0

Related Questions