2016-11-07 4 views
0

wsimport을 사용하여 클라이언트 코드를 생성하는 WSDL 사양이 있습니다. (내가 전에 여러 번 해왔 던 것처럼).SOAP, JAXB 정렬 동작

지금 XSD의 유형 중 하나

<xs:complexType name="Credential"> 
    <xs:sequence> 
    <xs:element minOccurs="0" name="UID" nillable="true" type="xs:string"/> 
    <xs:element minOccurs="0" name="UIDBranch" nillable="true" type="xs:string"/> 
    <xs:element minOccurs="0" name="PWD" nillable="true" type="xs:string"/> 
    <xs:element minOccurs="0" name="Signature" nillable="true" type="xs:string"/> 
    </xs:sequence> 
</xs:complexType> 

그리고 해당 자바 바인딩 :

<ns2:Credentials> 
    <ns4:string>login</ns4:string> 
    <ns4:string>password</ns4:string> 
    <ns4:string>signature</ns4:string> 
</ns2:Credentials> 
:
@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "Credential", namespace = "http://schemas.datacontract.org/2004/07/...", propOrder = { 
    "uid", 
    "uidBranch", 
    "pwd", 
    "signature" 
}) 
public class Credential { 

    @XmlElementRef(name = "UID", namespace = "http://schemas.datacontract.org/2004/07/...", type = JAXBElement.class, required = false) 
    protected JAXBElement<String> uid; 
    @XmlElementRef(name = "UIDBranch", namespace = "http://schemas.datacontract.org/2004/07/...", type = JAXBElement.class, required = false) 
    protected JAXBElement<String> uidBranch; 
    @XmlElementRef(name = "PWD", namespace = "http://schemas.datacontract.org/2004/07/...", type = JAXBElement.class, required = false) 
    protected JAXBElement<String> pwd; 
    @XmlElementRef(name = "Signature", namespace = "http://schemas.datacontract.org/2004/07/...", type = JAXBElement.class, required = false) 
    protected JAXBElement<String> signature; 

    ... the rest: getters/setters 

요청에 이러한 유형의 요소가 같이 일어나는

그러나 형식 안에있는 요소의 이름이 손실되면 위의 조각은 다음과 같아야합니다.

<ns2:Credentials>                
    <ns4:UID>login</ns4:UID>                
    <ns4:PWD>password</ns4:PWD>                
    <ns4:Signature>signature</ns4:Signature> 
</ns2:Credentials> 

왜 클라이언트가 올바른 방식으로 작동하도록 할 수 있습니까?

업데이트 자격 증명 (ofObjectFactory이다)이 같은 개체가 만들어집니다 : 당신이 of.createString(login)을 사용하기 때문에

Credential cr = of.createCredential() 
cr.setUID(of.createString(login)) 
cr.setPWD(of.createString(password)) 
cr.setSignature(of.createString(sign)) 
+0

어떻게 'Credentials' 객체를 구성합니까? – lexicore

+0

@lexicore 질문에서 업데이트 됨 – dmitry

답변

1

당신은

<ns4:string>login</ns4:string> 

를 얻을. ns4:UID을 원하면 of.createUID(...)과 같은 것을 사용하십시오.

문제는 JAXBElement<String>은 문자열 값 (예 : 로그인)뿐 아니라 요소 이름 (각각 getValue()getName())을가집니다. 이 이름은 XML 요소의 이름을 제공합니다. wsimport/xjc에 의해 생성 된 ObjectFactory은 일반적으로 이러한 인스턴스를 생성하는 메소드를 포함합니다. 이 createFoo -method는 입력 값을 받아 해당 XML 이름과 함께 JAXBElement으로 줄 바꿈합니다. 따라서 createString을 사용하면 실제로 요소 이름으로 string을 원한다고합니다. (createString)은 값 유형이 아닌 요소 이름입니다.

그래서 ObjectFactory도 있어야한다 방법 등 createUID, createPWD, createSignature처럼 대신 createString의 이러한 방법을 사용합니다.

그런데 실제로 디버깅 해 보셨습니까? ObjectFactory의 소스 코드를 살펴 본다면 그 모든 이야기를 피할 수 있습니다.

+0

만세, 고마워요! – dmitry