You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@abdera.apache.org by Takasho <ta...@gmail.com> on 2008/02/15 10:52:40 UTC

Trying to create a working spring example

Hi All,

I am using the trunk code and I am trying to get a very simple spring
example working. I have read through the online docs, pilfered bits
from unit tests and worked through the server re-factor pdf. I have
now hit a bit of a wall as I'm pretty sure what I have should work but
it just throws errors.

I have an applicationContext.xml:

<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="dao" class="org.example.dao.CustomerDAOMemoryImpl" />

	<bean id="adapter" class="org.example.CustomerCollectionAdapter">
		<property name="dao" ref="dao" />
	</bean>

	<a:provider>
		<property name="workspaces">
    		<ref bean="simpleWorkspace"/>
    	</property>
		<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:provider>
	
	<bean id="simpleWorkspace"
class="org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo">
  	<property name="title" value="Customer Workspace"/>
  	<property name="collections">
  		<list>
  			<bean class="org.example.CustomerCollectionAdapter"/>
      		<ref bean="adapter"/>
  		</list>
  	</property>
  </bean>
</beans>

And a web.xml containing:

<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext.xml</param-value>
	</context-param>

	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>

	<servlet id="abdera">
		<servlet-name>Abdera</servlet-name>
		<servlet-class>
			org.apache.abdera.spring.SpringAbderaServlet
		</servlet-class>
	</servlet>

	<servlet-mapping id="abdera-mapping">
		<servlet-name>Abdera</servlet-name>
		<url-pattern>/atom/*</url-pattern>
	</servlet-mapping>

And then my customer collection adapter just extends
AbstractEntityCollectionAdapter. I have a simple pojo for a Customer
object and an in-memory map storing collections of customers.

The code is deployed as a war to jetty and sucessfully initializes:

11957 [Timer-0] INFO org.springframework.web.context.ContextLoader -
Root WebApplicationContext: initialization completed in 567 ms

When I hit any URI in the application it throws the following error:

25725 [btpool0-4] ERROR
org.apache.abdera.protocol.server.servlet.AbderaServlet - Error
servicing request
java.lang.ClassCastException:
org.apache.abdera.protocol.server.impl.RegexTargetResolver cannot be
cast to org.apache.abdera.protocol.server.TargetBuilder
	at org.apache.abdera.protocol.server.impl.DefaultProvider.getTargetBuilder(DefaultProvider.java:118)
	at org.apache.abdera.protocol.server.impl.AbstractProvider.urlFor(AbstractProvider.java:93)
	at org.apache.abdera.protocol.server.context.AbstractRequestContext.urlFor(AbstractRequestContext.java:183)
	at org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter.getHref(AbstractCollectionAdapter.java:61)
	at org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager.getCollectionAdapter(DefaultWorkspaceManager.java:25)
	at org.apache.abdera.protocol.server.impl.AbstractProvider.process(AbstractProvider.java:116)
	at org.apache.abdera.protocol.server.FilterChain.next(FilterChain.java:42)
	at org.apache.abdera.protocol.server.servlet.AbderaServlet.service(AbderaServlet.java:90)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

At this point I am stuck as the code is internal to Abdera and I'm
hoping that someone has seen where I'm going wrong or has a very
simple working example I can dismantle and build on.

Thanks,

Takasho

Re: Trying to create a working spring example

Posted by Takasho <ta...@gmail.com>.
I get the generated service document listing the workspace and
collection however the collection URI is listed as /atom (relative to
my deployment) which is the service document. I'm convinced that is
down to some code I have missed somewhere. Perhaps it is part of using
the spring interface that does it. The output I get is:

<?xml version='1.0' encoding='UTF8'?><service
xmlns="http://www.w3.org/2007/app"><workspace><title
xmlns="http://www.w3.org/2005/Atom" type="text">Customer
Workspace</title><collection href="/example/atom/"><title
xmlns="http://www.w3.org/2005/Atom" type="text">The
Title</title><accept>application/atom+xml;type=entry</accept></collection></workspace></service>

Any further requests to /atom/feed or /atom/feed/customers gets me an
abdera 404 xml response it is as if the target resolvers in the spring
applicationContext.xml are not being interpreted.

Takasho.

On 15/02/2008, James M Snell <ja...@gmail.com> wrote:
> I checked in the patch.
>
> Regarding the 404 response... are you seeing behavior similar to what
> Sam Ruby describes here http://intertwingly.net/blog/2008/02/12/CouchDB-ASF
>
> - James
>
> Takasho wrote:
> > Hi David,
> >
> > That patch has fixed the problem I just have to debug the code now to
> > find out why every URI returns an Abdera 404 xml response when calling
> > /atom/ or  /atom/feed/ or /atom/feed/customer.
> >
> > Thanks
> >
> > Takasho.
> >
> > On 15/02/2008, David Calavera <da...@gmail.com> wrote:
> >> Hi Takaso, I think this exception is due a bug into DefaultProvider. I've
> >>  opended a ticket into the jira and I've submitted a patch.
> >>
> >>  https://issues.apache.org/jira/browse/ABDERA-119
> >>
> >>  Cheers
> >
>

Re: Trying to create a working spring example

Posted by James M Snell <ja...@gmail.com>.
I checked in the patch.

Regarding the 404 response... are you seeing behavior similar to what 
Sam Ruby describes here http://intertwingly.net/blog/2008/02/12/CouchDB-ASF

- James

Takasho wrote:
> Hi David,
> 
> That patch has fixed the problem I just have to debug the code now to
> find out why every URI returns an Abdera 404 xml response when calling
> /atom/ or  /atom/feed/ or /atom/feed/customer.
> 
> Thanks
> 
> Takasho.
> 
> On 15/02/2008, David Calavera <da...@gmail.com> wrote:
>> Hi Takaso, I think this exception is due a bug into DefaultProvider. I've
>>  opended a ticket into the jira and I've submitted a patch.
>>
>>  https://issues.apache.org/jira/browse/ABDERA-119
>>
>>  Cheers
> 

Re: Trying to create a working spring example

Posted by Takasho <ta...@gmail.com>.
That sounds very comprehensive and would be a very good example to get
a good head start with abdera and spring. I wish there were more open
source implementations/working examples that people can contribute to
and extend.

It would be good to see different working examples that people can
collaborate on in order to extend the reach of the project. As soon as
I get up and running I can hopefully contribute my code back to the
project. I'm all for getting feedback on how I can make my code more
efficient.

Takasho.

On 15/02/2008, Remy Gendron <re...@arrova.ca> wrote:
> I come to the conclusion that Abdera should probably not include a Spring
> integration package but only some examples:
>         * Some will want Spring 2.0.x, others 2.5.x.
>         * Some prefer XML based configuration, others will go for
> annotations or Java code.
>         * There are many possible variations depending on architectural
> taste.
>         * It would be hard to please everyone.
>
> I am putting together an Abdera + Spring example project for my team. I will
> submit it to the Abdera folks for possible inclusion in the Abdera examples
> or documentation, whichever is best.
>
> A number of things that were put forth in this demo:
>
> * The feed server is powered by Abdera under Spring control.
> * The unit tests do not use Spring at all, only Abdera.
> * Base classes for unit testing.
>         * The unit tests start the feed server in an embedded Jetty.
>         * The unit tests load, start and populate an embedded HSQLDB.
> * My applicationContext.xml is empty.
>         * All components are auto-discovered. (@Component annotation)
>         * Auto-wiring is used for everything. (@Autowired)
>         * The servlet and provider are all generic and automatic.
>         * All adapters are auto-discovered and injected automatically.
>         * AbstractSpringAdapter generalizes some adapter behaviours.
> * Base classes for model objects and services.
>         * No DTOs, only entities (model objects).
>         * Access to entities thru an interface to restrict client access.
>         * With the goal of preventing the presentation layer from
> manipulating the model directly to implement business rules.
> * No text configuration (XML or properties). Java config is preferred.
> * Some convention over configuration.
>
> I should be able to submit this example sometime next week.
>
> Remy
>
> -----Original Message-----
> From: Takasho [mailto:takasho@gmail.com]
> Sent: February 15, 2008 07:17
> To: abdera-user@incubator.apache.org
> Subject: Re: Trying to create a working spring example
>
> Hi David,
>
> That patch has fixed the problem I just have to debug the code now to
> find out why every URI returns an Abdera 404 xml response when calling
> /atom/ or  /atom/feed/ or /atom/feed/customer.
>
> Thanks
>
> Takasho.
>
> On 15/02/2008, David Calavera <da...@gmail.com> wrote:
> > Hi Takaso, I think this exception is due a bug into DefaultProvider. I've
> >  opended a ticket into the jira and I've submitted a patch.
> >
> >  https://issues.apache.org/jira/browse/ABDERA-119
> >
> >  Cheers
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.5.516 / Virus Database: 269.20.5/1278 - Release Date: 2008.02.14
> 10:28
>
>
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.5.516 / Virus Database: 269.20.5/1278 - Release Date: 2008.02.14
> 10:28
>
>
>

RE: Trying to create a working spring example

Posted by Remy Gendron <re...@arrova.ca>.
I come to the conclusion that Abdera should probably not include a Spring
integration package but only some examples:
	* Some will want Spring 2.0.x, others 2.5.x.
	* Some prefer XML based configuration, others will go for
annotations or Java code.
	* There are many possible variations depending on architectural
taste.
	* It would be hard to please everyone.

I am putting together an Abdera + Spring example project for my team. I will
submit it to the Abdera folks for possible inclusion in the Abdera examples
or documentation, whichever is best.

A number of things that were put forth in this demo:

* The feed server is powered by Abdera under Spring control.
* The unit tests do not use Spring at all, only Abdera.
* Base classes for unit testing.
	* The unit tests start the feed server in an embedded Jetty.
	* The unit tests load, start and populate an embedded HSQLDB.
* My applicationContext.xml is empty.
	* All components are auto-discovered. (@Component annotation)
	* Auto-wiring is used for everything. (@Autowired)
	* The servlet and provider are all generic and automatic.
	* All adapters are auto-discovered and injected automatically.
	* AbstractSpringAdapter generalizes some adapter behaviours.
* Base classes for model objects and services.
	* No DTOs, only entities (model objects).
	* Access to entities thru an interface to restrict client access. 
	* With the goal of preventing the presentation layer from
manipulating the model directly to implement business rules.
* No text configuration (XML or properties). Java config is preferred.
* Some convention over configuration.

I should be able to submit this example sometime next week.

Remy

-----Original Message-----
From: Takasho [mailto:takasho@gmail.com] 
Sent: February 15, 2008 07:17
To: abdera-user@incubator.apache.org
Subject: Re: Trying to create a working spring example

Hi David,

That patch has fixed the problem I just have to debug the code now to
find out why every URI returns an Abdera 404 xml response when calling
/atom/ or  /atom/feed/ or /atom/feed/customer.

Thanks

Takasho.

On 15/02/2008, David Calavera <da...@gmail.com> wrote:
> Hi Takaso, I think this exception is due a bug into DefaultProvider. I've
>  opended a ticket into the jira and I've submitted a patch.
>
>  https://issues.apache.org/jira/browse/ABDERA-119
>
>  Cheers

No virus found in this incoming message.
Checked by AVG Free Edition. 
Version: 7.5.516 / Virus Database: 269.20.5/1278 - Release Date: 2008.02.14
10:28
 

No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.516 / Virus Database: 269.20.5/1278 - Release Date: 2008.02.14
10:28
 


Re: Trying to create a working spring example

Posted by Takasho <ta...@gmail.com>.
Hi David,

That patch has fixed the problem I just have to debug the code now to
find out why every URI returns an Abdera 404 xml response when calling
/atom/ or  /atom/feed/ or /atom/feed/customer.

Thanks

Takasho.

On 15/02/2008, David Calavera <da...@gmail.com> wrote:
> Hi Takaso, I think this exception is due a bug into DefaultProvider. I've
>  opended a ticket into the jira and I've submitted a patch.
>
>  https://issues.apache.org/jira/browse/ABDERA-119
>
>  Cheers

Re: Trying to create a working spring example

Posted by David Calavera <da...@gmail.com>.
Hi Takaso, I think this exception is due a bug into DefaultProvider. I've
opended a ticket into the jira and I've submitted a patch.

https://issues.apache.org/jira/browse/ABDERA-119

Cheers

On 2/15/08, Takasho <ta...@gmail.com> wrote:
>
> Hi All,
>
> I am using the trunk code and I am trying to get a very simple spring
> example working. I have read through the online docs, pilfered bits
> from unit tests and worked through the server re-factor pdf. I have
> now hit a bit of a wall as I'm pretty sure what I have should work but
> it just throws errors.
>
> I have an applicationContext.xml:
>
> <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="dao" class="org.example.dao.CustomerDAOMemoryImpl" />
>
>         <bean id="adapter" class="org.example.CustomerCollectionAdapter">
>                 <property name="dao" ref="dao" />
>         </bean>
>
>         <a:provider>
>                 <property name="workspaces">
>                 <ref bean="simpleWorkspace"/>
>         </property>
>                 <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:provider>
>
>         <bean id="simpleWorkspace"
> class="org.apache.abdera.protocol.server.impl.SimpleWorkspaceInfo">
>         <property name="title" value="Customer Workspace"/>
>         <property name="collections">
>                 <list>
>                         <bean class="org.example.CustomerCollectionAdapter
> "/>
>                 <ref bean="adapter"/>
>                 </list>
>         </property>
>   </bean>
> </beans>
>
> And a web.xml containing:
>
> <context-param>
>                 <param-name>contextConfigLocation</param-name>
>                 <param-value>/WEB-INF/applicationContext.xml</param-value>
>         </context-param>
>
>         <listener>
>                 <listener-class>
>
> org.springframework.web.context.ContextLoaderListener
>                 </listener-class>
>         </listener>
>
>         <servlet id="abdera">
>                 <servlet-name>Abdera</servlet-name>
>                 <servlet-class>
>                         org.apache.abdera.spring.SpringAbderaServlet
>                 </servlet-class>
>         </servlet>
>
>         <servlet-mapping id="abdera-mapping">
>                 <servlet-name>Abdera</servlet-name>
>                 <url-pattern>/atom/*</url-pattern>
>         </servlet-mapping>
>
> And then my customer collection adapter just extends
> AbstractEntityCollectionAdapter. I have a simple pojo for a Customer
> object and an in-memory map storing collections of customers.
>
> The code is deployed as a war to jetty and sucessfully initializes:
>
> 11957 [Timer-0] INFO org.springframework.web.context.ContextLoader -
> Root WebApplicationContext: initialization completed in 567 ms
>
> When I hit any URI in the application it throws the following error:
>
> 25725 [btpool0-4] ERROR
> org.apache.abdera.protocol.server.servlet.AbderaServlet - Error
> servicing request
> java.lang.ClassCastException:
> org.apache.abdera.protocol.server.impl.RegexTargetResolver cannot be
> cast to org.apache.abdera.protocol.server.TargetBuilder
>         at
> org.apache.abdera.protocol.server.impl.DefaultProvider.getTargetBuilder(
> DefaultProvider.java:118)
>         at org.apache.abdera.protocol.server.impl.AbstractProvider.urlFor(
> AbstractProvider.java:93)
>         at
> org.apache.abdera.protocol.server.context.AbstractRequestContext.urlFor(
> AbstractRequestContext.java:183)
>         at
> org.apache.abdera.protocol.server.impl.AbstractCollectionAdapter.getHref(
> AbstractCollectionAdapter.java:61)
>         at
> org.apache.abdera.protocol.server.impl.DefaultWorkspaceManager.getCollectionAdapter
> (DefaultWorkspaceManager.java:25)
>         at org.apache.abdera.protocol.server.impl.AbstractProvider.process
> (AbstractProvider.java:116)
>         at org.apache.abdera.protocol.server.FilterChain.next(
> FilterChain.java:42)
>         at org.apache.abdera.protocol.server.servlet.AbderaServlet.service
> (AbderaServlet.java:90)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>
> At this point I am stuck as the code is internal to Abdera and I'm
> hoping that someone has seen where I'm going wrong or has a very
> simple working example I can dismantle and build on.
>
> Thanks,
>
>
> Takasho
>



-- 
David Calavera
http://www.thinkincode.net