2011-04-22 6 views
3

현재 JAXB 및 웹 서비스를 배우고 있으며이 문제는 해결 방법을 알고 있습니다.JAXB에서 SOAP 특성 만들기

JAXB로 주석을 작성한 매우 간단한 클래스가 있다고 가정합니다.

@XmlRootElement 
public class Customer { 
    private int custID; 
    private String custName; 
    //getters and setters 
} 

그리고이 클래스는 웹 서비스로 공개됩니다. 비누 봉투 응답은 다음과 같이이다

@WebService 
public class CustomerWS { 

    @WebMethod(operationName = "customerData") 
    public Customer getCustomer(){ 
     Customer cust = new Customer(); 
     cust.setCustID(12345); 
     cust.setCustName("John Doe");  
     return cust; 
    } 
} 

: (I 단순 여기 모든 하드 코딩하지만이 DB에 연결 참고).

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <ns2:customerDataResponse xmlns:ns2="http://test.com/"> 
     <return> 
      <custID>12345</custID> 
      <custName>John Doe</custName> 
     </return> 
     </ns2:customerDataResponse> 
    </S:Body> 
</S:Envelope> 

은 이제 고객 개체라는 상태에서 다른 속성을 가지고 있고 아래 대신 고객의 요소의 일부가되는처럼되고 비누 응답 속성으로이 속성을 원하는 가정합니다. (A = 활성, I = 비활성)

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <ns2:customerDataResponse status="A" xmlns:ns2="http://test.com/"> 
     <return> 
      <custID>12345</custID> 
      <custName>John Doe</custName> 
     </return> 
     </ns2:customerDataResponse> 
    </S:Body> 
</S:Envelope> 

@XmlRootElement 
public class Customer { 
    private int custID; 
    private String custName; 

    //Another Annotation??? (A or I only) 
    private String status; 
    //getters and setters 
} 

이 요구 사항을 충족시키기 위해 수업에 주석을 달려면 어떻게해야합니까? 감사합니다

답변

4

고객 클래스에 주석이 달린 모든 것은 고객 요소에 상대적입니다.

JAX-WS가 메시지 봉투를 작성하고 JAXB가이 봉투에 메시지 본문을 정렬하기 때문입니다. JAXB가 시체를 마샬링 할 시간이되면 엔벨로프를 변경하기에는 너무 늦습니다.

+0

답변 해 주셔서 감사합니다. 내가 원하는 것을 할 수 있도록 대안이나 해결 방법이 있습니까? 또한, 엔티티의 일부가 아니더라도 엔벨로프에 어떤 속성을 하드 코딩 할 수있는 방법이 있습니까? –