How to get JAX-WS response HTTP status code

前端 未结 2 2021
傲寒
傲寒 2021-01-21 22:56

When calling a JAX-WS endpoint, how can I get the HTTP response code?

In the sample code bellow, when calling the web service at port.getCustomer(customerID);

相关标签:
2条回答
  • 2021-01-21 23:19

    Completing @Praveen answer, you have to turn the port into a raw BindingProvider and then get the values from the context.

    Don't forget that transaction will be marked for rollback if an exception occours in your managed web service client.

    @Stateless
    public class CustomerWSClient {
    
        @WebServiceRef(wsdlLocation = "/customer.wsdl")
        private CustomerService service;
    
        public void getCustomer(Integer customerID) throws Exception {
            Customer port = service.getCustomerPort();
            try {
                port.getCustomer(customerID);  
            } catch(Exception e) {
                throw e;
            } finally {
                // Get the HTTP code here!
                int responseCode = (Integer)((BindingProvider) port).getResponseContext().get(MessageContext.HTTP_RESPONSE_CODE);
            }
        }
    
    }
    
    0 讨论(0)
  • 2021-01-21 23:24

    The below post is similar to your question. Hopefully it should work for you

    https://stackoverflow.com/a/35914837/4896191

    0 讨论(0)
提交回复
热议问题