从mule esb使用.NET ASMX Web服务会引发CXF异常:401未经授权 [英] Consuming .NET ASMX Web Service from mule esb throws CXF Exception: 401 Unauthorized

查看:185
本文介绍了从mule esb使用.NET ASMX Web服务会引发CXF异常:401未经授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在不同的服务器上有一个.NET ASMX Web服务,我在另一台服务器上安装了mule standalone CE 3.4。我有一个非常简单的流程,需要调用此.NET Web服务并传递两个字符串参数。

I have a .NET ASMX web service in a different server and I have installed the mule standalone CE 3.4 in another server. I have a very simple flow which needs to call this .NET web service and pass two string parameters.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd">
    <custom-transformer returnClass="java.lang.String[]" mimeType="text/plain" class="com.rms.corpapps.utils.WebServiceParamsTransformer" name="Java" doc:name="Java"/>
<http:connector name="httpConnector" enableCookies="true" proxyHostname="myserver" proxyUsername="domain\myusername" proxyPassword="mypassword" proxyPort="80" >
    <spring:property name="proxyNtlmAuthentication" value="true"/>
</http:connector>
<flow name="sftestFlow1" doc:name="sftestFlow1">
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP" path="flows/sftest"/>
    <custom-transformer class="com.mycompany.utils.WebServiceParamsTransformer" doc:name="Transform Data for web service" doc:description="This java component prepares the input for web service"/>
    <cxf:jaxws-client doc:name="SOAP"
        clientClass="com.mycompany.WebServiceListener" port="WebServiceListenerSoap"  operation="ProcessExternalMessage"
    />
    <outbound-endpoint address="http://myserver/sm/webservicelistener.asmx?wsdl" doc:name="Generic" exchange-pattern="request-response" connector-ref="httpConnector"/>
</flow>

基本上,我暴露了http入站端点(用于测试目的)调用流并使用java转换器类返回需要传递给Web服务的字符串。以下是WebServiceParamsTransformer类的代码。

Basically, I'm exposing an http inbound endpoint (for testing purposes) to invoke the flow and using a java transformer class which returns the strings that needs to be passed to the web service. Here is the code for the WebServiceParamsTransformer class.

public class WebServiceParamsTransformer extends AbstractTransformer {
    @Override
    public Object doTransform(Object src, String encoding) throws TransformerException {
        Object[] out = new Object[2];
    out[0] = "Update Ticket Service";
    out[1] = Base64.encode("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><event source=\"SHUB\" target=\"TP\" type=\"SUB8\" version=\"1.0\" timestamp=\"2013-09-16T15:52:14.0000+00.00\"><new-eta-event><incident-number>123456</incident-number><user-name>hari</user-name><eta-timestamp>2013-09-16T15:52:14.0000+00.00</eta-timestamp></new-eta-event></event>");

    return out;
    }
}

不幸的是这不起作用 - 我收到了以下错误'响应代码:401。未经授权'。以下是错误日志的摘录:

Unfortunately this is not working - I'm receiving the following error 'Response code: 401. Unauthorized'. Here is the excerpt from the error log:

INFO  2013-09-17 13:54:13,396 [[sftest].httpConnector.receiver.02] org.apache.commons.httpclient.auth.AuthChallengeProcessor: **ntlm authentication scheme selected**
INFO  2013-09-17 13:54:13,397 [[sftest].httpConnector.receiver.02] org.apache.commons.httpclient.HttpMethodDirector: **No credentials available for NTLM <any realm>@myserver:80**
INFO  2013-09-17 13:54:13,397 [[sftest].httpConnector.receiver.02] org.mule.transport.http.HttpClientMessageDispatcher: **Received a redirect, but followRedirects=false. Response code: 401 Unauthorized**
WARN  2013-09-17 13:54:13,398 [[sftest].httpConnector.receiver.02] org.apache.cxf.phase.PhaseInterceptorChain: Interceptor for {http://tempuri.org/}WebServiceListener#{http://tempuri.org/}ProcessExternalMessage has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType.  Incoming portion of HTML stream: **You do not have permission to view this directory or page.**

.NET Web服务由Windows集成身份验证保护,并在.NET Framework 2.0中的Windows Server 2008下的IIS 7中运行。以下是显示身份验证设置的屏幕截图。

The .NET web service is secured by Windows Integrated Authentication and runs in IIS 7 under Windows Server 2008 in .NET Framework 2.0. Here is the screenshot that shows the authentication setting.

我在哪里做错了?我的要求是简单地调用一个由mule esb集成身份验证保护的Web服务。非常感谢任何帮助。

Where am I doing wrong? My requirement is to simply call a web service that is secured by integrated authentication from mule esb. Any help is much appreciated.

推荐答案

这是因为身份验证异常。

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>

此处Credential Supplier是一个扩展WSS4JOutInterceptor的bean。并进行身份验证。

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

凭证供应商:

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;
    }
}

这篇关于从mule esb使用.NET ASMX Web服务会引发CXF异常:401未经授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆