Hi Achim,

thanks for replying me.
I explain in details why I need to configure Jetty in this way.
The goal of my test is to create a cluster of servicemix instances where the Jetty servers can have shared sessions. A possible solution for achieving this with a standalone Jetty is to modify the jetty.xml by adding the following statements

   <Set name="sessionIdManager">
            <New id="jdbcidmgr"
   class="org.eclipse.jetty.server.session.JDBCSessionIdManager">
                <Arg>
                    <Ref id="Server"/>
                </Arg>
                <Set name="workerName">jetty-node1</Set>
                <Set name="DatasourceName">jdbc/MyDatasource</Set>
                <Set name="scavengeInterval">60</Set>
            </New>
   </Set>

   <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">
             <Arg/>
             <Arg>jdbc/MyDatasource</Arg>
             <Arg>
                <New
   class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                   <Set
   name="Url">jdbc:mysql://localhost:3306/sessions</Set>
                   <Set name="User">root</Set>
                   <Set name="Password">root</Set>
                </New>
               </Arg>
     </New>

defining a SessionManager, linked to a DataSource (registered as a JNDI resource), that can be used by the web applications to retrieve the shared sessions (stored on a DB). As said in the previous mail, I got a Config error during the Jetty startup when using the above configuration in the jetty.xml file.

I tried to implement your proposal as well. I registered the DataSource as a JNDI resource by creating and deploying the following blueprint xml file

   <blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0";>
        <bean class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
   id="datasourceBean">
            <property name="serverName" value="localhost"></property>
            <property name="databaseName" value="database"></property>
            <property name="port" value="3306"></property>
            <property name="user" value="********"></property>
            <property name="password" value="********"></property>
        </bean>
        <service id="datasourceService"
   interface="javax.sql.DataSource" ref="datasourceBean">
            <service-properties>
                <entry key="osgi.jndi.service.name"
   value="MyDataSource"></entry>
            </service-properties>
        </service>
   </blueprint>

and then I added the following statement only inside the jetty.xml file

        <Set name="sessionIdManager">
            <New id="jdbcidmgr"
   class="org.eclipse.jetty.server.session.JDBCSessionIdManager">
                <Arg>
                    <Ref id="Server"/>
                </Arg>
                <Set name="workerName">jetty-node1</Set>
            <Set
   
name="DatasourceName">osgi:services/javax.sql.DataSource/(osgi.jndi.service.name=MyDataSource)</Set>

                <Set name="scavengeInterval">60</Set>
            </New>
        </Set>

In this case I got an exception when Jetty tries to create the /SessionManager/. Following the Stacktrace:

   javax.naming.NoInitialContextException: Cannot instantiate class:
   org.eclipse.jetty.jndi.InitialContextFactory [Root exception is
   java.lang.ClassNotFoundException:
   org.eclipse.jetty.jndi.InitialContextFactory]
        at
   
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)[:1.6.0_37]

        at
   
javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)[:1.6.0_37]

        at
   javax.naming.InitialContext.init(InitialContext.java:223)[:1.6.0_37]
        at
   javax.naming.InitialContext.<init>(InitialContext.java:175)[:1.6.0_37]
        at
   
org.eclipse.jetty.server.session.JDBCSessionIdManager.initializeDatabase(JDBCSessionIdManager.java:459)[107:org.eclipse.jetty.server:7.4.5.v20110725]

        at
   
org.eclipse.jetty.server.session.JDBCSessionIdManager.doStart(JDBCSessionIdManager.java:407)[107:org.eclipse.jetty.server:7.4.5.v20110725]

        at
   
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)[119:org.eclipse.jetty.util:7.4.5.v20110725]

        at
   
org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:41)[119:org.eclipse.jetty.util:7.4.5.v20110725]

        at
   
org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:50)[107:org.eclipse.jetty.server:7.4.5.v20110725]

        at
   
org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90)[107:org.eclipse.jetty.server:7.4.5.v20110725]

        at
   
org.eclipse.jetty.server.Server.doStart(Server.java:258)[107:org.eclipse.jetty.server:7.4.5.v20110725]

        at
   
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)[119:org.eclipse.jetty.util:7.4.5.v20110725]

        at
   
org.ops4j.pax.web.service.jetty.internal.JettyServerImpl.start(JettyServerImpl.java:98)[122:org.ops4j.pax.web.pax-web-jetty:1.0.7]

        at
   
org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl$Stopped.start(ServerControllerImpl.java:356)[122:org.ops4j.pax.web.pax-web-jetty:1.0.7]

        at
   
org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl.start(ServerControllerImpl.java:67)[122:org.ops4j.pax.web.pax-web-jetty:1.0.7]

        at
   
org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl$Unconfigured.configure(ServerControllerImpl.java:510)[122:org.ops4j.pax.web.pax-web-jetty:1.0.7]

        at
   
org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl.configure(ServerControllerImpl.java:84)[122:org.ops4j.pax.web.pax-web-jetty:1.0.7]

        at
   
org.ops4j.pax.web.service.internal.Activator$2.updated(Activator.java:150)[124:org.ops4j.pax.web.pax-web-runtime:1.0.7]

        at
   
org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1160)[5:org.apache.felix.configadmin:1.2.8]

        at
   
org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:104)[5:org.apache.felix.configadmin:1.2.8]

        at java.lang.Thread.run(Thread.java:662)[:1.6.0_37]
   Caused by: java.lang.ClassNotFoundException:
   org.eclipse.jetty.jndi.InitialContextFactory
        at
   java.net.URLClassLoader$1.run(URLClassLoader.java:202)[:1.6.0_37]
        at java.security.AccessController.doPrivileged(Native
   Method)[:1.6.0_37]
        at
   java.net.URLClassLoader.findClass(URLClassLoader.java:190)[:1.6.0_37]
        at
   java.lang.ClassLoader.loadClass(ClassLoader.java:306)[:1.6.0_37]
        at
   sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)[:1.6.0_37]

        at
   java.lang.ClassLoader.loadClass(ClassLoader.java:247)[:1.6.0_37]
        at java.lang.Class.forName0(Native Method)[:1.6.0_37]
        at java.lang.Class.forName(Class.java:247)[:1.6.0_37]
        at
   
com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)[:1.6.0_37]

        at
   
javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)[:1.6.0_37]

        ... 20 more

This is very odd since the missing class (/org.eclipse.jetty.jndi.InitialContextFactory/) is owned by the Active "Jetty :: JNDI Naming (7.4.5.v20110725)" bundle that properly exports the package /org.eclipse.jetty.jndi/ containing the missing class. I think that the Config error I face when using the first approach may be related to the above issue.
Any ideas are welcome.

Regards,
Vincenzo

Il 02/01/2013 21:40, Achim Nierbeck ha scritto:
Well the jetty in ServiceMix/Karaf does work quite differently compared to
a standalone.
So this doesn't necessarily work. But since you are using a OSGi container,
why don't you reference your Connection pool via services?
If JNDI is required you still can use Aries to provide it as a JNDI
service.

Regards, Achim


2013/1/2 Vincenzo Laudizio <[email protected]>

Hi,

I'm trying to configure the servicemix 4.4.2 embedded Jetty in order to
register a Datasource as a JNDI Resource.
If I add the following statement:

         <New id="DSTest" class="org.eclipse.jetty.plus.**jndi.Resource">
              <Arg/>
              <Arg>jdbc/DSTest</Arg>
              <Arg>
                 <New
    class="com.mysql.jdbc.jdbc2.**optional.**MysqlConnectionPoolDataSource"
**>
                    <Set
    name="Url">jdbc:mysql://**localhost:3306/sessions</Set>
                    <Set name="User">root</Set>
                    <Set name="Password">root</Set>
                 </New>
               </Arg>
         </New>


in <ServiceMix_Home>/etc/jetty.**xml file and i run servicemix, i get the
following error:

    org.eclipse.jetty.util - 7.4.5.v20110725 | Config error at <New
    id="DSTest" class="org.eclipse.jetty.plus.**jndi.Resource"> ...

This is very odd since the same configuration works well on a standalone
Jetty (version 7.4.5.v20110725).

Where am I wrong?

Vincenzo






Reply via email to