Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 379180

Summary: Jetty server complains about missing context root
Product: [RT] Jetty Reporter: Steven Hung <sghung>
Component: serverAssignee: Jesse McConnell <jesse.mcconnell>
Status: CLOSED INVALID QA Contact:
Severity: blocker    
Priority: P3 CC: eyuen7, janb, jetty-inbox, tjwatson
Version: unspecified   
Target Milestone: 7.6.x   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Bug Depends on:    
Bug Blocks: 366092    
Attachments:
Description Flags
Web project example none

Description Steven Hung CLA 2012-05-10 15:49:48 EDT
Build Identifier: WTP S-3.4.0M7-20120507135259

This bug is related to bug 378493. After the required bundles were updated to use the jetty-8, there are complaints about the context root.

1. Use the patch from bug 378493 (otherwise the J2EE preview server cannot be started)
2. Create a new J2EE preview server
3. Create a dynamic web project (version 2.5) with a servlet
4. Add the project to the server
5. Start the server, the console will list the module 
6. When I run the servlet, it says:

Error 404 - Not Found
No context on this server matched or handled this request.
Contexts known to this server are: 
<lists my module and context root>

When taking a look at the generated metadata in Eclipse, it looks the same between Juno and Indigo (Indigo works), so this bug is for investigating why this context root issue is occurring.

Reproducible: Always
Comment 1 Jan Bartel CLA 2012-05-10 16:14:51 EDT
Hi Steven,

Can you paste (or can you point me to the repository) the code for how you create the Jetty server, and then create and deploy the webapp?

Are there any exceptions printed? You might also try turning up the debug level. If you're using jetty's stderr logger, then you do that by setting the system property -D-Dorg.eclipse.jetty.LEVEL=DEBUG, although you may be using some other slf4j plugin, in which case you control the debug level according to that particular logging framework.

You've probably also aready seen it, but just in case, here's the link to the porting docs from jetty 6-to jetty-7, which are also valid for porting to jetty-8: http://wiki.eclipse.org/Jetty/Starting/Porting_to_Jetty_7

thanks
Jan
Comment 2 Steven Hung CLA 2012-05-11 11:29:12 EDT
Created attachment 215489 [details]
Web project example

The repository is :pserver:anonymous@dev.eclipse.org:/cvsroot/webtools

The plug-ins are: 
1. org.eclipse.jst.server.preview.adapter
2. org.eclipse.wst.server.preview

The server is created via org.eclipse.wst.server.preview.internal.PreviewStarter.run()

An outline of what we do in this method is:
org.eclipse.jetty.server.Server server;
server = new Server(config.getPort()); // we use a preview.xml file to store the port
server.setStopAtShutdown(true);

...

server.setHandler(handlers); // We add a handler, used to handle errors
server.start();

Publishing copies the web project to a location specified in the preview.xml that we generated. For example:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<server port="8080">
  <module context="TestPreviewServer" name="TestPreviewServer" path="D:/WTP34/eclipse/workspace/runtime-New_configuration/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/TestPreviewServer" type="j2ee"/>
</server>

An example of the directory it points to is the attachment I have provided.

For publishing, I'll need to look into it more to provide more details. Since right now, it doesn't seem to be using the preview.xml file (I'll need to look at a working version of the preview server in pre-Juno) to see how it's done.

I didn't see any errors either. I will try with the vm argument to see what happens.

Thanks, I will continue to investigate and provide updates.
Comment 3 Steven Hung CLA 2012-05-11 17:25:46 EDT
The issue is related to how the modules are being published.

In pre-Juno, the publishing code is:

WebAppContext wac = new WebAppContext();
wac.setContextPath(module.getContext());
wac.setWar(module.getPath());
wac.setErrorHandler(errorHandler);
handlers.addHandler(wac);

In Juno, the publishing code is:

ContextHandler wac = new ContextHandler();
wac.setContextPath(module.getContext());
// wac.setWar(module.getPath());
wac.setErrorHandler(errorHandler);
handlers.addHandler(wac);

What should be used for publishing in Jetty 7 and above? Is ContextHandler the correct API? Also, is there an equivalent to ".setWar" that would let the server know where the resources to publish are located?

Thanks
Comment 4 Jan Bartel CLA 2012-05-11 18:28:50 EDT
Steven,

If you were using a WebAppContext with jetty-6, then you should continue to use one for jetty-7/8, as this is the correct way to set up a web app in jetty. The ContextHandler is intended for lighter-weight setups without the full support for webapps (ie sessions, servlets, WEB-INF/web.xml etc etc).

regards,
Jan



(In reply to comment #3)
> The issue is related to how the modules are being published.
> 
> In pre-Juno, the publishing code is:
> 
> WebAppContext wac = new WebAppContext();
> wac.setContextPath(module.getContext());
> wac.setWar(module.getPath());
> wac.setErrorHandler(errorHandler);
> handlers.addHandler(wac);
> 
> In Juno, the publishing code is:
> 
> ContextHandler wac = new ContextHandler();
> wac.setContextPath(module.getContext());
> // wac.setWar(module.getPath());
> wac.setErrorHandler(errorHandler);
> handlers.addHandler(wac);
> 
> What should be used for publishing in Jetty 7 and above? Is ContextHandler the
> correct API? Also, is there an equivalent to ".setWar" that would let the
> server know where the resources to publish are located?
> 
> Thanks
Comment 5 Steven Hung CLA 2012-05-14 10:58:52 EDT
Thanks for the information

The following are installed by default into Juno:
org.eclipse.jetty.continuation, org.eclipse.jetty.http, org.eclipse.jetty.io, org.eclipse.jetty.security, org.eclipse.jetty.server, org.eclipse.jetty.servlet, and org.eclipse.jetty.util 

However, to get the servlet case to work, the plug-ins org.eclipse.jetty.xml and org.eclipse.jetty.webapp also need to be installed. I used the p2 update site http://download.eclipse.org/jetty/updates/jetty-bundles-8.x to get all the plug-ins.

Note: WebAppContext is from org.eclipse.jetty.webapp

Can org.eclipse.jetty.xml and org.eclipse.jetty.webapp (both version 8) be added to Juno?

There is an issue with JSPs that I am still investigating, but at least the servlet works.
Comment 6 Steven Hung CLA 2012-05-14 14:17:44 EDT
For the JSP issue, that is caused by Bug 377886.

Even if we set the system property org.apache.jasper.compiler.disablejsr199 to true, it will complain that "PWC6349: Cannot find a java compiler for compilation."

Therefore, I believe the work required here is to add the plug-ins mentioned in comment 5 into Juno.
Comment 7 Steven Hung CLA 2012-05-14 15:59:20 EDT
*** Bug 366092 has been marked as a duplicate of this bug. ***
Comment 8 Steven Hung CLA 2012-05-24 14:06:38 EDT
Since the J2EE preview server is broken in Juno due to the missing plug-ins, is there any plan to add org.eclipse.jetty.xml and org.eclipse.jetty.webapp (both version 8) into Juno?
Comment 9 Steven Hung CLA 2012-05-24 14:21:47 EDT
Marking as blocking, due to comment 8.
Comment 10 Jan Bartel CLA 2012-05-29 12:25:20 EDT
Jesse,

Can you comment on how jetty jars can get added into Juno.

thanks
Jan
Comment 11 Jesse McConnell CLA 2012-05-29 12:28:13 EDT
I think this is equinox decision on what they are pulling in.

I am cc'ing him on this bug
Comment 12 Thomas Watson CLA 2012-05-29 13:59:34 EDT
(In reply to comment #11)
> I think this is equinox decision on what they are pulling in.
> 
> I am cc'ing him on this bug

The Eclipse/Equinox projects pull in only the minimum jetty bundles to get the Eclipse help system to work as well as our OSGi HttpService implementation to work.  If WTP needs additional jetty bundles then they would need to pull those in themselves.  We will not be adding any more jetty bundles than necessary for our usecases.
Comment 13 Jesse McConnell CLA 2012-05-29 14:42:54 EDT
so my understanding of these things is that WTP can resolve this problem themselves by pulling those jetty bundles that they need..

correct?
Comment 14 Thomas Watson CLA 2012-05-29 17:00:07 EDT
(In reply to comment #13)
> so my understanding of these things is that WTP can resolve this problem
> themselves by pulling those jetty bundles that they need..
> 
> correct?

That is my understand from comment 5.  WTP should ensure that all the jetty bundles they need to function are included when WTP is installed.  That is not up to the "classic" eclipse download (EPP etc.) to provide in its features.
Comment 15 Jesse McConnell CLA 2012-06-14 12:54:16 EDT
closing as not a jetty issue