我们有一个代理服务,它使用jms传输来接收消息。收到的消息需要使用http POST发送到后端REST服务。 以下是对消息进行的
REST服务端点需要使用作为来自jms的输入消息的一部分的值之一动态附加路径参数。网址看起来像
http://<server-ip>/service/<client>
。这里“客户”的值是消息的一部分。
我们如何使用wso2 esb动态添加路径参数?
答案 0 :(得分:2)
我认为链接[1]&amp; [2]将帮助您使用WSO2代理设置jms ...要动态地将路径参数添加到URL,请使用链接[3],它用于XML配置文件。与此类似,您可以将消息的一部分分配给属性add,将其附加到url ...
[1] http://docs.wso2.org/wiki/display/ESB460/Publish-Subscribe+%28Pub-Sub%29+with+JMS
[2] http://wso2.org/library/articles/2011/11/wso2-esb-example-two-wayrequestresponse-semantic-jms
[3] How to dynamically route message in WSO2 ESB based on XML configuration file
谢谢,
莫汉
答案 1 :(得分:2)
我相信你要找的是REST_URL_POSTFIX
属性。如果设置此属性,则该值将附加到其余端点URL。
可以使用axis2的范围定义如下。
<property name="REST_URL_POSTFIX"
expression="//client"
scope="axis2"
type="STRING"/>
有关此问题的示例,请参阅本指南Using REST with a Proxy Service。
编辑:以下是使用带有curl的POST请求的简单代理的示例。根据评论提供。在这里,我在WSO2 Application Server中调用jaxrs_basic rest服务。
curl -H "Content-Type: application/xml" -H "Accept: application/json" -d "<Customer><name>KasunG</name></Customer>" http://localhost:8281/services/new1/
curl -H "Content-Type: application/json" -H "Accept: application/json" -d "{ 'Customer' : { 'name' : 'KasunG' } } " http://localhost:8281/services/new1/
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="new1"
transports="https http"
startOnLoad="true"
trace="disable">
<description/>
<target>
<inSequence>
<property name="REST_URL_POSTFIX"
value="customers"
scope="axis2"
type="STRING"/>
<property name="ContentType" value="text/xml" scope="axis2" type="STRING"/>
<switch source="$axis2:HTTP_METHOD">
<case regex="GET">
<property name="HTTP_METHOD" value="GET" scope="axis2" type="STRING"/>
</case>
<case regex="POST">
<property name="messageType" value="application/json" scope="axis2"/>
<property name="ContentType"
value="application/JSON"
scope="axis2"
type="STRING"/>
<property name="HTTP_METHOD" value="POST" scope="axis2" type="STRING"/>
</case>
<default/>
</switch>
<send>
<endpoint>
<address uri="http://localhost:8888/jaxrs_basic/services/customers/customerservice"
format="rest"/>
</endpoint>
</send>
</inSequence>
<outSequence>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</outSequence>
</target>
</proxy>