Cayenne User Documentation
Remote Object Persistence Tutorial WebService

### Deploying a Web Service

Now lets get back to the `"cayenne-tutorial"` project that contains a web application.

- Add `hessian.jar` to the list of project libraries by right clicking the `"cayenne-tutorial"` project, selecting `"Java Build Path > Libraries"` and clicking "Add External Jar" button on the right. As a reminder, Hessian jar can be downloaded from here if you haven't done this already.

- Cayenne web service is specified declaratively in `web.xml`. It is simply a servlet - `org.objectstyle.cayenne.remote.hessian.service.HessianServlet`. No extra code is needed on the server. Open `cayenne-tutorial/webapp/WEB-INF/web.xml` in Eclipse and add the servlet section.

web.xml

    ...
    <servlet>
        <servlet-name>cayenne-service</servlet-name>
        <servlet-class>org.apache.cayenne.remote.hessian.service.HessianServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>cayenne-service</servlet-name>
        <url-pattern>/cayenne-service</url-pattern>
    </servlet-mapping>

- Since our web application serves JSP files as well, you also need to remap Cayenne Filter setup earlier, so that it only applies to JSPs. The resulting complete `web.xml` will look like this:

web.xml

    <?xml version="1.0" encoding="utf-8"?>
     <!DOCTYPE web-app
       PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
       "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
        <display-name>Cayenne Tutorial</display-name>
        <filter>
            <filter-name>CayenneFilter</filter-name>
            <filter-class>org.apache.cayenne.conf.WebApplicationContextFilter</filter-class>
        </filter>
        <filter-mapping>
            <filter-name>CayenneFilter</filter-name>
            <url-pattern>/</url-pattern>
        </filter-mapping>
        <filter-mapping>
            <filter-name>CayenneFilter</filter-name>
            <url-pattern>*.jsp</url-pattern>
        </filter-mapping>

        <servlet>
            <servlet-name>cayenne-service</servlet-name>
            <servlet-class>org.apache.cayenne.remote.hessian.service.HessianServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>cayenne-service</servlet-name>
            <url-pattern>/cayenne-service</url-pattern>
        </servlet-mapping>

        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>

- Now you can run the web application (that contains a web service) with JettyLauncher, as described before.

- Web application URLs (e.g. http://localhost:8080/) should continue to work as before, but let's try the service URL: http://localhost:8080/cayenne-service. You will see "Hessian Requires POST" error message in the browser, that means that the service is alive, but you need a client other than the web browser to access it.

Now you can shutdown the web application in Eclipse.

### Final Step...

As of version 1.2, both client and server persistent classes need to be present on the server (client of course only needs client classes). This is a minor inconvenience that will be addressed in the future releases. To satisfy this requirement, right click the `"cayenne-tutorial"` project, select `"Java Build Path > Projects > Add..."` and add `cayenne-tutorial-client` as a project dependency.

Next Step: Remote Object Persistence Tutorial Client Code

.
Copyright ©2001-2008 Apache Software Foundation