2012-11-04 60 views
0

我已經創建了一個簡單的流程,公開了鏈接到REST服務的HTTP端點。 REST服務返回一個字符串,然後使用請求 - 響應模式將其放置到JMS隊列中。這個想法是,放在隊列中的字符串將被某些消費者使用,並且使用回覆地址創建一個響應。所以基本上這是實現同步JMS。如何在Mule ESB中使用同步JMS實現HTTP基本認證?

該流程按預期工作,除非HTTP端點使用基本身份驗證進行保護。在這種情況下,響應是:

java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: MuleResponseWriter$1 

並且沒有消息放置在隊列中。在拋出基本身份驗證結果時不會引發異常。另外,刪除JMS出站端點會導致字符串被回顯,這導致我認爲問題出在JMS端點上。我懷疑問題出自JMS端點的響應,因爲將流中的組件設置爲單向否定問題。我認爲問題可能是端點正在向沒有認證憑證的HTTP端點發送一些響應,並且由於它而失敗,但我不確定如何處理此問題。

下面是我創建的流程:

<mule 
    xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" 
    xmlns:context="http://www.springframework.org/schema/context" xmlns="http://www.mulesoft.org/schema/mule/core" 
    xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:jms="http://www.mulesoft.org/schema/mule/jms" 
    xmlns:jersey="http://www.mulesoft.org/schema/mule/jersey" 
    xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" 
    xmlns:spring="http://www.springframework.org/schema/beans" xmlns:core="http://www.mulesoft.org/schema/mule/core" 
    version="CE-3.3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:mule-ss="http://www.mulesoft.org/schema/mule/spring-security" 
    xmlns:json="http://www.mulesoft.org/schema/mule/json" 
    xmlns:ss="http://www.springframework.org/schema/security" xsi:schemaLocation=" 
    http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd 
    http://www.mulesoft.org/schema/mule/jms http://www.mulesoft.org/schema/mule/jms/current/mule-jms.xsd 
    http://www.mulesoft.org/schema/mule/jersey http://www.mulesoft.org/schema/mule/jersey/current/mule-jersey.xsd 
    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/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd 
    http://www.mulesoft.org/schema/mule/spring-security http://www.mulesoft.org/schema/mule/spring-security/3.1/mule-spring-security.xsd 
    http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd "> 
<jms:activemq-connector name="Active_MQ" specification="1.1" brokerURL="tcp://localhost:61616" 
         validateConnections="true" doc:name="Active MQ"/> 
<mule-ss:security-manager> 
    <mule-ss:delegate-security-provider name="memory-provider" delegate-ref="authenticationManager"/> 
</mule-ss:security-manager> 
<spring:beans> 
    <ss:authentication-manager alias="authenticationManager"> 
     <ss:authentication-provider> 
      <ss:user-service id="userService"> 
       <ss:user name="username" password="password" authorities="ROLE_ADMIN"/> 
      </ss:user-service> 
     </ss:authentication-provider> 
    </ss:authentication-manager> 
</spring:beans> 
<flow name="RESTAPISync" doc:name="RESTAPISync"> 
    <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"> 
     <mule-ss:http-security-filter realm="realm"/> 
    </http:inbound-endpoint> 
    <jersey:resources doc:name="REST"> 
     <component class="SFREST"/> 
    </jersey:resources> 
    <jms:outbound-endpoint exchange-pattern="request-response" queue="tmp" connector-ref="Active_MQ" 
          doc:name="JMS"/> 
</flow> 

的SFREST.java組件:

import javax.ws.rs.GET; 
import javax.ws.rs.Path; 


@Path("/pops") 
public class SFREST{ 

    @GET 
    public String getPOPs() throws Exception{ 
     return "hello"; 
    } 

} 

和異常:

ERROR 2012-11-04 21:40:57,485 [[jmstest].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
******************************************************************************** 
Message    : Authentication Attempt Failed. Message payload is of type: String 
Code     : MULE_ERROR-54999 
-------------------------------------------------------------------------------- 
Exception stack is: 
1. Bad credentials (org.springframework.security.authentication.BadCredentialsException) 
    org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider:137 (null) 
2. Authentication Attempt Failed. Message payload is of type: String (org.mule.api.security.UnauthorisedException) 
org.mule.security.MuleSecurityManager:96 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/security/UnauthorisedException.html) 
-------------------------------------------------------------------------------- 
Root Exception stack trace: 
org.springframework.security.authentication.BadCredentialsException: Bad credentials 
at org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider.authenticate(AbstractUserDetailsAuthenticationProvider.java:137) 
at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156) 
at org.mule.module.spring.security.SpringProviderAdapter.authenticate(SpringProviderAdapter.java:70) 
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything) 
******************************************************************************** 

ERROR 2012-11-04 21:41:04,522 [[jmstest].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy: 
******************************************************************************** 
Message    : java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: MuleResponseWriter$1 
Code     : MULE_ERROR-29999 
-------------------------------------------------------------------------------- 
Exception stack is: 
1. com.sun.jersey.spi.container.ContainerResponse (java.io.NotSerializableException) 
java.io.ObjectOutputStream:1164 (null) 
2. java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException) 
org.apache.commons.lang.SerializationUtils:111 (null) 
3. java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse (org.apache.commons.lang.SerializationException). Message payload is of type: MuleResponseWriter$1 (org.mule.api.MessagingException) 
org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:35 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html) 
-------------------------------------------------------------------------------- 
Root Exception stack trace: 
java.io.NotSerializableException: com.sun.jersey.spi.container.ContainerResponse 
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164) 
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:330) 
at org.apache.commons.collections.map.AbstractHashedMap.doWriteObject(AbstractHashedMap.java:1182) 
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything) 
******************************************************************************** 

任何想法?

回答

0

異常的原因,是因爲任何的球衣組件返回你需要它傳播到下一個消息處理器之前轉換爲講解了com.sun.jersey.spi.container.ContainerResponse here

+0

似乎並不奏效。我創建了一個AbstractMessageTransformer,它實現鏈接中的代碼,除了現在返回的錯誤是java.io.NotSerializableException:com.sun.jersey.spi.container.ContainerResponse(org.apache.commons.lang.SerializationException)。消息有效負載的類型爲:String'。這似乎很奇怪,因爲如果基本身份驗證關閉,則將字符串傳遞給JMS出站組件。 – allanchang