Calling Java App methods from Jetty JSP/Servlet?

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

Calling Java App methods from Jetty JSP/Servlet?

Internet Man
Hello all.

I'd like to use Jetty as an embedded Servlet/JSP container into an existing
Java App. My question is, how can I call a method living in the main app
from a Servlet or JSP started by Jetty?

- NB




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java App methods from Jetty JSP/Servlet?

Niclas Hedhman
On Monday 06 June 2005 13:51, Internet Man wrote:
> Hello all.
>
> I'd like to use Jetty as an embedded Servlet/JSP container into an existing
> Java App. My question is, how can I call a method living in the main app
> from a Servlet or JSP started by Jetty?

I let the main app or the bootstrapper, create a servlet context entry
containing the bridging elements.

Niclas


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

RE: Calling Java App methods from Jetty JSP/Servlet?

rasto1968
In reply to this post by Internet Man
If the servlet/JSP is only ever going to be used in your server, then either
make a static method in the server that returns it's instance - you can then
access the public methods of the server easily. An even more simple way is
to just make the server methods you want to call static.

Rob

-----Original Message-----
From: [hidden email]
[mailto:[hidden email]]On Behalf Of Internet
Man
Sent: 06 June 2005 06:51
To: [hidden email]
Subject: [jetty-discuss] Calling Java App methods from Jetty
JSP/Servlet?


Hello all.

I'd like to use Jetty as an embedded Servlet/JSP container into an existing
Java App. My question is, how can I call a method living in the main app
from a Servlet or JSP started by Jetty?

- NB




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you
shotput
a projector? How fast can you ride your desk chair down the office luge
track?
If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss



-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java App methods from Jetty JSP/Servlet?

Chris Haynes
In reply to this post by Internet Man
I have a large numbers of Objects cached from recent database queries. Each has
an ID String. I hold the objects in a static Map<String,DB_Object> within a
well-known class (actually the one that manages the cache). The web pages return
the IDs as references, so I do a look-up from each servlet to get the app-wide
objects it requires.

Chris Haynes

"Internet Man" asked

> Hello all.
>
> I'd like to use Jetty as an embedded Servlet/JSP container into an existing
> Java App. My question is, how can I call a method living in the main app from
> a Servlet or JSP started by Jetty?
>
> - NB
>





-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java App methods from Jetty JSP/Servlet?

Greg Wilkins-5
In reply to this post by Internet Man
Internet Man wrote:
> Hello all.
>
> I'd like to use Jetty as an embedded Servlet/JSP container into an
> existing Java App. My question is, how can I call a method living in the
> main app from a Servlet or JSP started by Jetty?

The best way to communicate from an application to the contained webapp
is to pass objects via context attributes as you construct/configure jetty.

cheers




-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you shotput
a projector? How fast can you ride your desk chair down the office luge track?
If you want to score the big prize, get to know the little guy.  
Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java App methods from Jetty JSP/Servlet?

Internet Man
In reply to this post by Niclas Hedhman

Niclas,

My confusion is the following: I don't want a specific .jsp or servlet to
handle a request. What I want is for a method within my application to
handle a request.

As for creating "a servlet context entry containing the bridging elements",
does that mean passing a reference to one of my classes into the servlet
context and then using that reference from a jsp to access my class? If yes,
how do I "put" that reference into the context (the javadoc is not clear on
this).

THANKS!!!

>From: Niclas Hedhman <[hidden email]>
>Reply-To: [hidden email]
>To: [hidden email]
>Subject: Re: [jetty-discuss] Calling Java App methods from Jetty
>JSP/Servlet?
>Date: Mon, 6 Jun 2005 14:29:01 +0800
>
>On Monday 06 June 2005 13:51, Internet Man wrote:
> > Hello all.
> >
> > I'd like to use Jetty as an embedded Servlet/JSP container into an
>existing
> > Java App. My question is, how can I call a method living in the main app
> > from a Servlet or JSP started by Jetty?
>
>I let the main app or the bootstrapper, create a servlet context entry
>containing the bridging elements.
>
>Niclas
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by: NEC IT Guy Games.  How far can you
>shotput
>a projector? How fast can you ride your desk chair down the office luge
>track?
>If you want to score the big prize, get to know the little guy.
>Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20
>_______________________________________________
>jetty-discuss mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/jetty-discuss




-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java App methods from Jetty JSP/Servlet?

Anthony Cook
Greetings,

Internet Man wrote:
> As for creating "a servlet context entry containing the bridging
> elements", does that mean passing a reference to one of my classes into
> the servlet context and then using that reference from a jsp to access
> my class? If yes, how do I "put" that reference into the context (the
> javadoc is not clear on this).
>

Use the getServletContext method of ServletHttpContext to get the
created context and add a reference to your class as an attribute to it.

Regards,

Anthony

vschade.vcf (226 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java App methods from Jetty JSP/Servlet?

Niclas Hedhman
In reply to this post by Internet Man
On Saturday 09 July 2005 23:37, Internet Man wrote:

> Niclas,
>
> My confusion is the following: I don't want a specific .jsp or servlet to
> handle a request. What I want is for a method within my application to
> handle a request.
>
> As for creating "a servlet context entry containing the bridging elements",
> does that mean passing a reference to one of my classes into the servlet
> context and then using that reference from a jsp to access my class? If
> yes, how do I "put" that reference into the context (the javadoc is not
> clear on this).

As I said, provided that you have your own bootstrapping of Jetty.


1. So, you have some type of service that handles the request. You need to
figure out what interface exposes, as ideally it should probably not be Http
specific.

  public interface MyService
  {
      void execute( PrintWriter out, BufferedReader in, Map args );
  }


2. Create Jetty, i.e a HttpServer, Listeners and a ServletHttpContext.
Add an attribute to the ServletHttpContext pointing to the MyService
implementation.
  MyService myService = ....
  ServletHttpContext shc = ....
  shc.setAttribute( "my.service", myService );

3. Create a Servlet that converts the Http request and response into the
chosen signature of your MyService interface, and picks up the MyService
implementation from the servlet context's attribute.
  ServletContext context = getServletContext();
  MyService myService = (MyService) context.getAttribute( "my.service" );
 


Hope I didn't forget something important in this early hour :o)
But I think you get the idea.


Cheers
Niclas


-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Calling Java App methods from Jetty JSP/Servlet?

Internet Man

Niclas,

Thanks for your detailed reply. I think I can pick it up from there on my
own. I really appreciate it.

N.B.

>From: Niclas Hedhman <[hidden email]>
>Reply-To: [hidden email]
>To: [hidden email]
>Subject: Re: [jetty-discuss] Calling Java App methods from Jetty
>JSP/Servlet?
>Date: Mon, 11 Jul 2005 11:18:36 +0800
>
>On Saturday 09 July 2005 23:37, Internet Man wrote:
> > Niclas,
> >
> > My confusion is the following: I don't want a specific .jsp or servlet
>to
> > handle a request. What I want is for a method within my application to
> > handle a request.
> >
> > As for creating "a servlet context entry containing the bridging
>elements",
> > does that mean passing a reference to one of my classes into the servlet
> > context and then using that reference from a jsp to access my class? If
> > yes, how do I "put" that reference into the context (the javadoc is not
> > clear on this).
>
>As I said, provided that you have your own bootstrapping of Jetty.
>
>
>1. So, you have some type of service that handles the request. You need to
>figure out what interface exposes, as ideally it should probably not be
>Http
>specific.
>
>   public interface MyService
>   {
>       void execute( PrintWriter out, BufferedReader in, Map args );
>   }
>
>
>2. Create Jetty, i.e a HttpServer, Listeners and a ServletHttpContext.
>Add an attribute to the ServletHttpContext pointing to the MyService
>implementation.
>   MyService myService = ....
>   ServletHttpContext shc = ....
>   shc.setAttribute( "my.service", myService );
>
>3. Create a Servlet that converts the Http request and response into the
>chosen signature of your MyService interface, and picks up the MyService
>implementation from the servlet context's attribute.
>   ServletContext context = getServletContext();
>   MyService myService = (MyService) context.getAttribute( "my.service" );
>
>
>
>Hope I didn't forget something important in this early hour :o)
>But I think you get the idea.
>
>
>Cheers
>Niclas
>
>
>-------------------------------------------------------
>This SF.Net email is sponsored by the 'Do More With Dual!' webinar
>happening
>July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
>core and dual graphics technology at this free one hour event hosted by HP,
>AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
>_______________________________________________
>jetty-discuss mailing list
>[hidden email]
>https://lists.sourceforge.net/lists/listinfo/jetty-discuss




-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA.  To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
jetty-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/jetty-discuss