spring-ws jaxb pojo字段没有填充/ umarshalled

时间:2013-10-04 19:09:04

标签: java xml spring web-services jaxb

This post is the closest one to my problem。但是,没有解释问题如何解决或者问题是什么。

我尝试过一种非常基本的配置来消除任何潜在的问题。

我的spring-ws-context.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:sws="http://www.springframework.org/schema/web-services"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
      http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
      http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
      http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.2.xsd">
<context:component-scan base-package="test" />

<sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller" />

<sws:dynamic-wsdl id="person" portTypeName="Person"
    locationUri="/personService/" targetNamespace="http://myschema/person/definitions">
    <sws:xsd location="classpath:person.xsd" />
</sws:dynamic-wsdl>
<sws:interceptors>
    <bean
        class="org.springframework.ws.soap.server.endpoint.interceptor.SoapEnvelopeLoggingInterceptor">
        <property name="logRequest" value="true"></property>
        <property name="logResponse" value="true"></property>
    </bean>
</sws:interceptors>

<oxm:jaxb2-marshaller id="marshaller">
    <oxm:class-to-be-bound name="test.request.GetPersonRequest" />
</oxm:jaxb2-marshaller>

我的GetPersonRequest.java就是这个

@XmlRootElement(name = "GetPersonRequest", namespace = PersonEndpoint.NAMESPACE_URI)
@XmlAccessorType(XmlAccessType.FIELD)
public class GetPersonRequest {
    @XmlElement
    private Integer id;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

}

我的终点就是这样:

@Endpoint
public class PersonEndpoint {

    public static final String NAMESPACE_URI = "http://myschema/person/schemas";

    @Autowired
    PersonService service;

    @PayloadRoot(namespace = NAMESPACE_URI, localPart="GetPersonRequest")
    public @ResponsePayload GetPersonResponse handleGetPersonRequest(@RequestPayload Element request) {
        System.out.println("handleGetPersonRequest()");
        // TODO: Go to service.getPerson(request)
        return new GetPersonResponse();
    }
}

我想要注意的是,整个服务运行良好且没有错误。到目前为止这是可以的(按照上面的说明):

1)端点可以将wsdl显示给soapui和浏览器。

2)soap xml可以提交,没有错误。

3)日志文件显示正在发送xml正文。

但是对于我的生活@RequestPayload GetPersonRequest请求是空白的!它只有一个chrissakes字段,它甚至不会被设置!

现在,如果我不使用JAXB作为请求对象,而是使用org.w3c.dom.Element,我可以看到我提交的所有数据都在那里。

我错过了什么?我不禁想到我错过了一些简单的东西。

这是样本输入(至少是日志显示的内容):

  <sch1:GetPersonRequest xmlns:sch1="http://myschema/person/schemas">
     <sch1:id>1</sch1:id>
  </sch1:GetPersonRequest>

1 个答案:

答案 0 :(得分:0)

我无法找到更好的解决方案。到目前为止,我能想出的唯一答案是使用package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = test.ws.PersonEndpoint.NAMESPACE_URI, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package test.request;

我的旧项目没有使用spring和spring要求xsd文件具有targetNamespace属性。我想通过目前使用命名空间来简化我当前的应用程序,但它似乎不适用于spring-ws。