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