Skip to main content

How to set HTTP response code in a JAX-WS SOAP webservice implemented as an EJB ?

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
3 replies [Last post]
jpsl
Offline
Joined: 2006-12-28

In an old SunAS 9.1 + JAX-WS 2.1.6 + Sun JRE 1.6.0_18 (*1), I have an HTTP SOAP web-service implemented as an EJB endpoint. There is no output message, only the HTTP response headers.

When an exception occurs on the server side (and the message content is not properly processed), it returns an HTTP 202 (Accepted) status code to the WS client.

I am trying to handle the fault, and set an HTTP 500 error status code, so that the WS client will attempt to redeliver again later, but I am unable to do so.

I have tried several variations of code like:

  // @OneWay
  messageContext.put(MessageContext.HTTP_RESPONSE_CODE, new Integer(500));
  messageContext.setScope(MessageContext.HTTP_RESPONSE_CODE, MessageContext.Scope.APPLICATION);
  //throw new javax.xml.ws.http.HTTPException(500);

inside message handler's handleFault() and close() methods (and in the endpoint EJB), but to no success. (The SOAP WS client always gets an HTTP 202 status code).

Does anyone know of a working example of similar code ?

Jo

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jpsl
Offline
Joined: 2006-12-28

Am I the only one having this problem ? (Am I asking the wrong question ?)

Any other alternative tips ? (Re-write the endpoints as servlets and not EJBs ?)

(As some webservices were designed as one-way operations - without an acknowledge reply message - this seems a very important issue to fix as, as it is now, JAX-WS always signals the acceptance of some messages that cannot be processed).

Any tips appreciated...

weepy
Offline
Joined: 2012-12-16

I was trying to set http status, my endpoints are all servlets wrapped in a filter to have more control. But so far I was unsuccessful in JAXWS RI. I tried:

- dumbly, setting HttpServletResponse status after having reply generated by jaxws
- less dumbly, throwing an HTTPException (though this seems to be a logical way to go - sadly, HTTP 500 is returned with soapfault xml)

All I got was 200 or 500 in case of fault... if your client recognizes more that 2 states, i'd recommend parsing message body, there is nothing "non-one-way" on that, its just pain in the backside.

Or if you want to play more, try setting the scope to request/handler, not application, maybe its the wrong one (you don't want all of your responses have same HTTP status). Also, using servlet filter, http states can usually be resolved without passing request to the WS framework (thus being free choose the status code), like basic HTTP auth, redirection hints.. maybe 403,404, but in general, SOAP WS are very unREST and what you (correctly) want sounds a bit RESTy :).

jpsl
Offline
Joined: 2006-12-28

Thank you for the feedback.
I have moved on to another unrelated project (on another customer) but I will notify some developers on this project (in case they are still attempting to fix this issue).

Happy holidays!