これまでのところ、ご協力いただきありがとうございます。必要なすべてを表示していないため、推奨される変更を示して質問を更新しています。石鹸の出力はまだ私が望んでいたものではありません。
サーブレット.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));
}
}
このテストはパスするので正しいに違いありませんが、soap の出力には 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>]
この名前空間はどこに追加されますか?