SAP CPI working with Web address redirection (Http errors 301, 302 or 303)
Sometimes we need access a WebService address, but this address was redirected to a new one, but the CPI cannot process correctly the HTTP error (Http 301,302 or 303) message correctly and not redirect our call to the new address.
Htpp 301 error – moved permanently
Htpp 302 error – temporally moved
Http 303 error – redirection error
Some application does this automatically (if you configure) like Postman as can you see in below image and the message was returned correctly from the new web address and the change could be transparent to the consumer system side.
After any Http 301,302 or 303 error code from the access, in the HTTP header, a parameter called “Location” is returned with the new web address, the idea is to use this parameter to redirect our CPI to access the new webservice dynamically inside our I-Flow integration.
Apparently there is an easy approach could be used for us to solve this “problem”, basically we will do a simple call in the firs web address what we have in our hands and if we have a Http 301, 302 or 303 error code, we call a loop pattern to made a call to the web address returned inside the header “Location” parameters until the Http 200 is not returned ( attention, do this for few time 3 or 4 times, after this return the error message to the sender system because some WebServices could be configured wrong and you will be in an eternal looping process.
I started my I-Flow with a content modifier pattern to set an exchange property called “urlMaintanence” what I will “Externalize” to make the address configurable outside the I-Flow artifact.
After url was configured in the property.urlMaintence, I do the first connection attempt to the webservice as can you see below using a “Request Reply” CPI Pattern.
If the WebService works, and Http200 was returned nothing the especial happens and the response message was returned to the sender request system.
But if any HTTP error was returned the magic happens, the CPI I-Flow will call a Exception subprocess and inside this internal process we start the loop if the returned error is a Http 301 (for example).
I´m using a “Non-XML” expression to access directly the HTTP header and get the response code and the loop will execute 10 times if the error persists.
For call the WebService again, I need create a new Internal Process to reference in the CPI Loop pattern.
Just trying to access the information returned in the HTTP Header inside the “Location “ parameter (this the only one difference from the first call).
And, if the Http 200 is returned, the response message is delivered to the sender system and if other HTTP error different from redirection error is returned, the error is returned to the sender system too.
That´s all folks!! Thank you for the audience to this blog post.
Hrmm, I think you need a little fine tuning on this one regarding your wording
But overall a nice solution to the redirection issue within CPI
thank you for the feedback
you are right HTTP codes different from 20x not all reference for errors, is just another way to understand the functionality.
The attempts to access the levels is just a hint, in my case i did 10 levels but other colleagues would like do more and if you just do this indefinitely until HTTP 20x was not returned, if the webservice provider has a error it could be a problem and the process could be locked
One question. Because its not mentioned anywhere and in any redirection related posts, shouldn't the redirected IP or IP range be whitelisted first? else you will get the timeout errors.
Unfortunately not, because just in the HTTP header from 30x errors