blob: 27fd7827dd6e05bd3027e97b227af5c6a432aa44 [file] [log] [blame]
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>&quot;cayenne-tutorial&quot;</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>&quot;cayenne-tutorial&quot;</TT> project, selecting <TT>&quot;Java Build Path &gt; Libraries&quot;</TT> and clicking &quot;Add External Jar&quot; 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">...
&lt;servlet&gt;
&lt;servlet-name&gt;cayenne-service&lt;/servlet-name&gt;
&lt;servlet-class&gt;org.objectstyle.cayenne.remote.hessian.service.HessianServlet&lt;/servlet-class&gt;
&lt;/servlet&gt;
&lt;servlet-mapping&gt;
&lt;servlet-name&gt;cayenne-service&lt;/servlet-name&gt;
&lt;url-pattern&gt;/cayenne-service&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;</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">&lt;?xml version=<SPAN class="code-quote">&quot;1.0&quot;</SPAN> encoding=<SPAN class="code-quote">&quot;utf-8&quot;</SPAN>?&gt;
&lt;!DOCTYPE web-app
PUBLIC <SPAN class="code-quote">&quot;-<SPAN class="code-comment">//Sun Microsystems, Inc.//DTD Web Application 2.3//EN&quot;</SPAN>
</SPAN> <SPAN class="code-quote">&quot;http:<SPAN class="code-comment">//java.sun.com/dtd/web-app_2_3.dtd&quot;</SPAN>&gt;
</SPAN>&lt;web-app&gt;
&lt;display-name&gt;Cayenne Tutorial&lt;/display-name&gt;
&lt;filter&gt;
&lt;filter-name&gt;CayenneFilter&lt;/filter-name&gt;
&lt;filter-class&gt;org.objectstyle.cayenne.conf.WebApplicationContextFilter&lt;/filter-class&gt;
&lt;/filter&gt;
&lt;filter-mapping&gt;
&lt;filter-name&gt;CayenneFilter&lt;/filter-name&gt;
&lt;url-pattern&gt;/&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;
&lt;filter-mapping&gt;
&lt;filter-name&gt;CayenneFilter&lt;/filter-name&gt;
&lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt;
&lt;/filter-mapping&gt;
&lt;servlet&gt;
&lt;servlet-name&gt;cayenne-service&lt;/servlet-name&gt;
&lt;servlet-class&gt;org.objectstyle.cayenne.remote.hessian.service.HessianServlet&lt;/servlet-class&gt;
&lt;/servlet&gt;
&lt;servlet-mapping&gt;
&lt;servlet-name&gt;cayenne-service&lt;/servlet-name&gt;
&lt;url-pattern&gt;/cayenne-service&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
&lt;welcome-file-list&gt;
&lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
&lt;/welcome-file-list&gt;
&lt;/web-app&gt;</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 &quot;Hessian Requires POST&quot; 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>&quot;cayenne-tutorial&quot;</TT> project, select <TT>&quot;Java Build Path &gt; Projects &gt; Add...&quot;</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>