File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Web services in Glassfish and HTTP status codes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web services in Glassfish and HTTP status codes" Watch "Web services in Glassfish and HTTP status codes" New topic

Web services in Glassfish and HTTP status codes

Wenceslaus Mumala

Joined: Jun 20, 2009
Posts: 3

I have a web service deployed in glassfish. I have a few methods that are return void.
When a client requests any of these void operations, glassfish returns HTTP 202 to the client.

I would like to return HTTP 204 to the client instead of HTTP 202. (Unfortunately) glassfish sends HTTP 202 before the method is called and i have been left wondering how/where i can fix this.

I would appreciate any tips.

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
Returning a status code 202 means that the request was accepted for processing, which is the semantics prescribed by the JAX-WS 2.1 specification:
From section 11.3.1 on One-Way Operations:
Note that completion of the HTTP request simply means that the transmission of the request is complete,
not that the request was accepted or processed.

A method in a web service endpoint implementation class that has the return type void, does not throw any checked exceptions and have no parameters that implements the Holder interface will become a one-way operation (section 3.5.1 JAX-WS 2.1 specification).
Thus, as far as I understand, the simplest way would be for you to declare that the method throws a checked exception or add a parameter that implements the Holder interface. This way, your web service operation should become a request-response operation and the response code should become 200.
Best wishes!
Wenceslaus Mumala

Joined: Jun 20, 2009
Posts: 3
Thanks Ivan for your reply,

I must say I am a bit new to web services.

The thing is that i am expected to return an HTTP 204 whenever the web method returns a void.
I have experimented with a request-response operation by removing the @Oneway annotation on the method but glassfish sends an empty soap envelope with a status of 200.

I have a soaphandler where i tried to force the SoapMessage on the SoapMessageContext to null and tried to force the status to 204 but glassfish wouldnt listen.


Wenceslaus Mumala

Joined: Jun 20, 2009
Posts: 3
I sorted out the problem, my solution is below:

I removed the @Oneway annotation so that i now have a request/response operation.
I added the following code to the operations affected.

msgContext.put(MessageContext.HTTP_RESPONSE_CODE, new Integer(

where msgContext is of type MessageContext.
In my soaphandler, i also set context.setMessage(null).
Consider Paul's rocket mass heater.
subject: Web services in Glassfish and HTTP status codes
Similar Threads
GlassFish ESB
Tomcat or Glassfish?
web service client's frameworks handling of empty responces from web service
Return Complex Type (GlassFish v2 and .Net 3.5 client)
unable to find valid certification path to requested target