如何配置Spring-WS以使用JAXB Marshaller?

到目前为止,谢谢你的帮助,我正在更新问题,因为我没有显示我需要的所有内容,显示更改建议。 肥皂产量仍然不是我想要的。

servlet.xml中

              

我的注释类看起来像什么

 @XmlRootElement(name = "GetTemperaturesRequest") public class GetTemperaturesRequest { @XmlElement(required = true) protected String city; @XmlElement(required = true) @XmlSchemaType(name = "date") protected List date; public String getCity() { return city; } public void setCity(String value) { this.city = value; } public List getDate() { if (date == null) { date = new ArrayList(); } return this.date; } public void setDates(List dates) { this.date = dates; } } 

端点

 @Endpoint public class TemperatureMarshallingEndpoint { private static final String namespaceUri = "http://test.au/schema/weather"; public static final String request_local_name = "GetTemperaturesRequest"; private WeatherService weatherService; public void setWeatherService(WeatherService weatherService) { this.weatherService = weatherService; } @PayloadRoot(localPart = request_local_name, namespace = namespaceUri) @ResponsePayload public GetTemperaturesResponse getTemperature(@RequestPayload GetTemperaturesRequest request) throws JAXBException { List temperatures = weatherService.getTemperatures(request.getCity(), request.getDate()); return new GetTemperaturesResponse(temperatures); } } 

考试

 @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:servlet.xml"}) public class testOther { @Autowired private ApplicationContext applicationContext; private MockWebServiceClient mockClient; @Before public void createClient() { mockClient = MockWebServiceClient.createClient(applicationContext); } @Test public void TemperatureMarshallingEndpoint() throws Exception { Source requestPayload = new StringSource( "" + "Houston" + "2007-12-01" + ""); Source responsePayload = new StringSource( "" + "5.010.08.0" + ""); mockClient.sendRequest(withPayload(requestPayload)). andExpect(payload(responsePayload)); } } 

并且这个测试通过所以它必须正确但肥皂输出添加NS2前缀

 DEBUG: org.springframework.ws.server.MessageTracing.sent - Sent response [    5.0 10.0 8.0  ] for request [   Houston 2007-12-01 ] 

这个命名空间在哪里添加?

我建议这样做,这是基于最新的Spring-WS更加标准:

使用oxm命名空间来定义你的marhsaller:

     

或者指定contextPath:

  

删除对GenericMarshallingMethodEndpointAdapterPayloadRootAnnotationMethodEndpointMapping 引用 ,用PayloadRootAnnotationMethodEndpointMapping命名空间替换它们:

  

或者显式指定marshaller / unmarshaller:

  

如果使用@EndPoint annotaion定义了端点,请按以下方式进行:

 @Endpoint public class MyEndPoint{ @PayloadRoot(namespace = "myns", localPart = "rootelement") @ResponsePayload public MyResponse myMethod(@RequestPayload MyRequest request) 

它应该工作。 此外,如果您的@XmlRootElement类具有@XmlRootElement注释,您甚至不需要指定编组器,它将使用内置的MethodArgumentResolver自动MethodArgumentResolver

参考: http : //static.springsource.org/spring-ws/sites/2.0/reference/html/server.html#server-endpoints

Interesting Posts