xmlrootelement xmlaccessortype tutorial sirve que para marshaller español ejemplo java spring jaxb spring-ws endpoint

java - xmlaccessortype - ¿Cómo configurar Spring-WS para usar JAXB Marshaller?



jaxb tutorial español (1)

Recomendaría hacerlo de esta manera, que es un poco más estándar basado en el último Spring-WS:

Use el espacio de nombres oxm para definir su marsaller:

<oxm:jaxb2-marshaller id="marshaller" > <oxm:class-to-be-bound name="...Your XMlRootElements.."/> <oxm:class-to-be-bound name="more.."/> </oxm:jaxb2-marshaller>

O especifica el contextoPath:

<oxm:jaxb2-marshaller id="marshaller" contextPath="au.test.weather.ws"/>

Quite la referencia a GenericMarshallingMethodEndpointAdapter y PayloadRootAnnotationMethodEndpointMapping , reemplace ambos en su lugar con el espacio de nombre sws :

<sws:annotation-driven />

O especifique explícitamente el marshaller / unmarshaller:

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

Con estos si su punto final se define con la anotación @EndPoint, en esta línea:

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

Simplemente debería funcionar. Además, si su clase MyRequest tiene una anotación @XmlRootElement , ni siquiera necesita especificar el @XmlRootElement marshaller, se resolverá automáticamente utilizando un MethodArgumentResolver .

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

Gracias por su ayuda en esto hasta ahora, estoy actualizando la pregunta ya que no mostré todo lo que necesitaba, con los cambios recomendados. la salida de jabón todavía no es lo que yo quería.

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>

cómo se ven mis clases anotadas

@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; } }

Punto final

@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); } }

la prueba

@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)); } }

y esta prueba pasa, por lo que debe ser correcta, sin embargo, la salida de jabón agrega el prefijo 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>]

¿Dónde se agrega este espacio de nombres?