【问题标题】:Slow initialization of apache cxf clientapache cxf客户端初始化缓慢
【发布时间】:2012-10-31 02:23:18
【问题描述】:

我正在使用 wsdl2java 生成的类和这段代码:

MyService f = new MyService();
MyServicePortType type = f.getMyServicePortType();

每个调用最多需要 30 秒。这是为什么呢?

【问题讨论】:

    标签: java apache soap cxf


    【解决方案1】:

    经过数小时的谷歌搜索和修补,问题在于如何引用方案文件: 尽管 WSDL 和 XSD 存储在本地,但仍然有一些引用到 w3.org,如下所示:

    <!DOCTYPE schema PUBLIC "-//W3C//DTD XMLSchema 200102//EN" "http://www.w3.org/2001/XMLSchema.dtd" [...
    
    <import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd" />
    

    w3.org 服务器响应速度超慢,因此我的客户端初始化缓慢。

    我已将引用更改为本地:

    <import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="xmldsig-core-schema.xsd" />
    

    【讨论】:

      【解决方案2】:

      我欠你一大笔债,因为我已经为此苦苦挣扎了好几天,而你的回答为我指明了正确的方向。

      确实 w3.org URL 需要很长时间才能响应,但是实际上没有理由说明从 WSDL 生成的 SOAP 客户端仍然需要在运行时解析 WSDL。

      事实上并没有,但是默认生成的委托人会强制这样做。

      我发现可以通过以不同方式实例化服务端口并通过请求上下文指定服务端点来跳过此操作,如下所示:

      // creating the service this way passes null as the wsdlLocation, preventing the runtime resolution and parsing of the wsdl
      Service service =  ZefixService.create(ZefixService.SERVICE);
      
      ZefixServicePortType zefixServicePort = service.getPort(ZefixServicePortType.class);
      
      
      Map<String, Object> requestContext = ((BindingProvider) zefixServicePort).getRequestContext();
      // because we create the service without the wsdl location, we need to specify the service base url ourselves
      requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, Configuration.get(Constants.API_BASE_URI_PROPERTY));
      requestContext.put(BindingProvider.USERNAME_PROPERTY, Configuration.get(Constants.USER_PROPERTY));
      requestContext.put(BindingProvider.PASSWORD_PROPERTY, Configuration.get(Constants.PASSWORD_PROPERTY));
      
      return zefixServicePort;
      

      我希望这对您和其他人将来有用。

      再次感谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-12-12
        • 2017-06-13
        • 1970-01-01
        • 2017-02-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多