当前位置: 动力学知识库 > 问答 > 编程问答 >

Passing a dynamic input in proxy url wso2 esb

问题描述:

I am trying to simply host a REST service as a proxy service in WSO2 ESB. I am using Custom Proxy to do this. When I run the created proxy, I am not able to pass parameters to the proxy service at run time. How do I do this?

My REST service will be hit on a URL of format:http://ip:host/requestMapping/{name}

The parameter 'name' has to be passed from the UI through the ESB to the service through a proxy service hosted on the ESB. Can you help me with the steps to follow to make this work?

I tried using this page: http://wso2.com/library/articles/2013/12/restful-integration-with-wso2-esb/

But that is for creating APIs which I have been successfully in creating. But I am unable to do this using Proxy services.

Basically in my program, when the user interacts with the UI, he enters a name as input. This name has to be passed to the proxy service hosted in the ESB which should forward this as a path variable to my REST service.

Right now, my service body is:

<inSequence>

<send>

<endpoint>

<http method="POST" uri-template="http://ip:port/resourceMapping/{uri.var.name}"></http>

</endpoint>

</send>

</inSequence>

<outSequence>

<send></send>

</outSequence>

网友答案:

You can use the Header mediator to change the value of "To" header to the desired concat expression.

For example, check this link: Defining dynamic endpoint in wso2esb

Alternatively, if you haven't yet, you can also check the answers to a similar question here: wso2-esb-dynamically-change-endpoint-address According to this, you should set the property "uri.var.name" in advance. i.e.,

<inSequence>
   <parameter name="uri.var.name" expression="" />
   <send>
   <endpoint>
   <http method="POST" uri-template="http://ip:port/resourceMapping/{uri.var.name}"></http>

    </endpoint>
   </send>
</inSequence>
<outSequence>
  <send></send>
</outSequence>

The expression would depend on the way the input is formatted - XML, JSON, etc. You can read more about XPath here: https://docs.wso2.com/display/ESB490/Synapse+XPath+Variables and here: http://www.w3schools.com/xsl/xpath_syntax.asp

网友答案:

use the + to control encoding as this is part of the URI Template specification. try below code.

<inSequence>
<parameter name="uri.var.name" expression="YOUR EXPRESSION" />
  <send>
   <endpoint>
   <http method="POST" uri-template="http://ip:port/resourceMapping/{+uri.var.name}"></http>
    </endpoint>
   </send>
</inSequence>
<outSequence>
  <send></send>
</outSequence>

WSO2ESB HTTP Endpoint throws exception when using uri.var parameters in the uri-template

分享给朋友:
您可能感兴趣的文章:
随机阅读: