Get HTTP response code from JAX-WS asynchronous we

2019-06-08 22:32发布

问题:

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.

回答1:

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. ; )