Debian Codegraph @

src/docbkx/agents/osgi.xml

raw
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3 ~ Copyright 2009-2013 Roland Huss
4 ~
5 ~ Licensed under the Apache License, Version 2.0 (the "License");
6 ~ you may not use this file except in compliance with the License.
7 ~ You may obtain a copy of the License at
8 ~
9 ~ http://www.apache.org/licenses/LICENSE-2.0
10 ~
11 ~ Unless required by applicable law or agreed to in writing, software
12 ~ distributed under the License is distributed on an "AS IS" BASIS,
13 ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ~ See the License for the specific language governing permissions and
15 ~ limitations under the License.
16 -->
17
18 <section id="agents-osgi">
19 <title>OSGi Agents</title>
20 <sidebar>There are several free implementations available of OSGi
21 HttpService. This bundle has been tested with the <ulink
22 url="http://wiki.ops4j.org/display/paxweb/Pax+Web">Pax Web</ulink>
23 and <ulink
24 url="http://felix.apache.org/site/apache-felix-http-service.html">Apache
25 Felix</ulink> HttpService, both of which come with an embedded Jetty
26 as servlet container by default.</sidebar>
27 <para>
28 Jolokia agents are also available as <ulink
29 url="http://www.osgi.org">OSGi</ulink> bundles. There are two
30 flavors of this agent: A nearly bare agent
31 <filename>jolokia-osgi.jar</filename> declaring all its package
32 dependencies as imports in its Manifest and an all-in-one bundle
33 <filename>jolokia-osgi-bundle.jar</filename> with minimal
34 dependencies. The pure bundle fits best with the OSGi philosophy and is
35 hence the recommended bundle. The all-in-one monster is good for a
36 quick start since normally no additional bundles are required.
37 </para>
38 <section id="agents-osgi-pure">
39 <title>jolokia-osgi.jar</title>
40 <para>
41 This bundle depends mostly on a running <ulink
42 url="http://www.osgi.org/javadoc/r4v42/org/osgi/service/http/HttpService.html">OSGi
43 HttpService</ulink> which it uses for registering the agent
44 servlet.
45 </para>
46 <para>
47 All package imports of this bundle are listed in <xref
48 linkend="table-agents-osgi-deps"/>. Note that the
49 <classname>org.osgi.framework.*</classname> and
50 <classname>javax.*</classname> packages are typically exported
51 by the system bundle, so no extra installation effort is
52 required here. Whether the
53 <classname>org.osgi.service.*</classname> interfaces are
54 available depends on your OSGi container. If they are not
55 provided, they can be easily fetched and installed from e.g.
56 <ulink
57 url="http://repo1.maven.org/maven2/org/osgi/org.osgi.compendium/4.2.0/org.osgi.compendium-4.2.0.jar">maven
58 central</ulink>. Often the LogService interface is exported
59 out of the box, but not the HttpService. You will notice any
60 missing package dependency during the resolve phase while
61 installing <filename>jolokia-osgi.jar</filename>.
62 </para>
63 <table id="table-agents-osgi-deps">
64 <title>Package Imports of jolokia-osgi.jar (SB: exported by system bundle)</title>
65 <thead>
66 <tr>
67 <td>Package</td>
68 <td>SB</td>
69 <td>Package</td>
70 <td>SB</td>
71 <td>Package</td>
72 <td>SB</td>
73 <td>Package</td>
74 <td>SB</td>
75 </tr>
76 </thead>
77 <tr>
78 <td>org.osgi.framework</td>
79 <td>X</td>
80 <td>javax.servlet</td>
81 <td></td>
82 <td>org.w3c.dom</td>
83 <td>X</td>
84 <td>javax.management</td>
85 <td>X</td>
86 </tr>
87 <tr>
88 <td>org.osgi.service.http</td>
89 <td></td>
90 <td>javax.servlet.http</td>
91 <td></td>
92 <td>org.xml.sax</td>
93 <td>X</td>
94 <td>javax.management.openmbean</td>
95 <td>X</td>
96 </tr>
97 <tr>
98 <td>org.osgi.service.log</td>
99 <td>?</td>
100 <td>javax.naming</td>
101 <td>X</td>
102 <td>javax.xml.parsers</td>
103 <td>X</td>
104 <td>javax.management.remote</td>
105 <td>X</td>
106 </tr>
107 <tr>
108 <td>org.osgi.util.tracker</td>
109 <td>X</td>
110 <td></td>
111 <td></td>
112 <td></td>
113 <td></td>
114 <td></td>
115 <td></td>
116 </tr>
117 </table>
118 <para>
119 This agent bundle consumes two services by default: As stated
120 above, an
121 <classname>org.osgi.service.http.HttpService</classname> which
122 is used to register (deregister) the Jolokia agent as a servlet
123 under the context <literal>/jolokia</literal> by default as soon
124 as the HttpService becomes available (unavailable). Secondly, an
125 <classname>org.osgi.service.log.LogService</classname> is used
126 for logging, if available. If such a service is not registered,
127 the Jolokia bundle uses the standard
128 <methodname>HttpServlet.log()</methodname> method for its
129 logging needs.
130 </para>
131 <para>
132 The Jolokia OSGi bundle can be configured via the OSGi Configuration Admin
133 service using the PID <literal>org.jolokia.osgi</literal>
134 (e.g. if using Apache Karaf, place properties in
135 <literal>etc/org.jolokia.osgi.cfg</literal>), or alternatively via global
136 properties which typically can be configured in a configuration file of
137 the OSGi container. All properties start with the prefix
138 <literal>org.jolokia</literal> and are listed in <xref
139 linkend="table-agents-osgi-properties"/>. They are mostly the
140 same as the <literal>init-param</literal> options for
141 a Jolokia servlet when used in a Java EE WAR artifact.
142 </para>
143 <table id="table-agents-osgi-properties">
144 <title>Jolokia Bundle Properties</title>
145 <thead>
146 <tr>
147 <td>Property</td>
148 <td>Default</td>
149 <td>Description</td>
150 </tr>
151 </thead>
152 <tr>
153 <td>org.jolokia.user</td>
154 <td></td>
155 <td>User used for authentication with HTTP Basic
156 Authentication. If not given, no authentication is used.</td>
157 </tr>
158 <tr>
159 <td>org.jolokia.password</td>
160 <td></td>
161 <td>Password used for authentication with HTTP Basic
162 Authentication.</td>
163 </tr>
164 <tr>
165 <td>org.jolokia.agentContext</td>
166 <td>/jolokia</td>
167 <td>Context path of the agent servlet</td>
168 </tr>
169 <tr>
170 <td>org.jolokia.agentId</td>
171 <td></td>
172 <td>
173 A unique ID for this agent. By default a unique id is
174 calculated. If provided it should be ensured that this id is
175 unique among all agent reachable via multicast requests used
176 by the discovery mechanism. It is recommended not to set
177 this value. Within the <literal>agentId</literal> specification you
178 can use the same placeholders as in <literal>discoveryAgentUrl</literal>.
179 </td>
180 </tr>
181 <tr>
182 <td>org.jolokia.agentDescription</td>
183 <td></td>
184 <td>
185 An optional description which can be used for clients to
186 present a humand readable label for this agent.
187 </td>
188 </tr>
189 <tr>
190 <td>org.jolokia.dispatcherClasses</td>
191 <td></td>
192 <td>
193 Class names (comma separated) of request dispatchers used in
194 addition to the LocalRequestDispatcher. E.g using a value
195 of
196 <classname>org.jolokia.jsr160.Jsr160RequestDispatcher</classname>
197 allows the agent to play the role of a JSR-160 proxy.
198 By default no extract dispatchers are enabled.
199 You can use the system property <literal>org.jolokia.jsr160ProxyEnabled</literal> or the
200 environment variable <literal>JOLOKIA_JSR160_PROXY_ENABLED</literal> to enable the the JSR-160 proxy.
201 In that case you should be sure that you enable authentication for the web application to protect access
202 to the proxy.
203 </td>
204 </tr>
205 <tr>
206 <td>org.jolokia.debug</td>
207 <td>false</td>
208 <td>
209 Debugging state after startup. This can be changed via the
210 Config MBean (<literal>jolokia:type=Config</literal>) at
211 runtime
212 </td>
213 </tr>
214 <tr>
215 <td>org.jolokia.debugMaxEntries</td>
216 <td>100</td>
217 <td>
218 Maximum number of entries to keep in the local debug history
219 if switched on. This can be changed via the config MBean at
220 runtime.
221 </td>
222 </tr>
223 <tr>
224 <td>org.jolokia.maxDepth</td>
225 <td>0</td>
226 <td>
227 Maximum depth when traversing bean properties.
228 If set to 0, depth checking is disabled
229 </td>
230 </tr>
231 <tr>
232 <td>org.jolokia.maxCollectionSize</td>
233 <td>0</td>
234 <td>
235 Maximum size of collections returned when
236 serializing to JSON. When set to 0,
237 collections are not truncated.
238 </td>
239 </tr>
240 <tr>
241 <td>org.jolokia.maxObjects</td>
242 <td>0</td>
243 <td>
244 Maximum number of objects which are traversed
245 when serializing a single response. Use this
246 as an airbag to avoid boosting your memory and
247 network traffic. Nevertheless, when set to 0
248 no limit is imposed.
249 </td>
250 </tr>
251 <tr>
252 <td>org.jolokia.historyMaxEntries</td>
253 <td>10</td>
254 <td>
255 Number of entries to keep in the history. This can be changed at
256 runtime via the Jolokia config MBean.
257 </td>
258 </tr>
259 <tr>
260 <td>org.jolokia.listenForHttpService</td>
261 <td>true</td>
262 <td>
263 If <literal>true</literal> the bundle listens for an OSGi
264 <literal>HttpService</literal> and if available registers an
265 agent servlet to it.
266 </td>
267 </tr>
268 <tr>
269 <td>org.jolokia.httpServiceFilter</td>
270 <td></td>
271 <td>
272 Can be any valid OSGi filter for locating a which
273 <classname>org.osgi.service.http.HttpService</classname>
274 is used to expose the Jolokia servlet. The syntax is that
275 used by the <classname>org.osgi.framework.Filter</classname>
276 which is in turn a <ulink url="http://www.ietf.org/rfc/rfc1960.txt">
277 RFC 1960 based filter</ulink>. The use of this property
278 is described in <xref linkend="running-on-glassfish"/>
279 </td>
280 </tr>
281 <tr>
282 <td>org.jolokia.useRestrictorService</td>
283 <td>false</td>
284 <td>
285 If <literal>true</literal> the Jolokia agent will use any
286 <classname>org.jolokia.restrictor.Restrictor</classname>
287 service for applying access restrictions. If this option is
288 <literal>false</literal> the standard method of looking up a
289 security policy file is used, as described in <xref
290 linkend="security-policy"/>.
291 </td>
292 </tr>
293 <tr>
294 <td>org.jolokia.canonicalNaming</td>
295 <td>true</td>
296 <td>
297 This option specifies in which order the key-value
298 properties within ObjectNames as returned by
299 <constant>list</constant> or <constant>search</constant> are
300 returned. By default this is the so called 'canonical order'
301 in which the keys are sorted alphabetically. If this option
302 is set to <constant>false</constant>, then the natural order
303 is used, i.e. the object name as it was registered. This
304 option can be overridden with a query parameter of the same
305 name.
306 </td>
307 </tr>
308 <tr>
309 <td>org.jolokia.includeStackTrace</td>
310 <td>true</td>
311 <td>
312 Whether to include a stacktrace of an exception in case of
313 an error. By default it it set to <constant>true</constant>
314 in which case the stacktrace is always included. If set to
315 <constant>false</constant>, no stacktrace is included. If
316 the value is <constant>runtime</constant> a stacktrace is
317 only included for RuntimeExceptions. This global option can
318 be overridden with a query parameter.
319 </td>
320 </tr>
321 <tr>
322 <td>org.jolokia.serializeException</td>
323 <td>false</td>
324 <td>
325 When this parameter is set to <constant>true</constant>,
326 then an exception thrown will be serialized as JSON and
327 included in the response under the key
328 <constant>error_value</constant>. No stactrace infornmation
329 will be included, though. This global option can be
330 overridden by a query parameter of the same name.
331 </td>
332 </tr>
333 <tr>
334 <td>org.jolokia.detectorOptions</td>
335 <td></td>
336 <td>
337 An optional JSON representation for application specific
338 options used by detectors for post-initialization steps. See the description of
339 <literal>detectorOptions</literal> in
340 <xref linkend="agent-war-init-params"/> for details.
341 </td>
342 </tr>
343 <tr>
344 <td>org.jolokia.discoveryEnabled</td>
345 <td>false</td>
346 <td>
347 Is set to <literal>true</literal> then this servlet will
348 listen for multicast request (multicast-group 239.192.48.84,
349 port 24884 by default, but can be configued).
350 By default this option is disabled in order to
351 avoid conflicts with an Java EE standards (though this should't
352 harm anyways). This option can also be switched on with an
353 environment variable
354 <literal>JOLOKIA_DISCOVERY</literal> or the system
355 property <literal>jolokia.discoveryEnabled</literal> set to
356 <literal>true</literal>.
357 </td>
358 </tr>
359 <tr>
360 <td>org.jolokia.discoveryAgentUrl</td>
361 <td></td>
362 <td>
363 Sets the URL to respond for multicast discovery requests. If
364 given, <constant>discoveryEnabled</constant> is set
365 implicetly to true. This URL can also be provided by an
366 environment variable
367 <literal>JOLOKIA_DISCOVERY_AGENT_URL</literal> or the system
368 property <literal>jolokia.discoveryUrl</literal>. Within the value you can use the
369 placeholders <literal>${host}</literal> and <literal>${ip}</literal> which gets replaced
370 by the autodetected local host name/address. Also with <literal>${env:ENV_VAR}</literal> and
371 <literal>${sys:property}</literal> environment and system properties can be referenced, respectively.
372 </td>
373 </tr>
374 <tr>
375 <td><constant>org.jolokia.multicastGroup</constant></td>
376 <td><constant>239.192.48.84</constant></td>
377 <td>The multicast group IPv4 address. This group IP can be also given as an environment variable <literal>JOLOKIA_MULTICAST_GROUP</literal> or a system property <literal>jolokia.multicastGroup</literal></td>
378 </tr>
379 <tr>
380 <td><constant>org.jolokia.multicastPort</constant></td>
381 <td><constant>24884</constant></td>
382 <td>The multicast port. This port can be also given as an environment variable <literal>JOLOKIA_MULTICAST_PORT</literal> or a system property <literal>jolokia.multicastPort</literal></td>
383 </tr>
384 <tr>
385 <td>org.jolokia.realm</td>
386 <td>jolokia</td>
387 <td>
388 Sets the security realm to use. If the <constant>authMode</constant> is set to
389 <literal>jaas</literal> this is also used as value for the security domain.
390 E.g. for Karaf 3 and later, this realm should be <literal>karaf</literal> since
391 all JMX MBeans are guarded by this security domain.
392 </td>
393 </tr>
394 <tr>
395 <td>org.jolokia.authMode</td>
396 <td>basic</td>
397 <td>
398 Can be either <literal>basic</literal> (the default), <literal>jaas</literal>,
399 <literal>service-all</literal> or <literal>service-any</literal>. If
400 <literal>jaas</literal> is used, the user and password which are given in the <literal>Authorization:</literal>
401 header are used for login in via JAAS and, if successful, the return subject is used for all Jolokia operation.
402 When no user is set and the <literal>authMode</literal> is either <literal>service-all</literal> or
403 <literal>service-any</literal> then a <literal>org.jolokia.osgi.security.Authenticator</literal> service is looked up in the
404 OSGi service registry. If more then one of such service is registered, <literal>service-all</literal> requires
405 that all authenticators succeed, for <literal>service-any</literal> it is sufficient that one authenticator
406 successfully authenticates. In any case if no such Authenticator service can be found, the request is rejected.
407 </td>
408 </tr>
409 </table>
410 <para>
411 This bundle also exports the service
412 <classname>org.jolokia.osgi.servlet.JolokiaContext</classname>
413 which can be used to obtain context information of the
414 registered agent like the context path under which this
415 servlet can be reached. Additionally, it exports
416 <classname>org.osgi.service.http.HttpContext</classname>, which
417 is used for authentication. Note that this service is only
418 available when the agent servlet is active (i.e. when an
419 HttpService is registered).
420 </para>
421 </section>
422 <section id="running-on-glassfish">
423 <title>Running on Glassfish v3 upwards</title>
424 <para>
425 You have a couple of choices when running jolokia on
426 Glassfish v3 and up, since Glassfish is a both a fully
427 fledged Java EE container and an OSGi container. If you
428 choose to run the <xref linkend="agents-war"/> then it
429 is completely straight forward just deploy the war
430 in the normal way. If you choose to deploy
431 the <xref linkend="agents-osgi"/> then you will need
432 to configure the <literal>org.jolokia.httpServiceFilter</literal>
433 option with a filter to select either the Admin
434 <classname>HttpService</classname> (4848 by default) or the Default
435 <classname>HttpService</classname> which is where WAR files are
436 deployed to.
437
438 </para>
439 <para>
440 In Glassfish 3.1.2 the OSGi bundle configuration is done in
441 <constant>glassfish/conf/osgi.properties</constant> in version's
442 prior to this the configuration is by default in
443 <constant>glassfish/osgi/felix/conf/config.properties</constant>
444 or if you are using Equinox
445 <constant>glassfish/osgi/equinox/configuration/config.ini</constant>
446 </para>
447 <informalexample>
448 <programlisting><![CDATA[
449 # Restrict the jolokia http service selection to the admin host
450 org.jolokia.httpServiceFilter=(VirtualServer=__asadmin)
451 # Or alternatively to the normal http service use : (VirtualServer=server)
452 ]]></programlisting>
453 </informalexample>
454 <para>
455 Deploying the bundle can be either be done by coping the
456 <literal>jolokia-osgi.jar</literal> into the domain
457 <constant>glassfish/domains/&lt;domain&gt;/autodeploy/bundles</constant>
458 directory or it can be added to all instances by copying the jar
459 to <constant>glassfish/modules/autostart</constant>
460 </para>
461 <para>
462 By default the agent will be available on <constant>http://localhost:&lt;port&gt;/osgi/jolokia</constant>
463 rather than <constant>http://localhost:&lt;port&gt;/jolokia</constant> as with WAR deployment.
464 </para>
465 </section>
466 <section id="agents-osgi-bundle">
467 <title>jolokia-osgi-bundle.jar</title>
468 <para>
469 The all-in-one bundle includes an implementation of
470 <classname>org.osgi.service.http.HttpService</classname>,
471 i.e. the <ulink
472 url="http://felix.apache.org/site/apache-felix-http-service.html">Felix
473 implementation</ulink>. The HttpService will be registered as
474 OSGi service during startup, so it is available for other
475 bundles as well. The only package import requirement for this
476 bundle is <classname>org.osgi.service.LogService</classname>,
477 since the Felix Webservice requires this during startup. As
478 mentioned above, normally the LogService interface gets exported
479 by default in the standard containers, but if not, you need to
480 install it e.g. from the OSGi <ulink
481 url="http://repo1.maven.org/maven2/org/osgi/org.osgi.compendium/4.2.0/org.osgi.compendium-4.2.0.jar">compendium
482 </ulink> definitions.
483 </para>
484 <para>
485 This bundle can be configured the same way as the pure bundle as
486 described in <xref linkend="agents-osgi-pure"/>. Additionally,
487 the embedded Felix HttpService can be configured as described in
488 its <ulink
489 url="http://felix.apache.org/site/apache-felix-http-service.html#ApacheFelixHTTPService-ConfigurationProperties">documentation</ulink>.
490 e.g. setting the port to 9090 instead of the default port 8080, a property
491 <literal>org.osgi.service.http.port=9090</literal> needs to be
492 set. This might be useful, if this bundle is used within
493 containers which already occupy the default port (Glassfish,
494 Eclipse Virgo) but don't expose an OSGi HttpService.
495 </para>
496 </section>
497 <section id="agents-osgi-servlet">
498 <title>Programmatic servlet registration</title>
499 <para>
500 It is also possible to register the Jolokia agent servlet
501 manually instead of relying of the OSGi bundle activator which
502 comes with the agents. For this use case
503 <filename>jolokia-osgi.jar</filename> should be used. This
504 bundle exports the package
505 <classname>org.jolokia.osgi.servlet</classname> which includes
506 the servlet class <classname>JolokiaServlet</classname>. This
507 class has three constructors: A default constructor without
508 arguments, one with a single
509 <classname>BundleContext</classname> argument and finally one
510 with an additional <classname>Restrictor</classname> (see <xref
511 linkend="security-restrictor"/> for details how access
512 restrictions can be applied). The constructor with a
513 <classname>BundleContext</classname> as its argument has the
514 advantage that it will use an OSGi
515 <classname>LogService</classname> if available and adds various
516 OSGi server detectors which adds server information like product
517 name and version to the <literal>version</literal>
518 command. Refer to <xref linkend="version"/> for details about the
519 server infos provided.
520 </para>
521 <para>
522 Please note that for this use case the bundle
523 <classname>org.jolokia.osgi</classname> should not be
524 <emphasis>started</emphasis> but left in the state
525 <emphasis>resolved</emphasis>. Otherwise, as soon as an OSGi
526 HttpService registers, this bundle will try to add yet another
527 agent servlet to this service, which is probably not what you
528 want. Alternatively, the bundle property
529 <literal>org.jolokia.listenForHttpService</literal> can be set
530 to <literal>false</literal> in which case there will be never an
531 automatic servlet registration to an HttpService.
532 </para>
533 </section>
534 <section>
535 <title>Restrictor service</title>
536 <para>
537 As described in <xref linkend="security-restrictor"/>, the
538 Jolokia agent can use custom restrictors implementing the
539 interface
540 <classname>org.jolokia.restrictor.Restrictor</classname>. If the
541 bundle property
542 <literal>org.jolokia.useRestrictorService</literal> is set to
543 true and no restrictor is configured by other means, the agent
544 will use one or more OSGi service which register under the name
545 <classname>org.jolokia.restrictor.Restrictor</classname>. If no
546 such service is available, access to the agent is always
547 denied. If one such restrictor service is available, the access
548 decision is delegated to this service. When more than one
549 restrictor service is available, access is ony granted if all of
550 them individually grant access. A sample restrictor service as a
551 maven project can be found in the Jolokia source at
552 <filename>agent/osgi/restrictor-sample</filename>.
553 </para>
554 </section>
555 </section>