• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web services in Glassfish and HTTP status codes

 
Wenceslaus Mumala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

/Wency
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
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
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

/wency

 
Wenceslaus Mumala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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(
HttpServletResponse.SC_NO_CONTENT));

where msgContext is of type MessageContext.
In my soaphandler, i also set context.setMessage(null).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic