Pax Web Extender - War - Examples

Pax Web Extender - War includes a set of examples that demonstrates its usage. While running the examples bellow under Felix, version <= 1.0.1 you may get will logging enabled quite a lot of error messages. You can ignore them as Felix logs a FrameworkEvent.ERROR every time it cannot find a class, fact that clashes with Spring way of searching for BeanInfo classes. This issue is resolved in the upcoming version on Felix.

Wicket Examples

Wicket provides an example war file that includes various examples related to Wicket
To deploy the wicket examples war (that is available in maven central repo) you just have to deploy to your preferred OSGi framework the following bundles:

Alternatively you can easy do the deployment using Pax Runner:

pax-run scan-file:jar:mvn:org.ops4j.pax.web-extender.samples/provision!/wicket-examples-1.3.0-wrap.bundles

The wicket-examples-1.3.0-wrap.bundles file above is a simple text file that lists all the bundles to be installed.

Once you have everything running point your browser to http://localhost:8080/wicket.examples/index.html. Notice that re-packaging of Wicket Examples War may take a while as the war file has about 9Mb (depending on your connection speed - file is downloaded from maven central repository). Anyhow, this is done just first time you run the example and it helps if you already have the war file in your local maven repository.

You can start it up even simpler by using the new war: protocol handler (you need Pax Runner version >= 0.6.0):

pax-run war:mvn:org.apache.wicket/wicket-examples/1.3.0/war --profiles=war

As you will see the war: protocol handler will do all that is necessary to directly deploy a war file. Note that in this case the context name will be generated automatically, so you should use http://localhost:8080/mvn_org.apache.wicket_wicket-examples_1.3.0_war/index.html to access the application (upcoming version 0.2.0 of war protocol will permit context name setup).

Spring PetClinic

Spring provides an example application named PetClinic. The Petclinic sample application is designed to show how the Spring application frameworks can be used to build simple, but powerful database-oriented enterprise applications.
To deploy the PetClinic war you will have first to build it by yourself (Spring PetClinic is not available in a maven repository and anyhow it needs some small changes; it is, however, available via subversion):

  • Follow the build instructions provided by Spring
  • Before building the war file you have to change petclinic-servlet.xml as follows. You have to do this change not because of Pax Web but because the <context:component-scan .../> does not work in an OSGi environment (Spring DM guys are working on that).
    • Edit petclinic-servlet.xml
    • Replace line
      <context:component-scan base-package="org.springframework.samples.petclinic.web">
      
      with
      <context:annotation-config/>
      <bean class="org.springframework.samples.petclinic.web.ClinicController"/>
      <bean class="org.springframework.samples.petclinic.web.AddOwnerForm"/>
      <bean class="org.springframework.samples.petclinic.web.AddPetForm"/>
      <bean class="org.springframework.samples.petclinic.web.AddVisitForm"/>
      <bean class="org.springframework.samples.petclinic.web.EditOwnerForm"/>
      <bean class="org.springframework.samples.petclinic.web.EditPetForm"/>
      <bean class="org.springframework.samples.petclinic.web.FindOwnersForm"/>
      
    • Save the file and build Spring PetClinic according to instructions
  • Start the PetClinic database (not required but otherwise you cannot use the whole application)

Then deploy to your preferred OSGi framework the following bundles:

Alternatively you can easy do the deployment using Pax Runner (you must start Pax Runner from PetClinic's dist directory so it can find the war file):

pax-run scan-file:jar:mvn:org.ops4j.pax.web-extender.samples/provision!/spring-petclinic-2.5-wrap.bundles

The spring-petclinic-2.5-wrap.bundles file above is a simple text file that lists all the bundles to be installed.

Once you have everything running point your browser to http://localhost:8080/petclinic/index.jsp. Notice that re-packaging of Spring PetClinic war file may take a while as the war file has about 15Mb. Anyhow, this is done just first time you run the example.

Note also then when running under Felix version before 1.0.3 you will see quite a lot of stack traces displayed on the screen (if you have logging enabled). Just ignore them as they are only log messages from Felix shown when a class cannot be found and Spring tries to load classes related to bean support, classes that do not exist. This (error messages) are all gone if you use Felix >= 1.0.3.

You can start it up even simpler by using the new war: protocol handler (you need Pax Runner version >= 0.6.0):

pax-run war:file:petclinic.war --profiles=war mvn:org.ops4j.pax.web/pax-web-jsp

As you will see the war: protocol handler will do all that is necessary to directly deploy a war file. Spring PetClinic makes use of JSP so the command line provision also Pax Web JSP Support. Note that in this case the context name will be generated automatically, so you should use http://localhost:8080/file_petclinic.war/ to access the application (upcoming version 0.2.0 of war protocol will permit context name setup).

(warning) Notes

Using the above mentioned methods involves that Spring Petclinic WAR file is processed first by war: url protocol handler in order to make it a bundle. As the WAR file is particularly large it requires "extensive" resources to process in terms of memory, so you may encounter java.lang.StackOverflowError or java.lang.OutOfMemoryError depending on your execution platform (Windows/*nix) as they differ in "defaults". To avoid this problems you will have to set some extra start up parameters for JVM, such as:

  • java.lang.StackOverflowError: {-Xss}}, as for example -Xss=512k
  • java.lang.OutOfMemoryError: -Xmx, as for example -Xmx256m

It may be that the example values are too much or too less for your case so feel free to experiment.
In order to set this options you have to do the following (example uses both settings but you may only need one of them):

  • Windows:
    set JAVA_OPTS=-Xss512k -Xmx256m
    pax-run ...
    
  • *nix
    export JAVA_OPTS=-Xss512k -Xmx256m
    pax-run ...