Friday, September 3, 2010

Follow HTTP redirects -OSB HTTP Transport Level setting


I started on the journey with Oracle service bus very recently even though I have been trying to catch this bus for a long time, but was never quite successful. It was quite different approach as considered to the more commonly used BPEL and ESB approach. Getting used to the Eclipse IDE, then exploring different options takes bit of your  time to get familiarized. But as always new journeys give us more opportunities to learn.
One of the first hurdles that came up was with testing the business service. The scenario goes like this. There is a web service exposed in one of our target systems which we tried to consume as a Business service from OSB. Developing the Business service is very straight forward, but testing it and making it work looked cumbersome. As part of testing we were encountering ‘Bad Request’ Error even though the payload was thoroughly tested using SOAP UI. The response code returns response code as 400 which meant that the request was not even reaching the web service.
What OSB gives us to debug the issue?
OSB Console test window will give you Response Document and Response Metadata using which you need to figure out the error.
Response Document returns
The invocation resulted in an error: Bad Request.
Response Metadata returns
<con:metadata xmlns:con="http://www.bea.com/wli/sb/test/config">
            <tran:headers             xsi:type="http:HttpResponseHeaders" xmlns:http="http://www.bea.com/wli/sb/transports/http" xmlns:tran="http://www.bea.com/wli/sb/transports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            <http:Connection>close</http:Connection>
            <http:Content-Type>text/html; charset=iso-8859-1</http:Content-Type>
            <http:Date>Fri, 03 Sep 2010 05:11:17 GMT</http:Date>
            <http:Transfer-Encoding>chunked</http:Transfer-Encoding>
            </tran:headers>
            <tran:response-code   xmlns:tran="http://www.bea.com/wli/sb/transports">1</tran:response-code>
            <tran:response-message         xmlns:tran="http://www.bea.com/wli/sb/transports">Bad Request</tran:response-message>
            <tran:encoding           xmlns:tran="http://www.bea.com/wli/sb/transports">iso-8859-1</tran:encoding>
            <http:http-response-code         xmlns:http="http://www.bea.com/wli/sb/transports/http">400</http:http-response-code>
            </con:metadata>

So after a bit analysis and help from the Mohan the issue was found that the request was not getting forwarded to the external system and to ensure that the request gets forwarded to the end system  we need to enable  Follow HTTP redirects  setting . By default HTTP redirect will be disabled.
How to enable the HTTP redirect setting?
Go to HTTP Transport tab in the business service.biz file. Go to Advanced settings -> Enable Follow HTTP redirects

What Follow HTTP redirects setting does?
               A re-direct occurs when you send an outbound request to the URL of a business service, and that service returns a response code (for example, 302) that says the URL is no longer valid and this request needs to be sent to another URL. If the Follow HTTP Redirects check box is selected, Oracle Service Bus automatically re-sends the request to the new URL without any action on your part.
Note:
Another point to note is that 'chunked streaming mode' and 'follow HTTP redirects' setting cannot be enabled together. By default 'chunked streaming mode' will be enabled and HTTP redirects will be disabled. If you try to enable both settings of a business service, it will throw a compile time error mentioning
HTTP business service cannot have both 'chunked streaming mode' and 'follow HTTP redirects' options enabled.       
That’s it to start off with, m back to work J

6 comments:

Anonymous said...

Good stuff

Anonymous said...

Thanks. This helped me to solve my problem

Anonymous said...

good one..

Nauman AHmed said...

God Bless!!! I spent lot of time breaking my head to figure this out....

Anonymous said...

This setting helps while invoking Siebel EAI service when you are getting "Supplied input is not well formed or does not contain the expected data.(SBL-EAI-00137)" error.

muddu said...

Awesome...This blog was helped me a lot.I was struggling with the below error sometime back. After applying this fix its worked. Thanks again.

Error Snippet:

502 - Web server received an invalid response while acting as a gateway or proxy server

"There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server"