Debian Codegraph @

samples/osgi-http-service/README.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <!--
3
4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5
6 Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
7
8 The contents of this file are subject to the terms of either the GNU
9 General Public License Version 2 only ("GPL") or the Common Development
10 and Distribution License("CDDL") (collectively, the "License"). You
11 may not use this file except in compliance with the License. You can
12 obtain a copy of the License at
13 http://glassfish.java.net/public/CDDL+GPL_1_1.html
14 or packager/legal/LICENSE.txt. See the License for the specific
15 language governing permissions and limitations under the License.
16
17 When distributing the software, include this License Header Notice in each
18 file and include the License file at packager/legal/LICENSE.txt.
19
20 GPL Classpath Exception:
21 Oracle designates this particular file as subject to the "Classpath"
22 exception as provided by Oracle in the GPL Version 2 section of the License
23 file that accompanied this code.
24
25 Modifications:
26 If applicable, add the following below the License Header, with the fields
27 enclosed by brackets [] replaced by your own identifying information:
28 "Portions Copyright [year] [name of copyright owner]"
29
30 Contributor(s):
31 If you wish your version of this file to be governed by only the CDDL or
32 only the GPL Version 2, indicate your decision by adding "[Contributor]
33 elects to include this software in this distribution under the [CDDL or GPL
34 Version 2] license." If you don't indicate a single choice of license, a
35 recipient has the option to distribute your version of this file under
36 either the CDDL, the GPL Version 2 or to extend the choice of license to
37 its licensees as provided above. However, if you add GPL Version 2 code
38 and therefore, elected the GPL Version 2 license, then the option applies
39 only if the new code is made subject to such option by the copyright
40 holder.
41
42 -->
43 <html><head><title>OSGi HttpService Example</title></head>
44
45
46 <body>
47 <h1>OSGi HttpService Example</h1>
48
49 <p>This example demonstrates how to develop a simple OSGi bundle registering
50 a Jersey based RESTful web service as an <a href="http://www.osgi.org/javadoc/r4v42/org/osgi/service/http/HttpService.html">OSGi HttpService</a></p>
51
52 <h2>Contents</h2>
53 <p>The example bundle (see the <tt>bundle</tt> module) consists of just one Jersey resource:</p>
54 <dl>
55 <dt><code>com.sun.jersey.samples.osgihttpservice.StatusResource</code></dt>
56 <dd>that produces a textual response to an HTTP GET</dd>
57 </dl>
58 <p>The mapping of the URI path space is presented in the following table:</p>
59 <table border="1">
60 <tr>
61 <th>URI path</th>
62 <th>Resource class</th>
63 <th>HTTP methods</th>
64 </tr>
65 <tr>
66 <td>/status</td>
67 <td>StatusResource</td>
68 <td>GET</td>
69 </tr>
70 </table>
71
72 <h2>Running the Example</h2>
73 <p>To run the example, you would need to build the OSGi bundle in the <tt>bundle</tt> module
74 and install it to an OSGi runtime (e.g. Apache Felix) together with other OSGi bundles.
75 Look at the attached <tt>functional-test</tt> module for details on the programmatical runtime configuration</p>
76 To build the bundle jar file and run the tests, you can just launch
77 <pre>%mvn clean install
78 </pre>
79 </p>
80 <p>After <a href="http://felix.apache.org/site/downloads.cgi">downloading</a>
81 and installing <a href="http://felix.apache.org/site/index.html">Felix</a>,
82 you can also start the HTTP service manually as shown below.
83 The following steps are known to work with the Felix version 3.0.9. You will need to replace <b>&lt;version&gt;</b>
84 with the current Jersey version, and <b>&lt;repository&gt;</b> with either <code>snapshots</code> or <code>releases</code> based on whether
85 you depend on a snapshot or stable release version of Jersey respectively, in the install commands below.
86 <pre>
87 %unzip ~/Downloads/org.apache.felix.main.distribution-3.0.9.zip
88 %cp bundle/target/bundle*jar felix-framework-3.0.9
89 %cd felix-framework-3.0.9
90 %java -jar bin/felix.jar
91 ____________________________
92 Welcome to Apache Felix Gogo
93
94 g! lb
95 START LEVEL 1
96 ID|State |Level|Name
97 0|Active | 0|System Bundle (3.0.9)
98 1|Active | 1|Apache Felix Bundle Repository (1.6.2)
99 2|Active | 1|Apache Felix Gogo Command (0.8.0)
100 3|Active | 1|Apache Felix Gogo Runtime (0.8.0)
101 4|Active | 1|Apache Felix Gogo Shell (0.8.0)
102 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
103 Bundle ID: 5
104 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
105 Bundle ID: 6
106 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
107 Bundle ID: 7
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: 8
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: 9
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: 10
114 g! install file:bundle-1.9.jar
115 Bundle ID: 11
116 g! lb
117 START LEVEL 1
118 ID|State |Level|Name
119 0|Active | 0|System Bundle (3.0.9)
120 1|Active | 1|Apache Felix Bundle Repository (1.6.2)
121 2|Active | 1|Apache Felix Gogo Command (0.8.0)
122 3|Active | 1|Apache Felix Gogo Runtime (0.8.0)
123 4|Active | 1|Apache Felix Gogo Shell (0.8.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|jersey-core (1.9.0)
128 9|Installed | 1|jersey-server (1.9.0)
129 10|Installed | 1|jersey-servlet (1.9.0)
130 11|Installed | 1|OSGi HttpService - Jersey Sample Bundle (1.9.0)
131 g! start 5 6 7 8 9 10 11
132 Mar 22, 2011 10:04:30 PM com.sun.jersey.samples.osgihttpservice.Activator start
133 INFO: STARTING HTTP SERVICE BUNDLE
134 Mar 22, 2011 10:04:30 PM com.sun.jersey.samples.osgihttpservice.Activator rawRegisterServlets
135 INFO: JERSEY BUNDLE: REGISTERING SERVLETS
136 Mar 22, 2011 10:04:30 PM com.sun.jersey.samples.osgihttpservice.Activator rawRegisterServlets
137 INFO: JERSEY BUNDLE: HTTP SERVICE = org.ops4j.pax.web.service.internal.HttpServiceProxy@1d25d06e
138 Mar 22, 2011 10:04:30 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
139 INFO: Initiating Jersey application, version 'Jersey: 1.9 09/02/2011 12:48 PM'
140 Mar 22, 2011 10:04:30 PM com.sun.jersey.server.impl.application.DeferredResourceConfig$ApplicationHolder <init>
141 INFO: Instantiated the Application class com.sun.jersey.samples.osgihttpservice.JerseyApplication
142 Mar 22, 2011 10:04:31 PM com.sun.jersey.samples.osgihttpservice.Activator rawRegisterServlets
143 INFO: JERSEY BUNDLE: SERVLETS REGISTERED
144 Mar 22, 2011 10:04:31 PM com.sun.jersey.samples.osgihttpservice.Activator start
145 INFO: HTTP SERVICE BUNDLE STARTED
146 </pre>
147
148 Now the Jersey resource should become
149 available at <a href="http://localhost:8080/jersey-http-service/status">http://localhost:8080/jersey-http-service/status</a>
150 </p>
151 <h2>Troubleshooting</h2>
152 <h3>HTTP Proxy</h3>
153 <p>Behind a HTTP proxy, Apache Felix returns <tt>java.net.ConnectException: Connection timed out</tt> when
154 installing bundles from the Internet. You will need to setup the following system properties:
155 <ul>
156 <li>http.proxyHost - the name of the proxy host.</li>
157 <li>http.proxyPort - the port of the proxy host.</li>
158 <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>
159 </ul>
160
161 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>
162
163 </body></html>