【发布时间】:2017-03-24 13:12:55
【问题描述】:
调用 JAX-WS 端点时,如何获取 HTTP 响应代码?
在下面的示例代码中,在port.getCustomer(customerID); 调用Web 服务时可能会抛出异常,例如401 或500。
在这种情况下,如何从 HTTP 响应中获取 HTTP 状态码?
@Stateless
public class CustomerWSClient {
@WebServiceRef(wsdlLocation = "/customer.wsdl")
private CustomerService service;
public void getCustomer(Integer customerID) throws Exception {
Customer port = service.getCustomerPort();
port.getCustomer(customerID); // how to get HTTP status
}
}
【问题讨论】:
-
您是否尝试过捕获异常?