users@grizzly.java.net

Re: Grizzly and Servlet Adapter

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Mon, 02 Feb 2009 14:32:13 -0500

Salut,

Richard Corsale wrote:
> Ok, so.. unless im missing something here, the servlet to adapter ration
> is 1:1 like i can only add one servlet to one adapter and I have to make
> a new adapter for each servlet?

Yes.

>
> If thats the case, whats the
> sadapter.addServletListener("API.Web.Servlets"); for? as shown in the
> latest example on
> http://weblogs.java.net/blog/jfarcand/archive/2009/01/extending_the_g_5.html

Can you elaborate? You add the listener to the Servlet you want via the
ServletAdapter. An example can be seen here:

https://grizzly.dev.java.net/nonav/xref/com/sun/grizzly/hudson/Hudson.html

A+

--Jeanfrancois


>
>
> --Thanks
> Richard
>
>
>
> ------------------------------------------------------------------------
> *From:* Survivant 00 <survivant00_at_gmail.com>
> *To:* users_at_grizzly.dev.java.net
> *Sent:* Saturday, January 31, 2009 7:28:11 PM
> *Subject:* php on GrizzlyWebServer 100%java with JSR 223
>
> I have something that can do PHP wihtout native php installation.
>
> I wasn't able to get Quercus servlet to work with GrizzlyWebServer, but
> I have a workaround for now that will allow the users to run php with
> the JSR223.
>
> you have a create a serlvet that you will use with GrizzlyWebServer
> (I'll post a complete demo on my blog later this weekend)
>
>
>
>
> protected void doPut (HttpServletRequest req, HttpServletResponse
> res) throws ServletException, IOException {
>
> System.out.println("doPut");
>
> Object php2javaResult = null;
>
> ScriptContext context = phpEngine.getContext();
>
> try {
> context.setWriter(new StringWriter());
>
> //put the parameters and attributes into the engine
> Enumeration attributes = req.getAttributeNames();
>
> while (attributes.hasMoreElements()) {
> String key = (String) attributes.nextElement();
>
> // put the parameters and attributes into the engine
> phpEngine.put(key, req.getAttribute(key));
> }
>
> Map<String, Object> params = req.getParameterMap();
>
> for (Iterator iterator = params.keySet().iterator();
> iterator.hasNext();) {
> String key = (String) iterator.next();
>
> // put the parameters and attributes into the engine
> phpEngine.put(key, params.get(key));
> }
>
> // need a better way to find the requested file
> String uri = req.getRequestURI();
>
> if(uri.startsWith("/")){
> uri = uri.substring(1);
> }
>
> php2javaResult = phpEngine.eval(new FileReader(uri), context);
> //php2javaResult = phpEngine.eval(new
> FileReader("phpinfo.php"), context);
> StringWriter writer = (StringWriter) context.getWriter();
> res.getWriter().println(writer.toString());
> } catch (Exception ex) {
> ex.printStackTrace();
> }
>
> }
>
> protected void doGet (HttpServletRequest req, HttpServletResponse
> res) throws ServletException, IOException {
> doPut(req, res);
> }
>
>
> if I enter the URL :
> http://localhost/phpinfo.php?coucou&id=12
> <http://localhost/phpinfo.php?coucou&id=12>
>
> the file phpinfo will be executed with the params in the URL.
>
>
> PS. if I need to put attributes in the response just tell me.. I did
> though about that.
>
> PS2 : if you need a complete solution... Glassfish with Quercus is one
> good solution.
>
> PS3 : I used Quercus librairies for this example.
>
> 2009/1/29 Richard Corsale <igf1_at_yahoo.com <mailto:igf1_at_yahoo.com>>
>
> Great tutorial man!! I was wondering about this very subject the
> other day.
>
> I still can't get my PHP scripts to run on Grizzly... I don't know
> why I wrote them in SQL?? :)
>
> --Richard
>
>
> ------------------------------------------------------------------------
> *From:* Survivant 00 <survivant00_at_gmail.com
> <mailto:survivant00_at_gmail.com>>
> *To:* users_at_grizzly.dev.java.net <mailto:users_at_grizzly.dev.java.net>
> *Sent:* Thursday, January 29, 2009 1:53:27 PM
> *Subject:* Demo : How to host jsp files with GrizzlyWebServer
>
> I did a little demo how to use JSP and GrizzlyWebServer.
>
> http://weblogs.java.net/blog/survivant/archive/2009/01/jsp_on_grizzlyw.html
>
> you won't do a complete web server with that.. but I'm sure you can
> still have fun :)
>
>
>
>