6 Replies Latest reply on Apr 28, 2011 3:53 AM by hhasting

    camel-http4 component setting redirect to off

    hhasting

      Hi

       

      I am using spring dsl to define my camel context and having trouble working out how to turn the automatic redirecting off for http.

       

      The documentation suggests that http4 component should be used as the handle redirect option cannot be set in http because it is based on HttpClient 3.x.

       

      However I tried httpClient.handleRedirects=false as an option but I get

      org.apache.cxf.interceptor.Fault: Socket Closed

      ...

      Caused by: java.net.SocketException: Socket Closed

       

      the camel route has

       

       

      any suggestions on how to resolve this would be greatly appreciated

        • 1. Re: camel-http4 component setting redirect to off
          davsclaus

          Check the Apache Http Client 4.x documentation about redirects.

           

          The stacktrace you posted seems like CXF related.

           

          Try using a simple test and have a simulated server return redirect code such as 301.

          • 2. Re: camel-http4 component setting redirect to off
            njiang

            We need more information about the route.

            According to the stack trace, I can't tell why CXF is getting involved.

             

            BTW, did you have a chance to change the camel-http4 endpoint to camel-http endpoint ?

            I just want to make sure the other part of route is working rightly.

             

            Willem

            • 3. Re: camel-http4 component setting redirect to off
              hhasting

              Hi Willem

               

              To remove the cxf part I've changed the camel context to have two routes a quartz route which calls the other route to do the http call. Route below:

               

               

                          <from uri="quartz://scripts/quartzRoute?cron=0*+*?&amp;job.name=quartzRoute"/>

                           

               

              Basically I need to call https://shopfront3.telstra.com.au:443/LOLOSTGBb2b/services/ActivityHistoryService and I should get back a redirect location however as soon as I have httpClient.handleRedirects=false I get

               

              Camel Thread 0 - seda://foo] SedaConsumer                   ERROR Error processing exchange. Exchange[Message: ]. Caused by:

              java.net.SocketException: Socket Closed

                   at java.net.PlainSocketImpl.setOption(PlainSocketImpl.java:201)

                   at java.net.Socket.setSoTimeout(Socket.java:1017)

                   at com.sun.net.ssl.internal.ssl.SSLSocketImpl.setSoTimeout(SSLSocketImpl.java:2107)

                   at org.apache.http.impl.io.SocketInputBuffer.isDataAvailable(SocketInputBuffer.java:145)

                   at org.apache.http.impl.io.IdentityInputStream.available(IdentityInputStream.java:74)

                   at org.apache.http.conn.EofSensorInputStream.available(EofSensorInputStream.java:171)

                   at org.apache.camel.util.IOHelper.copy(IOHelper.java:90)

                   at org.apache.camel.util.IOHelper.copy(IOHelper.java:86)

                   at org.apache.camel.component.http4.HttpProducer.doExtractResponseBody(HttpProducer.java:228)

                   at org.apache.camel.component.http4.HttpProducer.extractResponseBody(HttpProducer.java:220)

                   at org.apache.camel.component.http4.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:138)

                   at org.apache.camel.component.http4.HttpProducer.process(HttpProducer.java:92)

                   at org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:106)

                   at org.apache.camel.processor.SendProcessor$1.doInProducer(SendProcessor.java:103)

                   at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:189)

                   at org.apache.camel.processor.SendProcessor.doProcess(SendProcessor.java:103)

                   at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:87)

                   at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)

                   at org.apache.camel.processor.DelegateProcessor.processNext(DelegateProcessor.java:53)

                   at org.apache.camel.processor.DelegateProcessor.proceed(DelegateProcessor.java:82)

                   at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:97)

                   at org.apache.camel.processor.interceptor.HandleFaultInterceptor.process(HandleFaultInterceptor.java:47)

                   at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)

                   at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:228)

                   at org.apache.camel.processor.TryProcessor.process(TryProcessor.java:63)

                   at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)

                   at org.apache.camel.processor.DelegateProcessor.processNext(DelegateProcessor.java:53)

                   at org.apache.camel.processor.DelegateProcessor.proceed(DelegateProcessor.java:82)

                   at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:97)

                   at org.apache.camel.processor.interceptor.HandleFaultInterceptor.process(HandleFaultInterceptor.java:47)

                   at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)

                   at org.apache.camel.processor.DefaultChannel.process(DefaultChannel.java:228)

                   at org.apache.camel.processor.Pipeline.process(Pipeline.java:75)

                   at org.apache.camel.processor.UnitOfWorkProcessor.processNext(UnitOfWorkProcessor.java:70)

                   at org.apache.camel.processor.DelegateProcessor.process(DelegateProcessor.java:48)

                   at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:67)

                   at org.apache.camel.component.seda.SedaConsumer.sendToConsumers(SedaConsumer.java:160)

                   at org.apache.camel.component.seda.SedaConsumer.run(SedaConsumer.java:108)

                   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)

                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

                   at java.lang.Thread.run(Thread.java:619)

               

               

              I have run it in debug with a breakpoint in org.apache.http.client.params.HttpClientParams and the parameters are coming across ok

              static = org.apache.http.client.params.HttpClientParams

              params = {org.apache.http.impl.client.ClientParamsStack@4506}

              applicationParams = null

              clientParams = {org.apache.http.params.BasicHttpParams@3870}

              parameters = {java.util.HashMap@4532} size = 4

              = {java.util.HashMap$Entry@4545} http.connection.stalecheck -> false

              key: java.lang.String = {java.lang.String@4549}"http.connection.stalecheck"

              value: java.lang.Boolean = {java.lang.Boolean@4553}"false"

              = {java.util.HashMap$Entry@4558} http.socket.timeout -> 60000

              key: java.lang.String = {java.lang.String@4560}"http.socket.timeout"

              value: java.lang.Integer = {java.lang.Integer@4564}"60000"

              = {java.util.HashMap$Entry@4569} http.connection.timeout -> 60000

              key: java.lang.String = {java.lang.String@4571}"http.connection.timeout"

              value: java.lang.Integer = {java.lang.Integer@4575}"60000"

              = {java.util.HashMap$Entry@4578} http.protocol.handle-redirects -> false

              key: java.lang.String = {java.lang.String@4580}"http.protocol.handle-redirects"

              value: java.lang.Boolean = {java.lang.Boolean@4553}"false"

              requestParams = {org.apache.http.params.BasicHttpParams@4531}

              parameters = {java.util.HashMap@4536} size = 0

              overrideParams = null

               

              But I'm not sure what is causing the socket closed to occur

              • 4. Re: camel-http4 component setting redirect to off
                davsclaus

                Hi

                 

                Can you try without those timeout parameters on the http endpoint, to see if it makes a difference?

                • 5. Re: camel-http4 component setting redirect to off
                  davsclaus

                  I added an unit test to camel-http4 which tests redirects based on your configuration

                  http://svn.apache.org/viewvc?rev=1079692&view=rev

                   

                  It uses a local test server and not a CXF but nevertheless it works.

                   

                  So the issue could be related to Apache CXF.

                   

                  I wonder if we should add some catch exception in camel-http producer when extracting response body. Because if its an error anyway we can still fail. However if its a OK answer we may have to re-throw the exception as we couldn't grab the response body.

                  • 6. Re: camel-http4 component setting redirect to off
                    hhasting

                    Hi

                     

                    Thankyou for all the replies it has been very helpful we ended up using a different approach for that particular functionality however I am now having a problem trying to get a 302 HTTP response back.

                     

                    I am using the HTTP4 component with the below in my camel context defined using Spring DSL

                     

                     

                     

                    with debug on I can see that a 302 response is shown which is what I am expecting at the moment but then it is changed to java.net.SocketException which is not what I was expecting I was expecting a HttpOperationFailedException. Does anyone know how to get the 302 response back as I need to check for this as the response and handle in a particular way. I have tried with throwExceptionOnFailure=false and same issue

                     

                    HttpProducer                   DEBUG Http responseCode: 302

                     

                    exception: java.net.SocketException caused by: Socket is closed