Has Jetty a JNDI <ResourceLink> feature similar to Tomcat?

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

Has Jetty a JNDI <ResourceLink> feature similar to Tomcat?

Daniel Mueller
Hi,

I'm currently trying to migrate my application from Tomcat to Jetty 6.1.1. I can get everything working, but I lose a nice feature on the way: the resourcelinks defined in the tomcat context xmls. Is there a way to have this kind of configuration in jetty?

I'll do a quick outline of our configuration requirement, which can be done in tomcat, and for which I haven't found a way to solve in jetty:
- We define Datasources, MessageQueues and whatnot in the server.xml. Each of them is bound to a unique name in the global JNDI scope (e.g. jms/cfForTesting, jms/cfForDemo, etc.).
- We bind those global ressources in the global scope to a web-app in Tomcat's context.xmls with something like:
     <ResourceLink name="jms/connectionFactory" global="jms/cfForTesting" type="javax.jms.ConnectionFactory"/>
  The name is what is then retrieved in the webapplication and referenced in the web.xml.
This setup comes in extremely handy when you want to define a ressource once in the server.xml but don't want to enforce a given name over more than one application deployed in the same container.

I tried to fix it with JNDI Names only first, without much success. Then I found the <Ref> tag in the configuration description, which I hoped would solve my problem. Which was unfortunately untrue.

In the context XML file:
  <New class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>jdbc/Database</Arg>
    <Arg><Ref id="jdbc/cfForTesting"/></Arg>
  </New>

In the jetty-plus.xml:
  <New id="jms/cfForTesting" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>jms/cfForTesting</Arg>
    <Arg>
      <New class="org.apache.activemq.ActiveMQConnectionFactory">
        <Set name="brokerURL">failover://(tcp://*****,tcp://*****)</Set>
      </New>
    </Arg>
  </New>


Jetty barfs with:

2007-04-03 18:29:43.446::INFO:  jetty-6.1.1
2007-04-03 18:29:43.587::WARN:  Config error at <New class="org.mortbay.jetty.plus.naming.Resource"><Arg>jms/connectionFactory</Arg><Arg><Ref id="jms/cfForTesting"/></Arg></New>
2007-04-03 18:29:43.587::WARN:  EXCEPTION
java.lang.IllegalStateException: No object for id=jms/cfForTesting
        at org.mortbay.xml.XmlConfiguration.refObj(XmlConfiguration.java:632)
        at org.mortbay.xml.XmlConfiguration.itemValue(XmlConfiguration.java:877)
        at org.mortbay.xml.XmlConfiguration.value(XmlConfiguration.java:798)
        at org.mortbay.xml.XmlConfiguration.newObj(XmlConfiguration.java:580)
        at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:245)
        at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:203)
        at org.mortbay.jetty.deployer.ContextDeployer.createContext(ContextDeployer.java:353)
        at org.mortbay.jetty.deployer.ContextDeployer.deploy(ContextDeployer.java:250)
        at org.mortbay.jetty.deployer.ContextDeployer.access$000(ContextDeployer.java:67)
        at org.mortbay.jetty.deployer.ContextDeployer$ScannerListener.fileAdded(ContextDeployer.java:88)
        at org.mortbay.util.Scanner.reportAddition(Scanner.java:347)
        at org.mortbay.util.Scanner.reportDifferences(Scanner.java:271)
        at org.mortbay.util.Scanner.scan(Scanner.java:232)
        at org.mortbay.jetty.deployer.ContextDeployer.doStart(ContextDeployer.java:315)
        at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
        at org.mortbay.jetty.Server.doStart(Server.java:187)
        at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
        at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:929)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.mortbay.start.Main.invokeMain(Main.java:183)
        at org.mortbay.start.Main.start(Main.java:497)
        at org.mortbay.start.Main.main(Main.java:115)

The rest of the configuration is more or less directly out of the distribution-file.

Is there a way in Jetty to achieve the desired effect?

Thanks
Daniel

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Has Jetty a JNDI <ResourceLink> feature similar to Tomcat?

David Yu-3
Hi Muller,

    Once you declare your resource in jetty-plus.xml/jetty.xml, that
resource is globally accessible.
    Declaring it on a WEB-INF/jetty-env.xml will make it exclusive for
that particular webapp.

If you wanted it global, inserting this in your jetty.xml/jetty-plus.xml
will make it accessible globally without extra configuration.

  <New id="jms/cfForTesting" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>jms/cfForTesting</Arg>
    <Arg>
      <New class="org.apache.activemq.ActiveMQConnectionFactory">
        <Set name="brokerURL">failover://(tcp://*****,tcp://*****)</Set>
      </New>
    </Arg>
  </New>



Else if you want it exclusive on a particular webapp,
create a WEB-INF/jetty-env.xml :

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">

<Configure class="org.mortbay.jetty.webapp.WebAppContext">

  <New id="jms/cfForTesting" class="org.mortbay.jetty.plus.naming.Resource">
    <Arg>jms/cfForTesting</Arg>
    <Arg>
      <New class="org.apache.activemq.ActiveMQConnectionFactory">
        <Set name="brokerURL">failover://(tcp://*****,tcp://*****)</Set>
      </New>
    </Arg>
  </New>

</Configure>


Hope this helps,
David
   

Müller Daniel wrote:

> Hi,
>
> I'm currently trying to migrate my application from Tomcat to Jetty 6.1.1. I can get everything working, but I lose a nice feature on the way: the resourcelinks defined in the tomcat context xmls. Is there a way to have this kind of configuration in jetty?
>
> I'll do a quick outline of our configuration requirement, which can be done in tomcat, and for which I haven't found a way to solve in jetty:
> - We define Datasources, MessageQueues and whatnot in the server.xml. Each of them is bound to a unique name in the global JNDI scope (e.g. jms/cfForTesting, jms/cfForDemo, etc.).
> - We bind those global ressources in the global scope to a web-app in Tomcat's context.xmls with something like:
>      <ResourceLink name="jms/connectionFactory" global="jms/cfForTesting" type="javax.jms.ConnectionFactory"/>
>   The name is what is then retrieved in the webapplication and referenced in the web.xml.
> This setup comes in extremely handy when you want to define a ressource once in the server.xml but don't want to enforce a given name over more than one application deployed in the same container.
>
> I tried to fix it with JNDI Names only first, without much success. Then I found the <Ref> tag in the configuration description, which I hoped would solve my problem. Which was unfortunately untrue.
>
> In the context XML file:
>   <New class="org.mortbay.jetty.plus.naming.Resource">
>     <Arg>jdbc/Database</Arg>
>     <Arg><Ref id="jdbc/cfForTesting"/></Arg>
>   </New>
>
> In the jetty-plus.xml:
>   <New id="jms/cfForTesting" class="org.mortbay.jetty.plus.naming.Resource">
>     <Arg>jms/cfForTesting</Arg>
>     <Arg>
>       <New class="org.apache.activemq.ActiveMQConnectionFactory">
>         <Set name="brokerURL">failover://(tcp://*****,tcp://*****)</Set>
>       </New>
>     </Arg>
>   </New>
>
>
> Jetty barfs with:
>
> 2007-04-03 18:29:43.446::INFO:  jetty-6.1.1
> 2007-04-03 18:29:43.587::WARN:  Config error at <New class="org.mortbay.jetty.plus.naming.Resource"><Arg>jms/connectionFactory</Arg><Arg><Ref id="jms/cfForTesting"/></Arg></New>
> 2007-04-03 18:29:43.587::WARN:  EXCEPTION
> java.lang.IllegalStateException: No object for id=jms/cfForTesting
>         at org.mortbay.xml.XmlConfiguration.refObj(XmlConfiguration.java:632)
>         at org.mortbay.xml.XmlConfiguration.itemValue(XmlConfiguration.java:877)
>         at org.mortbay.xml.XmlConfiguration.value(XmlConfiguration.java:798)
>         at org.mortbay.xml.XmlConfiguration.newObj(XmlConfiguration.java:580)
>         at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:245)
>         at org.mortbay.xml.XmlConfiguration.configure(XmlConfiguration.java:203)
>         at org.mortbay.jetty.deployer.ContextDeployer.createContext(ContextDeployer.java:353)
>         at org.mortbay.jetty.deployer.ContextDeployer.deploy(ContextDeployer.java:250)
>         at org.mortbay.jetty.deployer.ContextDeployer.access$000(ContextDeployer.java:67)
>         at org.mortbay.jetty.deployer.ContextDeployer$ScannerListener.fileAdded(ContextDeployer.java:88)
>         at org.mortbay.util.Scanner.reportAddition(Scanner.java:347)
>         at org.mortbay.util.Scanner.reportDifferences(Scanner.java:271)
>         at org.mortbay.util.Scanner.scan(Scanner.java:232)
>         at org.mortbay.jetty.deployer.ContextDeployer.doStart(ContextDeployer.java:315)
>         at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
>         at org.mortbay.jetty.Server.doStart(Server.java:187)
>         at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:40)
>         at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:929)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
>         at java.lang.reflect.Method.invoke(Unknown Source)
>         at org.mortbay.start.Main.invokeMain(Main.java:183)
>         at org.mortbay.start.Main.start(Main.java:497)
>         at org.mortbay.start.Main.main(Main.java:115)
>
> The rest of the configuration is more or less directly out of the distribution-file.
>
> Is there a way in Jetty to achieve the desired effect?
>
> Thanks
> Daniel
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
> _______________________________________________
> Jetty-support mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/jetty-support
>
> !DSPAM:531,4612848d82701032652825!
>  


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Has Jetty a JNDI <ResourceLink> feature similar to Tomcat?

Daniel Mueller
Hi David,

Your suggested approach still doesn't solve my problem. I want to configure the ressources globally and then rebind them  for each webapp (which gets you a n-n mapping for ressources). The global config should go to jetty-plus.xml/jetty.xml and the rebinding to contexts/<webapp-name>.xml.

Daniel

Reply | Threaded
Open this post in threaded view
|

Re: Has Jetty a JNDI <ResourceLink> feature similar to Tomcat?

jan_bartel
Hi Daniel,

It's unfortunate that the servlet spec didn't allow for
mappings from names in the container-specifc environment
to the webapp-environment. Thus, every container has had to
do something special in a separate container-specific
descriptor.

Jetty has simply made the rule that the name in the
webapp scope must be the same as the name in the
container environment. I guess we could add something
to a jetty-env.xml file which would allow for linkages.

However this will become unnecessary with resource injection,
because the mapping is supported by the spec - cf the
"mappedName" attribute of @Resource:

@Resource(name=”customerDB” mappedName="jdbc/myglobalname")
private void setMyDB(DataSource ds)
{    
    myDB = ds;
}

cheers
Jan

Daniel Mueller wrote:

> Hi David,
>
> Your suggested approach still doesn't solve my problem. I want to configure
> the ressources globally and then rebind them  for each webapp (which gets
> you a n-n mapping for ressources). The global config should go to
> jetty-plus.xml/jetty.xml and the rebinding to contexts/<webapp-name>.xml.
>
> Daniel
>
>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support
Reply | Threaded
Open this post in threaded view
|

Re: Has Jetty a JNDI <ResourceLink> feature similar to Tomcat?

Daniel Müller-4
Hi Jan,

I don't think that this will solve my problem. What I want is not to embed anything container specific or configuration specific into my war. Take the following use case: you have one war, which refers to a jdbc ressource via JNDI. You want to deploy it for whatever reason twice in the same container but linked to different databases. In this case you'd absolutely need a <ResourceLink> in the webapp context, because otherwise there's no way to get this working properly without touching the contents of the war-file. Doing the linking via Resource injection and  is about halfway where I want to go, because I'd like to do the
      name="customerDB" mappedName="jdbc/myglobalname"
mapping in the context file outside the webapp.

cheers,
Daniel

On 4/6/07, Jan Bartel <[hidden email]> wrote:
Hi Daniel,

It's unfortunate that the servlet spec didn't allow for
mappings from names in the container-specifc environment
to the webapp-environment. Thus, every container has had to
do something special in a separate container-specific
descriptor.

Jetty has simply made the rule that the name in the
webapp scope must be the same as the name in the
container environment. I guess we could add something
to a jetty-env.xml file which would allow for linkages.

However this will become unnecessary with resource injection,
because the mapping is supported by the spec - cf the
"mappedName" attribute of @Resource:

@Resource(name="customerDB" mappedName="jdbc/myglobalname")
private void setMyDB(DataSource ds)
{
    myDB = ds;
}

cheers
Jan

Daniel Mueller wrote:

> Hi David,
>
> Your suggested approach still doesn't solve my problem. I want to configure
> the ressources globally and then rebind them  for each webapp (which gets
> you a n-n mapping for ressources). The global config should go to
> jetty-plus.xml/jetty.xml and the rebinding to contexts/<webapp-name>.xml.
>
> Daniel
>
>


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support


-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jetty-support mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-support