Consuming .NET ASMX Web Service from mule esb throws CXF Exception: 401 Unauthorized

橙三吉。 提交于 2019-12-05 21:33:11

This occurs because of an authentication exception.

<cxf:jaxws-client operation="Get_Workers"
            clientClass="com.saba.workday.ws.human_resources.HumanResourcesService"
            port="Human_Resources" wsdlLocation="classpath:Human_Resources.wsdl"
            doc:name="Get_Workers">
            <cxf:outInterceptors>
                <spring:ref bean="CredentialsSupplierBean" />
            </cxf:outInterceptors>
        </cxf:jaxws-client>

Here Credential Supplier is a bean which extends WSS4JOutInterceptor. and does the authentication.

Credential Supplier:

public class CredentialsSupplier extends WSS4JOutInterceptor {

 public CredentialsSupplier() {
    setProperty("action", "UsernameToken");
    setProperty("passwordType", "PasswordText");
 }

    @Override
    public void handleMessage(SoapMessage message) {
        super.handleMessage(prepareHandleMessage(message));
    }

    protected SoapMessage prepareHandleMessage(SoapMessage message) {
            message.setContextualProperty("user", "username");
            message.setContextualProperty("password", "pswd");
        return message;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!