ops4j / org.ops4j.pax.web

OSGi R7 Http Service, Whiteboard and Web Applications (OSGi CMPN Release chapters 102, 140 and 128) implementation using Jetty 9, Tomcat 9 or Undertow 2.
https://ops4j1.jira.com/wiki/display/paxweb/Pax+Web
Other
144 stars 183 forks source link

Unable to start Jetty within pax-web-jetty-bundle [PAXWEB-1025] #1311

Closed ops4j-issues closed 7 years ago

ops4j-issues commented 7 years ago

Massimo Bono created PAXWEB-1025

I'm playing with OSGi via the framework implementation Felix 5.4. Currently I want to install an application server on a OSGi framework as a bundle. I've look at Pax-web and it seems the perfect solution for me. However, after successfully started up all the required bundles, The software complains with the following error:

org.ops4j.pax.web.pax-web-jetty-bundleorg.ops4j.pax.web.service.internal.Activator : Unable to start pax web server: Exception while starting Jetty
java.lang.RuntimeException: Exception while starting Jetty
at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl.start(JettyServerImpl.java:188)
at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl$Stopped.start(ServerControllerImpl.java:415)
at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl.start(ServerControllerImpl.java:71)
at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl$Unconfigured.configure(ServerControllerImpl.java:707)
at org.ops4j.pax.web.service.jetty.internal.ServerControllerImpl.configure(ServerControllerImpl.java:87)
at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:353)
at org.ops4j.pax.web.service.internal.Activator$3.run(Activator.java:295)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.ops4j.pax.web.service.jetty.internal.JettyServerImpl.start(JettyServerImpl.java:151)
... 11 more
Caused by: java.lang.NoSuchMethodException: class org.eclipse.jetty.server.HttpConfiguration.setMaxErrorDispatches(class java.lang.String)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.set(XmlConfiguration.java:582)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:411)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.newObj(XmlConfiguration.java:815)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:423)
at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.configure(XmlConfiguration.java:298)
at org.eclipse.jetty.xml.XmlConfiguration.configure(XmlConfiguration.java:248)
... 16 more

By looking at the error, it seems that some Jetty configurations are not available in the pax-embedded jetty version. In particular maxErrorDispatches, blockingTimeout and persistentConnectionsEnabled causes the error. However, even commenting out those 3 properties, pax-web won't start (can't connect to 127.0.0.1) and, after some logs, will simply print:

org.ops4j.pax.web.pax-web-jetty-bundleorg.ops4j.pax.web.service.internal.ConfigurationImpl : Reading configuration property org.ops4j.pax.web.config.url has failed

I've tried to solve this issue, but since I'm no expert in neither OSGi and Jetty I couldn't come up with no solution. To add some context to my scenario, here's some additional information:

As an attachment you can find the whole felix distribution I used in order to reproduce the error and the log my test output. Thanks for any reply


Affects: 4.3.0 Attachments:

Votes: 0, Watches: 3

ops4j-issues commented 7 years ago

Achim Nierbeck commented

did you verify that you have all required bundles running.
We do have a integration test for the jetty-bundle bundle which still passes:

https://github.com/ops4j/org.ops4j.pax.web/blob/master/pax-web-itest/pax-web-itest-container/pax-web-itest-container-jetty/src/test/java/org/ops4j/pax/web/itest/jetty/JettyBundleIntegrationTest.java#L50-L57

so could you verify this first?

Second, it looks like you got a org.osgi jar in your folder, don't know if you also have it in your CP but I'd remove that. At Pax-Web we'll also provide the needed OSGi packages of the services implemented.

Third, did you try to configure pax-web the osgi way?
http://ops4j.github.io/pax/web/SNAPSHOT/User-Guide.html#basic-configuration

Jetty is only there for additional configurations and specialties which can't be handled by the osgi configuration. So please first check this.

ops4j-issues commented 7 years ago

Massimo Bono commented

As for the second point, osgi.jar was actually redundant. However, removing the bundledid not solve the issue.

As for the tests, I checked out the entire project and, via eclipse m2e I tried to run the tests. However, for some reason, Ecipse kept telling me tests were skipped. Even adding "-Dmaven.test.skip=false" did not solve the problem. After looking for "skip" inside the project, I realized in line 792 of pax-web-itest-container-jetty.pom there was the entry "<skip>true</skip>". After resetting it to "<skip>false</skip>" the tests finally started (only for that POM) (in order to start them, I "maven install" the whole project and then I invoked "maven test" from eclipse "pax-web-itest-container-jetty" project menu. Those test actually failed.
You can find the log eclipse showed me at the link error log: I tried to attach the log to this comment, but apparently a general error occured.

Please tell me if I my process was faulty.

ops4j-issues commented 7 years ago

Massimo Bono commented

Sorry to spam comments in the section, but can you please update me to this issue? I'm unsure whether or not this is effectively a bug or not.

Thanks

ops4j-issues commented 7 years ago

Achim Nierbeck commented

No trouble with that ... I'm a bit short on time ...
BUT ... do you happen to have an application running with it?
Per default ... and requested by users, the port only listens on port 80 or whatever you configured with a running application.

ops4j-issues commented 7 years ago

Massimo Bono commented

Hi, thanks for replying.

Up until now I had no application due to the fact that even by going to "127.0.0.1:8080" (as you can see I used the line "org.osgi.service.http.port=8080" to configure the port) the browser told me "connecion failure".
From your last comment I tried to come up with an easy bundle to use as test (you can find it in this issue as attachment by the name "angularjs-example-0.0.1-SNAPSHOT.war".
I followed the guide at pax web extender, however it still doesn't work (at installing phase the application complaints with the log:

g! install angularjs-example-0.0.1-SNAPSHOT.war
org.ops4j.pax.web.pax-web-extender-warorg.ops4j.pax.web.extender.war.internal.Activator : Starting destruction process for bundle com.massimobono.microsi.angularjs-example
org.ops4j.pax.web.pax-web-extender-warorg.ops4j.pax.web.extender.war.internal.Activator : Not an extended bundle or destruction of extension already finished for com.massimobono.microsi.angularjs-example.
Bundle ID: 19

Maybe my bundle isn't configured properly (no imports are used since it's just a angular-js hello world; from the documentation seems I have the proper manifest entry). Do you have an "hello world" war file you know is working to test the setup with? Probably you're already know, but just in case, I've already shared with you the new setup I'm currently working on in the attachment "felix-framework-5.6.0-testbundle-included-port-8080" felix-framework-5.6.0-testbundle-included-port-8080.zip

Thanks

ops4j-issues commented 7 years ago

Achim Nierbeck commented

sample apps ... we do have plenty of those :grinning:
pick one of the produced here:

ops4j-issues commented 7 years ago

Massimo Bono commented

Yeah I've seen them. However (probably because I took only a couple of minutes trying) I couldn't compile them. I ask you if you had already something already compile to make a quick test :smile:

Ok, I'll try to compile them! hello world seems nice. Can you update me with the "<skip>true</skip>" issue I've encounter in my previous comment? Was is incidental? Or it was there for a reason?

ops4j-issues commented 7 years ago

Achim Nierbeck commented

oh ... those samples are also available from maven central:
http://search.maven.org/#search%7Cga%7C1%7Corg.ops4j.pax.web.samples
Just get them from there :wink:

ops4j-issues commented 7 years ago

Achim Nierbeck commented

regarding the

<skip>true</skip>

thing .. do you have a quick link for me ... I wasn't able to find it. Or at least couldn't come up with the one you where looking for.

ops4j-issues commented 7 years ago

Massimo Bono commented

Regarding the

<skip>true</skip>

I've cited, you can find it in pax-web-itest-container-jetty pom at line 792.

By setting it to "false" the jetty tests (at least on my laptop with my weird setup) fail.

ops4j-issues commented 7 years ago

Achim Nierbeck commented

ah ... now I follow.
Well you disable Unit tests because those tests are run as Integration tests.
With those integration tests, all pax-web including the pax-web-jetty-bundle tests are successful

ops4j-issues commented 7 years ago

Massimo Bono commented

ah ok! How can I run those tests? My aim would be to get the list of the bundles required to make everything work! :smile:

Sorry for my dumb questions

ops4j-issues commented 7 years ago

Massimo Bono commented

Ok, still not working :slightly_frowning_face:

Given its simplicity, at the end I chose as my test artifact "wab-jetty-web"... it should be the perfect artifact to test whether or not the setup is working or not.

Looking at automated test it seems I need only to install and start the bundle. However, a 404 error is thrown when I do so. From the logs, it seems the bundle is correctly deployed but for some weird reason all the requests fail,

As per your suggestion, I included in the setup the bundle "pax-url-war".
I couldn't upload the new setup in the attachments, hence you can download my setup here

I really don't understand how it can be so difficult to setup a web app. sad panda

ops4j-issues commented 7 years ago

Massimo Bono commented

Sorry, I nearly forgot... I kept track of the log file of my previous test: you can find it here (output2.log). Inside it I saw some exception... I don't really know if there are expected or not

ops4j-issues commented 7 years ago

Achim Nierbeck commented

I don't get what you are trying to achieve?
The integration tests are only there to a) make sure we don't break anything b) be a resource for users on how to one might use it.

Now depending on your use-case, I'm thinking you might be better of using Apache Karaf with Pax-Web already included, so you don't need to Hasel with the basic setup of the scenario and can go on with your main intent.

ops4j-issues commented 7 years ago

Massimo Bono commented

Hi, sorry for not replying back. I was full of other stuff and temporary left behind this side project of mine.

I just want to setup a web server on OSGi. I know I can do it in karaf, but I think that, just by installing the correct bundles, I can do it in Felix as well... I don't see why I couldn't do that. My "main intent" is just this: make pax web work with standard felix installation and show a webapp mounted on pax from browser.

As for the log I've sent you in my prevoius message, can please give me the cause of the exception I've getting? (search for "java.lang.IllegalStateException: Committed" inside the log).

I'm also posting you the list of bundles installed detected by felix (I know I've already sent you the whole test folder I've been using, but this might help you in detecting the problem as well)

g! lb
START LEVEL 1
ID|State |Level|Name
0|Active | 0|System Bundle (5.6.0)|5.6.0
1|Active | 1|ASM (5.1.0)|5.1.0
2|Active | 1|ASM commons classes (5.1.0)|5.1.0
3|Active | 1|ASM Tree class visitor (5.1.0)|5.1.0
4|Active | 1|bndlib (3.3.0.201609221906)|3.3.0.201609221906
5|Active | 1|OPS4J Pax Url - war (2.5.1)|2.5.1
6|Active | 1|javax.servlet API v.3.0 (3.0.0.SNAPSHOT)|3.0.0.SNAPSHOT
7|Active | 1|OPS4J Base - Lang (1.5.0)|1.5.0
8|Active | 1|OPS4J Base - Monitors (1.5.0)|1.5.0
9|Active | 1|OPS4J Base - Net (1.5.0)|1.5.0
10|Active | 1|OPS4J Base - Util - Property (1.5.0)|1.5.0
11|Active | 1|Apache Felix Bundle Repository (2.0.8)|2.0.8
12|Active | 1|Apache Felix Configuration Admin Service (1.8.10)|1.8.10
13|Active | 1|Apache Felix Gogo Command (0.16.0)|0.16.0
14|Active | 1|Apache Felix Gogo Runtime (0.16.2)|0.16.2
15|Active | 1|Apache Felix Gogo Shell (0.10.0)|0.10.0
16|Active | 1|OPS4J Pax Logging - API (1.9.0)|1.9.0
17|Active | 1|OPS4J Pax Swissbox :: Bnd Utils (1.8.2)|1.8.2
18|Active | 1|OPS4J Pax Swissbox :: Property (1.8.2)|1.8.2
19|Active | 1|OPS4J Pax Url - Commons (2.5.1)|2.5.1
20|Active | 1|OPS4J Pax Web - API (4.3.0)|4.3.0
21|Active | 1|OPS4J Pax Web - Extender - WAR (4.3.0)|4.3.0
22|Active | 1|OPS4J Pax Web - Jetty Bundle (4.3.0)|4.3.0
23|Active | 1|OPS4J Pax Web - Jsp Support (4.3.0)|4.3.0
24|Active | 1|OPS4J Pax Web - Runtime (4.3.0)|4.3.0
25|Active | 1|OPS4J Pax Web - Service SPI (4.3.0)|4.3.0
26|Active | 1|Apache XBean OSGI Bundle Utilities (4.5.0)|4.5.0
27|Active | 1|Apache XBean :: Classpath Resource Finder (4.5.0)|4.5.0
28|Active | 1|OPS4J Pax Web - Samples - Wab with jetty-web.xml (4.4.0)|4.4.0

I know I sound stubborn, but I really want to make it work! Hope you can understand that :smile:

ops4j-issues commented 7 years ago

Massimo Bono commented

Looking at the log, I also found the cause of that exception (look for "NoSuchMethodException while parsing jetty-web.xml"). It seems the software is unable to load a method from jetty-web.xml... I'm really confused now :|

ops4j-issues commented 7 years ago

Achim Nierbeck commented

No trouble with your stubbornness :wink:
But here comes mine :wink:
if you start with a mininmal Karaf plus Pax-Web you end up with what you need :grinning:

anyway.
First make sure you have the following setup.
The bundles as used for example in the Pax-Web Itests for pax-jetty-bundle usage.
https://github.com/ops4j/org.ops4j.pax.web/blob/master/pax-web-itest/pax-web-itest-container/pax-web-itest-container-jetty/src/test/java/org/ops4j/pax/web/itest/jetty/ITestBase.java#L87-L94

Now the more important part is seems is about your configuration of Pax-Web :smile:

First of all, as Pax-Web is a mediation layer on top of three different flavors of Web-Containers and also an implementation for the HttpService it needs to follow some rules.
Therefore you need to configure Pax-Web by the means of a HttpService, not a Jetty Container.
Take a look at the configuration section here:
http://ops4j.github.io/pax/web/SNAPSHOT/User-Guide.html#basic-configuration
If you also want to use an external Jetty configuration for extra "fine" tuning, you'll need to declare that.

http://ops4j.github.io/pax/web/SNAPSHOT/User-Guide.html#using-external-jetty-xml-file

If you want to add extra connectors to it, you'll need to define it similar to the syntax here:
https://github.com/ops4j/org.ops4j.pax.web/blob/master/samples/jetty-config-fragment/src/main/resources/jetty.xml#L34-L63

Keep in mind, Pax-Web is already started, therefore the jetty container is already configured, your configuration is an extra therefore needs to call methods like addConnector and not newConnector.

the jetty-web.xml is never used, as Pax-Web isn't about a single Web-Container (we support Jetty, Tomcat and Undertow) it's more about the OSGi HttpService, WAB and almost about the WhiteBoard HttpService (we're almost there, even though all versions prior to 6 already have a whiteboard extender, though not compliant with the spec)

One more thing, this issues really looks like, it should have been asked on the mailing list :smile:
https://groups.google.com/forum/#!forum/ops4j
maybe next time ask on the ML :wink:

ops4j-issues commented 7 years ago

Grzegorz Grzybek commented

Massimo Bono Please check history of what I did to run pax-web 4.3.0 + jetty 9.2.19 on felix 5.6.0 starting from scratch: https://github.com/grgrzybek/paxweb-1025/commits/master

After you set up infrastructure, you just:

g! install angularjs-example-0.0.1-SNAPSHOT.war
Bundle ID: 29
g! start 29

And you can successfully access http://localhost:8181/myapp

ops4j-issues commented 7 years ago

Grzegorz Grzybek commented

Ah - the main problem you had was probably from jetty.xml taken from Jetty 9.3.x instead of from Jetty 9.2.x (used by pax-web 4.3.0).

ops4j-issues commented 7 years ago

Massimo Bono commented

Hi!

I don't remember all the details about the infrastructure I used back then, but from what I understand from your last comment it seems that I used the wrong version of jetty.xml.

I'll try the procedure as soon as possible, but it seems it should perfectly work! :smile:
Sorry for the trouble (next time I'll ask on the mailing list... sorry I thought it was bug of some sort :slightly_frowning_face: )

ops4j-issues commented 7 years ago

Grzegorz Grzybek commented

No problem :wink:
But there may be one problem - you used pax-web-jetty-bundle which includes jetty classes (Private-Package), but it's not full pax-web - there are some classes missing. So if you use separate pax-web-* bundles and jetty bundles, you should be ok.

For pax-web-jetty-bundle, Achim Nierbeck, do you remember if that "should just work"™?

ops4j-issues commented 7 years ago

Achim Nierbeck commented

The goal for the pax-web-jetty-bundle is to not have all required jetty bundles also on your classpath.
Besides that everything should work as with all other bundles.
So you have two choices:
1) pax-web-jetty + jetty bundles
2) pax-web-jetty-bundle (contains all jetty bundles)

ops4j-issues commented 7 years ago

Grzegorz Grzybek commented

Achim Nierbeck thanks. Ah, it works with pax-web-jetty-bundle as well. First I had problem, because I had both pax-web-jetty-bundle and pax-web-runtime, which caused configadmin problems with config location.

Massimo Bono, here's a branch where you can see pax-web-jetty-bundle: https://github.com/grgrzybek/paxweb-1025/commits/pax-web-jetty-bundle

ops4j-issues commented 7 years ago

Massimo Bono commented

Ok, I tried your github project and it worked perfectly! Thanks for your time