Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Virgo and Eclipse RAP: An Update

DZone's Guide to

Virgo and Eclipse RAP: An Update

Let's take a look at the latest updates to the Virgo app server and a guide on how to get Eclipse RAP working within it.

· Java Zone
Free Resource

Learn how to troubleshoot and diagnose some of the most common performance issues in Java today. Brought to you in partnership with AppDynamics.

Virgo has moved on since my since my first and second posts on my experiences with Virgo and getting Eclipse RAP to work in the application server. With the 3.7.x release of Virgo well on the way (3.7.2 has been released by now), it was time to see if I could make my server configuration a bit neater, as the former 3.6.4 release was a bit bloated and required a lot of manual tweaking. As it turned out, I managed to get everything working within an hour, so I thought I'd share these happy tidings!

My server configuration currently consists of:

The former Jetty server implementation was not well suited for Eclipse RAP, and it used to require a bit of tweaking, But luckily, in this setup, it only requires a slight modification. Another definite bonus is that the management console works without problems, which was not the case in the previous configuration. For the most part, the changes are similar to my previous post:

  • Virgo 3.7.0 supports Java 7. It is no longer needed to change the java6-server.profile 
  • Activate the javax.crypto package by adding the following to the java6-server.profile file:
org.osgi.framework.system.packages = \
 ...
 javax.crypto,\
 javax.crypto.interfaces,\
 javax.crypto.spec,\
 ...
org.osgi.framework.bootdelegation = \
 org.eclipse.virgo.nano.authentication,\
 com.sun.*,\
 javax.xml.*,\
 javax.crypto.*,\
 org.apache.xerces.jaxp.*,\
 org.w3c.*,\
 org.xml.*,\
 sun.*


  • The org.osgi.framework.system.packages basically provides packages from the JRE for use in the user region, while the org.osgi.framework.bootdelegation releases packages for Equinox' boot loader. The system packages are already prepared in the Virgo Jetty release, but the the crypto packages still needed to be added to the boot delegation. Any bundle that uses javax.crypto must import the javax.crypto packages in the MANIFEST.MF, even if they are not referenced! If not, you will get a runtime error when the application needs the packages.
  • Update RAP to version 3.1.0 (or 3.2.0 for that matter). This is done by creating a subdirectory under the 'repository' directory with a suitable name (e.g. 'rap') and adding the three essential rap bundles to this folder, together with the corresponding plan:
<?xml version="1.0" encoding="UTF-8"?>
<plan name="org.eclipse.rap" version="3.0.0" scoped="false" atomic="true"
        xmlns="http://www.eclipse.org/virgo/schema/plan"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="
                http://www.eclipse.org/virgo/schema/plan
                http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd">
    <artifact type="bundle" name="org.eclipse.rap.rwt" version="[3.0.0, 4.0.0)" />
    <artifact type="bundle" name="org.eclipse.rap.rwt.osgi" version="[3.0.0, 4.0.0)" />
    <artifact type="bundle" name="org.eclipse.rap.jface" version="[3.0.0, 4.0.0)" />
</plan>


  • Add the RAP repository to the org.eclipse.virgo.repository file in Virgo's configuration folder:
ext.type=external
ext.searchPattern=repository/ext/{artifact}

usr.type=watched
usr.watchDirectory=repository/usr

#RAP extension
rap.type=external
rap.searchPattern=repository/rap/{artifact}

chain=ext,rap, usr


  • Add the plan to the userregion properties file, also in the configuration folder:
initialArtifacts = repository:plan/org.eclipse.virgo.kernel.userregion.blueprint,\
 repository:plan/org.eclipse.virgo.web.jetty,\
 repository:plan/org.eclipse.rap,\
 repository:plan/org.eclipse.virgo.management


With these modifications, the Virgo application server is almost ready! If you would start the server you will get access to the admin console, but now we need to activate the RAP bundles. For this we need to modify the org.eclipse.virgo.web.jetty plan that is located in the 'ext' repository:

<?xml version="1.0" encoding="UTF-8"?>
<plan name="org.eclipse.jetty" version="8.1.3" scoped="false" atomic="true"
        xmlns="http://www.eclipse.org/virgo/schema/plan"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
        http://www.eclipse.org/virgo/schema/plan
        http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd">

<artifact type="bundle" name="org.eclipse.equinox.http.servlet" version="[1.1.0, 2.0.0)" />
<artifact type="bundle" name="org.eclipse.equinox.http.jetty" version="[3.0.0, 4.0.0)" />

<artifact type="bundle" name="javax.servlet" version="[3, 4)" />
<artifact type="bundle" name="org.eclipse.jetty.util" version="[8.1.3, 10.0.0)" />
<artifact type="bundle" name="org.eclipse.jetty.io" version="[8.1.3, 10.0.0)" />
<artifact type="bundle" name="org.eclipse.jetty.http" version="[8.1.3, 10.0.0)" />
<artifact type="bundle" name="org.eclipse.jetty.servlet" version="[8.1.3, 10.0.0)" />
</plan>


With this, we add the OSGI HTTP service to Jetty and support for servlet containers. This is the most essential change in order to get RAP up and running. As you can see, this plan has a different name than the original file, so we need to change that in the userregion configuration file.

Note: Jetty starts your application on a default port defined in the config file:org.osgi.service.http.port=8080. Basically, two bundles are added to the default plan in order to link the RAP bundles to Jetty.

Last you want to add your cool apps to the Virgo application server. This simply means repeating the last steps we just performed:

  • Add a repository with an appropriate name to the 'repostory' folder, e.g. myapp1
  • Add the bundles you built and create a Virgo plan for them (for an example, see the RAP plan)

  • Include the repository in the org.eclipse.virgo.repository configuration file:
ext.type=external
ext.searchPattern=repository/ext/{artifact}

usr.type=watched
usr.watchDirectory=repository/usr

#RAP extension
rap.type=external
rap.searchPattern=repository/rap/{artifact}

#My Application
myapp1.type=external
myapp1.searchPattern=repository/myapp1/{artifact}

chain=ext,rap,myapp1,usr


  • Include the plan to Virgo's org.eclipse.virgo.kernel.userregion configuration file. Note that the name of the modified jetty plan is changed as well:
initialArtifacts = repository:plan/org.eclipse.virgo.kernel.userregion.blueprint,\
 repository:plan/org.eclipse.jetty,\
 repository:plan/org.eclipse.rap,\
 repository:plan/org.eclipse.myapp1,\
 repository:plan/org.eclipse.virgo.management


Restart the server, check the log messages and, if none are reported, your app should be available on the server!

Understand the needs and benefits around implementing the right monitoring solution for a growing containerized market. Brought to you in partnership with AppDynamics.

Topics:
eclipse rap ,virgo ,java ,app server ,tutorial

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}