Как настроить Spring -WS для использования JAXB Marshaller?

Спасибо за помощь в этом вопросе, я обновляю вопрос, так как я не показал все, что мне нужно, с показанными рекомендованными изменениями. выход мыла все еще не то, что я хотел.

servlet.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:p="http://www.springframework.org/schema/p"
    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.0.xsd"
                        >

<!--Enables @Endpoint and related Spring-WS annotations.-->
<sws:annotation-driven marshaller="marshaller" unmarshaller="marshaller"/> 

<bean id="weatherService"
    class="au.test.weather.ws.WeatherServiceImpl" />

<bean id="schema" class="org.springframework.xml.xsd.SimpleXsdSchema" 
    p:xsd = "classpath:au/test/weather/ws/schemas/Temperature.xsd"/>

<oxm:jaxb2-marshaller id="marshaller" >
    <oxm:class-to-be-bound name="au.test.weather.ws.GetTemperaturesResponse"/> 
    <oxm:class-to-be-bound name="au.test.weather.ws.GetTemperaturesRequest"/>
    <oxm:class-to-be-bound name="au.test.weather.ws.schemas.Jaxb2Marshaller"/>  
</oxm:jaxb2-marshaller> 

<bean id="temperatureEndpoint"
    class="au.test.weather.ws.TemperatureMarshallingEndpoint">
    <property name="weatherService" ref="weatherService" />
</bean>

как выглядят мои аннотированные классы

@XmlRootElement(name = "GetTemperaturesRequest")
public class GetTemperaturesRequest {

    @XmlElement(required = true)
    protected String city;
    @XmlElement(required = true)
    @XmlSchemaType(name = "date")
    protected List<XMLGregorianCalendar> date;

    public String getCity() {
        return city;
    }

    public void setCity(String value) {
        this.city = value;
    }

    public List<XMLGregorianCalendar> getDate() {
        if (date == null) {
            date = new ArrayList<XMLGregorianCalendar>();
        }
        return this.date;
    }

    public void setDates(List<XMLGregorianCalendar> 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<GetTemperaturesResponse.TemperatureInfo> 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( 
        "<GetTemperaturesRequest xmlns='http://test.au/schema/weather'>" +
        "<city>Houston</city>" +
        "<date>2007-12-01</date>" + 
        "</GetTemperaturesRequest>");      

        Source responsePayload = new StringSource(
        "<GetTemperaturesResponse xmlns='http://test.au/schema/weather'>" +
        "<TemperatureInfo city='Houston' date='2007-12-01'><min>5.0</min><max>10.0</max><average>8.0</average></TemperatureInfo>" +
        "</GetTemperaturesResponse>");

        mockClient.sendRequest(withPayload(requestPayload)).  
        andExpect(payload(responsePayload));  
    }
} 

и этот тест проходит, поэтому он должен быть правильным, однако выход мыла добавляет префикс NS2

DEBUG: org.springframework.ws.server.MessageTracing.sent - 
Sent response 
[<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/><SOAP-ENV:Body>
<ns2:GetTemperaturesResponse xmlns:ns2="http://test.au/schema/weather">
    <ns2:TemperatureInfo city="Houston" date="2007-12-01">
        <ns2:min>5.0</ns2:min>
        <ns2:max>10.0</ns2:max>
        <ns2:average>8.0</ns2:average>
    </ns2:TemperatureInfo>
</ns2:GetTemperaturesResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>] 
for request 
[<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/><SOAP-ENV:Body>
<GetTemperaturesRequest xmlns="http://test.au/schema/weather">
    <city>Houston</city>
    <date>2007-12-01</date></GetTemperaturesRequest>
</SOAP-ENV:Body></SOAP-ENV:Envelope>]

где это пространство имен добавляется?

7
задан Sean F 23 July 2012 в 02:49
поделиться