Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: added imports, fix code bug

...

First, declare a private field for the WebServiceContext in your service implementation, and annotate it as a resource:

...

Then, within your implementing methods, you can access the MessageContext, HttpServletRequest, and HttpServletResponse as follows:

Code Block
java
java
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.handler.MessageContext;
import org.apache.cxf.transport.http.AbstractHTTPDestination;
...

MessageContext ctx = context.getMessageContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
HttpServletRequestHttpServletResponse response = (HttpServletResponse) ctx.get(AbstractHTTPDestination.HTTP_RESPONSE);

...