我有一个从SoapUI和Apache CXF组件生成的Web服务客户端。当我在Mule ESB服务器上运行它时收到以下错误:
org.mule.transport.http.HttpClientMessageDispatcher - Received a redirect, but followRedirects=false. Response code: 401 Unauthorized
这里有趣的事实是,当我从Anypoint Studio本地运行它时一切正常。如何允许我的服务客户端处理重定向。还有其他错误吗? 这是我的代码:
URL wsdlURL = MPServiceService.WSDL_LOCATION;
MPServiceService ss = new MPServiceService(wsdlURL, SERVICE_NAME);
MPService port = ss.getDomino();
BindingProvider prov = (BindingProvider) port;
prov.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
requestpath);
prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, username);
prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, password);
String result = port.webServiceFoo();
return result;
您的错误似乎来自您的网址所服务的Mule应用,而不是来自上面的代码。当你点击你的web服务时,Mule在流程中发出了一个请求 - 很可能是使用http:request
或http:outbound-endpoint
组件 - 这导致了一个错误,并且你的网络服务正在返回这个错误。
您的Mule应用程序是问题,而不是上面的Java代码。有关如何解决您的Mule问题,请参阅can Mule HTTP out-bound handler redirect requests?。
问题是由另一个具有以下cxf配置的应用程序引起的:
<cxf:configuration name="CXF_Configuration" initializeStaticBusInstance="true" enableMuleSoapHeaders="false" doc:name="CXF Configuration"/>
我们更改了initializeStaticBusInstance =“false”所以它看起来像这样:
<cxf:configuration name="CXF_Configuration" initializeStaticBusInstance="false" enableMuleSoapHeaders="false" doc:name="CXF Configuration"/>