| Title: Remote Object Persistence Tutorial WebService |
| |
| |
| <H3><A name="RemoteObjectPersistenceTutorialWebService-DeployingaWebService"></A>Deploying a Web Service</H3> |
| |
| <P>Now lets get back to the <TT>"cayenne-tutorial"</TT> project that contains a web application. </P> |
| |
| <UL> |
| <LI>Add <TT>hessian.jar</TT> to the list of project libraries by right clicking the <TT>"cayenne-tutorial"</TT> project, selecting <TT>"Java Build Path > Libraries"</TT> and clicking "Add External Jar" button on the right. As a reminder, Hessian jar can be downloaded <A href="http://www.caucho.com/hessian/" class="external-link" rel="nofollow">from here</A> if you haven't done this already.</LI> |
| </UL> |
| |
| |
| <UL> |
| <LI>Cayenne web service is specified declaratively in <TT>web.xml</TT>. It is simply a servlet - <TT>org.objectstyle.cayenne.remote.hessian.service.HessianServlet</TT>. No extra code is needed on the server. Open <TT>cayenne-tutorial/webapp/WEB-INF/web.xml</TT> in Eclipse and add the servlet section.</LI> |
| </UL> |
| |
| |
| <DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>web.xml</B></DIV><DIV class="codeContent panelContent"> |
| <PRE class="code-java">... |
| <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></PRE> |
| </DIV></DIV> |
| |
| <UL> |
| <LI>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 <TT>web.xml</TT> will look like this:</LI> |
| </UL> |
| |
| |
| <DIV class="code panel" style="border-width: 1px;"><DIV class="codeHeader panelHeader" style="border-bottom-width: 1px;"><B>web.xml</B></DIV><DIV class="codeContent panelContent"> |
| <PRE class="code-java"><?xml version=<SPAN class="code-quote">"1.0"</SPAN> encoding=<SPAN class="code-quote">"utf-8"</SPAN>?> |
| <!DOCTYPE web-app |
| PUBLIC <SPAN class="code-quote">"-<SPAN class="code-comment">//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"</SPAN> |
| </SPAN> <SPAN class="code-quote">"http:<SPAN class="code-comment">//java.sun.com/dtd/web-app_2_3.dtd"</SPAN>> |
| </SPAN><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></PRE> |
| </DIV></DIV> |
| |
| <UL> |
| <LI>Now you can run the web application (that contains a web service) with JettyLauncher, as described <A href="tutorial-webapp.html" title="Tutorial Webapp">before</A>.</LI> |
| </UL> |
| |
| |
| <UL> |
| <LI>Web application URLs (e.g. <A href="http://localhost:8080/" class="external-link" rel="nofollow">http://localhost:8080/</A>) should continue to work as before, but let's try the service URL: <A href="http://localhost:8080/cayenne-service" class="external-link" rel="nofollow">http://localhost:8080/cayenne-service</A>. 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.</LI> |
| </UL> |
| |
| |
| <P>Now you can shutdown the web application in Eclipse.</P> |
| |
| <H3><A name="RemoteObjectPersistenceTutorialWebService-FinalStep..."></A>Final Step...</H3> |
| |
| <P>As of version 1.2, both client and server persistent classes need to be present <B>on the server</B> (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 <TT>"cayenne-tutorial"</TT> project, select <TT>"Java Build Path > Projects > Add..."</TT> and add <TT>cayenne-tutorial-client</TT> as a project dependency.</P> |
| |
| <HR> |
| <P><B>Next Step: <A href="remote-object-persistence-tutorial-client-code.html" title="Remote Object Persistence Tutorial Client Code">Remote Object Persistence Tutorial Client Code</A></B></P> |
| <HR> |