2012-07-07 67 views
0

我有下面的代碼在「HTTP://本地主機:8080 /阿爾法」:配置澤西服務如何從Mule入站端點中的一組URI中過濾單個URI?

*** my mule config *** 

<flow name="flow1"> 
    <inbound-endpoint address="http://localhost:8080/" exchange-pattern="request-response" /> 
<jersey:resources> 
    <component> 
     <singleton-object class="com.address.Flow1Resource"/> 
    </component> 
</jersey:resources> 
</flow> 

*** Flow1Resource.java *** 

@Path("/alpha") 
public class Flow1Resource {...} 

我想添加一個新的入站端點,處理在「HTTP中的所有地址: // localhost:8080「,除了」http:// localhost:8080/alpha「(例如」http:// localhost:8080/beta「)。這些新地址需要一個球衣資源。例如:

*** my mule config *** 

<flow name="flow1"> 
    <inbound-endpoint address="http://localhost:8080/" exchange-pattern="request-response" /> 
<jersey:resources> 
    <component> 
     <singleton-object class="com.address.Flow1Resource"/> 
    </component> 
</jersey:resources> 
</flow> 

<flow name="flow2"> 
    <inbound-endpoint address="http://localhost:8080/*" exchange-pattern="request-response" /> 
<jersey:resources> 
    <component> 
     <singleton-object class="com.address.Flow2Resource"/> 
    </component> 
</jersey:resources> 
</flow> 

*** Flow1Resource.java *** 

@Path("/alpha") 
public class Flow1Resource {...} 

*** Flow2Resource.java *** 

@Path("/") 
public class Flow2Resource { 
    @Path("beta") 
    public void beta() {...} 
    @Path("gamma") 
    public void gamma() {...} 
    ... 
} 

如何設置了騾子的入站端點捕捉到所有的地址(即測試版&伽馬),除了特定的URL(即阿爾法)。

我知道我可以在mule配置中對路徑進行硬編碼,但是這會導致重複,因爲每個地址(即betagamma)都需要它自己的流和資源代碼,它們是相似的。

請注意,我在上面的代碼中使用了「http:// localhost:8080/*」作爲概念示例。這是行不通的。

---更新---

我忘了提及的是,β和γ的URI還帶有安全使用:

<http:inbound-endpoint ...> 
    <spring-security:http-security-filter realm="mule-realm"/> 
</http:inbound-endpoint> 

我嘗試添加一個「選擇」元素的端點,但它抱怨春季安全在選擇決策結構內無效。

解決方案還需要適應此功能。

+0

你的意思是最常見的HTTP屬性列表?你是否只需要alpha或beta進行驗證? – genjosanzo 2012-07-08 14:10:06

回答

0

一個簡單的方法來實現你的目標是結合你的流量到一個和使用選擇路由器。在這個配置你的流程將類似於以下:

<flow name="stackoverflowFlow1" doc:name="stackoverflowFlow1"> 
    <http:inbound-endpoint exchange-pattern="request-response" 
     host="localhost" port="8081" doc:name="HTTP" /> 
    <logger level="ERROR" /> 
    <choice doc:name="Choice"> 
     <when expression="#[message.inboundProperties['http.request'] == '/']"> 
      <processor-chain> 
       <logger message="/ invoked " level="ERROR" /> 
       <jersey:resources doc:name="REST"> 
        <component class="Resource" /> 
       </jersey:resources> 
      </processor-chain> 
     </when> 
     <otherwise> 
      <processor-chain> 
       <logger message="otherwise invoked " level="ERROR" /> 

       <jersey:resources doc:name="REST"> 
        <component class="ApplicationsResource" /> 
       </jersey:resources> 
      </processor-chain> 
     </otherwise> 
    </choice> 
</flow> 

你可以想像,你可以採取的路徑上或任何其他HTTP頭的最高決策。

你可以找到這個路由器文檔here,您可以使用通過將彈簧安全的選擇路由器,讓您的選擇here

+0

這可行,但在我原來的問題中忽略提及的一個項目上的錯誤。 beta和gamma URI需要以下內容:「」,它必須保留在入站端點中。有了你提供的解決方案,如果我添加它,它會被調用所有的uri,而不僅僅是我想要的兩個。有沒有辦法將其添加到您的解決方案? – TERACytE 2012-07-07 20:19:13