Any way to pass arguments to proxy besides the url?

3119
2
03-15-2016 06:59 AM
ChrisWitt3
New Contributor

I have an esri 3.9 webapp running with a weblogic server backend. I've already set up a proxy servlet to use when I want to load data from a site that's not CORS enabled, which append an API key to the URL when the request is sent out.

That works well. However, I want to be able to use that proxy class for other services, which have different API keys.

I looked at manually checking the url to verify what key the proxy should add before making the call, but I would like to handle that from the front end and make the back end look for an argument sent on the proxy call.

From what I already have set up, I set the proxy by calling

esri.addProxyRule({
     urlPrefix: "api.blahblah.com",
     proxyUrl: "/gis/proxy"
});

I tried to add the argument to the url, but the esri javascript seems to just ignore the arguments and only take the base url of /gis/proxy.

So my question is:

Does anybody know of a way I could replace

proxyUrl: "/gis/proxy"

with something like

proxyUrl: "/gis/proxy?request=blahblahservice"

so that I can differentiate on the backend which service it is?

..or is there a way to disable that ignoring of the arguments?

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus

Chris,

  This can be done if you modify the actual proxy code for the language of proxy that you are using. For example if you are using the dot net proxy then you download the proxy source code from the GitHub resource proxy page and open it in visual studio and make your changes to it using c sharp (assuming you know that language). I have not had the need to do this so I can not provide a code example of the necessary changes though.

0 Kudos
VinceAngelo
Esri Esteemed Contributor

A proxy is just a proxy.  They're very easy to write (trivial implementations can be done in 12-15 lines of Java, good ones in 120-150 LOC), and there's lots of samples out there.

There's more of a philosophical issue at play here, though, since proxies aren't supposed to make changes to the URL, just switchyard requests.  And if your proxy is consuming URL parameters, what  happens if the applications start using that same key?  Do you change the proxy?  Escape the key to have the proxy rewrite it?  This is where complex proxies come from.

One thing you can look at is hiding information in the HTTP request headers.  Getting the data in there can be a pain, and making it stay can be challenging through multiple hops, but it certainly wouldn't change the URLs.

- V

0 Kudos