具有授权和重试策略的Apache cxf客户端

我正在尝试将apache cxf客户端(使用maven插件从wsdl生成的代码)与基本的授权和重试机制一起使用。

要对此进行测试,首先将SOAP服务关闭。我的连接被拒绝。

org.apache.cxf.interceptor.Fault: Could not send Message.
    at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:67)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308)

我可以看到SOAP调用多次重试 然后,我启动SOAP服务。现在,HTTP 401的授权失败。

org.apache.cxf.transport.http.HTTPException: HTTP response '401: Unauthorized' when communicating with http://.....
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.doProcessResponseCode(HTTPConduit.java:1618)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:1625)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:1570)
    at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1371)

这是我尝试的代码。我的授权以前在工作。我介绍了retryStrategy之后,就折腾了。

        JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

        factory.setServiceclass(MyService.class);
        factory.setaddress("<uri_of_wsdl>");

        myService= (MyService) factory.create();

        Client client = ClientProxy.getclient(myService);
        client.getconduitSelector().setEndpoint(client.getEndpoint());
        RetryStrategy retryStrategy = new RetryStrategy();
        retryStrategy.setMaxNumberOfRetries(5);
        FailoverFeature failoverFeature = new FailoverFeature();
        failoverFeature.setStrategy(retryStrategy);
        failoverFeature.initialize(client,client.getBus());

        HTTPConduit http = (HTTPConduit) client.getconduit();
        HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

        httpClientPolicy.setConnectionTimeout(2000);
        httpClientPolicy.setReceiveTimeout(30000);
        http.setClient(httpClientPolicy);
        http.getauthorization().setusername(clientConfiguration.getusername());
        http.getauthorization().setPassword(clientConfiguration.getPassword());

任何帮助都会很棒。

谢谢

lmn1101 回答:具有授权和重试策略的Apache cxf客户端

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3121880.html

大家都在问