From 6a8343c01da4b8dbdfffe997dd50376b16613993 Mon Sep 17 00:00:00 2001 From: Gregor Pfeifer Date: Wed, 31 Jan 2024 20:21:41 +0100 Subject: [PATCH] Add an example of a Jersey OSGi bundle for Jetty 12 (ee8) Signed-off-by: Gregor Pfeifer --- .../.gitignore | 1 + .../osgi-helloworld-webapp-jetty-12/README.md | 47 ++++++ .../osgi-helloworld-webapp-jetty-12/pom.xml | 47 ++++++ .../war-bundle/.gitignore | 3 + .../war-bundle/README.md | 11 ++ .../war-bundle/pom.xml | 145 ++++++++++++++++++ .../osgi/helloworld/HelloResource.java | 29 ++++ .../osgi/helloworld/HelloResourceConfig.java | 31 ++++ .../src/main/webapp/WEB-INF/web.xml | 31 ++++ 9 files changed, 345 insertions(+) create mode 100644 examples/osgi-helloworld-webapp-jetty-12/.gitignore create mode 100644 examples/osgi-helloworld-webapp-jetty-12/README.md create mode 100644 examples/osgi-helloworld-webapp-jetty-12/pom.xml create mode 100644 examples/osgi-helloworld-webapp-jetty-12/war-bundle/.gitignore create mode 100644 examples/osgi-helloworld-webapp-jetty-12/war-bundle/README.md create mode 100644 examples/osgi-helloworld-webapp-jetty-12/war-bundle/pom.xml create mode 100644 examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResource.java create mode 100644 examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResourceConfig.java create mode 100644 examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/webapp/WEB-INF/web.xml diff --git a/examples/osgi-helloworld-webapp-jetty-12/.gitignore b/examples/osgi-helloworld-webapp-jetty-12/.gitignore new file mode 100644 index 0000000000..9f970225ad --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/.gitignore @@ -0,0 +1 @@ +target/ \ No newline at end of file diff --git a/examples/osgi-helloworld-webapp-jetty-12/README.md b/examples/osgi-helloworld-webapp-jetty-12/README.md new file mode 100644 index 0000000000..40b98f671c --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/README.md @@ -0,0 +1,47 @@ +[//]: # " Copyright (c) 2015, 2018 Oracle and/or its affiliates. All rights reserved. " +[//]: # " " +[//]: # " This program and the accompanying materials are made available under the " +[//]: # " terms of the Eclipse Distribution License v. 1.0, which is available at " +[//]: # " http://www.eclipse.org/org/documents/edl-v10.php. " +[//]: # " " +[//]: # " SPDX-License-Identifier: BSD-3-Clause " + +HelloWorld OSGi Example +======================= + +This example demonstrates how to develop a simple OSGi WAR bundle +containing a RESTful hello world web service + +Contents +-------- + +The example WAR (see the `war-bundle` module) consists of two Jersey +resources: + +`org.glassfish.jersey.examples.osgi.helloworld.resource.HelloWorldResource` + +that produces a textual response to an HTTP GET + +`org.glassfish.jersey.examples.osgi.helloworld.resource.AnotherResource` + +that produces a different textual response to an HTTP GET. The +purpose of this resource is to show how to define multiple web +resources within a web application. + +The mapping of the URI path space is presented in the following table: + +URI path | Resource class | HTTP method +------------------ | -------------------- | ------------- +**_/helloworld_** | HelloWorldResource | GET +**_/another_** | AnotherResource | GET + +Running the Example +------------------- + +To run the example, you would need to build the WAR file and install it +to an OSGi runtime (e.g. Apache Felix) together with other OSGi modules. +Look at the attached `functional-test` module for details on the +programatical runtime configuration. To build the war archive and run +the tests, you can just launch + +> mvn clean install diff --git a/examples/osgi-helloworld-webapp-jetty-12/pom.xml b/examples/osgi-helloworld-webapp-jetty-12/pom.xml new file mode 100644 index 0000000000..1954bde975 --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/pom.xml @@ -0,0 +1,47 @@ + + + + + + 4.0.0 + + + org.glassfish.jersey.examples + project + 2.42-SNAPSHOT + + + osgi-helloworld-webapp-jetty-12 + jersey-examples-osgi-helloworld-webapp-jetty-12 + pom + + + war-bundle + + + + + + pre-release + + + + org.apache.maven.plugins + maven-assembly-plugin + + + + + + + diff --git a/examples/osgi-helloworld-webapp-jetty-12/war-bundle/.gitignore b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/.gitignore new file mode 100644 index 0000000000..f105c80491 --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/.gitignore @@ -0,0 +1,3 @@ +target/ +.vscode/ + diff --git a/examples/osgi-helloworld-webapp-jetty-12/war-bundle/README.md b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/README.md new file mode 100644 index 0000000000..4cae4fb1fc --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/README.md @@ -0,0 +1,11 @@ +# A minimalistic Hello World OSGi Bundle for Jetty 12 e88 + +The Resource will be available under: + + {{base_url}}/helloworld/webresources/hello + +**helloworld** is configured in the MANIFEST.MF + +**webresources** is configured in web.xml + +**hello** is path to the resource \ No newline at end of file diff --git a/examples/osgi-helloworld-webapp-jetty-12/war-bundle/pom.xml b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/pom.xml new file mode 100644 index 0000000000..b62329873e --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/pom.xml @@ -0,0 +1,145 @@ + + + + + + 4.0.0 + + + org.glassfish.jersey.examples + osgi-helloworld-webapp-jetty-12 + 2.42-SNAPSHOT + + + org.glassfish.jersey.examples.osgi-helloworld-jetty-12-webapp + war-bundle + jersey-examples-osgi-helloworld-jetty-12-webapp-wab + war + + OSGi Helloworld Webapp WAR bundle for Jetty 12 + + + + org.glassfish.jersey.containers + jersey-container-servlet-core + provided + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + + + javax.servlet + servlet-api + ${servlet2.version} + provided + + + + org.apache.felix + org.apache.felix.eventadmin + provided + + + org.apache.felix + org.apache.felix.framework + provided + + + + + + + + org.apache.felix + maven-bundle-plugin + true + + + bundle-manifest + process-classes + + manifest + + + + + ${project.build.directory}/META-INF + + bundle + war + + + ${project.artifactId} + + org.glassfish.jersey.servlet, + * + + + org.glassfish.jersey.examples.osgi.helloworld + + helloworld + helloworld + ee8 + <_wab>src/main/webapp + + + + + + org.apache.maven.plugins + maven-war-plugin + + true + + ${project.build.directory}/META-INF/MANIFEST.MF + + + + + + + + + release + + + + + org.apache.maven.plugins + maven-assembly-plugin + + true + + + + + + + moxy + + + moxy + + + + + org.eclipse.persistence + org.eclipse.persistence.moxy + ${moxy.version} + provided + + + + + + diff --git a/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResource.java b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResource.java new file mode 100644 index 0000000000..e5ebe67788 --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResource.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0, which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.glassfish.jersey.examples.osgi.helloworld; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +/** + * The Hello resource + * + * @author Gregor Pfeifer + */ +@Path("/hello") +public class HelloResource { + + @GET + public String sayHello() { + return "Hello world :-)"; + } + +} diff --git a/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResourceConfig.java b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResourceConfig.java new file mode 100644 index 0000000000..3a06794888 --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResourceConfig.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2024. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0, which is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.glassfish.jersey.examples.osgi.helloworld; + +import org.glassfish.jersey.server.ResourceConfig; + +/** + * The Hello ResourceConfig + * + * @author Gregor Pfeifer + */ +public class HelloResourceConfig extends ResourceConfig { + + public static Class[] CLASSES = new Class[] { + HelloResource.class + }; + + public HelloResourceConfig() { + super(CLASSES); + } + + +} \ No newline at end of file diff --git a/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/webapp/WEB-INF/web.xml b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..ede62d8747 --- /dev/null +++ b/examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,31 @@ + + + + + + + + Jersey Web Application + org.glassfish.jersey.servlet.ServletContainer + + javax.ws.rs.Application + org.glassfish.jersey.examples.osgi.helloworld.HelloResourceConfig + + 1 + + + Jersey Web Application + /webresources/* + + +