Hi,
 
            I was finally able to get this to work.  Here are the things I had 
to do.
 
1) I upgraded OSGi from 3.4 version to 3.6, just in case that was the problem.
 
2) I had missed including jetty-servlets jar in the list of bundles, so 
included that jar
 
3) Started a small webapp, as mentioned above. Did not run into issues. Was 
able to set defaultDescriptor as null
 
4) Later used WebAppProvider class, but this kept failing with this problem 
(http://stackoverflow.com/questions/29274336/getting-java-lang-classnotfoundexception-org-eclipse-jetty-servlet-listener-int)
 java.lang.ClassNotFoundException: 
org.eclipse.jetty.servlet.listener.IntrospectorCleanerIn order to resolve this, 
had to alter the jetty-webapp manifest to import org.jetty.servlet.listener 
package.Now the webapps are correctly getting deployed for me. I also had to 
specify a proper defaultDescriptor for it to work when using WebAppProvider 
Also another problem I found was that the server does not now work with my 
legacy web applications, as the DTD for web.xml appears to be differentMy 
web.xml had <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web 
Application 2.3//EN"      "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd";>, and 
this was causing errorosgi> 2015-08-17 
18:03:09.578:WARN:oejx.XmlParser:Scanner-2: 
FATAL@http://www.oracle.com/webfolder/technetwork/jsc/j2ee/dtds/web-app_2_3.dtd 
line:1 col:1 : org.
xml.sax.SAXParseExceptionpublicId: -//Sun Microsystems, Inc.//DTD Web 
Application 2.3//EN; systemId: 
http://www.oracle.com/webfolder/technetwork/jsc/j2ee/dtds/w
eb-app_2_3.dtd; lineNumber: 1; columnNumber: 1; The markup declarations 
contained or pointed to by the document type declaration must be well-formed.
2015-08-17 18:03:09.581:WARN:oejw.WebAppContext:Scanner-2: Failed startup of 
context 
o.e.j.w.WebAppContext@611cd826{/zenworks-ping,file:/C:/Users/Ksrijith/AppDa
ta/Local/Temp/jetty-0.0.0.0-7629-zenworks-ping.war-_zenworks-ping-any-4389934712582603675.dir/webapp/,null}{E:\jettyTest\webapps\zenworks-ping.war}
org.xml.sax.SAXParseExceptionpublicId: -//Sun Microsystems, Inc.//DTD Web 
Application 2.3//EN; systemId: 
http://www.oracle.com/webfolder/technetwork/jsc/j2ee/dt
ds/web-app_2_3.dtd; lineNumber: 1; columnNumber: 1; The markup declarations 
contained or pointed to by the document type declaration must be well-formed.
            at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
            at 
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:177)
            at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:441)
            at 
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)
            at 
com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1436)
 So overall was able to get things to work, but looks like I will have to make 
a lot of changes here and there :(.Thanks for all the help.Thanks,
Srijith
>>> Joakim Erdfelt <[email protected]> 8/14/2015 7:22 PM >>>
There are people on this forum that work on the jetty-osgi layers, stick 
around, they'll show up.
You might have more luck using those layers vs making your own bundle.

I just can't help you, as I avoid OSGi with a 100km pole.
But I know that the jetty-osgi layers represent at least 1,000 man hours of 
effort between all of the jetty and osgi experts that commit to it.



Joakim Erdfelt / [email protected]

On Fri, Aug 14, 2015 at 6:29 AM, Srijith Kochunni <[email protected]> wrote:


Well, that's really too bad, considering this was working well in Jetty 6. Is 
there any other forum where I can get some help.? Is there anyone else on this 
list who has done similar thing.?
Thanks for your help anyway.
>>> Joakim Erdfelt <[email protected]> 8/14/2015 6:50 PM >>>
Oh crap, i didn't notice you were using OSGi, sorry.
Configurations under the OSGi environment cannot be made that simply, sorry.
Disregard everything i said.
I have no advice for you under OSGi.


Joakim Erdfelt / [email protected]

On Fri, Aug 14, 2015 at 5:50 AM, Srijith Kochunni <[email protected]> wrote:


Hi Joakim,
Thank you for your answer. However unfortunately, it is not helping.
I made the changes you suggested, so effectively my code now, is
Server server = new Server(port);

WebAppContext webapp = new WebAppContext();
webapp.setContextPath("/");
webapp.setExtractWAR(true);
webapp.setWar("E:\\jettyTest\\webapps\\testWebApp.war");

server.setHandler(webapp);
server.start();
But even with this change, I am seeing that the exception still is, as follows
2015-08-14 18:05:48.563:INFO:oejs.Server:OSGi Console: jetty-9.2.12.v20150709
2015-08-14 18:05:48.616:WARN:oejw.WebAppContext:OSGi Console: Failed startup of 
context o.e.j.w.WebAppContext@4e8aa935{/,file:/C:/Users/Ksrijith/AppData/Local/T
( 
mailto:o.e.j.w.WebAppContext@4e8aa935%7B/,file:/C:/Users/Ksrijith/AppData/Local/T)
 
emp/jetty-0.0.0.0-8810-testWebApp.war-_-any-5346091878461296465.dir/webapp/,null}{E:\jettyTest\webapps\testWebApp.war}
java.io.FileNotFoundException: 
E:\jettyTest\org\eclipse\jetty\webapp\webdefault.xml (The system cannot find 
the path specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:146)
at 
org.eclipse.jetty.util.resource.FileResource.getInputStream(FileResource.java:290)
at org.eclipse.jetty.webapp.Descriptor.parse(Descriptor.java:54)
at org.eclipse.jetty.webapp.WebDescriptor.parse(WebDescriptor.java:207)
at org.eclipse.jetty.webapp.MetaData.setDefaults(MetaData.java:171)
at 
org.eclipse.jetty.webapp.WebXmlConfiguration.preConfigure(WebXmlConfiguration.java:53)
at org.eclipse.jetty.webapp.WebAppContext.preConfigure(WebAppContext.java:468)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:504)
at 
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at 
org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:387)
at 
org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:114)
at 
org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:354)
at 
org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at com.microfocus.jettyserver.JettyServer.startServer(JettyServer.java:44)
at 
com.microfocus.jettyserver.bundle.JettyServerCmdProvider._startServer(JettyServerCmdProvider.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at 
org.eclipse.osgi.framework.internal.core.FrameworkCommandInterpreter.execute(FrameworkCommandInterpreter.java:150)
at 
org.eclipse.osgi.framework.internal.core.FrameworkConsole.docommand(FrameworkConsole.java:302)
at 
org.eclipse.osgi.framework.internal.core.FrameworkConsole.console(FrameworkConsole.java:287)
at 
org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:223)
at java.lang.Thread.run(Thread.java:745)
2015-08-14 18:05:48.672:INFO:oejs.ServerConnector:OSGi Console: Started 
ServerConnector@716afedb{HTTP/1.1}{0.0.0.0:8810
( mailto:ServerConnector@716afedb%7BHTTP/1.1%7D%7B0.0.0.0:8810) }
>> Jetty 9.2.13.v20150730 is the current stable version of Jetty 9.2.x.
I have not tried moving to that version yet. Shall try that and update, But I 
am wondering if there is something more to this that I am missing. I did try 
placing the webdefault.xml that came along with the distribution, in the path 
it is looking for, but then that failed with some parsing exception. 
Thanks,
Srijith.
>>> Joakim Erdfelt <[email protected]> 8/14/2015 5:39 PM >>>


Server server = new Server(80);

ServletContextHandler context = new 
ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
context.addServlet(new ServletHolder(new HelloServlet()),"/hello");

ContextHandlerCollection contexts = new ContextHandlerCollection();

WebAppContext webapp = new WebAppContext();
webapp.setResourceBase(".");

Don't use this with a webapp (the .setWar() a few lines below this does this 
for you, and correctly)


webapp.setDescriptor("WEB-INF/web.xml");
webapp.setContextPath("/");

This is the same contextPath as your ServletContextHandler above, this will 
never work, as your ServletContextHandler will answer all requests, never 
letting your WebAppContext process anything.

Just skip the ServletContextHandler entirely.
Use webapp.addServlet() instead.


webapp.setExtractWAR(true);
webapp.setWar("E:\\jettyTest\\webapps\\testWebApp.war");
contexts.setHandlers(new Handler[]{context, webapp});

If you have no ServletContextHandler, then you don't need the 
ContextHandlerCollection.



server.setHandler(contexts);

If you have no ContextHandlerCollection, you can just use 
server.setHandler(webapp)


server.start();
The server starts up fine, the servlet handler is also registered fine, but my 
webapp Context startup always fails with the following exception
2015-08-14 14:06:13.523:INFO:oejs.Server:OSGi Console: jetty-9.2.12.v20150709

Jetty 9.2.13.v20150730 is the current stable version of Jetty 9.2.x


2015-08-14 14:06:13.527:INFO:oejsh.ContextHandler:OSGi Console: Started 
o.e.j.s.ServletContextHandler@12aa6801{/,null,AVAILABLE
( mailto:o.e.j.s.ServletContextHandler@12aa6801%7B/,null,AVAILABLE) }
2015-08-14 14:06:13.539:WARN:oejw.WebAppContext:OSGi Console: Failed startup of 
context o.e.j.w.WebAppContext@71922339{/,file:/E:/jettyTest/,null}{E:\jettyTest\
( 
mailto:o.e.j.w.WebAppContext@71922339%7B/,file:/E:/jettyTest/,null%7D%7BE:%5CjettyTest%5C)
 
webapps\testWebApp.war}
java.io.FileNotFoundException: 
E:\jettyTest\org\eclipse\jetty\webapp\webdefault.xml (The system cannot find 
the path specified)

The change to not use .setResourceBase() should have made an improvement here.
- Joakim
Click here
( https://www.mailcontrol.com/sr/MZbqvYs5QwJvpeaetUwhCQ==)  to report this 
email as spam.

_______________________________________________
jetty-users mailing list
[email protected]
To change your delivery options, retrieve your password, or unsubscribe from 
this list, visit
https://dev.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://dev.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://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to