Skip to Content
Technical Articles
Author's profile photo Carlos Rodrigo

SAP CPI working with Web address redirection (Http errors 301, 302 or 303)

Introduction

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.

 

Proposed Solution

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.

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Jens Schwendemann
      Jens Schwendemann

      Hrmm, I think you need a little fine tuning on this one regarding your wording

      • 301, 302, … are not errors
      • In the beginning you mention you will redirect 3 or 4 times (levels deep) but in the screenshots you configured 10 times
      • you said to follow the redirections “until the Http 200 is not returned”. However, I think you will do this until 200 is indeed returned

      But overall a nice solution to the redirection issue within CPI

      Cheers

      Jens

      Author's profile photo Carlos Rodrigo
      Carlos Rodrigo
      Blog Post Author

      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

      Author's profile photo Saurabh Semwal
      Saurabh Semwal

      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.

      Author's profile photo Carlos Rodrigo
      Carlos Rodrigo
      Blog Post Author

      Unfortunately not, because just in the HTTP header from 30x errors

      Author's profile photo Jaya Shankar Pichika
      Jaya Shankar Pichika

      Hi Carlos,

      I am working on the scenario where I am using GET method to get the ZIP file from the Microsoft JFROG Artifactory (Something like storage space where we save our files). I can be able to get from postman because we have an option Automatically follow redirects. But when I try from SAP CI, The flow is getting successfully executed but I am not getting any file because I am getting a 302-response code.

      I tried doing the same as it is in this blog but with no luck. You used an exception subprocess here, But the response code we are getting back is 302 which is not an error. So, when there is no error the flow does not even go through exception subprocess rite. I have used both End message and Escalation end.

      Could you or someone please help me to solve this. I am not getting any header like "Location" in the response.