为了账号安全,请及时绑定邮箱和手机立即绑定

如何将 apache-httpclient-4.x 附加到axis2存根

如何将 apache-httpclient-4.x 附加到axis2存根

汪汪一只猫 2022-11-02 16:47:36
我的axis2 soap 客户端应用程序(非专业)有问题。我使用了axis2,因为生成的客户端开箱即用。由于政策原因,CXF 或 Metro 客户发出了很多警告。Web 服务服务器由 SAP 工具 (oslt) 生成。由于很短的时间,当应用程序从我公司的测试环境调用soap webservice时发生错误(生产webservice的调用仍然有效)。我试图通过设置超时参数来解决问题,但没有奏效。也许有人能够识别错误。我的代码:private GetCatalogResponse getCatalogData(GetCatalog getCat) throws AxisFault, GetCatalogExceptionException, RemoteException, Exception {        PRODUCTCATALOGStub prodCat = new PRODUCTCATALOGStub(this.targetEndpoint);        GetCatalogResponse wsResponse;        // Basic Authentication        Options option = prodCat._getServiceClient().getOptions();        MultiThreadedHttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager();        HttpConnectionManagerParams params = connectionManager.getParams();        params.setConnectionTimeout(60000);        params.setSoTimeout(60000);        params.setDefaultMaxConnectionsPerHost(20);        params.setMaxTotalConnections(20);        connectionManager.setParams(params);        // using HttpClient 3.1        HttpClient httpClient = new HttpClient(connectionManager);        HttpConnectionManagerParams connectionManagerParams = httpClient.getHttpConnectionManager().getParams();        connectionManagerParams.setParameter("http.connection-manager.timeout", 30000);        HttpTransportPropertiesImpl.Authenticator auth = new HttpTransportPropertiesImpl.Authenticator();        auth.setPreemptiveAuthentication(true);        auth.setUsername(this.User);        auth.setPassword(Crypto.decipher(pw));        option.setProperty(HTTPConstants.AUTHENTICATE, auth);        option.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);        option.setProperty(HTTPConstants.MULTITHREAD_HTTP_CONNECTION_MANAGER, connectionManager);        option.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE);    }然后我尝试用 SoapUI 调用(测试)网络服务,它工作了。所以,在我看来,我的代码还不够好。我检查了 SoapUI 的消息,发现它使用的是 HTTP-Client 4.1.1。我的应用程序正在使用 HTTP-Client 3.1(请参阅上面的调试和错误消息)。
查看完整描述

1 回答

?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

我让它工作了。该解决方案可以在我已经提到的帖子中找到(stackoverflow:如何使用 httpClient4 使用 Axis2 配置 SSL)。应该读到最后,但我不需要 SSL。为了防止烦人的 INFO 记录,Axis2Repo 文件夹包含两个空文件夹servicesmodules


private GetCatalogResponse getCatalogData(GetCatalog getCat) throws AxisFault, GetCatalogExceptionException, RemoteException, Exception {


        ConfigurationContext ctx;

        ctx = ConfigurationContextFactory.createConfigurationContextFromFileSystem("MainFolder/Config-Files/Axis2Repo","MainFolder/Config-Files/axis2.xml");


        PRODUCTCATALOGStub prodCat = new PRODUCTCATALOGStub(ctx, this.targetEndpoint);


        GetCatalogResponse wsResponse;


        // Basic Authentication

        Options option = prodCat._getServiceClient().getOptions();


        HttpClient httpClient = new DefaultHttpClient();


        HttpTransportPropertiesImpl.Authenticator auth = new HttpTransportPropertiesImpl.Authenticator();


        auth.setPreemptiveAuthentication(true);

        auth.setUsername(this.User);

        auth.setPassword(Kryptologie.entschluesseln(Crypto.decipher(this.pw)));

        option.setProperty(HTTPConstants.AUTHENTICATE, auth);

        option.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, httpClient);


        // calling the webservice

        wsResponse = prodCat.getCatalog(getCat);


        return wsResponse;


    }

我唯一不喜欢的是类DefaultHttpClient已被弃用,但 Axis2 需要这个。也许有人知道另一种方式,不需要弃用的类。


查看完整回答
反对 回复 2022-11-02
  • 1 回答
  • 0 关注
  • 83 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信