Hi Simone,
Thank you for the suggestion. I tried it but it didn't work because
getServer() returns null at the time the WebAppContext instance is
configured.
Instead, I tried a slight variation on your idea. I added the connector
and the WebAppContext handler explicitly to the server calling setHandler
(see below). Do you think this is a reasonable way to do it?
Thanks,
Josh
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Map id="myContext">
...
</Map>
<Set name="Handler">
<New class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/mywar</Set>
<Set name="war">mywar.war</Set>
<Get name="ServletContext">
<Call name="setAttribute">
<Arg>adb-context</Arg>
<Arg><Ref refid="myContext"/></Arg>
</Call>
</Get>
</New>
</Set>
<Call name="addConnector">
<Arg>
<New id="myConnector"
class="org.eclipse.jetty.server.ServerConnector">
<Arg name="server"><Ref refid="Server"/></Arg>
<Arg name="factories"><Array
type="org.eclipse.jetty.server.ConnectionFactory"/></Arg>
</New>
</Arg>
</Call>
<Ref refid="myConnector">
<Call name="addConnectionFactory">
<Arg>
<New class="com.example.TestConnectionFactory">
<Arg><Ref refid="myContext"/></Arg>
</New>
</Arg>
</Call>
</Ref>
</Configure>
On Mon, Jan 20, 2020 at 8:56 AM Simone Bordet <[email protected]> wrote:
> Hi,
>
> On Mon, Jan 20, 2020 at 4:53 PM Josh Spiegel <[email protected]> wrote:
> >
> > I have the ConnectionFactory and the Connection implementations.
> > I have the Servlet (deployed in a war file)
> >
> > The ConnectionFactory/Connection are deployed using a Jetty module/xml
> with start.jar.
> > The servlet is deployed by dropping the war file in webapps.
> >
> > I have some dynamic state (mainly database connection pools) that I
> would like to share between the ConnectionFactory and the Servlet.
> >
> > I can set the state object as a context attribute from the servlet.
> However, then it isn't clear to me how I would retrieve it from either the
> ConnectionFactory or Connection.
>
> I would create your shared state bean, and add it as a Server
> attribute - this can be done via a Jetty XML file and module like you
> have already done.
> This bean would then be easily retrievable from the ConnectionFactory
> implementation, and passed to Connections.
>
> You can then have a custom context XML file for your webapp, that
> retrieves the bean from the server and sets it as a context attribute.
> This file can be something like (pseudo code to convert to XML):
>
> Server server = this.getServer();
> Object bean = server.getAttribute("mySharedBean");
> this.setAttribute("mySharedBean", bean);
>
> where "this" is a WebAppContext (as per Jetty context XML file).
>
> --
> Simone Bordet
> ----
> http://cometd.org
> http://webtide.com
> Developer advice, training, services and support
> from the Jetty & CometD experts.
> _______________________________________________
> jetty-users mailing list
> [email protected]
> To change your delivery options, retrieve your password, or unsubscribe
> from this list, visit
> https://www.eclipse.org/mailman/listinfo/jetty-users
>
_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://www.eclipse.org/mailman/listinfo/jetty-users