PageRenderTime 50ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/samples/helloworld-osgi-webapp/README.html

http://github.com/jersey/jersey-1.x
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
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <!--
  3. DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  4. Copyright (c) 2010-2013 Oracle and/or its affiliates. All rights reserved.
  5. The contents of this file are subject to the terms of either the GNU
  6. General Public License Version 2 only ("GPL") or the Common Development
  7. and Distribution License("CDDL") (collectively, the "License"). You
  8. may not use this file except in compliance with the License. You can
  9. obtain a copy of the License at
  10. http://glassfish.java.net/public/CDDL+GPL_1_1.html
  11. or packager/legal/LICENSE.txt. See the License for the specific
  12. language governing permissions and limitations under the License.
  13. When distributing the software, include this License Header Notice in each
  14. file and include the License file at packager/legal/LICENSE.txt.
  15. GPL Classpath Exception:
  16. Oracle designates this particular file as subject to the "Classpath"
  17. exception as provided by Oracle in the GPL Version 2 section of the License
  18. file that accompanied this code.
  19. Modifications:
  20. If applicable, add the following below the License Header, with the fields
  21. enclosed by brackets [] replaced by your own identifying information:
  22. "Portions Copyright [year] [name of copyright owner]"
  23. Contributor(s):
  24. If you wish your version of this file to be governed by only the CDDL or
  25. only the GPL Version 2, indicate your decision by adding "[Contributor]
  26. elects to include this software in this distribution under the [CDDL or GPL
  27. Version 2] license." If you don't indicate a single choice of license, a
  28. recipient has the option to distribute your version of this file under
  29. either the CDDL, the GPL Version 2 or to extend the choice of license to
  30. its licensees as provided above. However, if you add GPL Version 2 code
  31. and therefore, elected the GPL Version 2 license, then the option applies
  32. only if the new code is made subject to such option by the copyright
  33. holder.
  34. -->
  35. <html><head><title>HelloWorld OSGi Example</title></head>
  36. <body>
  37. <h1>HelloWorld OSGi Example</h1>
  38. <p>This example demonstrates how to develop a simple OSGi WAR bundle containing a RESTful hello world web service</p>
  39. <h2>Contents</h2>
  40. <p>The example WAR (see the <tt>war-bundle</tt> module) consists of two Jersey resources:</p>
  41. <dl>
  42. <dt><code>com.sun.jersey.samples.helloworld.HelloWorldResource</code></dt>
  43. <dd>that produces a textual response to an HTTP GET</dd>
  44. </dl>
  45. <dl>
  46. <dt><code>com.sun.jersey.samples.helloworld.AnotherResource</code></dt>
  47. <dd>that produces a different textual response to an HTTP GET.
  48. The purpose of this resource is to show how to define multiple
  49. web resources within a web application.</dd>
  50. </dl>
  51. <p>The mapping of the URI path space is presented in the following table:</p>
  52. <table border="1">
  53. <tr>
  54. <th>URI path</th>
  55. <th>Resource class</th>
  56. <th>HTTP methods</th>
  57. </tr>
  58. <tr>
  59. <td>/helloworld</td>
  60. <td>HelloWorldResource</td>
  61. <td>GET</td>
  62. </tr>
  63. <tr>
  64. <td>/another</td>
  65. <td>AnotherResource</td>
  66. <td>GET</td>
  67. </tr>
  68. </table>
  69. <h2>Running the Example</h2>
  70. <p>To run the example, you would need to build the WAR file
  71. and install it to an OSGi runtime (e.g. Apache Felix) together with other OSGi modules.
  72. Look at the attached <tt>functional-test</tt> module for details on the programatical runtime configuration.
  73. To build the war archive and run the tests, you can just launch
  74. <pre>%mvn clean install
  75. </pre>
  76. </p>
  77. <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.
  78. The following steps are known to work with the Felix version 4.2.1. You will need to replace <b>&lt;version&gt;</b>
  79. with the current Jersey version, and <b>&lt;repository&gt;</b> with either <code>snapshots</code> or <code>releases</code> based on whether
  80. you depend on a snapshot or stable release version of Jersey respectively, in the install commands below.
  81. The war archive built by the mvn command above
  82. should be located under the <tt>war-bundle/target</tt> subdirectory:
  83. <pre>
  84. %unzip ~/Downloads/org.apache.felix.main.distribution-4.2.1.zip
  85. %cp war-bundle/target/war-bundle*war felix-framework-4.2.1
  86. %cd felix-framework-4.2.1
  87. %java -jar bin/felix.jar
  88. ____________________________
  89. Welcome to Apache Felix Gogo
  90. g! lb
  91. START LEVEL 1
  92. ID|State |Level|Name
  93. 0|Active | 0|System Bundle (4.2.1)
  94. 1|Active | 1|Apache Felix Bundle Repository (1.6.6)
  95. 2|Active | 1|Apache Felix Gogo Command (0.12.0)
  96. 3|Active | 1|Apache Felix Gogo Runtime (0.10.0)
  97. 4|Active | 1|Apache Felix Gogo Shell (0.10.0)
  98. 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
  99. Bundle ID: 5
  100. 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
  101. Bundle ID: 6
  102. 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
  103. Bundle ID: 7
  104. 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
  105. Bundle ID: 8
  106. g! install http://repo1.maven.org/maven2/asm/asm-all/3.1/asm-all-3.1.jar
  107. Bundle ID: 9
  108. g! install https://maven.java.net/service/local/artifact/maven/redirect?r=<b>&lt;repository&gt;</b>&g=com.sun.jersey&a=jersey-core&v=<b>&lt;version&gt;</b>&e=jar
  109. Bundle ID: 10
  110. g! install https://maven.java.net/service/local/artifact/maven/redirect?r=<b>&lt;repository&gt;</b>&g=com.sun.jersey&a=jersey-server&v=<b>&lt;version&gt;</b>&e=jar
  111. Bundle ID: 11
  112. g! install https://maven.java.net/service/local/artifact/maven/redirect?r=<b>&lt;repository&gt;</b>&g=com.sun.jersey&a=jersey-servlet&v=<b>&lt;version&gt;</b>&e=jar
  113. Bundle ID: 12
  114. g! install file:war-bundle-1.18.war
  115. Bundle ID: 13
  116. g! lb
  117. START LEVEL 1
  118. ID|State |Level|Name
  119. 0|Active | 0|System Bundle (4.2.1)
  120. 1|Active | 1|Apache Felix Bundle Repository (1.6.6)
  121. 2|Active | 1|Apache Felix Gogo Command (0.12.0)
  122. 3|Active | 1|Apache Felix Gogo Runtime (0.10.0)
  123. 4|Active | 1|Apache Felix Gogo Shell (0.10.0)
  124. 5|Installed | 1|Apache Felix Configuration Admin Service (1.2.8)
  125. 6|Installed | 1|Apache Felix EventAdmin (1.2.10)
  126. 7|Installed | 1|OPS4J Pax Web - Jetty Bundle (0.7.1)
  127. 8|Installed | 1|OPS4J Pax Web - Extender - WAR (0.7.1)
  128. 9|Installed | 1|ASM all classes (3.1.0)
  129. 10|Installed | 1|jersey-core (1.18.0)
  130. 11|Installed | 1|jersey-server (1.18.0)
  131. 12|Installed | 1|jersey-servlet (1.18.0)
  132. 13|Installed | 1|Helloworld OSGi WebApp - Jersey Sample WAR (1.18.0)
  133. g! start 5 6 7 8 9 10 11 12 13
  134. Nov 15, 2013 5:05:46 PM com.sun.jersey.api.core.PackagesResourceConfig init
  135. INFO: Scanning for root resource and provider classes in the packages:
  136. com.sun.jersey.samples.helloworld
  137. Nov 15, 2013 5:05:46 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
  138. INFO: Root resource classes found:
  139. class com.sun.jersey.samples.helloworld.AnotherResource
  140. class com.sun.jersey.samples.helloworld.HelloWorldResource
  141. Nov 15, 2013 5:05:46 PM com.sun.jersey.api.core.ScanningResourceConfig init
  142. INFO: No provider classes found.
  143. Nov 15, 2013 5:05:46 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
  144. INFO: Initiating Jersey application, version 'Jersey: 1.18 11/15/2013 09:28 AM'
  145. </pre>
  146. <b>Note</b>: The version string can be updated to install another Jersey version runtime.<br><br>
  147. Now both Jersey resources should become available at:
  148. <ul>
  149. <li><a href="http://localhost:8080/helloworld/webresources/helloworld">http://localhost:8080/helloworld/webresources/helloworld</a></li>
  150. <li><a href="http://localhost:8080/helloworld/webresources/another">http://localhost:8080/helloworld/webresources/another</a></li>
  151. </ul>
  152. </p>
  153. <h2>Troubleshooting</h2>
  154. <h3>HTTP Proxy</h3>
  155. <p>Behind a HTTP proxy, Apache Felix returns <tt>java.net.ConnectException: Connection timed out</tt> when
  156. installing bundles from the Internet. You will need to setup the following system properties:
  157. <ul>
  158. <li>http.proxyHost - the name of the proxy host.</li>
  159. <li>http.proxyPort - the port of the proxy host.</li>
  160. <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>
  161. </ul>
  162. These system properties can be set directly on the command line when starting the JVM using the standard "-D&lt;prop&gt;=&lt;value&gt;" 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>
  163. </body></html>