Wicket Applications (Quick)
PAX-WICKET is very similar to Wicket. Also in it's class structure. To get your first Wicket application up and running you require a bundle containing a Wicket WebApplication and the Wicket Page. That PAX-WICKET knows you want to register that Application all you have to do is to export an OSGi service with org.ops4j.pax.wicket.api.WebApplicationFactory interface and the following two OSGi properties:
- pax.wicket.mountpoint
- pax.wicket.applicationname
The mount point is where you'll find your application mounted. For example "mount/here" will mount your application e.g. at "localhost:8080/mount/here". The application name is required in PAX-WICKET for extended features (like mounting, injection, ...). Since it is not relevant for the samples now any name could be chosen (e.g. myApplication).
BEFORE PAX-WICKET 3.0: PAX-WICKET requires that you add the following imports to your bundle (in addition to the packages which are auto-added e.g. by the maven-bundle-plugin):
org.apache.wicket.core.request.mapper, org.ops4j.pax.wicket.util.proxy, net.sf.cglib.proxy;version="[2,3)", net.sf.cglib.core;version="[2,3)", net.sf.cglib.reflect;version="[2,3)", javax.servlet;version="2.5.0", javax.servlet.http;version="2.5.0"
We're working to come up with something better here. Still most solutions will require us to completely bend the classloader beyond your bundle and we're not sure if we really want to do this...
Plain OSGi
If you like your services to be exported in plain OSGi and are paranoid of any PAX-WICKET imports into your bundle you can go ahead. If you like to let PAX-WICKET handle most of the stuff a sample is available showing you how. But basically it's not more than the following in your activator:
private DefaultWebApplicationFactory applicationFactory;
public void start(BundleContext context) throws Exception {
applicationFactory = new DefaultWebApplicationFactory(
context, WicketApplication.class, "plain.simple", "plain/simple");
applicationFactory.register();
}
Blueprint
If you prefer to get things done via Blueprint you're also free to do so. A full sample is available showing you the details. In short you have two options: either exporting the service yourself...
Any of the following blueprint samples need to be placed in any *.xml file in OSGI-INF/blueprint/ in the bundle you would like to do the action.
<service interface="org.ops4j.pax.wicket.api.WebApplicationFactory" >
<service-properties>
<entry key="pax.wicket.applicationname" value="blueprint.simple.default" />
<entry key="pax.wicket.mountpoint" value="blueprint/simple/default" />
</service-properties>
<bean class="org.ops4j.pax.wicket.util.SimpleWebApplicationFactory" >
<property name="wicketApplication"
value="org.ops4j.pax.wicket.samples.blueprint.simple.internal.WicketApplication" />
</bean>
</service>
Before version 2.0.0 use interface="org.apache.wicket.protocol.http.IWebApplicationFactory"
...or let PAX-WICKET do the entire work...
<blueprint ... xmlns:wicket="http://www.ops4j.org/schema/wicket" ...> <wicket:application id="applicationId" class="org.ops4j.pax.wicket.samples.blueprint.simple.internal.WicketApplication" applicationName="blueprint.simple.paxwicket" mountPoint="blueprint/simple/paxwicket" />
Spring DM
If your application is based on Spring (DM) you have the same options as for blueprint. Either you export the service yourself...
Any of the following spring samples need to be placed in any *.xml file in META-INF/spring/ in the bundle you would like to do the action.
<osgi:service interface="org.ops4j.pax.wicket.api.WebApplicationFactory">
<osgi:service-properties>
<entry key="pax.wicket.applicationname" value="springdm.simple.default" />
<entry key="pax.wicket.mountpoint" value="springdm/simple/default" />
</osgi:service-properties>
<bean class="org.ops4j.pax.wicket.util.SimpleWebApplicationFactory">
<property name="wicketApplication"
value="org.ops4j.pax.wicket.samples.springdm.simple.internal.WicketApplication" />
</bean>
</osgi:service>
Before version 2.0.0 use interface="org.apache.wicket.protocol.http.IWebApplicationFactory"
...or you let PAX-WICKET do the work...
<beans ... xmlns:wicket="http://www.ops4j.org/schema/wicket" ... xsi:schemaLocation="... http://www.ops4j.org/schema/wicket http://www.ops4j.org/schema/wicket/wicket.xsd ..."> <wicket:application id="applicationId" class="org.ops4j.pax.wicket.samples.springdm.simple.internal.WicketApplication" applicationName="springdm.simple.paxwicket" mountPoint="springdm/simple/paxwicket" />
For the details a full example is available again.
Declarative Services
Example for registering a ApplicationFactory with Declarative Services (using 'wicket' as the mount point and 'testapplication' as application name):
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="de.laeubisoft.wicket.test.applicationfactory">
<implementation class="de.laeubisoft.wicket.test.PAXWebApplicationFactory"/>
<property name="pax.wicket.applicationname" type="String" value="testapplication"/>
<property name="pax.wicket.mountpoint" type="String" value="wicket"/>
<service>
<provide interface="org.apache.wicket.protocol.http.IWebApplicationFactory"/>
</service>
</scr:component>
Before version 2.0.0 use interface="org.apache.wicket.protocol.http.IWebApplicationFactory"
Registering a FilterFactory with Declarative Services for the application above:
<?xml version="1.0" encoding="UTF-8 "?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="de.laeubisoft.wicket.test.filter">
<implementation class="de.laeubisoft.wicket.test.PAXFilterFactory"/>
<property name="pax.wicket.applicationname" type="String" value="testapplication"/>
<service>
<provide interface="org.ops4j.pax.wicket.api.FilterFactory"/>
</service>
</scr:component>
What's next
Now that you're application is up and running you can inject spring or blueprint beans, as explained on the next page.. If you're not interested in injection you may like to head directly to the extended quickstart guide showing some of the more advanced PAX-WICKET topics.