You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Josh2007 <jo...@gmail.com> on 2008/01/22 22:20:04 UTC

servlet-mapping in Cocoon 2.2 bean?

Hi,

I'm implementing an Xquery Servlet as a block in Cocoon 2.2
Prior to Cocoon 2.2 I was able to define servlet-mapping in my web.xml.
Now, is there a way to get the same result when the Servlet is declared as a
Spring bean?
something like:

<bean name="XqueryServlet" class="org.my.class.servlets.XqueryServlet">
    <servlet:context mount-path="/xquery"
context-path="blockcontext:/xquery/">
    <servlet:init-params>
    <entry key="basedir" value="WEB-INF"/>
    <entry key="start" value="true"/>
    </servlet:init-params>
    <servlet:mapping>
    <entry value="*.xq"/>
    <entry value="*.xql"/>
    </servlet:mapping>
    </servlet:context>
    </bean>

Thanks,

Josh

-- 
View this message in context: http://www.nabble.com/servlet-mapping-in-Cocoon-2.2-bean--tp15028682p15028682.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Josh2007 <jo...@gmail.com>.
Yes, after all the help I got I was thinking of writing a short tutorial
about integrating eXist in Cocoon 2.2 as a block and how to make use of
XQueryServlet with servletService to query the database.

eXist requires some files conf.xml (specific to eXist and not part of
web.xml),... and an empty folder Data to be added to the web-inf directory
of the block. 
For now I'm doing it by hand which is not convenient. I would like to find a
better solution before sharing.

Regards,

Josh



Grzegorz Kossakowski-2 wrote:
> 
> Josh2007 pisze:
>> Sorry to get back so late.
>> I debugged Cocoon and eXist and found the problem.
>> eXist XQueryServlet expects an URI in order to be executed. I modified
>> the
>> code so it can receive content and everything works just fine.
> 
> Have you considered sharing your experiences with others? I think more
> people would be interested in
> integration eXist and Cocoon 2.2.
> 
>> Thanks for your help.
> 
> No problem.
> 
> -- 
> Grzegorz Kossakowski
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/servlet-mapping-in-Cocoon-2.2-bean--tp15028682p15918391.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Grzegorz Kossakowski <gr...@tuffmail.com>.
Josh2007 pisze:
> Sorry to get back so late.
> I debugged Cocoon and eXist and found the problem.
> eXist XQueryServlet expects an URI in order to be executed. I modified the
> code so it can receive content and everything works just fine.

Have you considered sharing your experiences with others? I think more people would be interested in
integration eXist and Cocoon 2.2.

> Thanks for your help.

No problem.

-- 
Grzegorz Kossakowski

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Josh2007 <jo...@gmail.com>.
Sorry to get back so late.
I debugged Cocoon and eXist and found the problem.
eXist XQueryServlet expects an URI in order to be executed. I modified the
code so it can receive content and everything works just fine.
Thanks for your help.

Josh



Grzegorz Kossakowski-3 wrote:
> 
> Josh2007 pisze:
>> Hi Grzegorz,
>> 
>> I ran my webapp, but the same error occured.
>> Before going further I need to clarify one point about ServletService.
>> 
>> If I call my servlet this way:
>> <map:generate src="servlet:xquery:/exist-xquery-samples/guess.xql"
>> type="file"/>
>> 
>> it's the same as making an http request to xquery servlet, where
>> /exist-xquery-samples/guess.xql is considered as an URI?
> 
> Yes, I can confirm your assumption. I hope that you know how to setup
> Cocoon for debugging.
> 
> -- 
> Grzegorz Kossakowski
> Committer and PMC Member of Apache Cocoon
> http://reflectingonthevicissitudes.wordpress.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/servlet-mapping-in-Cocoon-2.2-bean--tp15028682p15914204.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Josh2007 pisze:
> Hi Grzegorz,
> 
> I ran my webapp, but the same error occured.
> Before going further I need to clarify one point about ServletService.
> 
> If I call my servlet this way:
> <map:generate src="servlet:xquery:/exist-xquery-samples/guess.xql"
> type="file"/>
> 
> it's the same as making an http request to xquery servlet, where
> /exist-xquery-samples/guess.xql is considered as an URI?

Yes, I can confirm your assumption. I hope that you know how to setup Cocoon for debugging.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Josh2007 <jo...@gmail.com>.
Hi Grzegorz,

I ran my webapp, but the same error occured.
Before going further I need to clarify one point about ServletService.

If I call my servlet this way:
<map:generate src="servlet:xquery:/exist-xquery-samples/guess.xql"
type="file"/>

it's the same as making an http request to xquery servlet, where
/exist-xquery-samples/guess.xql is considered as an URI?

Thanks,

Josh



Grzegorz Kossakowski-3 wrote:
> 
> Josh2007 pisze:
>> Thanks Grzegorz,
> 
> No problem.
> 
>> Servlet implementation and Spring bean registration:
>> I've, then, been able to set my XQuery Servlet in a block registered as a
>> bean.
>> I patched the block web.xml to implement eXist database servlet, and add
>> the
>> required dependencies in the pom.xml (after installing then in my mvn
>> local
>> repositery).
>> It works. I can now start XQuery block using [mvn jetty:run] and execute
>> any
>> XQuery file stored in my block under the root webapp and, in the
>> meantime,
>> access the database.
>> 
>> Servlet Service functionality:
>> I tried to access this block from another block (named block test1) by:
>> adding the XQuery block (named test2) as a dependency of the block test1,
>> in
>> test1 pom.xml.
>> adding the XQuery block entry in test1 servlet-sevice.xml 
>> creating, in test1 block, a sitemap pipeline calling the XQuery servlet:
>> 
>> pipeline :
>> <map:match pattern="trytest2">
>>   <map:generate src="servlet:test2:/header.xml" type="file"/>
>>   <map:serialize type="xml"/>
>> </map:match>
>> 
>> note: 
>> XQuery block has no use of sitemap.xmap but I kept
>> src/main/resources/COB-INF directory.
>> I've been succesful accessing another block from test1 block (this block
>> was
>> based on org.apache.cocoon.sitemap.SitemapServlet)
>>  
>> problem with my XQuery Servlet called from test1 block: 
>> I got an error:
>> 
> 
> <snip/>
> 
>> servlet:test2:/test2/header.xml_S-xml-;encoding=ISO-8859-1
>> 2008-01-25 20:27:04,665 btpool0-1 DEBUG util.ConfigurationHelper - Got
>> eXist
>> home from broker: C:\Users\BMS\Documents\test\test1
>> 
>> \target\rcl\webapp\WEB-INF
>> 2008-01-25 20:27:04,665 btpool0-1 WARN  http.Descriptor - Giving up
>> unable
>> to read descriptor file from C:\Users\BMS\Documents\test\test1
>> 
>> \target\rcl\webapp\WEB-INF\descriptor.xml
>> 2008-01-25 20:27:04,666 btpool0-1 WARN  http.Descriptor - Giving up
>> unable
>> to read descriptor.xml file from classloader in package 
>> 
> <snip/>
> 
> The detail worth attention is classloader words here.
> 
>> It seems it cannot find the file, but if I execute only the XQuery
>> Servlet,
>> it works.
>> Here's my XQuery Servlet bean:
>> <bean id="com.mycompany.test2.service"
>> class="org.exist.http.servlets.XQueryServlet">
>>     <servlet:context mount-path="/test2"
>> context-path="blockcontext:/test2/"/>
>> </bean>
>> 
>> Any idea?
> 
> When you run a block using just jetty:run in block's directory the Cocoon
> RCL[1] is run as well. It'
> s purpose is to enable RAD thus it plays with class reloading which may be
> an issue for eXist I
> think. I would suggest to try assembly a WAR archive by using webapp
> archetype[2]. If you run your
> app using:
> cd myCocoonWebapp
> mvn clean jetty:run
> 
> it will assemble a WAR package and run it with plain Jetty container. This
> way you will be able to
> find out if it's RCL's fault. Depending on your findings we will try to
> investigate further.
> 
> [1]
> http://cocoon.apache.org/2.2/maven-plugins/maven-plugin/1.0/1295_1_1.html
> [2] http://cocoon.apache.org/2.2/1362_1_1.html
> 
> -- 
> Grzegorz Kossakowski
> Committer and PMC Member of Apache Cocoon
> http://reflectingonthevicissitudes.wordpress.com/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
> For additional commands, e-mail: users-help@cocoon.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/servlet-mapping-in-Cocoon-2.2-bean--tp15028682p15145469.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Josh2007 pisze:
> Thanks Grzegorz,

No problem.

> Servlet implementation and Spring bean registration:
> I've, then, been able to set my XQuery Servlet in a block registered as a
> bean.
> I patched the block web.xml to implement eXist database servlet, and add the
> required dependencies in the pom.xml (after installing then in my mvn local
> repositery).
> It works. I can now start XQuery block using [mvn jetty:run] and execute any
> XQuery file stored in my block under the root webapp and, in the meantime,
> access the database.
> 
> Servlet Service functionality:
> I tried to access this block from another block (named block test1) by:
> adding the XQuery block (named test2) as a dependency of the block test1, in
> test1 pom.xml.
> adding the XQuery block entry in test1 servlet-sevice.xml 
> creating, in test1 block, a sitemap pipeline calling the XQuery servlet:
> 
> pipeline :
> <map:match pattern="trytest2">
>   <map:generate src="servlet:test2:/header.xml" type="file"/>
>   <map:serialize type="xml"/>
> </map:match>
> 
> note: 
> XQuery block has no use of sitemap.xmap but I kept
> src/main/resources/COB-INF directory.
> I've been succesful accessing another block from test1 block (this block was
> based on org.apache.cocoon.sitemap.SitemapServlet)
>  
> problem with my XQuery Servlet called from test1 block: 
> I got an error:
> 

<snip/>

> servlet:test2:/test2/header.xml_S-xml-;encoding=ISO-8859-1
> 2008-01-25 20:27:04,665 btpool0-1 DEBUG util.ConfigurationHelper - Got eXist
> home from broker: C:\Users\BMS\Documents\test\test1
> 
> \target\rcl\webapp\WEB-INF
> 2008-01-25 20:27:04,665 btpool0-1 WARN  http.Descriptor - Giving up unable
> to read descriptor file from C:\Users\BMS\Documents\test\test1
> 
> \target\rcl\webapp\WEB-INF\descriptor.xml
> 2008-01-25 20:27:04,666 btpool0-1 WARN  http.Descriptor - Giving up unable
> to read descriptor.xml file from classloader in package 
> 
<snip/>

The detail worth attention is classloader words here.

> It seems it cannot find the file, but if I execute only the XQuery Servlet,
> it works.
> Here's my XQuery Servlet bean:
> <bean id="com.mycompany.test2.service"
> class="org.exist.http.servlets.XQueryServlet">
>     <servlet:context mount-path="/test2"
> context-path="blockcontext:/test2/"/>
> </bean>
> 
> Any idea?

When you run a block using just jetty:run in block's directory the Cocoon RCL[1] is run as well. It'
s purpose is to enable RAD thus it plays with class reloading which may be an issue for eXist I
think. I would suggest to try assembly a WAR archive by using webapp archetype[2]. If you run your
app using:
cd myCocoonWebapp
mvn clean jetty:run

it will assemble a WAR package and run it with plain Jetty container. This way you will be able to
find out if it's RCL's fault. Depending on your findings we will try to investigate further.

[1] http://cocoon.apache.org/2.2/maven-plugins/maven-plugin/1.0/1295_1_1.html
[2] http://cocoon.apache.org/2.2/1362_1_1.html

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Josh2007 <jo...@gmail.com>.
Thanks Grzegorz,

Servlet implementation and Spring bean registration:
I've, then, been able to set my XQuery Servlet in a block registered as a
bean.
I patched the block web.xml to implement eXist database servlet, and add the
required dependencies in the pom.xml (after installing then in my mvn local
repositery).
It works. I can now start XQuery block using [mvn jetty:run] and execute any
XQuery file stored in my block under the root webapp and, in the meantime,
access the database.

Servlet Service functionality:
I tried to access this block from another block (named block test1) by:
adding the XQuery block (named test2) as a dependency of the block test1, in
test1 pom.xml.
adding the XQuery block entry in test1 servlet-sevice.xml 
creating, in test1 block, a sitemap pipeline calling the XQuery servlet:

pipeline :
<map:match pattern="trytest2">
  <map:generate src="servlet:test2:/header.xml" type="file"/>
  <map:serialize type="xml"/>
</map:match>

note: 
XQuery block has no use of sitemap.xmap but I kept
src/main/resources/COB-INF directory.
I've been succesful accessing another block from test1 block (this block was
based on org.apache.cocoon.sitemap.SitemapServlet)
 
problem with my XQuery Servlet called from test1 block: 
I got an error:

2008-01-25 20:27:04,624 btpool0-1 DEBUG cocoon - Resolving
'servlet:test2:/test2/header.xml' with base 

'file:///C:/Users/BMS/Documents/test/test1/./src/main/resources/COB-INF/' in
context 'file:/C:/Users/BMS/Documents/test/test1/'
2008-01-25 20:27:04,624 btpool0-1 DEBUG support.DefaultListableBeanFactory -
Returning cached instance of singleton bean 

'org.apache.avalon.framework.service.ServiceManager'
2008-01-25 20:27:04,624 btpool0-1 DEBUG support.DefaultListableBeanFactory -
Returning cached instance of singleton bean 

'org.apache.excalibur.source.SourceFactory/servlet'
2008-01-25 20:27:04,624 btpool0-1 DEBUG cocoon - Resolved to systemID :
servlet:test2:/test2/header.xml
2008-01-25 20:27:04,646 btpool0-1 DEBUG cocoon - Cached response not found
for 'trytest2' using key: PK_G-file-

servlet:test2:/test2/header.xml_S-xml-;encoding=ISO-8859-1
2008-01-25 20:27:04,665 btpool0-1 DEBUG util.ConfigurationHelper - Got eXist
home from broker: C:\Users\BMS\Documents\test\test1

\target\rcl\webapp\WEB-INF
2008-01-25 20:27:04,665 btpool0-1 WARN  http.Descriptor - Giving up unable
to read descriptor file from C:\Users\BMS\Documents\test\test1

\target\rcl\webapp\WEB-INF\descriptor.xml
2008-01-25 20:27:04,666 btpool0-1 WARN  http.Descriptor - Giving up unable
to read descriptor.xml file from classloader in package 

org.exist.http
2008-01-25 20:27:04,666 btpool0-1 DEBUG cocoon -
getValidityForInternalPipeline(0): generator: using getValidity,
validity==null
2008-01-25 20:27:04,689 btpool0-1 ERROR cocoon - Internal Cocoon Problem
org.apache.cocoon.ProcessingException: Failed to process pipeline
	at <map:serialize type="xml"> - 

file:///C:/Users/BMS/Documents/test/test1/./src/main/resources/COB-INF/sitemap.xmap:107:36
	at <map:generate type="file"> - 

file:///C:/Users/BMS/Documents/test/test1/./src/main/resources/COB-INF/sitemap.xmap:106:74
	at <map:match> - 

file:///C:/Users/BMS/Documents/test/test1/./src/main/resources/COB-INF/sitemap.xmap:105:37
	at
org.apache.cocoon.ProcessingException.throwLocated(ProcessingException.java:143)
	at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.handleException(AbstractProcessingPipeline.java:921)
	at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:546)
	at
org.apache.cocoon.components.pipeline.impl.AbstractCachingProcessingPipeline.processXMLPipeline

(AbstractCachingProcessingPipeline.java:275)
	at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.process(AbstractProcessingPipeline.java:437)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at
org.apache.cocoon.core.container.spring.avalon.PoolableProxyHandler.invoke(PoolableProxyHandler.java:72)
	at $Proxy8.process(Unknown Source)
	at
org.apache.cocoon.components.treeprocessor.sitemap.SerializeNode.invoke(SerializeNode.java:144)
	at
org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode.invokeNodes(AbstractParentProcessingNode.java:55)
	at
org.apache.cocoon.components.treeprocessor.sitemap.MatchNode.invoke(MatchNode.java:87)
...
...

at
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
Caused by: java.lang.NullPointerException
	at java.io.File.<init>(File.java:222)
	at org.exist.http.servlets.XQueryServlet.process(XQueryServlet.java:265)
	at org.exist.http.servlets.XQueryServlet.doGet(XQueryServlet.java:164)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
	at
org.apache.cocoon.servletservice.ServletServiceContext$PathDispatcher.forward(ServletServiceContext.java:567)
	at
org.apache.cocoon.servletservice.ServletServiceContext$NamedDispatcher.forward(ServletServiceContext.java:503)
	at
org.apache.cocoon.servletservice.ServletConnection.connect(ServletConnection.java:130)
	at
org.apache.cocoon.servletservice.components.ServletSource.connect(ServletSource.java:167)
	at
org.apache.cocoon.servletservice.components.ServletSource.getInputStream(ServletSource.java:78)
	at
org.apache.cocoon.components.source.util.SourceUtil.getInputSource(SourceUtil.java:395)
	at
org.apache.cocoon.components.source.util.SourceUtil.parse(SourceUtil.java:264)
	at
org.apache.cocoon.generation.FileGenerator.generate(FileGenerator.java:144)
	at
org.apache.cocoon.components.pipeline.AbstractProcessingPipeline.processXMLPipeline(AbstractProcessingPipeline.java:542)

It seems it cannot find the file, but if I execute only the XQuery Servlet,
it works.
Here's my XQuery Servlet bean:
<bean id="com.mycompany.test2.service"
class="org.exist.http.servlets.XQueryServlet">
    <servlet:context mount-path="/test2"
context-path="blockcontext:/test2/"/>
</bean>

Any idea?

Regards,

Josh

-- 
View this message in context: http://www.nabble.com/servlet-mapping-in-Cocoon-2.2-bean--tp15028682p15096282.html
Sent from the Cocoon - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: servlet-mapping in Cocoon 2.2 bean?

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Josh2007 pisze:
> Hi,
> 
> I'm implementing an Xquery Servlet as a block in Cocoon 2.2
> Prior to Cocoon 2.2 I was able to define servlet-mapping in my web.xml.
> Now, is there a way to get the same result when the Servlet is declared as a
> Spring bean?

You can still use web.xml for defining servlet-mapping but using SSF[1] and definig a servlet as a
Spring bean is advised because it brings several serious advantages.

> something like:
> 
> <bean name="XqueryServlet" class="org.my.class.servlets.XqueryServlet">
>     <servlet:context mount-path="/xquery"
> context-path="blockcontext:/xquery/">
>     <servlet:init-params>
>     <entry key="basedir" value="WEB-INF"/>
>     <entry key="start" value="true"/>
>     </servlet:init-params>
>     <servlet:mapping>
>     <entry value="*.xq"/>
>     <entry value="*.xql"/>
>     </servlet:mapping>
>     </servlet:context>
>     </bean>
> 

Yep, such configuration should work well apart from I'm not sure about <entry value="*.xq"/> is put
in a right place.

If you have more specific questions/troubles don't hesitate to ask.

[1] http://cocoon.zones.apache.org/daisy/cdocs-servlet-service-impl/g1/1412.html

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org