Question for JDBC JNDI look up issue

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

Question for JDBC JNDI look up issue

Lin Ren

Hi Team,

 

I’m not sure if I’m mailing the correct alias but I’ve a question about Jetty usage.

 

I’m currently trying to build up applications based on standalone Jetty and have a requirement that, some of the server services need be started before the war applications are deployed and started to provide general services for the deployed applications.

 

I tried to create a class which inherits “org.eclipse.jetty.util.component.AbstractLifeCycle” with annotation “@ManagedObject”, and also, it is injected by adding definitions into jetty.xml like below:

 

    <Call name="addManaged">

      <Arg>

        <New class="oraclel.ocsg.jetty.trial.MyAbstractLifeCycle"/>

      </Arg>

    </Call>

 

And, within the class, I need get access to the JDBC connection data source. I checked the document and found that, for applications, it is required to add the jdbc resource reference into the web.xml. While for my case, I don’t know how to get the data source. I tried to lookup JNDI in the MyAbstractLifeCycle class I created, but it failed.

 

Below is my JDBC connection pool definition in the jetty.xml:

 

    <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">

     <Arg></Arg>

     <Arg>jdbc/DSTest</Arg>

     <Arg>

        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">

           <Set name="Url">jdbc:mysql://10.182.12.146:3306/linren</Set>

           <Set name="User">ocsgtest</Set>

           <Set name="Password">123456</Set>

        </New>

     </Arg>

    </New>

 

Can anyone tell me how to get the JDBC connection from the inherited class MyAbstractLifeCycle?

 

Thanks!

 

Lin

 


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Question for JDBC JNDI look up issue

Joakim Erdfelt-8
org.eclipse.jetty.util.annotation.ManagedObject is for JMX MBean support.

Using Server.addManaged(MyAbstractLifeCycle) will just start your bean after the other beans in the Server.

Perhaps you want to just start your server services anyway, completely outside of the Server instance lifecycle.
If you have no need to access anything from your server services, then there's no need to include them as a bean (or an attribute) on the Server.
Just start them before Server.start() is called.




Joakim Erdfelt / [hidden email]

On Thu, Mar 22, 2018 at 8:25 AM, Lin Ren <[hidden email]> wrote:

Hi Team,

 

I’m not sure if I’m mailing the correct alias but I’ve a question about Jetty usage.

 

I’m currently trying to build up applications based on standalone Jetty and have a requirement that, some of the server services need be started before the war applications are deployed and started to provide general services for the deployed applications.

 

I tried to create a class which inherits “org.eclipse.jetty.util.component.AbstractLifeCycle” with annotation “@ManagedObject”, and also, it is injected by adding definitions into jetty.xml like below:

 

    <Call name="addManaged">

      <Arg>

        <New class="oraclel.ocsg.jetty.trial.MyAbstractLifeCycle"/>

      </Arg>

    </Call>

 

And, within the class, I need get access to the JDBC connection data source. I checked the document and found that, for applications, it is required to add the jdbc resource reference into the web.xml. While for my case, I don’t know how to get the data source. I tried to lookup JNDI in the MyAbstractLifeCycle class I created, but it failed.

 

Below is my JDBC connection pool definition in the jetty.xml:

 

    <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">

     <Arg></Arg>

     <Arg>jdbc/DSTest</Arg>

     <Arg>

        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">

           <Set name="Url">jdbc:mysql://10.182.12.146:3306/linren</Set>

           <Set name="User">ocsgtest</Set>

           <Set name="Password">123456</Set>

        </New>

     </Arg>

    </New>

 

Can anyone tell me how to get the JDBC connection from the inherited class MyAbstractLifeCycle?

 

Thanks!

 

Lin

 


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Question for JDBC JNDI look up issue

Jan Bartel
In reply to this post by Lin Ren
Make your class an AbstractLifeCycle, and add it to the Server with addBean(). Do it in jetty.xml before the call to setHandler, but after you've defined your datasource.  In your class, you can look up your datasource with context.lookup("jdbc/DSTest").

Jan

On 23 March 2018 at 00:25, Lin Ren <[hidden email]> wrote:

Hi Team,

 

I’m not sure if I’m mailing the correct alias but I’ve a question about Jetty usage.

 

I’m currently trying to build up applications based on standalone Jetty and have a requirement that, some of the server services need be started before the war applications are deployed and started to provide general services for the deployed applications.

 

I tried to create a class which inherits “org.eclipse.jetty.util.component.AbstractLifeCycle” with annotation “@ManagedObject”, and also, it is injected by adding definitions into jetty.xml like below:

 

    <Call name="addManaged">

      <Arg>

        <New class="oraclel.ocsg.jetty.trial.MyAbstractLifeCycle"/>

      </Arg>

    </Call>

 

And, within the class, I need get access to the JDBC connection data source. I checked the document and found that, for applications, it is required to add the jdbc resource reference into the web.xml. While for my case, I don’t know how to get the data source. I tried to lookup JNDI in the MyAbstractLifeCycle class I created, but it failed.

 

Below is my JDBC connection pool definition in the jetty.xml:

 

    <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">

     <Arg></Arg>

     <Arg>jdbc/DSTest</Arg>

     <Arg>

        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">

           <Set name="Url">jdbc:mysql://10.182.12.146:3306/linren</Set>

           <Set name="User">ocsgtest</Set>

           <Set name="Password">123456</Set>

        </New>

     </Arg>

    </New>

 

Can anyone tell me how to get the JDBC connection from the inherited class MyAbstractLifeCycle?

 

Thanks!

 

Lin

 


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



--
Jan Bartel <[hidden email]>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
Reply | Threaded
Open this post in threaded view
|

Re: Question for JDBC JNDI look up issue

Lin Ren

Thanks! It works!

 

From: Jan Bartel [mailto:[hidden email]]
Sent: 2018
323 6:55
To: JETTY user mailing list
Subject: Re: [jetty-users] Question for JDBC JNDI look up issue

 

Make your class an AbstractLifeCycle, and add it to the Server with addBean(). Do it in jetty.xml before the call to setHandler, but after you've defined your datasource.  In your class, you can look up your datasource with context.lookup("jdbc/DSTest").

 

Jan

 

On 23 March 2018 at 00:25, Lin Ren <[hidden email]> wrote:

Hi Team,

 

I’m not sure if I’m mailing the correct alias but I’ve a question about Jetty usage.

 

I’m currently trying to build up applications based on standalone Jetty and have a requirement that, some of the server services need be started before the war applications are deployed and started to provide general services for the deployed applications.

 

I tried to create a class which inherits “org.eclipse.jetty.util.component.AbstractLifeCycle” with annotation “@ManagedObject”, and also, it is injected by adding definitions into jetty.xml like below:

 

    <Call name="addManaged">

      <Arg>

        <New class="oraclel.ocsg.jetty.trial.MyAbstractLifeCycle"/>

      </Arg>

    </Call>

 

And, within the class, I need get access to the JDBC connection data source. I checked the document and found that, for applications, it is required to add the jdbc resource reference into the web.xml. While for my case, I don’t know how to get the data source. I tried to lookup JNDI in the MyAbstractLifeCycle class I created, but it failed.

 

Below is my JDBC connection pool definition in the jetty.xml:

 

    <New id="DSTest" class="org.eclipse.jetty.plus.jndi.Resource">

     <Arg></Arg>

     <Arg>jdbc/DSTest</Arg>

     <Arg>

        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">

           <Set name="Url">jdbc:mysql://10.182.12.146:3306/linren</Set>

           <Set name="User">ocsgtest</Set>

           <Set name="Password">123456</Set>

        </New>

     </Arg>

    </New>

 

Can anyone tell me how to get the JDBC connection from the inherited class MyAbstractLifeCycle?

 

Thanks!

 

Lin

 


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users



 

--

Jan Bartel <[hidden email]>

www.webtide.com
Expert assistance from the creators of Jetty and CometD

 


_______________________________________________
jetty-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users