Apache CXF 如何从根元素中删除命名空间

Apache CXF how to remove namespace from root element

我正在使用 Apache CXF 公开 Web 服务。看来,JAXB 在我的根元素上自动添加了 targetNameSpace。有没有办法删除名称空间前缀 "les:" 根据我的要求 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 对于相同的请求:

<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>

我的情况略有不同,我想从直接位于 soap:Body 下的元素中删除 xmlns 属性,并将其移动到其子元素。

我所做的是结合 CXF XSLT Interceptor with a stylesheet modeled after