Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

702
Views
Spring-Ws Eliminar el prefijo del espacio de nombres de las respuestas (ns2, ns3...)

Sé que esto se ha preguntado 100 mil veces. Pero no logro hacerlo. La respuesta siempre viene de la siguiente manera:

 <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns2:getReportResponse xmlns:ns2="http://www.example.net/myresource"> <ns2:Report>JVBE...</ns2:Report> <ns2:Messages/> </ns2:getReportResponse> </SOAP-ENV:Body>

Y quiero obtener:

 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <getReportResponse xmlns="http://www.example.net/example"> <Report>JVBE...</Report> <Messages/> </getReportResponse> </SOAP-ENV:Body>

Ya intenté configurar elementFormDefault="unqualified" sin ningún tipo de éxito (obtuve respuestas vacías cuando se hizo esto...). ¿Algunas ideas? @NameSpace(prefix="" namespace=NAMESPACE_URI) tampoco ayudó...

Gracias por adelantado.

PD. Me encantaría usar una solución Spring-WS pura, en lugar de usar cualquier tipo de marshallers, etc. de jaxb

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Me las arreglé para arreglarlo yo mismo. Aunque no obtuve una respuesta de la comunidad, me gustaría escribir la respuesta aquí para que nadie tenga que luchar con lo que tengo hoy.

No estoy seguro de si hay una manera de lograr esto directamente usando una @notation mágica de Spring. No obstante, me las arreglé para hacer esto yo mismo de la siguiente manera:

Creé un EndpointInterceptor donde implementé un posprocesador para eliminar los prefijos no deseados.

 public class GlobalEndpointInterceptor implements EndpointInterceptor { @Override public boolean handleRequest(MessageContext messageContext, Object o) throws Exception { return true; } @Override public boolean handleResponse(MessageContext messageContext, Object o) throws Exception { return true; } @Override public boolean handleFault(MessageContext messageContext, Object o) throws Exception { return false; } @Override public void afterCompletion(MessageContext messageContext, Object o, Exception e) throws Exception { try { SOAPMessage soapMessage = ((SaajSoapMessage) messageContext.getResponse()).getSaajMessage(); SOAPHeader header = soapMessage.getSOAPHeader(); SOAPBody body = soapMessage.getSOAPBody(); header.setPrefix(""); body.setPrefix(""); Iterator<SOAPBodyElement> it = body.getChildElements(); while (it.hasNext()) { SOAPBodyElement node = it.next(); node.setPrefix(""); Iterator<SOAPBodyElement> it2 = node.getChildElements(); while (it2.hasNext()) { SOAPBodyElement node2 = it2.next(); node2.setPrefix(""); Iterator<SOAPBodyElement> it3 = node2.getChildElements(); while (it3.hasNext()) { SOAPBodyElement node3 = it3.next(); node3.setPrefix(""); } } } } catch (SOAPException exx) { exx.printStackTrace(); } } }

Y luego simplemente agregó el interceptor implementado a la configuración de WS de la siguiente manera:

 @Configuration @EnableWs public class ExampleConfiguration extends WsConfigurerAdapter { @Override public void addInterceptors(List<EndpointInterceptor> interceptors) { interceptors.add(new GlobalEndpointInterceptor()); } . . . }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!