You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ch...@apache.org on 2006/11/10 10:15:38 UTC

svn commit: r473279 - in /webservices/axis2/branches/java/1_1/modules/samples/servicelifecycle/doc: ./ servicelifecycleguide.html

Author: chatra
Date: Fri Nov 10 01:15:37 2006
New Revision: 473279

URL: http://svn.apache.org/viewvc?view=rev&rev=473279
Log:
adding a guide for service life cycle sample

Added:
    webservices/axis2/branches/java/1_1/modules/samples/servicelifecycle/doc/
    webservices/axis2/branches/java/1_1/modules/samples/servicelifecycle/doc/servicelifecycleguide.html

Added: webservices/axis2/branches/java/1_1/modules/samples/servicelifecycle/doc/servicelifecycleguide.html
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/samples/servicelifecycle/doc/servicelifecycleguide.html?view=auto&rev=473279
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/samples/servicelifecycle/doc/servicelifecycleguide.html (added)
+++ webservices/axis2/branches/java/1_1/modules/samples/servicelifecycle/doc/servicelifecycleguide.html Fri Nov 10 01:15:37 2006
@@ -0,0 +1,190 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+       "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+  <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
+  <title>Service Life Cycle Sample Guide</title>
+  <meta name="generator" content="amaya 9.2.1, see http://www.w3.org/Amaya/"
+  />
+</head>
+
+<body>
+<h1>Service Life Cycle Sample Guide</h1>
+
+<h2>Introduction</h2>
+
+<p>This sample is to demonstrate usage of a service life cycle interface and
+session scoping with a sample on application scope session. The sample
+consists of two parts, Service and Client.</p>
+
+<p>Let's take a library system, which has the following operations, as the
+scenario for this sample.</p>
+<ul>
+  <li>Register user</li>
+  <li>Login to system</li>
+  <li>View all books</li>
+  <li>View available books</li>
+  <li>View lend books</li>
+  <li>Lend and return books</li>
+</ul>
+
+<h2>Why Do We Need Service Life Cycle Here?</h2>
+
+<p>In order to make sure that at the runtime service impl class can access
+data read from anywhere, we need to initialize the service at deployment.
+Let's forget about the session for a minute and think about the scenario
+where you want to populate a bean or need to start a Data Base connection for
+the service. In such a situation having service life cycle class is very
+useful.</p>
+
+<p>In this sample you will learn how to use the service life cycle class for
+your application. The interface has only two methods</p>
+<ol>
+  <li>startUp</li>
+  <li>shutDown</li>
+</ol>
+
+<p>Where startUp method will be called when the service is deployed and it
+will call only once for that particular service, while shutDown method calls
+when system shutdown.</p>
+
+<p>So in this sample, the life cycle class will load the library inside the
+startUp method. At the very first time the system will load from
+services.xml. It has all the available books in the system. And at the time
+of system shutdown it will save the status of the library into a file
+(library.xml) in the java.io.temp directory. So the next time onwards it will
+populate library using the above file. So all the changes will be there in
+the new instance as well.</p>
+
+<h2>Prerequisites</h2>
+
+<p>We have the option of running the sample client using <a
+href="http://ant.apache.org/">Apache Ant</a>. In which case you will have to
+install Apache Ant 1.6.2 or later.</p>
+
+<h2>Running the Sample</h2>
+
+<h3>How to Build the Service?</h3>
+
+<p>Building the service is just a matter of running ant build file. It will
+create the service aar file, or you could just run the copy.to.tomcat goal
+which will copy the aar file into tomcat/web-app/axis2/WEB-INF/services
+directory.</p>
+
+<p>Next, go to http://[url and port to your app server]/axis2 and see whether
+your service is listed there.</p>
+
+<h3>How to Run the Client</h3>
+
+<p>You can invoke complete service using REST API, but it only works in
+application servers like Apache Tomcat and it will not work in
+SimpleHttpServer. First try to use library system using REST API.</p>
+
+<p>This sample is a simple one and will not do complex tasks. So let's follow
+steps given below to make sure that the sample works as it should:</p>
+
+<p><strong>Step 1</strong>:- View all the available books in the library,
+just type the following URL on your favorite browser.</p>
+
+<p>http://127.0.0.1:8080/axis2/rest/Library/listAvailableBook</p>
+
+<p>You will see all the available books in the system</p>
+
+<p><strong>Step 2</strong> : View all the books in the system at
+http://127.0.0.1:8080/axis2/rest/Library/listAllBook</p>
+
+<p>In this case you will get exactly the same result for both the request,
+since no one has borrowed the book.</p>
+
+<p><strong>Step 3</strong>: Now look at all the lent books in the system. And
+you will see an empty list at
+http://127.0.0.1:8080/axis2/rest/Library/listLendBook</p>
+
+<p><strong>Step 4</strong> : Register a user. To lend a book or return a
+book, you need to register first. Do not register twice, if you try to do so
+you will get an exception.</p>
+
+<p>To register you need to give user name and password (have a look at the
+wsdl at http://127.0.0.1:port/axis2/services/serviceName?wsdl. You will see
+what you need to pass in)</p>
+
+<p>So let's create a user called 'foo' with the password '123'</p>
+
+<p>http://127.0.0.1:8080/axis2/rest/Library/register?userName=foo&amp;passWord=123</p>
+
+<p>Then you will get the following response, if everything has gone well.</p>
+<pre>&lt;ns:registerResponse&gt;
+&lt;ns:return&gt;true&lt;/ns:return&gt;
+&lt;/ns:registerResponse&gt;</pre>
+
+<p><strong>Step 5</strong> : Log into system. To log in you need to pass user
+name and password. So let's try to login to system.</p>
+
+<p>http://127.0.0.1:8080/axis2/rest/Library/login?userName=foo&amp;passWord=123</p>
+
+<p><strong>Step 6</strong> : Now we are ready to lend a book. To lend a book
+you need to pass isbn and userName. Let's try to lend the book with isbn
+0-937175-77-3, your request would look like below:</p>
+
+<p>http://127.0.0.1:8080/axis2/rest/Library/lendBook?isbn=0-937175-77-3&amp;userName=foo</p>
+
+<p>If everything went well, you will see the following response in the
+browser.</p>
+<pre>&lt;ns:lendBookResponse&gt;
+&lt;ns:return&gt;
+&lt;author&gt;John Bloomer&lt;/author&gt;
+&lt;isbn&gt;0-937175-77-3&lt;/isbn&gt;
+&lt;title&gt;Power Programming with RPC&lt;/title&gt;
+&lt;/ns:return&gt;
+&lt;/ns:lendBookResponse&gt;</pre>
+
+<p><strong>Step 7</strong> : Now go and look at lent list again at
+http://127.0.0.1:8080/axis2/rest/Library/listLendBook, you will see the
+following output in the browser.</p>
+<pre>&lt;ns:listLendBookResponse&gt;
+&lt;ns:return&gt;
+&lt;author&gt;John Bloomer&lt;/author&gt;
+&lt;isbn&gt;0-937175-77-3&lt;/isbn&gt;
+&lt;title&gt;Power Programming with RPC&lt;/title&gt;
+&lt;/ns:return&gt;
+&lt;/ns:listLendBookResponse&gt;</pre>
+
+<p>That's the book you just lent!</p>
+
+<p>Note : Now if we view the available books, you will not see the above book
+in that list.</p>
+
+<p><strong>Step 8</strong> : Now let's return the book.</p>
+
+<p>http://127.0.0.1:8080/axis2/rest/Library/returnBook?isbn= 0-937175-77-3</p>
+
+<p><strong>Step 9</strong> : Now let's look at the lent book list again, and
+you will realize that list is empty.</p>
+
+<p><strong>Step 10</strong> : Lend few more book and re-start the app server
+(say Tomcat), and see whether all the previous data is there in the new
+instance.</p>
+
+<h3>Running Java Client</h3>
+
+<p>Open up the LibraryServiceClient java class in your favorite IDE and run
+the main class. And you can comment and un-comment whatever method depending
+on what you want to invoke.</p>
+
+<p>Java client also can be run using <a href="http://ant.apache.org/">Ant</a>.
+</p>
+
+<p>=============================</p>
+
+<p>invoke</p>
+
+<p>ant run.client</p>
+
+<p></p>
+
+<p>And then follow the instructions as mentioned in the console.</p>
+
+<p></p>
+</body>
+</html>



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org