java - Apache CXF 如何从根元素中删除 namespace

标签 java apache web-services jaxb cxf

我正在使用 Apache CXF 公开 Web 服务。看来,JAXB 自动在我的根元素上添加 targetNameSpace。有没有办法删除命名空间前缀 “les:”来 self 的请求 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 中添加 namespace 。它将注入(inject) namespace 到所需的标签。

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

关于java - Apache CXF 如何从根元素中删除 namespace ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46731206/

相关文章:

php - 如何仅在服务器调用 PHP 脚本时运行它

java - 在 C++ 中使同步调用异步

java - Spring bean java.lang.NoSuchMethodError 错误

java - 根据 JSON 请求正文中的另一个属性反序列化抽象属性

java - 使用 Boolean.FALSE/.TRUE 初始化 boolean 值 - 为什么?

python - 从apache cgi python接收http post请求的xml内容

asp.net - 将静态内容与 Web 服务托管在不同的域上,如何避免跨域?

java - Spring JDBC 调试日志未显示在控制台上

java - OOPS概念调用父类而不是子类的函数

ruby-on-rails - Phusion Passenger 不显示 CSS、Javascript 文件