Cayenne User Documentation
Remote Object Persistence Tutorial WebService

## Setting up Dependencies

Now lets get back to the `"tutorial"` project that contains a web application and set up dependencies. The only extra one that we don't have yet is `resin-hessian.jar`, just like the client, so let's add it (and the caucho repo declaration) to the `pom.xml`.

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    	...
    	<dependencies>
    		...
    		<dependency>
    			<groupId>com.caucho</groupId>
    			<artifactId>resin-hessian</artifactId>
    			<version>3.1.6</version>
    		</dependency>
    	</dependencies>

    	<build>
    	...
    	</build>

    	<repositories>
    		<repository>
    			<id>caucho</id>
    			<name>Caucho Repository</name>
    			<url>http://caucho.com/m2</url>
    			<layout>default</layout>
    			<snapshots>
    				<enabled>false</enabled>
    			</snapshots>
    			<releases>
    				<enabled>true</enabled>
    			</releases>
    		</repository>
    	</repositories>
    </project>

| Maven Optimization Hint On a real project both server and client modules will likely share a common parent pom.xml where common repository delcaration can be placed, with child pom's "inheriting" it from parent. This would reduce build code duplication.

## Client Classes on the Server

Since ROP web service requires both server and client persistent classes, we need to generate a second copy of the client classes inside the server project (see instructions here, just pick the server project as a class generation target). This is a minor inconvenience that will hopefully go away in the future versions of Cayenne. Don't forget to refresh the project in Eclipse after class generation is done.

## Configuring `web.xml`

Cayenne web service is declared in the `web.xml`. It is implemented as a servlet `"org.apache.cayenne.remote.hessian.service.HessianServlet"`. Open `tutorial/src/main/webapp/WEB-INF/web.xml` in Eclipse and add a service declaration (you may keep the Cayenne filter declaration left there from the previous tutorial, or you can start clean, either way will work) :

    <?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>
    	<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>
    </web-app>

| Extending Server Behavior via Callbacks While no custom Java code is required on the server, just a service declaration, it is possible to customizing server-side behavior via callbacks and listeners (not shown in the tutorial).

## Running ROP Server

Use previosly created Eclipse Jetty run configuration available via `"Run > Run Configurations..."` (or create a new one if none exists yet). You should see output in the Eclipse console similar to the following:

    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Cayenne Tutorial
    [INFO]
    [INFO] Id: org.example.cayenne:tutorial:jar:0.0.1-SNAPSHOT
    [INFO] task-segment: [jetty:run]
    [INFO] ------------------------------------------------------------------------
    ...
    [INFO] [jetty:run]
    [INFO] Configuring Jetty for project: Cayenne Tutorial
    [INFO] Webapp source directory = /Users/andrus-tutorial/Desktop/work/tutorial/src/main/webapp
    ...
    [INFO] Starting jetty 6.1.22 ...
    2010-01-16 17:22:16.906:INFO::jetty-6.1.22
    2010-01-16 17:22:17.027:INFO::No Transaction manager found - if your webapp requires one, please configure one.
    INFO: started configuration loading.
    INFO: loaded domain: UntitledDomain
    INFO: loaded <map name='UntitledDomainMap' location='UntitledDomainMap.map.xml'>.
    INFO: loading <node name='UntitledDomainNode' datasource='UntitledDomainNode.driver.xml'
    factory='org.apache.cayenne.conf.DriverDataSourceFactory' schema-update-strategy='org.apache.cayenne.access.dbsync.CreateIfNoSchemaStrategy'>.
    INFO: using factory: org.apache.cayenne.conf.DriverDataSourceFactory
    INFO: loading driver information from 'UntitledDomainNode.driver.xml'.
    INFO: loading driver org.apache.derby.jdbc.EmbeddedDriver
    INFO: loading user name and password.
    INFO: Created connection pool: jdbc:derby:memory:testdb;create=true
    	Driver class: org.apache.derby.jdbc.EmbeddedDriver
    	Min. connections in the pool: 1
    	Max. connections in the pool: 1
    INFO: loaded datasource.
    INFO: no adapter set, using automatic adapter.
    INFO: loaded map-ref: UntitledDomainMap.
    INFO: finished configuration loading in 549 ms.
    2010-01-16 17:22:17.960:INFO::Started SelectChannelConnector@0.0.0.0:8080

Cayenne ROP service URL is http://localhost:8080/tutorial/cayenne-service. If you click on it, you will see `"Hessian Requires POST"` message, that means that the service is alive, but you need a client other than the web browser to access it.

Next Step: Remote Object Persistence Tutorial Client Code

.
Copyright ©2001-2010 Apache Software Foundation