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

我的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(请参阅上面的调试和错误消息)。


汪汪一只猫
浏览 84回答 1
1回答

蝴蝶不菲

我让它工作了。该解决方案可以在我已经提到的帖子中找到(stackoverflow:如何使用 httpClient4 使用 Axis2 配置 SSL)。应该读到最后,但我不需要 SSL。为了防止烦人的 INFO 记录,Axis2Repo 文件夹包含两个空文件夹services和modules。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 需要这个。也许有人知道另一种方式,不需要弃用的类。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java