11-10-2010, 11:15 AM
I have a complex situation where in to call a Rest service i have to login first and maintain a session, then my Rest service does some calculation before sending the loading data. Is there a way in which i can write a step to login first and then pass that information to call the Rest Service in the next step?
11-11-2010, 01:42 AM
I have done this on several occasions!
Do you know how an authenticated session is maintained between HTTP requests? Is it through HTTP authorization, a HTTP header parameter, or through cookies, or something else? As HTTP is not a stateful protocol, there is no normal way to do this.
If it is a HTTP header parameter, you could use the HTTP Post or HTTP Client (only v4.1 and above) which both support header parameters. There is also the HTTP job entry which supports header parameters too. All 3 components support HTTP authorization, but none support cookies (yet).
The general pattern I've seen is to make one HTTP request to "login" and obtain an authorization token which can then be parsed within PDI and put into a job variable. Then another request is made to call a specific HTTP web service which includes this token as a specific header.
If the session is maintained with cookies, you could use the Apache HTTPClient module directly with some code, similar to what is discussed here:
By the way, the postbin service is quite useful when you are debugging HTTP Post requests, it can help you check your request is constructed correctly: