2017-03-24 2 views
1

JAX-WS 엔드 포인트를 호출 할 때 HTTP 응답 코드는 어떻게 얻을 수 있습니까?JAX-WS 응답을 얻는 방법 HTTP 상태 코드

아래 예제 코드에서 웹 서비스를 port.getCustomer(customerID);으로 호출하면 401 또는 500과 같이 예외가 throw 될 수 있습니다.

그런 경우 어떻게 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   
    } 

} 
+0

예외를 캡처하려고 시도 했습니까? – efekctive

답변

1

이 @Praveen 대답을 완료하기위한 희망이 작동합니다, 당신은 원시 BindingProviderport을 설정 한 다음 컨텍스트에서 값을 얻을 수 있습니다.

관리되는 웹 서비스 클라이언트에서 예외가 발생할 경우 트랜잭션이 롤백으로 표시된다는 것을 잊지 마십시오.

@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); 
     } 
    } 

} 
1

아래의 게시물은 귀하의 질문과 유사합니다. 당신

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

+0

완벽하게 작동합니다. 검색을 많이 한 후에 어떻게 작동하지 않았는지 확실하지 않습니다. JAX-WS는 내가 생각한 것만 큼 많이 알지 못한다. – BonanzaOne