  | | | Migrating to Cocoon 2.2... calling servlets from Cocoon: ServletServiceGener | Migrating to Cocoon 2.2... calling servlets from Cocoon: ServletServiceGener 2007-11-22 - By Grzegorz Kossakowski
Back Josh2007 pisze: > Hi, > > I'm migrating from Cocoon 2.1 to Cocoon 2.2. > Cocoon 2.2 is deployed as a servlet in Tomcat along with 2 other servlets: > Axis 2 and eXist xmldb. > > It seems with Cocoon 2.2 I can call my 2 other servlets from Cocoon and get > any xml result they will generate in my sitemap.
Yep, but you can only call servlets that are registered as Spring-beans, using configuration file like this[1]: <bean id="org.apache.cocoon.servletservice.demo1.servlet" class="org.apache.cocoon.servletservice.demo1.DemoServlet"> <servlet:context mount-path="/test1"> <servlet:init-params> <entry key="foo" value="baz"/> </servlet:init-params> <servlet:connections> <entry key="demo2" value-ref="org.apache.cocoon.servletservice.demo2 .servlet"/> </servlet:connections> </servlet:context> </bean>
In most cases it's not a big problem to configure servlets that way.
> Can I do that with ServletServiceGenerator? Is there any example? I've been > searching without success for now.
Actually, ServletServiceGenerator does something more than just fetching data from other servlets (it's a job of servlet source). Take a look at this example[2]:
<!-- This is a test of basic servlet services functionality servletService generator makes a HTTP POST request on servlet:test2: /basic-service. Generator posts content of test.xml file and returns to the pipeline result of service call. --> <map:match pattern="test5"> <map:generate type="servletService" src="test.xml"> <map:parameter name="service" value="servlet:test2:/basic-service ?caller=generator"/> </map:generate> <map:serialize type="xml"/> </map:match>
The comment above the match explains what happens quite well. The idea is to fetch data that is based on POSTed data. This way servlet:test2:/basic-service can be viewed as pipeline *fragment* looking even implementation[2] looks like this: <!-- This basic service pipeline takes POSTed XML and applays simple transformation on it --> <map:match pattern="basic-service"> <map:generate src="service-consumer:"/> <map:transform src="service-test.xsl"> <map:parameter name="caller" value="{request-param:caller}"/> </map:transform> <map:serialize type="xml"/> </map:match>
> Will my sitemap look like this? > > <map:pipeline> > <map:match pattern="test"> > <map:generate src="anySoapRequest.xml" type="ServletServiceGenerator"/> > <map:serialize type="xml"/> > </map:match> > </map:pipeline>
I would say it would look like this: <map:pipeline> <map:match pattern="test"> <map:generate src="servlet:axis:/anySoapRequest" type="file"/> <map:serialize type="xml"/> </map:match> </map:pipeline>
> Thanks for your help,
I suggest to take a closer look at cocoon-servlet-service-sample module that contains some simple demos. Of course they are not ideal but at least they present the most important features of Servlet Service Framework.
I hope that helps a little.
[1] http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-servlet-service/cocoon -servlet-service-sample/src/main/resources/META-INF/cocoon/spring/cocoon-servlet -service-demo1-servletService.xml [2] http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-servlet-service/cocoon -servlet-service-sample/src/main/resources/COB-INF/test1/sitemap.xmap [3] http://svn.apache.org/repos/asf/cocoon/trunk/core/cocoon-servlet-service/cocoon -servlet-service-sample/src/main/resources/COB-INF/test2/sitemap.xmap
-- Grzegorz Kossakowski Committer and PMC Member of Apache Cocoon http://reflectingonthevicissitudes.wordpress.com/
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ------ To unsubscribe, e-mail: users-unsubscribe@(protected) For additional commands, e-mail: users-help@(protected)
|
|
 |