Classpath Settings
Mule Standalone
To set up the Mule classpath to run Abdera services, you must first download the Mule Abdera transport distribution. Then simply take all the JARs inside the distribution and put them in MULE_HOME/lib/user.
Maven
If you are using Maven, you can use the MuleForge repositories and add a dependency to Jersey that way. First add the MuleForge repository to your POM:
<repositories>
<repository>
<id>muleforge</id>
<name>MuleForge Repository</name>
<url>http://repository.muleforge.org</url>
</repository>
</repositories>
Then add the dependency:
<dependencies>
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-abdera</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Consuming Feeds and other Atom resources
One of the most common patterns is for integrating with Atom is polling for feed updates. With Mule this can be done quite easily. You must first write your class which receives an Atom Entry:
package org.mule.providers.abdera.example;
import org.apache.abdera.model.Feed;
public class EntryReceiver {
public Object onCall(MuleEventContext ctx) throws Exception {
Feed feed = (Feed) ctx.getMessage().getPayload(Feed.class);
System.out.println("Received " + feed.getEntries().size() + " events");
return null;
}
}
Then you need to set up the PollingHttpMessageReceiver to poll the feed every so often. This receiver respects ETags and the 304 Not Modified response code by default, so you don't need to worry about consuming unnecessary updates.
<http:connector name="PollingHttpConnector" >
<service-overrides messageReceiver="org.mule.transport.http.PollingHttpMessageReceiver"/>
</http:connector>
<model name="testModel">
<service name="eventConsumer">
<inbound>
<inbound-endpoint address="http://localhost:9002/events" connector-ref="PollingHttpConnector">
<properties>
<s:entry key="pollingFrequency" value="10000"/>
</properties>
</inbound-endpoint>
</inbound>
<component class="org.mule.providers.abdera.event.EventReceiver"/>
</service>
</model>
Publishing to Collections
You may also want to publish Atom entries or media entries to an AtomPub collection. Here is a simple example that uses quartz to periodically publish an Entry:
<quartz:connector name="quartzConnectorDefaults"/>
<endpoint name="quartz.in" address="quartz:/eventTimer">
<properties>
<s:entry key="repeatInterval" value="1000" />
<s:entry key="repeatCount" value="0" />
<s:entry key="startDelay" value="0" />
<s:entry key="payloadClassName" value="" />
</properties>
</endpoint>
<model name="testModel">
<service name="entryEventPublisher">
<component class="org.mule.providers.abdera.event.EntryEventPublisher"/>
<inbound-router>
<inbound-endpoint ref="quartz.in" remoteSync="true"/>
</inbound-router>
<outbound-router>
<outbound-pass-through-router>
<outbound-endpoint address="http://localhost:9002/events/feed">
<properties>
<entry key="Content-Type" value="application/atom+xml;type=entry"/>
</properties>
</outbound-endpoint>
</outbound-pass-through-router>
</outbound-router>
</service>
</model>
And the corresponding class is:
package org.mule.providers.abdera.example;
import java.util.Date;
import org.apache.abdera.Abdera;
import org.apache.abdera.factory.Factory;
import org.apache.abdera.model.Entry;
public class EntryPublisher {
public Entry newEvent() {
Factory factory = Abdera.getInstance().getFactory();
Entry entry = factory.newEntry();
entry.setTitle("Some Event");
entry.setContent("Foo bar");
entry.setUpdated(new Date());
entry.setId(factory.newUuidUri());
entry.addAuthor("Dan Diephouse");
return entry;
}
}
You can also post Media entries quite simply. In this case it will take whatever your message payload is and post it to the collection as a media entry. You can supply your own Slug via configuration or by setting a property on the mule message.
<service name="blobEventPublisher">
<inbound>
<inbound-endpoint ref="quartz.in" remoteSync="true"/>
</inbound>
<component class="org.mule.providers.abdera.event.BlobEventPublisher"/>
<outbound>
<outbound-pass-through-router>
<outbound-endpoint address="http://localhost:9002/events" connector-ref="HttpConnector">
<properties>
<s:entry key="Content-Type" value="text/plain"/>
<s:entry key="http.custom.headers">
<s:map>
<s:entry key="Slug" value="Blob Event"/>
</s:map>
</s:entry>
</properties>
</outbound-endpoint>
</outbound-pass-through-router>
</outbound>
</service>
Implementing an AtomPub Server
Abdera's service side component centers around the notion of a Provider. A Provider is manage's a service's Workspaces and Collections.
You can create an AtomPub service in Mule by using the <mule-abdera:component/> XML element and referencing an Abdera service context.
<model name="testModel">
<service name="atomPub">
<mule-abdera:component serviceContext-ref="serviceContext"/>
<inbound-router>
<inbound-endpoint address="http://localhost:9002" remoteSync="true" connector-ref="HttpConnector"/>
</inbound-router>
</service>
<a:provider id="provider">
<a:workspace title="Your Workspace">
<ref bean="yourCollectionAdapater"/>
</a:workspace>
</a:provider>
</model>
The <abdera:provider> creates an Abdera DefaultProvider and allows you to add Workspaces and Collections to it. For more information see: