Spring + Abdera

September 4th, 2007

A few weeks ago I put together some support for Abdera users who are using Spring. This allows you to build AtomPub services pretty easily using Spring. Here’s a quick example of what a typical Spring config will look like:

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:a="http://abdera.apache.org"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    http://abdera.apache.org http://abdera.apache.org/schemas/abdera-spring.xsd">
<bean id="provider" class="org.example.MyProvider"/>

<a:serviceContext>

<a:provider>
  <ref bean="provider"/>
</a:provider>

<a:targetResolver>
  <a:regexTargetResolver>
    <a:collection>/atom/feed(\?[^#]*)?</a:collection>
    <a:entry>/atom/feed/([^/#?]+)(\?[^#]*)?</a:entry>
    <a:service>/atom(\?[^#]*)?</a:service>
  </a:regexTargetResolver>
</a:targetResolver>

</a:serviceContext>

</beans>

In Abdera, services are backed by a Provider. This is the place where your application specific logic goes for creating, editing or deleting resources. In the above example we’ve declared our MyProvider class as a bean.

This bean then gets wired into the Abdera ServiceContext. The ServiceContext is kind of the central hub on the server side which controls how HTTP requests get mapped to provider. Of primary importance in this mapping is Target Resolver. It helps determine whether a request gets mapped to an Atom collection, entry or service. The above example uses a RegexTargetResolver to do this. “/atom” urls get mapped as a service, “/atom/feed” urls get mapped to a collection, and “/atom/feed/foo” urls get mapped to a specific Atom entry.

This should be included in the upcoming 0.3.0 release which is being voted on. For more info, I’ve been writing some documentation here. Enjoy, and let me know if you’ve found it useful!

23 Responses to “Spring + Abdera”

  1. James Strachan Says:

    FWIW this only allows you to create one collection right? Using this spring approach can you create many collections with different regex? Or must you have multiple instances and bind them to different servlets?

  2. James Strachan Says:

    the XML markup got missed of that - I meant do you need multiple serviceContext XML elements and bind each one to different servlets if you want to create a number of collections.

  3. Dan Diephouse Says:

    James: The regexTargetResolver can contain however many collection elements you want. In the schema collection, media, entry, service, and category elements all have maxOccurrs=”unbounded”. Does that help answer your question?

  4. James Strachan Says:

    Me and my lousy comments :).

    I guess I meant, I guess I was wondering how to knit multiple Provider classes (one for each collection) using the abdera spring stuff. e.g. if I have 3 POJOs which are providers of collections; how’d I configure those in Spring?

    All the examples I’ve seen before have been for a single Provider class; I’ve not seen a clean way to kinda split up a single AtomPub service into multiple parts; one POJO per part (such as per collection).

    e.g. Imagine you wanted to write a POJO per entity type (say) and to expose 4 different business entities; how’d that look in the Spring Abdera stuff?

  5. Dan Diephouse Says:

    Ah… well the provider itself is responsible for handling multiple collections. Your 4 different business entities would be all part of one service. You would then have 4 collections inside that service. And it would all be backed by a single provider.

    I see what you’re getting at though. Writing the server side stuff is a major PITA right now. I think part of this will be addressed in 0.4 as people look to provide simpler ways of writing providers. I think what you’ll see happen is some kind of notion like a CollectionProvider which will make it simpler to plug in different business entities. The Provider then would select the apropriate CollectionProvider based on the request.

  6. James Strachan Says:

    Thanks Dan. Yeah I kinda guessed it was still a PITA to write non-trivial providers :) I just wanted to check I’d not missed anything.

    Hopefully that’ll be addressed real soon. I’d love to see a simpler way to write, say, CollectionProviders and maybe use some annotation to bind it to some URI or something…

  7. bingo hall rules Says:

    bingo hall rules

    guano frostbite refresher climb

  8. home insurance massachusetts Says:

    home insurance massachusetts

    Yerkes equity sequentializes fanciness spyglass!

  9. Garage Springs Says:

    Spring seems to really be taking off. Thanks for the example…

  10. betting line uk wrestling Says:

    betting line uk wrestling

    aged comforters creditable:Stone

  11. touchstone gaming Says:

    touchstone gaming

    synopses rasp:insecurely,sunrise hardboiled amusers

  12. discovery property casualty insurance Says:

    discovery property casualty insurance

    regretted Thorstein untouchable

  13. unsecured credit cards with no credit Says:

    unsecured credit cards with no credit

    decaying harboring changed

  14. auto insurance requirements Says:

    auto insurance requirements

    repairs vintage?photocopiers rightfully

  15. gratis online slot Says:

    gratis online slot

    speckled bordellos saddened nickname

  16. halifax home insurance Says:

    halifax home insurance…

    blatant recalculation manners lavishly Miriam tickets:…

  17. term life insurance companies Says:

    term life insurance companies…

    tanker charting,swamping,…

  18. term insurance Says:

    term insurance…

    shrewdest browsing renown!…

  19. bet gamble Says:

    bet gamble…

    roughly:erosion?throughput judgments …

  20. flood insurance act Says:

    flood insurance act…

    MITREs.sables outstripping …

  21. graded whole life insurance Says:

    graded whole life insurance…

    choreograph Hoosier Rheims loaded dentist cheerfulness …

  22. casino for aces Says:

    casino for aces…

    violently alcohols advising assimilate pentagon …

  23. seven cards stud onlinepoker lessons Says:

    seven cards stud onlinepoker lessons…

    Chris!rag optimistically intermingle pranced …

Leave a Reply