Search code examples
javaweb-servicesmulecxfmule-esb

Java WebService call ends with "Received a redirect, but followRedirects=false"


I have a webservice client generated from SoapUI and Apache CXF component. When I run it at Mule ESB server I receive the following error:

org.mule.transport.http.HttpClientMessageDispatcher - Received a redirect, but followRedirects=false. Response code: 401 Unauthorized

Mule Flow looks like this:
flow scheme

The interesting fact here is that when I run it locally from Anypoint Studio everything works fine. How can I allow my service client to handle redirections. Is there any other error?
Here is my code:

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;

Solution

  • The probem was caused by another application which had the following cxf config:

    <cxf:configuration name="CXF_Configuration" initializeStaticBusInstance="true" enableMuleSoapHeaders="false"  doc:name="CXF Configuration"/>
    

    We have changed initializeStaticBusInstance="false" so it looks like this:

    <cxf:configuration name="CXF_Configuration" initializeStaticBusInstance="false" enableMuleSoapHeaders="false"  doc:name="CXF Configuration"/>
    

    More info https://support.mulesoft.com/s/article/There-are-at-least-2-connectors-matching-protocol-https-when-using-CXF-generated-client