You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by btt423 <bt...@diversecomputing.com> on 2015/05/27 22:48:13 UTC

Rest DSL with jetty and SSL

I was originally testing out the Rest DSL and using Jetty as the server. 
This works great and I'm a big fan.  My next step was to try and get SSL
working with my test application.  Based on the reading that I did, it looks
like I needed to add a jetty bean definition in blueprint.xml, and specify
the keystore, keystore password and key password.  When I add the bean
definition for jetty, I'm getting the exception listed below.  I have tried
a number of different troubleshooting attempts, but always get this
exception whenever I attempt to define the bean in blueprint xml (even
taking SSL completely out the equation).  The exception, details of my
environment and the applicable snippets of code/config are below - I would
appreciate any help that could be provided!!

******* Environment Info: *******

Camel 2.15.2
camel-blueprint 2.15.2
camel-jetty 2.15.2

******* Exception: *******

org.osgi.service.blueprint.container.ComponentDefinitionException: Error
when instantiating bean jetty of class class
org.apache.camel.component.jetty.JettyHttpComponent
	at
org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:333)
	at
org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)
	at
org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
	at
org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at
org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)
	at
org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)
	at
org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)
	at
org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:668)
	at
org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370)
	at
org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at
org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106)
	at
org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
	at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
	at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.InstantiationException
	at
sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
	at
org.apache.aries.blueprint.utils.ReflectionUtils.newInstance(ReflectionUtils.java:329)
	at
org.apache.aries.blueprint.container.BeanRecipe.newInstance(BeanRecipe.java:962)
	at
org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:331)
	... 21 more

******* blueprint.xml: *******

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.osgi.org/xmlns/blueprint/v1.0.0
http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
       http://camel.apache.org/schema/blueprint
http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">

    <bean id="jetty"
class="org.apache.camel.component.jetty.JettyHttpComponent">
        <property name="sslPassword" value="mypassword"/>
        <property name="sslKeyPassword" value="mypassword"/>
        <property name="keystore" value="/path/to/keystore"/>
    </bean>

  <bean id="restRouter" class="com.diversecomputing.RestRouter" />

  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
    <routeBuilder ref="restRouter" />
  </camelContext>

</blueprint>

******* RouteBuilder: *******

public class RestRouter extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        
        restConfiguration()
            .component("jetty")
            .host("localhost")
            .port("8082")
            //.scheme("https")
            .contextPath("rest")
            .bindingMode(RestBindingMode.auto)
            .dataFormatProperty("prettyPrint", "true");

        rest("/say")
            .get("/hello").to("direct:hello")
            .get("/bye").consumes("application/json").to("direct:bye")
            .post("/bye").to("mock:update");
        
        from("direct:hello")
            .transform().constant("Hello World");
        from("direct:bye")
            .transform().constant("Bye World");
    }
}



--
View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-with-jetty-and-SSL-tp5767572.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Rest DSL with jetty and SSL

Posted by Roman Vottner <ro...@gmx.at>.
I've had similar problems
(http://camel.465427.n5.nabble.com/Rest-DSL-how-to-configure-SSL-Basic-Auth-for-Jetty-component-td5758003.html)
and therefore created a github project
(https://github.com/RovoMe/CamelMultipleJettyComponents/tree/rest-dsl) to
test Camel's REST-DSL with SSL/Basic Auth configured for a Jetty Server. 

There are currently a couple of issues to keep in mind:

1) On specifying a security handler (for basic auth), this handler must be
added only once to a route! This has a short mentioning in the component
docs - but may be skiped easily! This was somehow no issue before Camel
2.14.0.
(http://camel.465427.n5.nabble.com/Issue-using-multiple-services-broadcast-via-JettyComponent-td5757958.html)
2) Setting a security handler via .componentProperty("handler",
"springBeanNameOfSecurityHandler") ignores the handler and therefore wont
even ask for the user credentials.
3) Having multiple HTTP operations defined within the same route and a
security handler defined via .endpointProperty("handlers",
"springBeanNameOfSecurityHandler") will try to initialize the handler for
each HTTP operation and therefore yield the problem described in 1)
4) I still have no clue on how to directly add a handler to the
JettyHttpComponent to avoid these multiple additions problem (which
furthermore does raise some unclear exception)

The example project linked above contains 3 route-classes: the first two
route classes simply define a Jetty endpoint via the services.properties
where the first route declares a basic authentication handler for Jetty
which is simply added via ...&handlers=#jettyAuthHandler&... to the
endpoint. As this handler is only allowed to be added once for the same port
the other routes must not add this handler. 

Route3 defines a REST route using Camels REST-DSL. Post and Delete
operations are currently disabled as they only work if the handlers endpoint
property configuration in Route3 is removed. You can though achieve global
basic auth handling by activating route1 (but still disable the endpoint
property specifications for handlers in Route3)

Currently the first two routes are disabled. To enable them simply remove
the comment declaration from ServicesSpringConfig. On enabling route1 make
sure to comment out the .endpointProperty("handlers", "jettyAuthHandler")
specification in Route3.

This project still lacks proper unit-tests, but you can test the behavior if
you simply run ServicesApp as a console application and point your browser
to https://localhost:8383/api/v1/serviceN where N should be replace by 1, 2
or 3 depending on which services you have enabled. If you have enabled the
basic auth handler you should be asked for user credentials (user=admin;
pw=secret)

Hope this helps and Claus or Willem can have a look at those issues



--
View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-with-jetty-and-SSL-tp5767572p5767688.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Rest DSL with jetty and SSL

Posted by Camel Guy <ca...@devguy.com>.
I'd also love to see the solution to this.

On Wed, May 27, 2015 at 1:48 PM, btt423 <bt...@diversecomputing.com> wrote:

> I was originally testing out the Rest DSL and using Jetty as the server.
> This works great and I'm a big fan.  My next step was to try and get SSL
> working with my test application.  Based on the reading that I did, it
> looks
> like I needed to add a jetty bean definition in blueprint.xml, and specify
> the keystore, keystore password and key password.  When I add the bean
> definition for jetty, I'm getting the exception listed below.  I have tried
> a number of different troubleshooting attempts, but always get this
> exception whenever I attempt to define the bean in blueprint xml (even
> taking SSL completely out the equation).  The exception, details of my
> environment and the applicable snippets of code/config are below - I would
> appreciate any help that could be provided!!
>
> ******* Environment Info: *******
>
> Camel 2.15.2
> camel-blueprint 2.15.2
> camel-jetty 2.15.2
>
> ******* Exception: *******
>
> org.osgi.service.blueprint.container.ComponentDefinitionException: Error
> when instantiating bean jetty of class class
> org.apache.camel.component.jetty.JettyHttpComponent
>         at
>
> org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:333)
>         at
>
> org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)
>         at
>
> org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)
>         at
> org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>         at
> org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)
>         at
>
> org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)
>         at
>
> org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)
>         at
>
> org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:668)
>         at
>
> org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370)
>         at
>
> org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261)
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>         at
>
> org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106)
>         at
>
> org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)
>         at
> java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
>         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
>         at
>
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
>         at
>
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
>         at
>
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
>         at
>
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
>         at java.lang.Thread.run(Thread.java:745)
> Caused by: java.lang.InstantiationException
>         at
>
> sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
>         at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
>         at
>
> org.apache.aries.blueprint.utils.ReflectionUtils.newInstance(ReflectionUtils.java:329)
>         at
>
> org.apache.aries.blueprint.container.BeanRecipe.newInstance(BeanRecipe.java:962)
>         at
>
> org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:331)
>         ... 21 more
>
> ******* blueprint.xml: *******
>
> <?xml version="1.0" encoding="UTF-8"?>
> <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="
>        http://www.osgi.org/xmlns/blueprint/v1.0.0
> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
>        http://camel.apache.org/schema/blueprint
> http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
>
>     <bean id="jetty"
> class="org.apache.camel.component.jetty.JettyHttpComponent">
>         <property name="sslPassword" value="mypassword"/>
>         <property name="sslKeyPassword" value="mypassword"/>
>         <property name="keystore" value="/path/to/keystore"/>
>     </bean>
>
>   <bean id="restRouter" class="com.diversecomputing.RestRouter" />
>
>   <camelContext xmlns="http://camel.apache.org/schema/blueprint">
>     <routeBuilder ref="restRouter" />
>   </camelContext>
>
> </blueprint>
>
> ******* RouteBuilder: *******
>
> public class RestRouter extends RouteBuilder {
>
>     @Override
>     public void configure() throws Exception {
>
>         restConfiguration()
>             .component("jetty")
>             .host("localhost")
>             .port("8082")
>             //.scheme("https")
>             .contextPath("rest")
>             .bindingMode(RestBindingMode.auto)
>             .dataFormatProperty("prettyPrint", "true");
>
>         rest("/say")
>             .get("/hello").to("direct:hello")
>             .get("/bye").consumes("application/json").to("direct:bye")
>             .post("/bye").to("mock:update");
>
>         from("direct:hello")
>             .transform().constant("Hello World");
>         from("direct:bye")
>             .transform().constant("Bye World");
>     }
> }
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Rest-DSL-with-jetty-and-SSL-tp5767572.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Re: Rest DSL with jetty and SSL

Posted by Willem Jiang <wi...@gmail.com>.
In Camel 2.15.x we has two JettyComponents to support Jetty9 and Jetty8 at the same time.
If you want to instantiate one of the Jetty component, you cannot use the JettyHttpComponent any more, as it is abstract class now.

If you want to use Jetty9, you need to use the class”JettyHttpComponent9", otherwise you need to chose “JettyHttpComponent8”.


--  
Willem Jiang

Red Hat, Inc.
Web: http://www.redhat.com
Blog: http://willemjiang.blogspot.com (English)
http://jnn.iteye.com (Chinese)
Twitter: willemjiang  
Weibo: 姜宁willem



On May 28, 2015 at 4:48:31 AM, btt423 (btatum@diversecomputing.com) wrote:
> I was originally testing out the Rest DSL and using Jetty as the server.
> This works great and I'm a big fan. My next step was to try and get SSL
> working with my test application. Based on the reading that I did, it looks
> like I needed to add a jetty bean definition in blueprint.xml, and specify
> the keystore, keystore password and key password. When I add the bean
> definition for jetty, I'm getting the exception listed below. I have tried
> a number of different troubleshooting attempts, but always get this
> exception whenever I attempt to define the bean in blueprint xml (even
> taking SSL completely out the equation). The exception, details of my
> environment and the applicable snippets of code/config are below - I would
> appreciate any help that could be provided!!
>  
> ******* Environment Info: *******
>  
> Camel 2.15.2
> camel-blueprint 2.15.2
> camel-jetty 2.15.2
>  
> ******* Exception: *******
>  
> org.osgi.service.blueprint.container.ComponentDefinitionException: Error  
> when instantiating bean jetty of class class
> org.apache.camel.component.jetty.JettyHttpComponent
> at
> org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:333)  
> at
> org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:806)  
> at
> org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:787)  
> at
> org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> at
> org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)  
> at
> org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:245)  
> at
> org.apache.aries.blueprint.container.BlueprintRepository.createAll(BlueprintRepository.java:183)  
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.instantiateEagerComponents(BlueprintContainerImpl.java:668)  
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:370)  
> at
> org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:261)  
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> at
> org.apache.aries.blueprint.container.ExecutorServiceWrapper.run(ExecutorServiceWrapper.java:106)  
> at
> org.apache.aries.blueprint.utils.threading.impl.DiscardableRunnable.run(DiscardableRunnable.java:48)  
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)  
> at java.util.concurrent.FutureTask.run(FutureTask.java:266)
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)  
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)  
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)  
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)  
> at java.lang.Thread.run(Thread.java:745)
> Caused by: java.lang.InstantiationException
> at
> sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)  
> at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
> at
> org.apache.aries.blueprint.utils.ReflectionUtils.newInstance(ReflectionUtils.java:329)  
> at
> org.apache.aries.blueprint.container.BeanRecipe.newInstance(BeanRecipe.java:962)  
> at
> org.apache.aries.blueprint.container.BeanRecipe.getInstance(BeanRecipe.java:331)  
> ... 21 more
>  
> ******* blueprint.xml: *******
>  
>  
> > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="
> http://www.osgi.org/xmlns/blueprint/v1.0.0
> http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
> http://camel.apache.org/schema/blueprint
> http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
>  
> > class="org.apache.camel.component.jetty.JettyHttpComponent">
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
>  
> ******* RouteBuilder: *******
>  
> public class RestRouter extends RouteBuilder {
>  
> @Override
> public void configure() throws Exception {
>  
> restConfiguration()
> .component("jetty")
> .host("localhost")
> .port("8082")
> //.scheme("https")
> .contextPath("rest")
> .bindingMode(RestBindingMode.auto)
> .dataFormatProperty("prettyPrint", "true");
>  
> rest("/say")
> .get("/hello").to("direct:hello")
> .get("/bye").consumes("application/json").to("direct:bye")
> .post("/bye").to("mock:update");
>  
> from("direct:hello")
> .transform().constant("Hello World");
> from("direct:bye")
> .transform().constant("Bye World");
> }
> }
>  
>  
>  
> --
> View this message in context: http://camel.465427.n5.nabble.com/Rest-DSL-with-jetty-and-SSL-tp5767572.html  
> Sent from the Camel - Users mailing list archive at Nabble.com.
>