Apache CXF如何从根元素中删除名称空间
问题描述:
我正在使用Apache CXF来公开Web服务。看来,JAXB会在我的根元素上自动添加targetNameSpace。有没有办法从我的请求XML中删除命名空间前缀 “les:”?Apache CXF如何从根元素中删除名称空间
<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对于相同的请求:
<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代码来处理请求:
@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;
}
}
答
我知道了解决......下面在CXF-servlet.xml中的配置,客户端不必在请求xml中添加名称空间。它会将名称空间注入到所需的标记中。
<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>