/samples/helloworld-osgi-webapp/README.html
HTML | 178 lines | 130 code | 7 blank | 41 comment | 0 complexity | c20dcda2438b14d2d56b5e844bfffd4b MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause-No-Nuclear-License-2014, GPL-2.0
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <!--
- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
- The contents of this file are subject to the terms of either the GNU
- General Public License Version 2 only ("GPL") or the Common Development
- and Distribution License("CDDL") (collectively, the "License"). You
- may not use this file except in compliance with the License. You can
- obtain a copy of the License at
- http://glassfish.java.net/public/CDDL+GPL_1_1.html
- or packager/legal/LICENSE.txt. See the License for the specific
- language governing permissions and limitations under the License.
- When distributing the software, include this License Header Notice in each
- file and include the License file at packager/legal/LICENSE.txt.
- GPL Classpath Exception:
- Oracle designates this particular file as subject to the "Classpath"
- exception as provided by Oracle in the GPL Version 2 section of the License
- file that accompanied this code.
- Modifications:
- If applicable, add the following below the License Header, with the fields
- enclosed by brackets [] replaced by your own identifying information:
- "Portions Copyright [year] [name of copyright owner]"
- Contributor(s):
- If you wish your version of this file to be governed by only the CDDL or
- only the GPL Version 2, indicate your decision by adding "[Contributor]
- elects to include this software in this distribution under the [CDDL or GPL
- Version 2] license." If you don't indicate a single choice of license, a
- recipient has the option to distribute your version of this file under
- either the CDDL, the GPL Version 2 or to extend the choice of license to
- its licensees as provided above. However, if you add GPL Version 2 code
- and therefore, elected the GPL Version 2 license, then the option applies
- only if the new code is made subject to such option by the copyright
- holder.
- -->
- <html><head><title>HelloWorld OSGi Example</title></head>
- <body>
- <h1>HelloWorld OSGi Example</h1>
- <p>This example demonstrates how to develop a simple OSGi WAR bundle containing a RESTful hello world web service</p>
- <h2>Contents</h2>
- <p>The example WAR (see the <tt>war-bundle</tt> module) consists of two Jersey resources:</p>
- <dl>
- <dt><code>com.sun.jersey.samples.helloworld.HelloWorldResource</code></dt>
- <dd>that produces a textual response to an HTTP GET</dd>
- </dl>
- <dl>
- <dt><code>com.sun.jersey.samples.helloworld.AnotherResource</code></dt>
- <dd>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.</dd>
- </dl>
- <p>The mapping of the URI path space is presented in the following table:</p>
- <table border="1">
- <tr>
- <th>URI path</th>
- <th>Resource class</th>
- <th>HTTP methods</th>
- </tr>
- <tr>
- <td>/helloworld</td>
- <td>HelloWorldResource</td>
- <td>GET</td>
- </tr>
- <tr>
- <td>/another</td>
- <td>AnotherResource</td>
- <td>GET</td>
- </tr>
- </table>
- <h2>Running the Example</h2>
- <p>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 <tt>functional-test</tt> module for details on the programatical runtime configuration.
- To build the war archive and run the tests, you can just launch
- <pre>%mvn clean install
- </pre>
- </p>
- <p>After <a href="http://felix.apache.org/site/downloads.cgi">downloading</a> and installing <a href="http://felix.apache.org/site/index.html">Felix</a>, you can also deploy the WAR manually as shown below.
- The following steps are known to work with the Felix version 4.2.1. You will need to replace <b><version></b>
- with the current Jersey version, and <b><repository></b> with either <code>snapshots</code> or <code>releases</code> based on whether
- you depend on a snapshot or stable release version of Jersey respectively, in the install commands below.
- The war archive built by the mvn command above
- should be located under the <tt>war-bundle/target</tt> subdirectory:
- <pre>
- %unzip ~/Downloads/org.apache.felix.main.distribution-4.2.1.zip
- %cp war-bundle/target/war-bundle*war felix-framework-4.2.1
- %cd felix-framework-4.2.1
- %java -jar bin/felix.jar
- ____________________________
- Welcome to Apache Felix Gogo
- g! lb
- START LEVEL 1
- ID|State |Level|Name
- 0|Active | 0|System Bundle (4.2.1)
- 1|Active | 1|Apache Felix Bundle Repository (1.6.6)
- 2|Active | 1|Apache Felix Gogo Command (0.12.0)
- 3|Active | 1|Apache Felix Gogo Runtime (0.10.0)
- 4|Active | 1|Apache Felix Gogo Shell (0.10.0)
- g! install http://repo2.maven.org/maven2/org/apache/felix/org.apache.felix.configadmin/1.2.8/org.apache.felix.configadmin-1.2.8.jar
- Bundle ID: 5
- g! install http://repo1.maven.org/maven2/org/apache/felix/org.apache.felix.eventadmin/1.2.10/org.apache.felix.eventadmin-1.2.10.jar
- Bundle ID: 6
- g! install http://repo2.maven.org/maven2/org/ops4j/pax/web/pax-web-jetty-bundle/0.7.1/pax-web-jetty-bundle-0.7.1.jar
- Bundle ID: 7
- g! install http://repo2.maven.org/maven2/org/ops4j/pax/web/pax-web-extender-war/0.7.1/pax-web-extender-war-0.7.1.jar
- Bundle ID: 8
- g! install http://repo1.maven.org/maven2/asm/asm-all/3.1/asm-all-3.1.jar
- Bundle ID: 9
- g! install https://maven.java.net/service/local/artifact/maven/redirect?r=<b><repository></b>&g=com.sun.jersey&a=jersey-core&v=<b><version></b>&e=jar
- Bundle ID: 10
- g! install https://maven.java.net/service/local/artifact/maven/redirect?r=<b><repository></b>&g=com.sun.jersey&a=jersey-server&v=<b><version></b>&e=jar
- Bundle ID: 11
- g! install https://maven.java.net/service/local/artifact/maven/redirect?r=<b><repository></b>&g=com.sun.jersey&a=jersey-servlet&v=<b><version></b>&e=jar
- Bundle ID: 12
- g! install file:war-bundle-1.18.war
- Bundle ID: 13
- g! lb
- START LEVEL 1
- ID|State |Level|Name
- 0|Active | 0|System Bundle (4.2.1)
- 1|Active | 1|Apache Felix Bundle Repository (1.6.6)
- 2|Active | 1|Apache Felix Gogo Command (0.12.0)
- 3|Active | 1|Apache Felix Gogo Runtime (0.10.0)
- 4|Active | 1|Apache Felix Gogo Shell (0.10.0)
- 5|Installed | 1|Apache Felix Configuration Admin Service (1.2.8)
- 6|Installed | 1|Apache Felix EventAdmin (1.2.10)
- 7|Installed | 1|OPS4J Pax Web - Jetty Bundle (0.7.1)
- 8|Installed | 1|OPS4J Pax Web - Extender - WAR (0.7.1)
- 9|Installed | 1|ASM all classes (3.1.0)
- 10|Installed | 1|jersey-core (1.18.0)
- 11|Installed | 1|jersey-server (1.18.0)
- 12|Installed | 1|jersey-servlet (1.18.0)
- 13|Installed | 1|Helloworld OSGi WebApp - Jersey Sample WAR (1.18.0)
- g! start 5 6 7 8 9 10 11 12 13
- Nov 15, 2013 5:05:46 PM com.sun.jersey.api.core.PackagesResourceConfig init
- INFO: Scanning for root resource and provider classes in the packages:
- com.sun.jersey.samples.helloworld
- Nov 15, 2013 5:05:46 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
- INFO: Root resource classes found:
- class com.sun.jersey.samples.helloworld.AnotherResource
- class com.sun.jersey.samples.helloworld.HelloWorldResource
- Nov 15, 2013 5:05:46 PM com.sun.jersey.api.core.ScanningResourceConfig init
- INFO: No provider classes found.
- Nov 15, 2013 5:05:46 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
- INFO: Initiating Jersey application, version 'Jersey: 1.18 11/15/2013 09:28 AM'
- </pre>
- <b>Note</b>: The version string can be updated to install another Jersey version runtime.<br><br>
- Now both Jersey resources should become available at:
- <ul>
- <li><a href="http://localhost:8080/helloworld/webresources/helloworld">http://localhost:8080/helloworld/webresources/helloworld</a></li>
- <li><a href="http://localhost:8080/helloworld/webresources/another">http://localhost:8080/helloworld/webresources/another</a></li>
- </ul>
- </p>
- <h2>Troubleshooting</h2>
- <h3>HTTP Proxy</h3>
- <p>Behind a HTTP proxy, Apache Felix returns <tt>java.net.ConnectException: Connection timed out</tt> when
- installing bundles from the Internet. You will need to setup the following system properties:
- <ul>
- <li>http.proxyHost - the name of the proxy host.</li>
- <li>http.proxyPort - the port of the proxy host.</li>
- <li>http.proxyAuth - the user name and password to use when connecting to the proxy; this string should be the user name and password separated by a colon (e.g., rickhall:mypassword).</li>
- </ul>
- These system properties can be set directly on the command line when starting the JVM using the standard "-D<prop>=<value>" syntax or you can put them in the lib/system.properties file of your Felix installation; see documentation on configuring Felix for more information.</p>
- </body></html>