【问题标题】:spring-ws jdom wrong responsespring-ws jdom 错误响应
【发布时间】:2014-02-14 14:47:09
【问题描述】:

我正在努力使用 Spring-WS,与 JDOM 一起使用。

代码:

    @Endpoint
    @Namespace(uri = "http://example.pl/gb/schemas", prefix = "gb")
    public class PdfCheckStatusEndPoint {
        private static final String NAMESPACE_URI = "http://example.pl/gb/schemas";

        ...    


        @PayloadRoot(namespace = NAMESPACE_URI, localPart = "PdfStatusRequest")
        @Namespace(uri = NAMESPACE_URI, prefix = "sch")
        @ResponsePayload
        public Element getPdfStatus(@XPathParam("//sch:policyNr") String policyNr) {

              org.jdom2.Namespace javaxml2Namespace = org.jdom2.Namespace.getNamespace("http://example.pl/gb/schemas");
              Element responseElement = new Element("PersonResponse", javaxml2Namespace);
              Element childElement1 = new Element("FullName");
              childElement1.setText("john doe");

              Element childElement2 = new Element("SSN");
              childElement2.setText("12345");

              responseElement.addContent(childElement1);
              responseElement.addContent(childElement2);
              return responseElement;
        }
    }

端点自行工作,但响应与预期不同:

  <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
     <env:Header/>
     <env:Body>
        <PersonResponse xmlns="http://example.pl/gb/schemas"/>
     </env:Body>
  </env:Envelope>

如您所见,没有返回子元素,只返回根元素。有什么想法吗?

【问题讨论】:

  • 您上面的代码看起来不错......方法之外还有其他事情发生。您可以在返回语句中调试该方法吗?然后跟随 XML 回到它的输出位置?
  • 第二条评论,childElements 应该在 NO-namespace 还是命名空间 http://example.pl/gb/schemas
  • 感谢您的意见,我提供了解决方案作为答案。

标签: java web-services spring-ws jdom jdom-2


【解决方案1】:

好像添加了这个依赖:

    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.3.3</version>
    </dependency>

连同bean定义:

<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
    <property name="messageFactory">
        <bean class="com.sun.xml.messaging.saaj.soap.ver1_1.SOAPMessageFactory1_1Impl"/>
    </property>
</bean>

做的工作。

【讨论】:

    猜你喜欢
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多