Search code examples
javaweb-serviceshttpjax-wsresponse

Get HTTP response code from JAX-WS asynchronous web service


I have an asynchronous JAX-WS web service (@WebService and @WebMethod annotations). I am invoking it in Java. and I would like to know how to get HTTP response code from that service in Java code.


Solution

  • I couldn't find anything on that subject, but I deduced solution based on how my request context is built, because I needed response context so I thought they may be similar. Request context:

    ((BindingProvider)port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint)

    So I thought that this may work:

    int responseCode = (int)((BindingProvider) port).getResponseContext().get(MessageContext.HTTP_RESPONSE_CODE);

    And it works. ; )