java.lang.IllegalStateException: unsupported protocol: 'https4'

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

java.lang.IllegalStateException: unsupported protocol: 'https4'

bcwajapey
Hi All,

I am using camel to call REST URLs. In doing so, I am setting the CamelHttpUri header to override the URI. This works properly with http/https (Http client 3.x). However, it fails for http4/https4 (Http Client 4.x).
Below is the stack trace for https4

Stacktrace
---------------------------------------------------------------------------------------------------------------------------------------
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
        at org.apache.camel.component.http.HttpMethods.createMethod(HttpMethods.java:49)
        at org.apache.camel.component.http.HttpProducer.createMethod(HttpProducer.java:391)
        at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:95)
        at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
        at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
        at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
        at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:163)
        at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
        at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
        at org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
        at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
        at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
        at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529)
        at org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497)
        at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365)
        at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497)
        at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:209)
        at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:139)
        at org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:125)
        at org.apache.camel.example.osgi.MyRouteBuilder.executeCamelRoutes(MyRouteBuilder.java:79)
        at org.apache.camel.example.osgi.MyRouteBuilder.main(MyRouteBuilder.java:51)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:497)
        at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
        at org.apache.camel.component.http.HttpMethods.createMethod(HttpMethods.java:47)
        ... 28 more
Caused by: java.lang.IllegalStateException: unsupported protocol: 'https4'
        at org.apache.commons.httpclient.protocol.Protocol.lazyRegisterProtocol(Protocol.java:149)
        at org.apache.commons.httpclient.protocol.Protocol.getProtocol(Protocol.java:117)
        at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
        at org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
        at org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
        at org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
        ... 33 more


The camel script that I am using is as below -

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:camel="http://camel.apache.org/schema/spring"
       xsi:schemaLocation="
         http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camelContext xmlns="http://camel.apache.org/schema/spring" trace="true">
      <camel:template id="camelTemplate"/>

      <route id="route1">
          <from uri="direct:start"/>
          <setHeader headerName="CamelHttpMethod">
              <constant>GET</constant>
          </setHeader>
         
          <to uri="https4://myapp.com/resource/v2/user?throwExceptionOnFailure=false"/>

          <setHeader headerName="employeeName">
              <jsonpath>$.consumer[0].employees[0].resources.employeeName</jsonpath>
          </setHeader>

          <setHeader headerName="CamelHttpMethod">
              <constant>GET</constant>
          </setHeader>
          <setHeader headerName="CamelHttpUri">
              <simple>https4://myapp.com${header.employeeName}?size=${header.size}</simple>
          </setHeader>
          <to uri="https4://myapp.com"/>
      </route>
    </camelContext>

</beans>

Also, I have included the dependency for camel-http4. Version = 2.18.0

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-http4</artifactId>
  <version>2.18.0</version>
</dependency>

Can you please tell me what is wrong with the camel script?

Note: This camel script works if I use http instead of http4.

Thanks,
Brahmachaitanya

Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: unsupported protocol: 'https4'

Claus Ibsen-2
Hi

Can you try with

 <setHeader headerName="CamelHttpUri">

<simple>https://myapp.com${header.employeeName}?size=${header.size}</simple>
          </setHeader>


On Fri, Oct 21, 2016 at 7:04 AM, bcwajapey <[hidden email]> wrote:

> Hi All,
>
> I am using camel to call REST URLs. In doing so, I am setting the
> CamelHttpUri header to override the URI. This works properly with http/https
> (Http client 3.x). However, it fails for http4/https4 (Http Client 4.x).
> Below is the stack trace for https4
>
> Stacktrace
> ---------------------------------------------------------------------------------------------------------------------------------------
> java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
>         at
> org.apache.camel.component.http.HttpMethods.createMethod(HttpMethods.java:49)
>         at
> org.apache.camel.component.http.HttpProducer.createMethod(HttpProducer.java:391)
>         at
> org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:95)
>         at
> org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
>         at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145)
>         at
> org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
>         at
> org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:163)
>         at
> org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:542)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
>         at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
>         at
> org.apache.camel.component.direct.DirectProducer.process(DirectProducer.java:62)
>         at
> org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:197)
>         at
> org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:97)
>         at
> org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:529)
>         at
> org.apache.camel.impl.ProducerCache$1.doInProducer(ProducerCache.java:497)
>         at org.apache.camel.impl.ProducerCache.doInProducer(ProducerCache.java:365)
>         at org.apache.camel.impl.ProducerCache.sendExchange(ProducerCache.java:497)
>         at org.apache.camel.impl.ProducerCache.send(ProducerCache.java:209)
>         at
> org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:139)
>         at
> org.apache.camel.impl.DefaultProducerTemplate.send(DefaultProducerTemplate.java:125)
>         at
> org.apache.camel.example.osgi.MyRouteBuilder.executeCamelRoutes(MyRouteBuilder.java:79)
>         at
> org.apache.camel.example.osgi.MyRouteBuilder.main(MyRouteBuilder.java:51)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>         at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>         at java.lang.reflect.Method.invoke(Method.java:497)
>         at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
> Caused by: java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>         at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>         at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
>         at
> org.apache.camel.component.http.HttpMethods.createMethod(HttpMethods.java:47)
>         ... 28 more
> Caused by: java.lang.IllegalStateException: unsupported protocol: 'https4'
>         at
> org.apache.commons.httpclient.protocol.Protocol.lazyRegisterProtocol(Protocol.java:149)
>         at
> org.apache.commons.httpclient.protocol.Protocol.getProtocol(Protocol.java:117)
>         at org.apache.commons.httpclient.HttpHost.<init>(HttpHost.java:107)
>         at
> org.apache.commons.httpclient.HttpMethodBase.setURI(HttpMethodBase.java:280)
>         at
> org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:220)
>         at
> org.apache.commons.httpclient.methods.GetMethod.<init>(GetMethod.java:89)
>         ... 33 more
>
>
> *The camel script that I am using is as below -*
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xmlns:camel="http://camel.apache.org/schema/spring"
>        xsi:schemaLocation="
>          http://www.springframework.org/schema/beans
> http://www.springframework.org/schema/beans/spring-beans.xsd
>          http://camel.apache.org/schema/spring
> http://camel.apache.org/schema/spring/camel-spring.xsd">
>
>     <camelContext xmlns="http://camel.apache.org/schema/spring"
> trace="true">
>       <camel:template id="camelTemplate"/>
>
>       <route id="route1">
>           <from uri="direct:start"/>
>           <setHeader headerName="CamelHttpMethod">
>               <constant>GET</constant>
>           </setHeader>
>
>           <to
> uri="https4://myapp.com/resource/v2/user?throwExceptionOnFailure=false"/>
>
>           <setHeader headerName="employeeName">
>
> <jsonpath>$.consumer[0].employees[0].resources.employeeName</jsonpath>
>           </setHeader>
>
>           <setHeader headerName="CamelHttpMethod">
>               <constant>GET</constant>
>           </setHeader>
>           <setHeader headerName="CamelHttpUri">
>
> <simple>https4://myapp.com${header.employeeName}?size=${header.size}</simple>
>           </setHeader>
>           <to uri="https4://myapp.com"/>
>       </route>
>     </camelContext>
>
> </beans>
>
> *Also, I have included the dependency for camel-http4. Version = 2.18.0*
>
> <dependency>
>   <groupId>org.apache.camel</groupId>
>   <artifactId>camel-http4</artifactId>
>   <version>2.18.0</version>
> </dependency>
>
> Can you please tell me what is wrong with the camel script?
>
> *Note: This camel script works if I use http instead of http4.*
>
> Thanks,
> Brahmachaitanya
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/java-lang-IllegalStateException-unsupported-protocol-https4-tp5789058.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: unsupported protocol: 'https4'

arno noordover
In reply to this post by bcwajapey
You have two things:
1. the uri-attribute in the to-element;
2. the "CamelHttpUri" headers.
Both have a "protocol" prefix. The "protocol"  prefix in de uri-attribute is used to select the component you want to use.
When using the "CamelHttpUri" to override the URL that gets determined in the component you need to provide the real URL in this header.
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: unsupported protocol: 'https4'

bcwajapey
In reply to this post by Claus Ibsen-2
Are you suggesting to use "https" (Http Client 3.x) instead of "https4" (Http Client 4.x)?
I have already tried it and https4 fails. Thats the error I have mentioned in the thread.
Reply | Threaded
Open this post in threaded view
|

Re: java.lang.IllegalStateException: unsupported protocol: 'https4'

bcwajapey
In reply to this post by arno noordover
@arno noordover : Sorry did not get exactly what you meant. Are you suggesting I have to give complete URL in "CamelHttpUri" header instead of using header variables like ${header.employeeName}?