abdera-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Adam Constabaris <a...@clownsinmycoffee.net>
Subject Re: Advice on implementing an APP server
Date Wed, 21 Feb 2007 14:53:44 GMT
Thanks. 

After I posted yesterday, I rolled up my sleeves in earnest and realized 
that subclassing wouldn't cut it.  I ended up following the same path 
you're describing (I subclassed DefaultServiceProvider, added the 
necessary setWhatever and overrode the getDefaultWhatever() methods, but 
it's pretty much the same thing).

On the chance it may prove useful, I've also got a Spring-configurable 
TargetResolver implementation based on the RegexTargetResolver, that's 
used like so:

 <bean id="targetResolver" 
class="net.foo.bar.SpringConfiguredTargetResolver">
        <property name="targetPatterns">
            <map>
                <entry key="/atom/app/service" value="SERVICE"/>
                <entry key="/atom/app/collection-one" value="COLLECTION"/>
                <entry key="/atom/app/collection-two" value="COLLECTION"/>
            </map>
        </property>
    </bean>

The key method:

    public void setTargetPatterns(Map<String,String> mappings) {
        for(Map.Entry<String,String> entry : mappings.entrySet() ) {
            String typeName = entry.getValue().toUpperCase();
            TargetType type = null;
            if ( TargetType.SERVICE.equals(typeName) ) {
                type = TargetType.TYPE_SERVICE;
            } else if ( TargetType.COLLECTION.equals(typeName) ) {
                type = TargetType.TYPE_COLLECTION;
            } else if ( TargetType.ENTRY.equals(typeName) ) {
                type = TargetType.TYPE_ENTRY;
            } else if ( TargetType.MEDIA.equals(typeName) ) {
                type = TargetType.TYPE_MEDIA;
            } else if ( TargetType.CATEGORIES.equals(typeName)) {
                type = TargetType.TYPE_CATEGORIES;
            } else {
                type = TargetType.TYPE_UNKNOWN;
            }

            if ( logger.isDebugEnabled() ) {
                logger.debug(String.format("Mapping URL pattern %s to 
%s", entry.getKey(), type.name()));
            }

            setPattern(entry.getKey(), type);
        }
    }

(aside: I would have thought that TargetType.get(entry.getValue()) would 
work, but I ran into identity vs. equality problems, even when I 
interned the strings)

cheers,

AC


Ugo Cei wrote:
>
> On Feb 20, 2007, at 3:26 PM, Adam Constabaris wrote:
>
>> While I'm on (2) (and this is nearer to my immediate concerns, but 
>> seems like a ripe subject for documentation): suppose my APP server 
>> is part of an existing application that uses Spring with 
>> JPA/Hibernate/JDO/iBatis for data access (or just that I really like 
>> Spring IoC and I want to use it behind my new APP server).  I've got 
>> this juicy set of services just sitting there, already initialized, 
>> and now I need to instantiate a ProviderManager and give it access to 
>> those things.  I can't use Spring to inject those services into the 
>> ProviderManager instance, because as long as I'm using the stock 
>> AbderaServlet, creation of the protocol's factory objects is 
>> controlled by the Abdera framework.  Since there doesn't seem to be a 
>> way to access the servlet context (where a reference to the Spring 
>> context can be held) through the framework classes, it looks like the 
>> cleanest approach is to subclass AbderaServlet, which can inject the 
>> Spring-managed dependencies into the Abdera factory classes.  Mutatis 
>> mutandis if I'm working with EJB3/Servlets 2.5 and I want to inject 
>> container-managed JPA EntityManagers into my Abdera-based classes.
>
> I can tell you what I'm doing in a situation like yours. I'm not sure 
> it makes perfectly sense, as it's mostly an experiment, but it might 
> be useful to you.
>
> First of all, I'm not extending AbderaServlet, but HttpServlet 
> instead, overriding the service() method as follows:
<snip>

Mime
View raw message