Apigee - modify target path when using targetserver - proxy

I have an API proxy that needs to be able to modify the path component of the eventual Target URL. This appears fairly straightforward in cases where there's a defined Target Endpoint URL for the entire proxy but we are using TargetServers and VirtualHosts which apparently are assigned after the TargetEndpoint PreFlow
I have a JS function in the Target Endpoint PreFlow and get unspecified JS errors when I attempt to modify context.targetRequest.path. Attempts to modify the path part of the incoming proxy during Proxy PreFlow also failed.
Dumping the values of targetRequest gives:
host=empty
path=/v2/cat1/cat2/?param=......
url=Identical to path!
The only variable that I've been able to "successfully" modify is targetRequest.url to achieve my aim but to do that I must assign the whole thing, including the protocol and host which aren't known to me!
Anyone know how to do this? I essentially want to modify the path replacing "/?" with just "?"
Thanks

You can also set it up at the target endpoint by leveraging the Path element along with TargetServer:
<TargetEndpoint>
...
<HTTPTargetConnection>
<LoadBalancer>
<Server name="TargetServerABC"/>
</LoadBalancer>
<Path>/v1/YourPathHere/json.ws?{flow.company.queryparams}</Path>
</HTTPTargetConnection>
</TargetEndpoint>
Note TargetServerABC needs to be a TargetServer created using the following these steps.

There seems to be an issue with manipulating target.path (there is a bug report open in Apigee for this).
The current workaround is to rewrite the entire URI either in the AssignMessage policy using the AssignVariable block:
<AssignVariable>
<Name>target.url</Name>
<Value>http://example.com/mypath?param=value&variable={apigee.variable}</Value>
<Ref/>
</AssignVariable>
or you can do it in Javascript with the context.setVariable function:
context.setVariable("target.url", mycompleteurl);

Related

look for assistance with the url rewrite module in IIS

I'm trying to set up a reverse proxy for single sign on to an application. the URL to reach my app and the defined authentication method is "http://servername.domain/app/main?authsource=sso_rp"
My current config just sends me to the application login prompt. I've tested my authentication source and confirmed its working. My question is, does my URL rewrite config look like it should? there are no conditions or variables defined. i know I'm missing something simple but this isn't documented on the vendor end so seeking your help.

Dredd can't find my API documentation, how do i tell it where it is if it's not on my local drive (it's on apiary.io server)

I am using the Dredd tool to test my API (which resides on apiary.io).
Question
I would like to provide dredd with a path to my documentation (it even asks for it), however my API doc is on apiary.io but i don't know the exact url that points to it. What would be the correct way to provide dredd with the API path?
What did work (but not what i'm looking for)
Note: I tried downloading the api to my local drive and providing dredd with a local path to the file (yml or apib) which works fine (yay!), but i would like to avoid keeping a local copy and simply providing dredd with the location of my real API doc which is being maintained on the apiary server.
How do I do this (without first fetching the file to local drive)?
Attempts to solve this that failed
I also read (and tried) on the following topics, they may be relevant but i wasn't successful in resolving the issue
- Using authentication token as environment variable
- Providing the domain provided by apiary.io//settings to dredd
- Providing the in the dredd command
all of these attempts still produces the same result, Dredd has no idea where to find the API document unless i provide a path in my local computer to the file (which i have to download or create manually on my computer first).
Any help is appreciated, Thanks!
If I understand it correctly, you would like to use dredd and feed it using the API description document residing on Apiar.io platform, right?
If so, you should be able to do that simply calling the init command with the right options:
dredd init -r apiary -j apiaryApiKey:privateToken -j apiaryApiName:sasdasdasd
You can find the private token going into the Test section of the target API (you'll find the button on the application header).
Let me know if this solves the problem for you - I'll make sure to propagate this and document it accordingly on our help page
P.S: You can also use your own reporter - in that case, simply omit -r apiary when writing the command line parameters.
You can feed Dredd not only with a path to file on your disk, but also with an URL.
If your API in Apiary is public, the API description document (in this case API Blueprint) should have a public URL. For example, if you go to http://docs.apiblueprintapi.apiary.io/, you can see on the left there is a Download link. Unfortunately, the link is visible only for users who do not have access to the editor of the API, so you can’t see the link if you’re owner of the API. Try to log out from Apiary and the link should appear:
Then you can feed Dredd with the link:
$ dredd 'http://docs.apiblueprintapi.apiary.io/api-description-document' 'http://example.com:8080/api'
I agree this isn’t very intuitive and since you’re not the first one to come up with this, I think we’ll think of some ways how to make it easier.
If your API isn't public then unfortunately there's no way to get the URL as of now. However, you can either use GitHub Sync or Apiary CLI to get the file on your disk in an automated manner.

Can I declare credentials only once for a REST API?

I am using Power Query within Power BI Designer to query a REST API. The first request is to:
http://domain/httpAuth/app/rest/server
which returns:
<server>
<builds href="/httpAuth/app/rest/builds"/>
</server>
From there I use Power Query to query http://domain/httpAuth/app/rest/builds in order to get a list of builds and then iterate over the list of builds, calling each one in turn. The format of the URL for each build is:
http://domain/httpAuth/app/rest/builds/id:buildId
The problem is I'm getting prompted to enter credentials for every single request. This is tedious and unworkable (we have a lot of builds).
Is there a way to define the credentials once for (say) stub http://domain/httpAuth/app/rest and have every resource under that stub use the same credentials?
At the moment there is no direct way to do this for HTTP sources. A workaround for now is to connect to the root source first (http://domain/httpAuth/app/rest/builds or just http://domain/) and set the credentials there.
If you trust all of the data sources you are connecting to, you can also disable the firewall by going to the Workbook Settings dialog and selecting the Ignore option for Fast Combine.
EDIT: Sorry, I misread the question. In the case of credentials, connect to the root source first and set the credential there. This credential should be used for the remaining URLs.
I believe you can set an Authorization Header and set it with your request.
(Apologies for for the Wiki link - http://en.wikipedia.org/wiki/Basic_access_authentication)

WSO2 ESB - Dynamic value for proxy parameters (transport)

I need to be able to specify a dynamic value for proxy parameter. Actually, I have to specify each parameter with complete URL like :
<parameter name="transport.vfs.FileNamePattern">.*.txt</parameter>
I see some samples with property mediator and I guess it's working for next proxies but the problem here is that I need to change the proxy parameters value before its execution I think. I tried with a "trigger" proxy calling a custom mediator which change SynapseConfiguration of required proxy but this wasn't working.
Is there a way to replace these fixed value with lookups to create some deployment configuration ?
Many thanks.
You can check out this post How to dynamically route message in WSO2 ESB based on XML configuration file for an example how to dynamically set values in a proxy sequence.
You can do something this:
<parameter name="transport.vfs.FileNamePattern">
<script language="js">mc.getProperty('MY_DYNAMIC_VALUE')</script>
</parameter>
I am not sure this will help you much, as I suspect that the vfs parameters are set when initializing the proxy and not on the fly. If you give it a try, if possible please post back to this thread if it works or not.
Regards, nidkil
The Parameters in the Proxy service definitions are service level Parameters which is in the Axis2Service Configuration . They are used when you are initialing the Axis2Service in this case its the Synapse/WSO2 ESB proxy service. So you can't change the parameters dynamically on the fly.
But i can suggest following approach. It might or might not applicable to your scenario.
Have set of VFS proxies that listen for separate locations. Each will look at a give file extension. (one for .txt one for .foo etc..)
Use another generic vfs proxy to copy files to correct places dynamically(which accepts any extension).(You can use vfs sender).
Hope this helps.
cheers,
Charith

mod_rewrite and server environment variables

The setup I have is as follows:
I have one Apache server acting as a URL rewriting engine (SERVER1).
I have a second server (Apache too) which runs a web application (SERVER2). First tries to authenticate users. Part of the authentication protocol involves a lot of redirection between that application server and the authentication server.
My problem is that once the authencation is successfull, the authentication server needs to redirect the user back to the application server, which is only visible from SERVER1. Effectively, SERVER2 needs to be able to reconstruct a URL based on SERVER1's parameters.
Most of the environement variable are helpful i.e. I know the host name, script name, page called etcc but I can 't figure out wether the call was made through HTTP or HTTPS: that information is wiped in the rewrite process by SERVER1...
Anybody knows if/how I can get that information through environement variables? I am limited in that I can't use query string parameters...
Thanks all !
This may sound strange, but I have found part of the answer to my question.
The rewrite engine (at least in Apache 2, I haven't looked anywhere else) allows for writting extra request header.
The rule should look something like that.
RewriteRule .* -
[E=INFO_PATH_INFO:%{PATH_INFO},NE]
Put simple, it creates a new header called INFO_PATH_INFO and sets the value to PATH_INFO.
( For more info check out http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html )
Then it can be retrieved in any languages.
For info I am using Oracle's OWA which adds an extra layer of complication due to the fact that the default environment variables are limited to a few and additional variables need to be specified in thr dads.conf
Hope this will help anyone !

Resources