【问题标题】:Apache CXF how to remove namespace from root elementApache CXF 如何从根元素中删除命名空间
【发布时间】:2017-10-13 13:32:41
【问题描述】:

我正在使用 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;
    }
}

【问题讨论】:

    标签: java apache web-services jaxb cxf


    【解决方案1】:

    我已经解决了...使用 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>
    

    【讨论】:

      【解决方案2】:

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

      我所做的是将CXF XSLT Interceptor 与仿照https://stackoverflow.com/a/16366984/5971497 的样式表结合起来

      【讨论】:

        猜你喜欢
        • 2019-10-01
        • 2011-01-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-29
        相关资源
        最近更新 更多