Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [equinox-dev] injecting Databaseconnection (or -pool) into servletbridge

Hi,

thanks for your reply. I tried to set the ContextLoader to the contextloader of the bridgeservlet, but I'm not sure how to get this BridgeServlet from within my code? This servlet is located in the WEB-INF/lib folder in the servletbridge.jar. But I can't get this from within my osgi-application, when adding a require-package to the org.eclipse.equinox.servletbridge package during startup I get a Package-not-available-exception.


-orgler

2009/9/10 Simon Kaegi <Simon_Kaegi@xxxxxxxxxx>

The short answer is that getting JNDI to work is a bit tricky as there are generally lookup dependencies on the context class loader and for some servers the lookup must be done by an incoming request thread. Here's an answer I wrote a ways back that should help but feel free to ask more questions as needed.

http://dev.eclipse.org/newslists/news.eclipse.technology.rap/msg05172.html


Inactive hide details for Johannes Michler ---09/10/2009 10:58:40 AM---Hi, I wrote a small application using eclipse equinox, tJohannes Michler ---09/10/2009 10:58:40 AM---Hi, I wrote a small application using eclipse equinox, that accesses a database


From:

Johannes Michler <orgler@xxxxxxxxx>

To:

equinox-dev@xxxxxxxxxxx

Date:

09/10/2009 10:58 AM

Subject:

[equinox-dev] injecting Databaseconnection (or -pool) into servletbridge

Sent by:

equinox-dev-bounces@xxxxxxxxxxx




Hi,

I wrote a small application using eclipse equinox, that accesses a database using eclipselink JPA and exposes some services using apache CXF. I manged to get this to work using the embedded jetty. In this scenario, the standalone application gets some command-line parameters specifying to which database connect and under what port to expose the http-server. This is fine, so I moved a step further and tried to deploy the same code using the servletbridge into some servlet-containers. After some troubles I managed to get this work for tomcat6 and Oracle 10g app-server (10.1.2). 

For passing the parameters specifying my database, I used the launch.ini in the servletbridge directory to set some environment-variables. But this solution has one mayor drawback: To adapt the jdbc-url I have to edit the  launch.ini, make a new .war and deploy this .war on my app-server. 
Is there a way to do this more conveniently? I'm new to application servers, here is what I tried so far:


But how do I get the jdbc-connection from within my eclipse-application? I'm doing the following to get the httpService in my Activator:
ServiceReference reference = context.getServiceReference( HttpService.class.getName());

        HttpService httpService = null;
        if ( reference != null)
            httpService = ( HttpService) context.getService( reference);

To get the db-connection I tried the following code from the tomcat-6 documentation (http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html):

try {
        javax.naming.Context initContext = new javax.naming.InitialContext();
        javax.naming.Context envContext  = (javax.naming.Context)initContext.lookup("java:/comp/env");
        javax.sql.DataSource ds = (javax.sql.DataSource)envContext.lookup("jdbc/myoracle");
        
            java.sql.Connection conn = ds.getConnection();
        } catch ( SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch ( NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

But this didn't work. Tomcat6 complained about "java.lang.ClassNotFoundException: org.apache.naming.java.javaURLContextFactory" and OC4J reported it could not find the java:/comp/env context.

Any hints on how to solve this? 


Best regards
-orgler_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev



_______________________________________________
equinox-dev mailing list
equinox-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/equinox-dev


GIF image

GIF image


Back to the top