-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example of a Jersey OSGi bundle for Jetty 12 (ee8)
Signed-off-by: Gregor Pfeifer <[email protected]>
- Loading branch information
Showing
9 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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 | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.glassfish.jersey.examples</groupId> | ||
<artifactId>project</artifactId> | ||
<version>2.42-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>osgi-helloworld-webapp-jetty-12</artifactId> | ||
<name>jersey-examples-osgi-helloworld-webapp-jetty-12</name> | ||
<packaging>pom</packaging> | ||
|
||
<modules> | ||
<module>war-bundle</module> | ||
<!-- | ||
TBD: Write functional tests. | ||
<module>functional-test</module> | ||
--> | ||
</modules> | ||
|
||
<profiles> | ||
<profile> | ||
<id>pre-release</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
3 changes: 3 additions & 0 deletions
3
examples/osgi-helloworld-webapp-jetty-12/war-bundle/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
target/ | ||
.vscode/ | ||
|
11 changes: 11 additions & 0 deletions
11
examples/osgi-helloworld-webapp-jetty-12/war-bundle/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
145 changes: 145 additions & 0 deletions
145
examples/osgi-helloworld-webapp-jetty-12/war-bundle/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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 | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.glassfish.jersey.examples</groupId> | ||
<artifactId>osgi-helloworld-webapp-jetty-12</artifactId> | ||
<version>2.42-SNAPSHOT</version> | ||
</parent> | ||
|
||
<groupId>org.glassfish.jersey.examples.osgi-helloworld-jetty-12-webapp</groupId> | ||
<artifactId>war-bundle</artifactId> | ||
<name>jersey-examples-osgi-helloworld-jetty-12-webapp-wab</name> | ||
<packaging>war</packaging> | ||
|
||
<description>OSGi Helloworld Webapp WAR bundle for Jetty 12</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-servlet-core</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>jakarta.ws.rs</groupId> | ||
<artifactId>jakarta.ws.rs-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>${servlet2.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>org.apache.felix.eventadmin</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>org.apache.felix.framework</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<!-- to generate the MANIFEST-FILE required by the bundle --> | ||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-bundle-plugin</artifactId> | ||
<extensions>true</extensions> | ||
<executions> | ||
<execution> | ||
<id>bundle-manifest</id> | ||
<phase>process-classes</phase> | ||
<goals> | ||
<goal>manifest</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<manifestLocation>${project.build.directory}/META-INF</manifestLocation> | ||
<supportedProjectTypes> | ||
<supportedProjectType>bundle</supportedProjectType> | ||
<supportedProjectType>war</supportedProjectType> | ||
</supportedProjectTypes> | ||
<instructions> | ||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> | ||
<Import-Package> | ||
org.glassfish.jersey.servlet, | ||
* | ||
</Import-Package> | ||
<Export-Package> | ||
org.glassfish.jersey.examples.osgi.helloworld | ||
</Export-Package> | ||
<Webapp-Context>helloworld</Webapp-Context> | ||
<Web-ContextPath>helloworld</Web-ContextPath> | ||
<Jetty-Environment>ee8</Jetty-Environment> | ||
<_wab>src/main/webapp</_wab> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-war-plugin</artifactId> | ||
<configuration> | ||
<attachClasses>true</attachClasses> | ||
<archive> | ||
<manifestFile>${project.build.directory}/META-INF/MANIFEST.MF</manifestFile> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<profiles> | ||
<profile> | ||
<id>release</id> | ||
<!-- do not create source zip bundles --> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-assembly-plugin</artifactId> | ||
<configuration> | ||
<skipAssembly>true</skipAssembly> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
<profile> | ||
<id>moxy</id> | ||
<activation> | ||
<property> | ||
<name>moxy</name> | ||
</property> | ||
</activation> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.persistence</groupId> | ||
<artifactId>org.eclipse.persistence.moxy</artifactId> | ||
<version>${moxy.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</profile> | ||
</profiles> | ||
|
||
</project> |
29 changes: 29 additions & 0 deletions
29
...war-bundle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 :-)"; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
...ndle/src/main/java/org/glassfish/jersey/examples/osgi/helloworld/HelloResourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
|
||
} |
31 changes: 31 additions & 0 deletions
31
examples/osgi-helloworld-webapp-jetty-12/war-bundle/src/main/webapp/WEB-INF/web.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012, 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 | ||
--> | ||
|
||
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> | ||
|
||
<!-- Jersey APP with a ResourceConfig--> | ||
<servlet> | ||
<servlet-name>Jersey Web Application</servlet-name> | ||
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> | ||
<init-param> | ||
<param-name>javax.ws.rs.Application</param-name> | ||
<param-value>org.glassfish.jersey.examples.osgi.helloworld.HelloResourceConfig</param-value> | ||
</init-param> | ||
<load-on-startup>1</load-on-startup> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>Jersey Web Application</servlet-name> | ||
<url-pattern>/webresources/*</url-pattern> | ||
</servlet-mapping> | ||
|
||
</web-app> |