Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty-11.0.11 embedded - WebAppContenxt class cannot parse file:jar references
  • From: Stefan Viljoen <viljoens@xxxxxxxxxxxxxxx>
  • Date: Tue, 6 Sep 2022 13:20:25 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=verishare.co.za; dmarc=pass action=none header.from=verishare.co.za; dkim=pass header.d=verishare.co.za; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vbkOQnFL5HQ2jzPCjT1oAVWXM1QRwV0ywW1Plwl2vw4=; b=ALNXI1z0nq4H4S3RsuAPZh7MOCoSqTyax1fHHAjWIbziV/9L8goWRiUxxl6kAqPfjxUdrbZBK9le6Fm7jDPDcCrlc9xIVEH3qZFPo4LbkhFtOvoHVTFSi89Niuq38oAnQcdRsw/wTJopFEilmZaUd1hNoJko/Lx+EPubzT1yzCheYlcitzivCuQC1gliNJxIO3mcqGMKoGA4ztJ/fIHDXAvaZufSjXug6Xii3raagy7ampc25YPkdYeHU0P/EwUSdGLuTZN9EHtwpiw0JWPhJD0ngsKc7iCM7zneUckwT8v4gtaUDWCVFjWMlj5+PQnHjfxpqm4QLXHSRKXEQhnVOA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WM8IW6P92pT4jHjt2Pas1P5GBBmtd8vRChpmXBnQeBZMS3wz+yCwEdXah859T+iPMVHePDA6aFX8EnsreAfZva1sQk+N5oNnZ1NfFARggLBwefh/zrxM1ECEq/2OUKOkdsJbEMTkYMz5GtK6cH3jM7eBzt5cWrM7wgSQumnoFFsxk2wFxr7e9oDuHmic3KmHgWI2yCH3uVhmgKpdDjIQSCavIkOzH2urC9yBWl34zWIJgIuMWjH79uTDwixAgJl2BNI3cjYs3uIedqJY8xqHFntm+dhPG2BanEkL0bz9mpFhpb3GkNv6bULC+1feElMndRYgzliMleefKsbxfC2UOg==
  • Delivered-to: jetty-users@xxxxxxxxxxx
  • List-archive: <https://www.eclipse.org/mailman/private/jetty-users/>
  • List-help: <mailto:jetty-users-request@eclipse.org?subject=help>
  • List-subscribe: <https://www.eclipse.org/mailman/listinfo/jetty-users>, <mailto:jetty-users-request@eclipse.org?subject=subscribe>
  • List-unsubscribe: <https://www.eclipse.org/mailman/options/jetty-users>, <mailto:jetty-users-request@eclipse.org?subject=unsubscribe>
  • Thread-index: AQHYwdNE8JuLKka6PUKIoLKXGnxqJ63STzcAgAASAtA=
  • Thread-topic: [jetty-users] Jetty-11.0.11 embedded - WebAppContenxt class cannot parse file:jar references

Hi Ludovic

 

Thanks for replying!

 

I’ve manged to do exactly what you describe, only it ONLY ever works -inside-  Netbeans 14 in windows. Running the JAR in Linux with the Oracle JRE  17 exhibits the error.

 

I’m new to Java and Jetty, not exactly sure how to setup a reproducer?

 

Did you run your test case in a detached JRE, -NOT- in an IDE? If I do this in Netbeans 14 in Windows, it works 100% perfectly.

 

It fails completely if run outside NetBeans, in the official Oracle JRE 17 on Linux, outside any IDE.

 

To reproduce:

In the JAR from which the embedded Jetty instance runs, there is a "static" folder in the root of the jar.

The "static" folder contains an index.html to render.

The JAR must be run in a detached JRE - not inside an IDE because it functions correctly as long as run inside the IDE (Netbeans 14 in my case) as the WebAppContext contextPath then becomes file:///... instead of jar:file:...

Code - WebHost.java:
''
server = new Server(AppSettings.getJettyServerPort());

String webDir = this.getClass().getClassLoader().getResource("static").toExternalForm();
WebAppContext waContext = new WebAppContext(webDir, "/");

waContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", "./[^/]servlet-api-[^/]\.jar$|./javax.servlet.jsp.jstl-.\.jar$|./[^/]taglibs.\.jar$");

server.setHandler(waContext);

server.setStopAtShutdown(true);
server.setStopTimeout(0x2710L);

server.start();
''

With

"webDir" = jar:file:/usr/src/verdi/verdi-12-JDK17-jar-with-dependencies.jar!/static

for 127.0.0.1:8086/index.html

Jetty 10.0.0 and up, if the JAR is run by a detached Oracle 17 JRE instance under Linux, returns

HTTP ERROR 404 Not Found

URI: | /index.jsp -- | -- 404 Not Found org.eclipse.jetty.servlet.ServletHandler$Default404Servlet-5dc3fcb7

Regress to latest Jetty 9, above works correctly, and

jar:file:/usr/src/verdi/verdi-12-JDK17-jar-with-dependencies.jar!/static

can be resolved by the WebAppContext class, with the code being run in a detached non-IDE based JRE in Linux.

Expected behaviour:

With an instance of the WebAppContext class registered as a handler in embedded Jetty server versions from 10.0.0 and up, instances of the WebAppContext class must be able to retrieve and serve resources in the same JAR the embedded Jetty instance is running out of, with WebAppContext.ContextPath specified as

jar:file:/usr/src/verdi/verdi-12-JDK17-jar-with-dependencies.jar!/static

when the code is run in a detached JRE separate from the  IDE where the code was created.

 

Thanks again!

 

Kind regards,

 

Description: signature

 

CONFIDENTIALITY NOTICE AND DISCLAIMER: This e-mail transmission contains confidential Information which is the property of the sender and which is subject to legal privilege and/or copyright and intended only for the above-mentioned addressee. If you are not the intended recipient, you are hereby notified that any unauthorized use, disclosure, copying or distribution of the content of the e-mail transmission or the taking of any action in reliance thereon or pursuant thereto, is strictly prohibited and may be unlawful and may lead to prosecution. Should you have received this e-mail in error, please immediately notify us. The views, policies and comments contained in this e-mail are those of the sender thereof and should not be construed as the views, policies and/or comments of the organization. We cannot assure that the integrity of this e-mail communication has been maintained nor that it is free of errors, interference or interception and will not accept any liability or responsibility in this regard. By opening our emails, you indemnify us of any liability.

 

From: jetty-users <jetty-users-bounces@xxxxxxxxxxx> On Behalf Of Ludovic Orban
Sent: Tuesday, September 6, 2022 2:09 PM
To: JETTY user mailing list <jetty-users@xxxxxxxxxxx>
Subject: Re: [jetty-users] Jetty-11.0.11 embedded - WebAppContenxt class cannot parse file:jar references

 

 

Hi,

 

I just tried configuring a WebAppContext and make it serve the contents of a jar file with Jetty 11 and it worked just fine.

 

Could you please create a reproducer we can try out? This way it should be rather quick to figure out what's wrong to help you out.

 

Cheers,

---

Ludovic Orban <lorban@xxxxxxxxxxx>

http://webtide.com - advice and support for jetty and cometd.

 

 

 

On Tue, Sep 6, 2022 at 11:30 AM Stefan Viljoen via jetty-users <jetty-users@xxxxxxxxxxx> wrote:

Hi guys

 

Ok I’ve refined this down. See  my original question below.

 

The problem there is that if I do this to set up a Jetty WebAppContext:

 

--

.

.

.

String webDir = this.getClass().getClassLoader().getResource("static").toExternalForm();

 

WebAppContext waContext = new WebAppContext(webDir, "/"); 

.

.

.

--

 

I get for “webDir”

 

--

jar:file:/usr/src/verdi/verdi-12-JDK17-jar-with-dependencies.jar!/static

--

 

which is CORRECT  - there IS a folder “static” in the root  of the JAR Jetty is embedded in and running out of, and  that “static” folder contains  the .html, .js, etc. files I need Jetty to serve as a static website at x.x.x.x:80 to web-browser, using an instance of the Jetty WebAppContext class.

 

However, it appears Jetty’s WebAppContext class -CANNOT- parse jar:file references to web app -files-.

 

If I have a “webDir” of file:/// (e.g. just plain files outside the JAR) it works perfectly, and the Jetty WebAppContext class can serve out the site and does so perfectly to web-browsers visiting the server IP over HTTP.

 

How can one get Jetty’s WebAppContext class (for Jetty 11.0.11) to parse file:jar references so one can serve static HTML out of an embedded Jetty 11.0.11 instance from the same physical JAR file Jetty 11.0.11 is embedded in and running out of?

(This was working in Jetty 9, I recently upgraded and the WebAppContext class seems to have lost the capacity to  parse file:jar references?)

 

Thanks!

 

Description: signature

 

CONFIDENTIALITY NOTICE AND DISCLAIMER: This e-mail transmission contains confidential Information which is the property of the sender and which is subject to legal privilege and/or copyright and intended only for the above-mentioned addressee. If you are not the intended recipient, you are hereby notified that any unauthorized use, disclosure, copying or distribution of the content of the e-mail transmission or the taking of any action in reliance thereon or pursuant thereto, is strictly prohibited and may be unlawful and may lead to prosecution. Should you have received this e-mail in error, please immediately notify us. The views, policies and comments contained in this e-mail are those of the sender thereof and should not be construed as the views, policies and/or comments of the organization. We cannot assure that the integrity of this e-mail communication has been maintained nor that it is free of errors, interference or interception and will not accept any liability or responsibility in this regard. By opening our emails, you indemnify us of any liability.

 

From: Stefan Viljoen
Sent: Monday, September 5, 2022 10:53 AM
To: jetty-users@xxxxxxxxxxx
Subject: Jetty-11.0.11 embedded - 404 for all static html files or .jsp's in JAR under Linux JDK 17

 

Hi guys

 

Desperately looking for some help or pointers – been at this issue for two weeks solid now:

 

I have a Maven-based embedded Jetty-11.0.11 project in an “uber JAR” (jar-with-all-dependencies) in JDK17 that I  inherited from a dev that left the company.

 

I got it from him at Jetty-9 under JDK1.8, and have successfully upgraded it to Jetty-11.0.11 under JDK17 (at least, it works, but only -inside- Netbeans14…!) by changing the maven pom.xml to refer to newer versions of apache-jsp, apache-jstl, and jetty itself (for Maven.)

 

I have no web.xml or WEB-INF folder at all in the project.

 

The static content (.html, .css and .js files) for the webpages it contains, are hosted in the project .JAR at src\main\webapp\static

 

After upgrading to Jetty-11.0.11 and JDK17, I could run the project in Netbeans 14 debug mode in Windows 10 and visit the “Netbeans 14”-ed Jetty instance in a browser which rendered the static .html and .jsp content correctly.

 

If I copy the Jetty-11.0.11-using JAR to a Linux host and run it under JDK17 there, NONE of the static .html and .jsp content inside the JAR can be found anymore. When running in JDK17 under Linux in the embedded JAR, Jetty responds:

--

HTTP ERROR 404 Not Found

URI:

/

STATUS:

404

MESSAGE:

Not Found

SERVLET:

org.eclipse.jetty.servlet.ServletHandler$Default404Servlet-726a17c4

--

 

for any and all .html and .jsp files inside the JAR.

 

Where can I start to look to get Jetty-11.0-11 embedded in an uber-JAR to render .html and .jsp files inside the JAR when run in a Linux-based JDK 17 instance?

 

No exceptions or any errors is emitted by Jetty.

 

I run Jetty in Ubuntu 20.04-LTS with official Oracle JDK17 as

 

/usr/lib/jvm/jdk-17/bin/java -Djavax.net.ssl.trustStore=/usr/lib/jvm/jdk-17/lib/security/cacerts -cp /usr/src/verdi/verdi-12-JDK17-jar-with-dependencies.jar verishare.App

 

Anybody got ANY idea why Jetty-11.0.11 only works inside Netbeans 14 debug mode in Windows under Oracle JDK 17, but not in a Linux-based Oracle JDK 17 (where it WAS working in Linux with JDK 1.8 and Jetty-9)?

 

Where do I even start?

 

More than willing to provide more info such as the POM and the server setup code if anybody wants to help…

 

Thanks!

 

Kind regards,

 

Stefan

 

Description: signature

 

CONFIDENTIALITY NOTICE AND DISCLAIMER: This e-mail transmission contains confidential Information which is the property of the sender and which is subject to legal privilege and/or copyright and intended only for the above-mentioned addressee. If you are not the intended recipient, you are hereby notified that any unauthorized use, disclosure, copying or distribution of the content of the e-mail transmission or the taking of any action in reliance thereon or pursuant thereto, is strictly prohibited and may be unlawful and may lead to prosecution. Should you have received this e-mail in error, please immediately notify us. The views, policies and comments contained in this e-mail are those of the sender thereof and should not be construed as the views, policies and/or comments of the organization. We cannot assure that the integrity of this e-mail communication has been maintained nor that it is free of errors, interference or interception and will not accept any liability or responsibility in this regard. By opening our emails, you indemnify us of any liability.

 

_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

 


Back to the top