1

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>
Alka
  • 95
  • 8
  • Why do you want to invoke your RESTful service via a proxy service? Can't you create another api in ESB and invoke your backend api via that one? – Amila Maharachchi Jun 17 '16 at 02:21
  • I need to search a user on the basis of user ID in multiple systems. Hence I an implementing scatter gather proxy implementation and cloning the requests to call multiple systems endpoints from one proxy URL. The url format to search a user is different in different systems but they all take userid as an input value which gets appended to the URL. – Alka Jun 17 '16 at 09:49
  • @Alka you can do scatter-gather with both proxy services and APIs. Both these types share the same core except for the front-end interface it exposes. That means, you can use the same mediators and sequences you would use for proxy services in APIs as well. – Kasun Gajasinghe Jun 19 '16 at 05:01
  • I need to call all the endpoints through a single URL. Will api serve the purpose? – Alka Jun 20 '16 at 09:49
  • That is why I am going for proxy implementation. So that I can have just one URL where I can dynamically pass user id and will in turn be passed to the different endpoints. Please help. – Alka Jun 20 '16 at 16:19

2 Answers2

1

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

Community
  • 1
  • 1
HM.Rajjaz
  • 369
  • 1
  • 3
  • 17
  • I am writing a curl script tp pass the user name as: – Alka Jun 21 '16 at 14:00
  • My curl script is: curl -X GET -H "Content-Type: text/xml" -d "123456 " http://host:port/services/testproxy and calling it in the esb configuration as below:
    I am not getting any value in uri.var.name property.Also, I am getting the below exception while using uri.var.name in the url: NativeWorkerPool Uncaught exception java.lang.RuntimeException: org.apache.synapse.SynapseException: Error while building message I tried with "+" as well
    – Alka Jun 21 '16 at 14:13
  • To add, I am using scatter gather proxy implementation as per the link: https://docs.wso2.com/display/IntegrationPatterns/Scatter-Gather – Alka Jun 21 '16 at 16:31
0

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

Community
  • 1
  • 1
Maria Ivanova
  • 1,146
  • 10
  • 19