Java 如何从Mule入站端点中的一组URI中筛选单个URI?
我有以下代码来配置Jersey服务http://localhost:8080/alpha:Java 如何从Mule入站端点中的一组URI中筛选单个URI?,java,spring,jersey,mule,Java,Spring,Jersey,Mule,我有以下代码来配置Jersey服务http://localhost:8080/alpha: *** my mule config *** <flow name="flow1"> <inbound-endpoint address="http://localhost:8080/" exchange-pattern="request-response" /> <jersey:resources> <component>
*** 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. 这些新地址需要一个jersey资源。例如:
*** 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() {...}
...
}
如何设置mule入站端点以捕获所有地址,即beta和gamma,特定url除外,即alpha
我知道我可以在mule config中硬编码路径,但这会导致重复,因为每个地址(即beta和gamma)都需要自己的流和资源代码,它们是相似的
请注意,我使用了http://localhost:8080/*在上面的代码中作为概念示例。它不起作用
--更新--
我忘了提到beta和gamma uri也有与之相关的安全性,使用:
<http:inbound-endpoint ...>
<spring-security:http-security-filter realm="mule-realm"/>
</http:inbound-endpoint>
我尝试向端点添加“choice”元素,但它抱怨spring安全性在choice决策结构中无效
解决方案还需要适应此功能。实现目标的简单方法是将流合并为一个流并使用choice router。在此配置中,您的流将如下所示:
<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头上做出决定
您可以找到此路由器文档和可用于做出选择的最常见http属性列表这是可行的,但有一项错误我在原始问题中忽略了提及。beta和gamma URI需要以下内容:,必须保存在入站端点中。对于您提供的解决方案,如果我将其添加进来,它将为所有uri调用,而不仅仅是我想要针对的两个uri。有没有办法将其添加到您的解决方案中?将spring安全性添加到choice路由器是什么意思?您是否只需要alpha或beta认证?