The Maven Cookbook

1.10. Proxying OSGi Bundle Repositories

1.10. Proxying OSGi Bundle Repositories

If you've followed the recipes in this chapter sequentially, you deployed an artifact to a Maven repository and you've seen two ways to get that repository to an OSGi container: via a standard Maven repository and via a virtual OBR repository that acts as a transformer between Maven and OSGi. This chapter has focused on hosted repositories so far, but one of the most common reasons for people to use repository managers is to proxy remote repositories. In this recipe, you will learn how to proxy a remote OSGi bundle repository using Nexus Professional's support for OBR.

1.10.1. Task

You would like to maintain a local cache of a remote OSGi Bundle repository that is populated with artifacts as they are requested. You need to do this for a few reasons, but mostly because you realized how inefficient it is for everyone in your organization to continuously query a remote server and download artifacts over the public internet. You are looking for more stability and control over what people are using from a remote OSGi bundle repository.

1.10.2. Action

Use Nexus Professional to create a proxy repository for a remote OSGi bundle repository. To do this:

  1. Load the Nexus interface in a web browser by opening the URL http://localhost:8081/nexus.

  2. Login as an administrative user using the default credentials of admin/admin123 (if you haven't already changed the default password).

  3. Click on Repositories in the left navigation menu.

  4. Click on the Add.. button above the list of Nexus repositories and groups.

  5. Select "Proxy Repository" from the resulting dropdown.

  6. In the New Virtual Repository window, supply the following values as shown in Figure 1.8, “Creating a New Proxy Repository”:

    1. Repository ID: felix-obr

    2. Repository Name: Felix OBR

    3. Provider: OBR

    4. Remote Storage Location: http://felix.apache.org/obr/releases.xml

  7. Click the Save button to create the new Proxy repository.

Creating a New Proxy Repository

Figure 1.8. Creating a New Proxy Repository


1.10.3. Detail

To verify that our new Proxy OBR repository is generating the the appropriate XML based on the remote OBR repository, click on Repositories in the left navigation menu, and then select "Felix OBR" from the list of repositories. If you look at the Browse tab for this repository and drill into the .meta/ directory, you can then right-click on the obr.xml file and select Download from the context menu. The URL for this new repository XML should be http://localhost:8081/nexus/content/repositories/felix-obr/.meta/obr.xml. Be warned, this is going to be a very large XML file, and you might not be able to make sense of the document by reading the source directly. Instead of dealing with this unwieldy XML file, use Apache Felix to browse the contents.

If you want to see the contents of this new proxy repository for the Felix OBR repository, install Felix and add a reference to the Nexus proxy repository:

  1. Download Apache Felix from http://www.apache.org/dist/felix/felix-1.8.0.tar.gz.

  2. Unpack the Felix distribution on your local workstation.

  3. Change directory to the Felix directory.

  4. Start Apache Felix with java -jar ./bin/felix.jar

  5. Add the Snapshots repository as an OBR repository by copying the URL to the repository.xml and passing it to the obr command: obr add-url http://localhost:8081/nexus/content/repositories/felix-obr/.meta/obr.xml

  6. List the contents of the OBR repository.

  7. Deploy the Servlet 2.1 bundle.

  8. Deploy the Apache Felix Web Management Console bundle.

  9. Start the installed bundles.

These commands are captured in the following screen listing:

~/programs $ wget http://www.apache.org/dist/felix/felix-1.8.0.tar.gz
--2009-07-14 22:46:19--  http://www.apache.org/dist/felix/felix-1.8.0.tar.gz
Resolving www.apache.org... 140.211.11.130
Connecting to www.apache.org|140.211.11.130|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 901620 (880K) [application/x-gzip]
Saving to: `felix-1.8.0.tar.gz'
2009-07-14 22:46:20 (924 KB/s) - `felix-1.8.0.tar.gz' saved [901620/901620]

~/programs $ tar xvzf felix-1.8.0.tar.gz 
felix-1.8.0/
felix-1.8.0/bin/
felix-1.8.0/bin/felix.jar
...
felix-1.8.0/NOTICE
~/programs $ cd felix-1.8.0
~/programs/felix-1.8.0 $ java -jar ./bin/felix.jar 

Welcome to Felix.
=================

-> obr add-url http://localhost:8081/nexus/content/repositories/felix-obr/.meta/obr.xml
-> obr list
Apache Felix Bundle Repository (1.2.1, ...)
Apache Felix Configuration Admin Service (1.0.4, ...)
Apache Felix Declarative Services (1.0.8, ...)
Apache Felix EventAdmin (1.0.0)
Apache Felix File Install (1.2.0, ...)
Apache Felix HTTP Service Jetty (1.0.1, ...)
Apache Felix iPOJO (1.2.0, ...)
Apache Felix iPOJO (0.8.0)
Apache Felix iPOJO Arch Command (1.2.0, ...)
Apache Felix iPOJO Composite (1.2.0)
Apache Felix iPOJO Composite (1.0.0, ...)
Apache Felix iPOJO Event Admin Handler (1.2.0, ...)
Apache Felix iPOJO Extender Pattern Handler (1.2.0)
Apache Felix iPOJO Extender Pattern Handler (1.0.0, ...)
Apache Felix iPOJO JMX Handler (1.2.0, ...)
Apache Felix iPOJO Temporal Service Dependency Handler (1.2.0, ...)
Apache Felix iPOJO White Board Pattern Handler (1.2.0, ...)
Apache Felix Log Service (1.0.0)
Apache Felix Metatype Service (1.0.2, ...)
Apache Felix Prefrences Service (1.0.2)
Apache Felix Remote Shell (1.0.2)
Apache Felix Shell Service (1.0.2, ...)
Apache Felix Shell TUI (1.0.2, ...)
Apache Felix UPnP Base Driver (0.8.0)
Apache Felix UPnP Extra (0.4.0)
Apache Felix UPnP Tester (0.4.0)
Apache Felix Web Management Console (1.2.10, ...)
OSGi OBR Service API (1.0.0)
OSGi R4 Compendium Bundle (4.0.0)
Servlet 2.1 API (1.0.0)
-> obr deploy "Servlet 2.1 API"
Target resource(s):
-------------------
   Servlet 2.1 API (1.0.0)

Deploying...done.
-> obr deploy "Apache Felix Web Management Console"
Target resource(s):
-------------------
   Apache Felix Web Management Console (1.2.10)

Required resource(s):
---------------------
   Apache Felix Log Service (1.0.0)
   Apache Felix Declarative Services (1.0.8)
   Apache Felix HTTP Service Jetty (1.0.1)
   OSGi R4 Compendium Bundle (4.0.0)

Deploying...done.
-> ps
START LEVEL 1
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (1.8.0)
[   1] [Active     ] [    1] Apache Felix Shell Service (1.2.0)
[   2] [Active     ] [    1] Apache Felix Shell TUI (1.2.0)
[   3] [Active     ] [    1] Apache Felix Bundle Repository (1.4.0)
[   4] [Installed  ] [    1] Servlet 2.1 API (1.0.0)
[   5] [Installed  ] [    1] Apache Felix Log Service (1.0.0)
[   6] [Installed  ] [    1] Apache Felix Declarative Services (1.0.8)
[   7] [Installed  ] [    1] HTTP Service (1.0.1)
[   8] [Installed  ] [    1] Apache Felix Web Management Console (1.2.10)
[   9] [Installed  ] [    1] OSGi R4 Compendium Bundle (4)
-> start 4 5 6 7 8 9
-> ps
START LEVEL 1
   ID   State         Level  Name
[   0] [Active     ] [    0] System Bundle (1.8.0)
[   1] [Active     ] [    1] Apache Felix Shell Service (1.2.0)
[   2] [Active     ] [    1] Apache Felix Shell TUI (1.2.0)
[   3] [Active     ] [    1] Apache Felix Bundle Repository (1.4.0)
[   4] [Active     ] [    1] Servlet 2.1 API (1.0.0)
[   5] [Active     ] [    1] Apache Felix Log Service (1.0.0)
[   6] [Active     ] [    1] Apache Felix Declarative Services (1.0.8)
[   7] [Active     ] [    1] HTTP Service (1.0.1)
[   8] [Active     ] [    1] Apache Felix Web Management Console (1.2.10)
[   9] [Active     ] [    1] OSGi R4 Compendium Bundle (4)
-> 

Now, if you load http://localhost:8080/system/console in a web browser and supply the default Felix administrative credentials (username "admin" and password "admin"), you will see the Apache Felix administrative web interface. Now that you've made use of the Nexus Proxy repository for the remote Felix OBR repository, the next time you browse the contents of the Felix OBR proxy repository, you are going to see that Nexus has cached all of the referenced bundles as shown in Figure 1.9, “Cached Bundles from a Remote OBR Repository”.

Cached Bundles from a Remote OBR Repository

Figure 1.9. Cached Bundles from a Remote OBR Repository