繁体   English   中英

apache cxf 客户端初始化缓慢

[英]Slow initialization of apache cxf client

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

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

这些调用中的每一个都需要长达 30 秒。 这是为什么?

经过数小时的谷歌搜索和修补,问题在于如何引用方案文件:尽管 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" />

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

确实 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;

我希望这在未来对你和其他人有用。

再次感谢

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM