Am 22.07.2013 16:10, schrieb Thorsten Scherler:
On 07/22/2013 12:17 PM, Piratenvisier wrote:
I have some problem getting the Restexample running:
In the pom I have :

<dependency>
  <groupId>org.apache.cocoon.pipeline</groupId>
  <artifactId>cocoon-pipeline</artifactId>
  <version>${cocoon.version}</version>
</dependency>

<dependency>
<groupId>org.apache.cocoon.databases</groupId>
  <artifactId>cocoon-databases</artifactId>
<version>${cocoon.version}</version>
</dependency>

<dependency>
   <groupId>org.apache.cocoon.sax</groupId>
   <artifactId>cocoon-sax</artifactId>
   <version>${cocoon.version}</version>
</dependency>

 <dependency>
      <groupId>org.apache.cocoon.rest</groupId>
      <artifactId>cocoon-rest</artifactId>
  <version>${cocoon.version}</version>
    </dependency>

    <dependency>
<groupId>org.apache.cocoon.stringtemplate</groupId>
<artifactId>cocoon-stringtemplate</artifactId>
  <version>${cocoon.version}</version>
    </dependency>

<dependency>
  <groupId>org.apache.cocoon.wicket</groupId>
  <artifactId>cocoon-wicket</artifactId>
  <version>${cocoon.version}</version>
</dependency>

  <dependency>
<groupId>org.apache.cocoon.optional</groupId>
      <artifactId>cocoon-optional</artifactId>
      <version>${cocoon.version}</version>
    </dependency>

 <dependency>
      <groupId>org.apache.xmlgraphics</groupId>
      <artifactId>fop</artifactId>
      <version>1.0</version>
    </dependency>

 <dependency>
   <groupId>org.apache.cocoon</groupId>
<artifactId>cocoon-serializers-charsets</artifactId>
<version>${cocoon.serializers.charset.version}</version>
    </dependency>
    </dependencies>

my sitemap includes :

 <map:pipeline>

      <map:match pattern="controller/{id}/{name}">
<controller:call controller="rest-controller" select="org.apache.cocoon.sample.controller.DemoRESTController">
          <map:parameter name="id" value="{map:id}" />
          <map:parameter name="name" value="{map:name}" />
        </controller:call>
      </map:match>
    </map:pipeline>
    <map:pipeline type="noncaching">
      <map:match pattern="controller/screen">
<map:generate src="controller/demo.html" type="controller-aware-string-template" />
        <map:serialize type="xml" status-code="202" />
      </map:match>
    </map:pipeline>

I included cocoon-sample-controller.xml :

<beans xmlns="http://www.springframework.org/schema/beans"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:p="http://www.springframework.org/schema/p"; xmlns:aop="http://www.springframework.org/schema/aop";
  xmlns:context="http://www.springframework.org/schema/context";
  xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
  ">

  <!-- Scan for all REST controllers and make them as beans available -->
<context:component-scan base-package="org.apache.cocoon.sample.controller" use-default-filters="false"
name-generator="org.apache.cocoon.rest.controller.ControllerBeanNameGenerator"
scope-resolver="org.apache.cocoon.rest.controller.ControllerBeanScopeResolver">
<context:include-filter type="annotation" expression="org.apache.cocoon.rest.controller.annotation.RESTController" />
  </context:component-scan>

  <context:annotation-config />

<bean id="org.apache.cocoon.sample.controller.aspect1" class="org.apache.cocoon.sample.controller.DemoRESTControllerAspect1" /> <bean id="org.apache.cocoon.sample.controller.aspect2" class="org.apache.cocoon.sample.controller.DemoRESTControllerAspect2" />
</beans>

and cocoon-sample-servlet-service.xml:

<beans xmlns="http://www.springframework.org/schema/beans";
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
       xmlns:servlet="http://cocoon.apache.org/schema/servlet";
       xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cocoon.apache.org/schema/servlet
http://cocoon.apache.org/schema/servlet/cocoon-servlet-1.0.xsd";>

  <!-- A Cocoon-Sitemap based servlet-service. -->

<bean id="org.apache.cocoon.sample.servlet" class="org.apache.cocoon.servlet.XMLSitemapServlet">
here I am not sure if I did this the right way:
<servlet:context mount-path="" context-path="jar:classpath:/WEB-INF/lib/cocoon-servlet-3.0.0-beta-1-SNAPSHOT!/webapp/"/>
  </bean>

  <!-- A servlet-service that exposes JAX-RS REST endpoints. -->
<!-- <bean id="org.apache.cocoon.sample.rest.servlet" class="org.apache.cocoon.rest.jaxrs.container.CocoonJAXRSServlet"> <servlet:context mount-path="/jax-rs" context-path="jar:classpath:lib/${project.build.finalName}.jar!/COB-INF/">
      <servlet:connections>
<entry key="sample" value-ref="org.apache.cocoon.sample.servlet" />
      </servlet:connections>
    </servlet:context>

    <property name="restResourcesList">
      <list>
        <ref bean="org.apache.cocoon.sample.rest.resource.one" />
        <ref bean="org.apache.cocoon.sample.rest.resource.two" />
      </list>
    </property>
  </bean>-->
</beans>

in web.xml the only part of importance is :

 <context-param>
<param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/applicationContext-resources.xml
            classpath:/applicationContext-dao.xml
            classpath:/applicationContext-service.xml
            /WEB-INF/applicationContext*.xml
    /WEB-INF/cocoon-sample-*.xml
        </param-value>
    </context-param>

I get the error:

java.net.MalformedURLException: unknown protocol: servlet at java.net.URL.<init>(URL.java:592) at java.net.URL.<init>(URL.java:482) at java.net.URL.<init>(URL.java:431) at org.apache.cocoon.rest.controller.response.URLResponse.<init>(URLResponse.java:49) at org.apache.cocoon.sample.controller.DemoRESTController.doGet(DemoRESTController.java:54)


Not sure but seems that he cannot resolve: return new URLResponse("servlet:/controller/screen", data);
When I went back to the original distribution without any changes and even when I try new URL(new URL("servlet:"),"servlet:/controller/screen") I get the same error,although I think that I once had success with the distribution. But I see a strong tendenca to a programmed pipeline and I found myself even without cocoon on this way.

However that seems pretty much as the sample block.
Try just to start cocoon-rest-optional and do mvn clean install jetty:run

I just added a small sample (I consider it quite clean) to use a pipeline in your java code.
How should i call the Restcontroller from the browser and what result should I see ?

HTH

salu2
--
Thorsten Scherler <scherler.at.gmail.com>
codeBusters S.L. - web based systems
<consulting, training and solutions>

http://www.codebusters.es/

Reply via email to