Java Jaxb2 中没有来自 SOAP 调用的数据

No data from SOAP call in Java Jaxb2

我解组了我的 wsdl,并将生成的源放在包下: generated.person

编组器设置:

@Configuration
public class MarshalConfig {
@Bean
public Jaxb2Marshaller marshaller() {
    Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    //marshaller.setContextPath("generated.person");
    marshaller.setPackagesToScan("generated.person");
    return marshaller;
}

@Bean
public RKIClient rkiClient(Jaxb2Marshaller marshaller) {
    RKIClient client = new RKIClient();
    client.setDefaultUri("https://uat.ws2.rki.dk/person.asmx");
    client.setMarshaller(marshaller);
    client.setUnmarshaller(marshaller);
    return client;
}

}

我的 spring 引导调用:

public SoegPersonCprResponse getPersonWithCPR(String cpr) {
    String retVal = "";
    SoegPersonCpr request = new SoegPersonCpr();
    request.setBrugernavn(RKIClient.RKI_USERNAME);
    request.setPassword(RKIClient.RKI_PASSWORD);
    request.setCPRnummer(cpr);
    SoegPersonCprResponse response = (SoegPersonCprResponse) getWebServiceTemplate()
            .marshalSendAndReceive("https://uat.ws2.rki.dk/person.asmx",
                    request,
                    new SoapActionCallback("http://webservices.rki.dk/SoegPersonCpr"));

    return response;
}

呼叫的响应是:(JSON 由于网络服务中的@responsebody)

"soegPersonCprResult": {
"error": null,
"person": null,
"adresser": null
}

但是当我在 SOAPui 中输入相同的数据时,我得到以下返回:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <SoegPersonCprResponse xmlns="http://webservices.rki.dk/">
         <SoegPersonCprResult>
            <Error xsi:type="XmlErrorOk" xmlns="http://webservices.rki.dk">
               <Code>0</Code>
               <Text>Ok</Text>
            </Error>
            <Person stamkortNr="3940982" xmlns="http://webservices.rki.dk">
               <Navnedata xsi:type="PersonNavnData" beskyttet="N">
                  <Fornavne>REAL LIFE NAME</Fornavne>
                  <Efternavn>LAST NAME</Efternavn>
               </Navnedata>
               <Adresse udenlandsk="N" beskyttet="N" VejNr="1671">
                  <PostDistrikt>
                     <Navn>ADRESS</Navn>
                     <PostNr>7777</PostNr>
                  </PostDistrikt>
                  <Kommune>
                     <Kode>766</Kode>
                  </Kommune>
                  <HusNr fraNr="5"/>
                  <Vej>wildroad</Vej>
                  <Dato>27082012</Dato>
               </Adresse>
               <Foedselsdato>15111996</Foedselsdato>
               <CprStatus>AKT</CprStatus>
               <Kreditadvarsel AendretDato="23032017">J</Kreditadvarsel>
            </Person>
            <Adresser xmlns="http://webservices.rki.dk">
               <StatusKode>1</StatusKode>
               <CodeMoniker>EksaktSvar</CodeMoniker>
            </Adresser>
         </SoegPersonCprResult>
      </SoegPersonCprResponse>
   </soap:Body>
</soap:Envelope>

配置:

String uri = "https://uat.ws2.rki.dk/person.asmx";

Jaxb2Marshaller jaxb2 = new Jaxb2Marshaller();
jaxb2.setContextPath(request.getClass().getPackage().getName());
WebServiceTemplate ws = getWebServiceTemplate();
ws.setMarshaller(jaxb2);
ws.setUnmarshaller(jaxb2);

以及带有调用本身的拦截器:

    try {

        final StringBuffer sb = new StringBuffer();

        ClientInterceptor clientInterceptor = new ClientInterceptor() {

            @Override
            public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
                WebServiceMessage message = messageContext.getResponse();
                ByteArrayOutputStream bytArrayOutputStream = new ByteArrayOutputStream();
                try {
                    message.writeTo(bytArrayOutputStream);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                String test = new String(bytArrayOutputStream.toByteArray());
                sb.append(test);
                // System.out.println(test);
                return true;
            }

            @Override
            public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
                // TODO Auto-generated method stub
                return true;
            }

            @Override
            public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
                // TODO Auto-generated method stub
                return true;
            }
        };
        ClientInterceptor[] interceptors = interceptors = new ClientInterceptor[1];
        interceptors[0] = clientInterceptor;
        ws.setInterceptors(interceptors);
        final StringBuffer sbuffer = new StringBuffer();                   

        SoegPersonCprResponse response =  (SoegPersonCprResponse) ws.marshalSendAndReceive(uri, request,
            new WebServiceMessageCallback() {
                @Override
                public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    message.writeTo(os);
                    sbuffer.append(new String(os.toByteArray()));
                }
            });
     } catch (Exception e) {
        throw e;
     }

PS:当从类型 SoegPersonCprResponse 或其他从 Jaxb 生成的对象创建对象时,我建议使用 ObjectFactory