I am using Apache CXF to expose a web service. It seems, JAXB adds automatically targetNameSpace on my root element. Is there a way to remove namespace prefix "les:" from my request XML?
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:les="http://LEServicios">
<soapenv:Header/>
<soapenv:Body>
<les:consultaRegistrosAltaRespRequest>
<id_consulta>16197586</id_consulta>
<numero_administrativo>?</numero_administrativo>
<rechazo>
<codigo>?</codigo>
<descripcion>?</descripcion>
</rechazo>
<registros_alta>
<fecha>?</fecha>
<velocidad_sincronismo_bajada>?</velocidad_sincronismo_bajada>
<velocidad_sincronismo_subida>?</velocidad_sincronismo_subida>
<atenuacion_subida>?</atenuacion_subida>
<potencia_recibida_ONT>?</potencia_recibida_ONT>
<potencia_transmitida_ONT>?</potencia_transmitida_ONT>
</registros_alta>
</les:consultaRegistrosAltaRespRequest>
</soapenv:Body>
</soapenv:Envelope>
XSD for same request:
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:tns="http://LEServicios" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
name="Servicios" targetNamespace="http://LEServicios">
<wsdl:types>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="consultaRegistrosAltaRespResponse">
<xsd:complexType>
<xsd:annotation>
<xsd:documentation>Objeto utilizado para indicar la aceptación ante el envío de una respuesta.</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:element name="id_consulta" type="xsd:string" minOccurs="1">
<xsd:annotation>
<xsd:documentation>Identificador generado por Telefonica para correlar peticiones y respuestas.</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
Java code to handle the request:
@WebService(endpointInterface = "leservicios.ConsultaRegistrosAltaRespuesta",targetNamespace = "http://LEServicios")
public class ConsultaRegistrosAlta implements leservicios.ConsultaRegistrosAltaRespuesta {
@Override
public ConsultaRegistrosAltaRespResponse consultaRegistrosAltaRespuesta(ConsultaRegistrosAltaRespRequest consultaRegistrosAltaRespRequest) {
String pfx = "consultaRegistrosAltaRespuesta method: ";
logger.info(pfx+"received request :");
String ackId = consultaRegistrosAltaRespRequest.getIdConsulta();
ConsultaRegistrosAltaRespResponse ack = new ConsultaRegistrosAltaRespResponse();
ack.setIdConsulta(ackId);
return ack;
}
}
I got it resolved... With below configuration in cxf-servlet.xml, client does not have to add namespace in request xml. It will inject namespace to required tag.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml"/>
<import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>
<jaxws:endpoint id="consultaRegistrosAltaRespuesta" address="/ConsultaRegistrosAltaRespuesta" implementor="motive.ws.esb.ConsultaRegistrosAlta">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
<bean id="transformFeature" class="org.apache.cxf.feature.StaxTransformFeature">
<property name="inTransformElements">
<map>
<entry key="consultaRegistrosAltaRespRequest" value="{http://LEServicios}consultaRegistrosAltaRespRequest" />
</map>
</property>
</bean>
</jaxws:features>
</jaxws:endpoint>
</beans>