Bogger Hot Links Widget That displays Summaries of Your Articles

Everyone wants to decorate their blogs with cool stuff. But rather than select widgets produced by blogger that are on a zillion other pages too, how about something new? Something new AND useful that will tempt users to stay on your blog by clicking more links. Described below is the Hot Links widget and how to integrate it with your blog. Have a look at the widget below. In this example it is configured to work with blog justtufun.blogspot.com . You can refresh the page a couple of time to see the widget change. Leave any questions or problems as comments and I will endeavour to answer them.



The widget will show an image if it's available. If not it will show 150 letters of text from the article.

What you need
AccountDescription
Blogger accountTo create and insert the widget
Free hosting accountSomething like googlepages etc, to host your html file


Installing the Widget
  • Download the single html file here. Extract the hotlinks.html file.
  • Log in to blogger and at the dashboard click on new posts, settings, layout etc of your blog. Go to the address box in your browser and get your blogid. It should look something like this

    http://www.blogger.com/posts.g?blogID=4928424574574982882
    What you are after is the big number after 'blogID=', i.e. your blog-id.
  • Edit the hotlinks.html - near line 39. Replace the blogid with your blog-id you obtained in the previous step. A full listing of the code can be found at the end of this page.

    37.  
    38.  /************************Edit this section with your details*******************/
    39.  //The number of links you want to appear.
    40.  nooflinks=5;
    41.  //Your blog id
    42.  blogid="2004095058158627785";
    43.  /******************************************************************************/
    44.
    
  • Save this file. You can click on the file. It should load the articles.
  • Upload this page to one of your free sites - example: http://www.mysite.com/hotlinks.html.
  • Go to layout in your blogger dashboard. Click Add a Gadget and select HTML/JavaScript gadget. Enter the below text into the box. Replace www.mysite.com/hotlinks.html with the place where you uploaded the page. There is no need for a title. Save it.

    1.  <iframe scrolling="no" 
    2.      frameborder="no" 
    3.      width="100%"      
    4.      src="http://righteous.ninja.googlepages.com/hotlinks.html>
    5.  </iframe>
  • The best place to place this Gadet is on top of your 'Blog Posts' in the layout.
  • Save your layout and now view your blog. It should be all good.
Code Listing

1.  <html>
2.  <head>
3.  <title></title>
4.  <!--****************************************************************************
5.  * Please feel free to use this code whichever way you feel fit. 
6.  * But don't forget that Ping Ching aka Righteous thought about it first!!!! 2008
7.  * ***************************************************************************-->
8.  <style  TYPE="text/css">
9.  .hotlinks_href{
10.      font-family:arial;
11.      font-size:9px;
12.      color:black;
13.      font-weight:bold}
14.  .hotlinks_summary{
15.      font-family:arial;
16.      font-size:9px;
17.      color:black;}
18.  .hotloading{
19.      font-family:arial;
20.      font-size:12px;
21.      font-weight:bold;}
22.  table{
23.    border-collapse:collapse;}    
24.  table td{
25.      vertical-align:top;}
26.  .hotlink_learn{
27.      color:#808080;
28.      font-family:arial;
29.      font-size:8px;}
30.  </style>
31.  <script type="text/javascript" src="http://www.google.com/jsapi"></script>
32.  <script>
33.  google.load("gdata", "1.s")
34.  google.setOnLoadCallback(getMyBlogFeed);
35.  var rc=0;
36.  var hrefs = new Array();
37.  
38.  /************************Edit this section with your details*******************/
39.  //The number of links you want to appear.
40.  nooflinks=5;
41.  //Your blog id
42.  blogid="2004095058158627785";
43.  /******************************************************************************/
44.  
45.  function InitContainers(){
46.      var s="<table cellpadding=\"5\" border='0' width='100%'><tr>";
47.      for (i=0;i<nooflinks;i++)
48.          s+="<td><div id=\"t"+i+"\"><font class='hotloading'>loading...</font></div></td>";
49.      s+="</tr></table>";
50.      document.getElementById("container").innerHTML=s;
51.  }
52.  
53.  function Draw(r, r2, r3, r4){
54.      var text;
55.      if(r3==null)
56.          text="<font class=\"hotlinks_summary\">"+r4+"...</font>";
57.      else
58.          text="<center><a target=\"_top\" href=\""+hrefs[r]+"\"><img border=\"0\" height=\"90px\" src=\""+r3+"\"/></center>"
59.      document.getElementById("t"+rc).innerHTML="<center><a target=\"_top\" href=\""+hrefs[r]+"\" class=\"hotlinks_href\">"+r2+"</a><br/></center>"+text;
60.      rc+=1;
61.  }
62.  
63.  function getMyBlogFeed(){
64.      InitContainers();
65.      var bloggerService = new google.gdata.blogger.BloggerService('GoogleInc-jsguide-1.0');
66.      var feedUri = "http://www.blogger.com/feeds/"+blogid+"/posts/full";
67.      var handleBlogPostFeed = function(postsFeedRoot) {
68.          var blogTitle = postsFeedRoot.feed.getTitle().getText();
69.              for(i=0 ; i<nooflinks ; i++){
70.                  var g=Math.round(postsFeedRoot.feed.getEntries().length*Math.random());
71.                  var postEntry = postsFeedRoot.feed.getEntries()[g]; // only get first post
72.                  var entryUri = postEntry.getSelfLink().getHref();   // post's uri
73.                  hrefs[postEntry.getId().getValue()] = postEntry.getHtmlLink().getHref();
74.                  bloggerService.getBlogPostEntry(entryUri, 
75.                      function(postRoot) {
76.                          var r3,r4;
77.                        var postTitle = postRoot.entry.getTitle().getText(); 
78.                      var text=postRoot.entry.getContent().getText();
79.                          if((s = text.indexOf("src=\"http://")) != -1 &&
80.                               (e = text.substr(s).toLowerCase().indexOf(".jpg\"")) !=-1){
81.                              r3 = text.substring(s+5,s+e+4);
82.                          }
83.                          else
84.                              r3=null;
85.                          r4=text.substring(0,150); //The amount of text to appear instead of an image
86.                          Draw(postRoot.entry.getId().getValue(),postTitle, r3, r4);    
87.                      }, 
88.                      handleError
89.                  );
90.              }
91.          };
92.          var handleError = function(error) {
93.      };
94.      var query = new google.gdata.blogger.BlogPostQuery("http://www.blogger.com/feeds/"+blogid+"/posts/default");
95.      query.setMaxResults(100);
96.      bloggerService.getBlogFeed(query, handleBlogPostFeed, handleError);
97.  }
98.  </script>
99.  </head>
100.  <body topmargin="0" leftmargin="0">
101.  <div id="container"></div>
102.  </body>
103.  </html>
104.  

Back to the tutorial trail | Home

Setting up Axis2 With Tomcat 6

Aim
To setup Axis2, do some tests and prepare for the axis tutorial (Web Serivces Example Using axis 2 and Tomcat). Also setup tcpmon required for SOAP debugging. Leave any questions or problems as comments and I will endeavour to answer them.

Assumptions
This article assumes that you have the JDK 1.5 or compatible already installed. Also you have a working and compatible version of tomcat installed and running. Tomcat is running on 8080 for this example.

Versions used in this example
Sofware/ComponentImage
Windows XP SP2N/A
Axis 2 (war)Axis2-1.4-war.zip
Axis 2 (bin)Axis2-1.4-bin.zip
tomcat 6apache-tomcat-6.0.18.zip
JDK 1.5.0N/A
Axis 1 (for tcpmon)axis-bin-1_4.zip
Links to these files can be found here.

Installing Axis2
  1. Download the Axis 2 war distribution (axis2-1.4-war.zip) and unzip it. Copy the axis2.war file to the webapps directory in your tomcat installation. After a couple of seconds you should see an axis2 directory automatically created by tomcat.
  2. `
  3. Go to http://127.0.0.1:8080/axis2. You should see a welcome message with the headings- Services, Validation and Administration.
  4. `
  5. Click on Administration, login using username 'admin' and password 'axis2.' have a play around. Your axis install is done.
  6. `
  7. Download the Axis 2 binary (axis2-1.4-bin.zip) distribution and unzip it to a directory. This is where all your tools and libs will be when we go to build a service.
  8. `
  9. You are now finished.

tcpmon (not required for axis 2, but useful for debugging)
  1. Download Axis 1 ( axis-bin-1_4.tar.gz). I'm doing this so I can get at the axis.jar file that contains tcpmon. I cannot seem to find tcpmon in the new Axis2 jars.
  2. `
  3. Unzip it to a directory ('D:\axis2-1.4.1-bin\' in this example).
  4. `
  5. Run the command below substituting the axis.jar directory with the location of your directory/file.

    .../anywhere>java -cp D:\axis2-1.4.1-bin\lib\axis.jar org.apache.axis.utils.tcpmon
    You should see a window with the tcpmon application. We'll be using this in the Axis2 tutorial

Back to the tutorial trail | Home

Setting Up JWSDP 2 With Tomcat 6

Aim
To set up the Java Web Services Development Pack 2 (JWSDP2) and configure Tomcat. There are versions of tomcat that come pre-configured with JSWDP support for the container. These can be downloaded from the Sun site - but this means a fresh install. We will be using vanilla tomcat install from Apache. Leave any questions or problems as comments and I will endeavour to answer them. The JWSDP is an alternative to using Axis.

Assumption
This article assumes that you have the JDK 1.5 already installed. Also you have a working and compatible version of tomcat installed and running. Tomcat is using port 8080 for this tutorial.

Versions used in this example
Sofware/ComponentImage
Windows XP SP2N/A
JWSDP 2jwsdp-2_0-windows-i586.exe
tomcat 6apache-tomcat-6.0.18.zip
Java JDK 1.5.0N/A
Links to these files can be found here.

Unzip/install JWSDP
  • You may wish to take a copy of your tomcat's 'bin' directory as files here will get replaced.
  • Download and install the jwsdp 2 (jwsdp-2_0-windows-i586.exe) make a note of the directory. 'C:\Sun\jwsdp-2.0' for this example. During the installation it will ask you whether you wish to download the tomcat conatiner - say no.
  • Go to jwsdp-shared\bin directory in your jwsdp install.
  • Edit the setenv.bat file. make sure all everything is pointing to the right places. This is what my environment looks like.
    set JAVA_HOME=D:\jdk1.5.0
    set ANT_HOME=C:\Sun\jwsdp-2.0\apache-ant
    set ANT_OPTS=-Djava.endorsed.dirs=C:\Sun\jwsdp-2.0\jaxp\lib\endorsed;C:\Sun\jwsdp-2.0\jaxp\lib
    set JWSDP_HOME=C:\Sun\jwsdp-2.0
    set CATALINA_HOME=C:\apache-tomcat-6.0.18

  • If you are using tomcat 6 then edit the jwsdpontomcat.bat file and make the change given below. Should be around line 52. basically get rid of the 'server.'
    original<available property="CATALINA_HOME" value="${catalina.home}"
    file="${catalina.home}/server/lib/catalina.jar" />
    modified<available property="CATALINA_HOME" value="${catalina.home}"
    file="${catalina.home}/lib/catalina.jar" />
    Tomcat six has a slightly altered directory structure from previous versions.
  • If you are using tomcat 6, edit jwsdpontomcat.xml and make the changes below. Should be round about line 43. Remove the 'server' from this line.
    original<available property="CATALINA_HOME" value="${catalina.home}"
    file="${catalina.home}/server/lib/catalina.jar" />
    modified<available property="CATALINA_HOME" value="${catalina.home}"
    file="${catalina.home}/lib/catalina.jar" />

  • Open a command prompt and 'cd' to the jwsdp-shared\bin directory in your jwsdp install.
  • Run setenv.bat.
  • Run jwsdpontomcat.bat. This will basically run ant on the jwsdpontomcat.xml file. It will copy everyting required over to your tomcat directory. At the end you should get the usual 'BUILD SUCCESSFUL' message.
  • Use a command prompt and cd into your tomcat bin directory. Your catalina.bat will now have been replaced with a new jwsdp version of if, have a look.
  • Run startup.bat. This should fire up your bootloader. You should see a small window open up in the right bottom hand side of your screen. The LauncheBootstrap will read the launcher.xml from your jswdb-shared\bin directory under your tomcat directory.
  • Go to your ./log directory under tomcat home and have a look at your 'launcher.server.log.' You may see a few ClassNotFound errors. Fix these by copying these files from your tomcat root directory to your tomcat lib directory.
    Tomcat
    _|_lib
    _|_saaj
    _|__|_lib
    _|__.__|_*.jar
    _|_jaxrpc
    _|__|_lib
    _|__.__|_*.jar
    _|_jwsdp-shared
    _|__|_lib
    _|__.__|_activation.jar
    _|_fastinfoset
    _|__|_lib
    _|__.__|_fastinfoset.jar
    _|_sjsxp
    _|__|_lib
    _.__.__|_*.jar
  • Also note that you may need the mail.jar file for MultiPartMime related classes.
  • Check your launcher.server.log again. All the errors should have disappeared and you are now done.

Test installation
  • Go to http://127.0.0.1:8080/jaxrpc-HelloWorld/hello?WSDL. You should see an xml file.
  • http://127.0.0.1:8080/saaj-book/

Back to the tutorial trail | Home

MVC Example using Struts 2 and Tomcat 6

Aim
To do a quick introduction to Struts2 framework on tomcat. This example is fairly easy, however it will highlight the use of most of the fundamentals of struts. Leave any questions or problems as comments and I will endeavour to answer them.

Assumptions
You have a compatible version of the JDK installed and tomcat installed and running.

Versions used in this example
Sofware/ComponentImage
Windows XP SP2N/A
Struts 2 struts-2.1.6-all.zip
tomcat 6apache-tomcat-6.0.18.zip
JDK 1.5.0N/A
Links to these files can be found here.

Although this is a quick 'helloworld' tutorial we will not sacrifice neatness for speed - so we will follow the standard example web application directory structure.

Create this directory structure in your working directory- similar to something you would get from eclipse. The structure used in this example is given below. Struts2HelloWorld will be referred to as your project or working directory. Create this structure.

Struts2HelloWorld
_|_WEB-INF
_|__|_web.xml
_|__|_classes
_|__|__|_helloworld
_|__|__|__|_package.properties
_|__|__|_helloworld.xml
_|__|__|_struts.xml
_|__|_lib
_|__|_src
_|__|__|_java
_|__.__.__|_helloworld
_|__.__.__.__|_StrutsHelloWorldController.java
_|_View
_.__|_index.html
_.__|_SubmitInfo.jsp



Unzip/Install Struts2
  1. Download and unzip/install the struts2 framework. For the purposes of this example the install directory is D:\downloads\struts-2.1.6
  2. `
  3. Navigate to the app directory in your Struts2 install directory.
  4. `
  5. Unzip the struts2-blank-2.1.6.war file.
  6. `
  7. Go to the struts2-blank-2.1.6\WEB-INF\lib and copy all the files to your 'lib' directory under Struts2HelloWorld. These are the core files required to run our example.

Create the HTML/JSP pages
  1. Create the index.html in the View directory under your project directory.
     1. <html>
     2. <head>
     3. <title>StrutsHelloWorld</title>
     4. </head>
     5. <body>
     6.     <a href="SubmitInfo.jsp">Enter details here</a>
     7.     <br/>
     8.     <a href="../helloworld/StrutsHelloWorldCallMe.action">Call the "CallMe" function</a>
     9. </body>
    10. </html>
    Hide line numbers
  2. `
  3. Create the SubmitInfo.jsp file and save it under View directory,
     1. <%@ page contentType="text/html; charset=UTF-8" %>
     2. <%@ taglib prefix="s" uri="/struts-tags" %>
     3. <html>
     4. <head>
     5.     <title>Hello World</title>
     6. </head>
     7. <body>
     8. 
     9. <s:if test="%{emailAddress==''}">
    10.     <s:text name="Greetings"/>
    11. </s:if>
    12. 
    13. <s:form namespace="/helloworld" action="StrutsHelloWorldFormSubmit">
    14.     <s:textfield  label="First Name" name="firstName" />
    15.     <s:textfield  label="Email Address" name="emailAddress"/>
    16.     <s:submit/>
    17. </s:form>
    18. 
    19. </body>
    20. </html>
    Hide line numbers

Create the struts support files
  1. Create the web.xml in the WEB-INF directory. This is a standard file web.xml file with a filter for struts' actions. You can copy this from struts2-blank-2.1.6\WEB-INF directory if you wish,
     1. <?xml version="1.0" encoding="UTF-8"?>
     2. <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     3. 
     4.     <display-name>Struts Blank</display-name>
     5. 
     6.     <filter>
     7.         <filter-name>struts2</filter-name>
     8.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
     9.     </filter>
    10. 
    11.     <filter-mapping>
    12.         <filter-name>struts2</filter-name>
    13.         <url-pattern>/*</url-pattern>
    14.     </filter-mapping>
    15. 
    16.     <welcome-file-list>
    17.         <welcome-file>index.html</welcome-file>
    18.     </welcome-file-list>
    19. 
    20. </web-app>
    Hide line numbers
  2. `
  3. Create the struts.xml in the WEB-INF\classes directory.
     1. <!DOCTYPE struts PUBLIC
     2.         "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
     3.         "http://struts.apache.org/dtds/struts-2.0.dtd">
     4. 
     5. <struts>
     6.     <constant name="struts.enable.DynamicMethodInvocation" value="false" />
     7.         
     8.     <package name="helloworld" namespace="/helloworld" extends="struts-default">
     9. 
    10.         <action name="StrutsHelloWorld" class="helloworld.StrutsHelloWorldController">
    11.             <result>/View/SubmitInfo.jsp</result>
    12.         </action>
    13. 
    14.         <action name="StrutsHelloWorldFormSubmit" 
    15.             class="helloworld.StrutsHelloWorldController">
    16.             <result name="input">/HelloWorld/SubmitInfo.jsp</result>        
    17.             <result>/View/ThankYou.jsp</result>
    18.         </action>
    19. 
    20.         <action name="StrutsHelloWorldCallMe" method="CallMe" 
    21.             class="helloworld.StrutsHelloWorldController">
    22.             <result name="input">/HelloWorld/ThankYou.jsp</result>
    23.             <result>/View/ThankYou.jsp</result>
    24.         </action>
    25. 
    26.     </package>
    27. </struts>
    Hide line numbers
  4. `
  5. Create the package.properties file in the WEB-INF\classes\helloworld directory and add this line in it,
     1. Greetings = Please enter your email address.
    Hide line numbers

Create and compile the Class(Bean)
  1. Create the class that will do all the work,
     1. package helloworld;
     2. 
     3. import com.opensymphony.xwork2.ActionSupport;
     4. 
     5. public class StrutsHelloWorldController extends ActionSupport{
     6. 
     7.     public String execute() throws Exception {
     8.         if( getFirstName()!=null && getFirstName().length() !=0 && 
     9.                 getEmailAddress()!=null && getEmailAddress().length() !=0)
    10.             return SUCCESS;
    11.         else 
    12.             return INPUT;
    13.     }
    14.     
    15.     public String CallMe() throws Exception{
    16.         setFirstName("Sheena");
    17.         setEmailAddress("sheena@hotmail.com");
    18.         return SUCCESS;
    19.     }
    20. 
    21.     private String firstName;
    22.     public String getFirstName(){
    23.         return firstName;
    24.     }
    25.     public void setFirstName(String firstName){
    26.         this.firstName=firstName;
    27.     }
    28.     
    29.     private String emailAddress;
    30.     public void setEmailAddress(String emailAddress){
    31.         this.emailAddress=emailAddress;
    32.     }
    33.     public String getEmailAddress(){
    34.         return emailAddress;
    35.     }
    36. }
    Hide line numbers
    Save this as HelloWorldController in the WEB-INF\src\java\helloworld directory under the project directory.
  2. `
  3. Open a prompt, cd to the src\java directory and compile. Make sure -extdirs is pointing to your local struts directory. This will compile and copy the classes to the classes directory,
    ...\Struts2HelloWorld\WEB-INF\src\java>javac -extdirs D:\downloads\struts-2.1.6\lib -d ..\..\classes helloworld\*.java
  4. `
  5. Copy the Struts2HelloWorld directory and paste it in your tomcat installations webapps directory. You might have to restart tomcat after this.

Testing
  1. Open up your browser and type http://127.0.0.1:8080/Struts2HelloWorld/View/index.html.
  2. `
  3. Select the links to test. Leaving the "Email Address" blank causes a message to be shown.

Back to the tutorial trail | Home

Web Services Example Using Axis 2 and Tomcat

Aim
The aim of this Java Axis tutorial is to write a simple 'Hello World' web service and client in Java, using the Axis2 framework. Once created, the web-service will be deployed in Axis2, running on Tomcat. The client will be a remote Java client. Leave any questions or problems as comments and I will endeavour to answer them. See Web Services Using JWSDP and Tomcat for a Sun alternative.

Assumptions
This article assumes that you have Axis 2 installed and configured on Tomcat and you have a working version of the Java JDK. Please see Setting up Axis2 on Tomcat for more details. For purposes of this example Tomcat is running on port 8080 and the project directory is Axis2TomcatHelloWorld. Also for tcpmon you have the axis.jar file from Axis1 installed. Again see Setting up Axis2 on Tomcat for more details.

Versions used in this example
Sofware/ComponentImage
Windows XP SP2N/A
Axis 2 (bin)Axis2-1.4-bin.zip
tomcat 6apache-tomcat-6.0.18.zip
Java JDK 1.5.0N/A
Axis 1 (for tcpmon)axis-bin-1_4.tar.gz
jav Links to these files can be found here.

Although this is a quick 'helloworld' tutorial we will not sacrifice neatness for speed - so all the source files, class files etc will be kept in separate directories and as clean as possible. You will thank me for this later.

Create this directory structure in your working directory- similar to something you would get from eclipse. The structure used in this example is given below. Axis2TomcatHelloworld will be referred to as your project or working directory. Create this structure.

Axis2TomcatHelloworld
_|_client_bin
_|_client_src
_|__|_Axis2TomcatHelloWorldClient.java
_|_web_bin
_|__|_META-INF
_|__.__|_services.xml
_|_web_src
_.__|_HelloWorldServiceImplementation.java
_.__|_HelloWorldServiceInterfacejava

You can download the zipped example here.


The axis 2 binaries are unzipped in D:\downloads\axis2\axis2-1.4.1 directory for this tutorial.


Compiling the webservice code
  1. Write the code. We don't really need an interface for this example, but I have added one for completeness, because we will use these exact same files for the JWSDP example. The  HelloCallEcho function will be exposed in this tutorial.
     1. package helloworld;
     2. 
     3. import java.rmi.RemoteException;
     4. 
     5. public interface HelloWorldServiceInterface extends java.rmi.Remote{
     6.     public String HelloCallEcho(String hellostring)throws java.rmi.RemoteException;
     7.     public int HelloCallAdd(int helloNumber1, int helloNumber2)throws java.rmi.RemoteException;
     8. }
    Hide line numbers
    Save this as HellowWorldServiceInterface.java in your web_src directory.
    next create the implementation.
     1. package helloworld;
     2. 
     3. public class HelloWorldServiceImplementation implements HelloWorldServiceInterface{
     4. 
     5.     public String HelloCallEcho(String hellostring) {
     6.         return "Web service echoing back - "+hellostring;
     7.     }
     8.     
     9.     public int HelloCallAdd(int helloNumber1, int helloNumber2) {
    10.         return helloNumber1 + helloNumber2;
    11.     }
    12. }
    Hide line numbers
    Save this as HelloWorldServiceImplementation.java under in your web_src directory.
  2. Open a command prompt and cd into your project directory (Axis2TomcateHelloWorld in this example).
  3. Compile the code using,

    ..workspace\Axis2TomcatHelloWorld>javac -d web_bin web_src\*.java

  4. Your web_bin directory should have some class file in there.
  5. Create the services.xml file in the web_bin\META-INF directory.
     1. <service>
     2.    <description>
     3.       This is my first service, which says hello
     4.    </description>
     5.    <parameter name="ServiceClass">helloworld.HelloWorldServiceImplementation</parameter>
     6.    <operation name="HelloCallEcho">
     7.       <messageReceiver
     8.       class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
     9.    </operation>
    10.    <operation name="HelloCallAdd">
    11.       <messageReceiver
    12.       class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
    13.    </operation>
    14. </service>
    Hide line numbers

  6. Cd into web_bin directory and jar it all up using,

    ..workspace\Axis2TomcatHelloWorld\web_bin>jar -cvf HelloWorldServices.aar *


Deploying the Service
  1. go to http://127.0.0.1:8080/axis2 - select Administration. The default username is 'admin' and the password is 'axis2.'
  2. Select upload service and navigate to the HelloWorldServices.aar and upload.
  3. Now navigate to 'available services' on the navigation pane on the left.
  4. You should be able to see your service. Click on it and it should open up yout WSDL file.

Generating the stub code - required for the client.
  1. Open a promt and cd to your working directory.
  2. Generate the client stub by running wsdl2java.bat. Wsdl2java should be in your Axis2 directory under bin. The -S specifies the output directory.
    ..workspace\Axis2TomcatHelloWorld>D:\downloads\axis2-1.4.1-bin\axis2-1.4.1\bin\wsdl2java.bat -uri http://127.0.0.1:8080/axis2/services/axis2tomcathelloworld?wsdl -S client_src
    You can now go to the client_src/helloworld directory to see the generated files.

Compiling the client
  1. Write the actual client code. All we are doing is setting up the stub and the request and then calling the function which returns a response. Save this file in the client_src directory.
     1. import helloworld.*;
     2. import org.apache.log4j.*;
     3. 
     4. public class Axis2TomcatHelloWorldClient {
     5.     static Logger logger = Logger.getLogger("Axis2TomcatHelloWorldClient.class");
     6. 
     7.     public static void main(String[] args) throws Exception {
     8. 
     9.         Axis2TomcathelloworldStub stub = new Axis2TomcathelloworldStub();
    10.         Axis2TomcathelloworldStub.HelloCallEcho helloReqEcho = 
    11.                                             new Axis2TomcathelloworldStub.HelloCallEcho();
    12.         helloReqEcho.setHellostring("client says hello Axis2");
    13.         Axis2TomcathelloworldStub.HelloCallEchoResponse helloRespEcho = 
    14.                                             stub.HelloCallEcho(helloReqEcho);
    15.         System.out.println(helloRespEcho.get_return());
    16.     }
    17. }
    Hide line numbers
    You can ignore the log4j stuff, it's just here for completetion.
  2. Now go to the client_src directory and compile it.

    ..workspace\Axis2TomcatHelloWorld\client_src>javac -d ..\client_bin -extdirs D:\downloads\axis2-1.4.1-bin\axis2-1.4.1\lib Axis2TomcatHelloWorldClient.java


Running the application
  1. CD into client_bin and run the client using the command below. Replace D:\downloads\axis2-1.4.1-bin\axis2-1.4.1\lib with the path to your Axis 2 lib directory,
    ...workspace\Axis2TomcatHelloWorld\client_bin>java -Djava.ext.dirs=D:\downloads\axis2-1.4.1-bin\axis2-1.4.1\lib Axis2TomcatHelloWorldClient
    You should see a printout saying 'hello back' from the web service.

Looking at the soap messages using tcpmon The way the monitor works is like a proxy. Your client connects to the monitor and the monitor connects to the web-service. Remember that tomcat is already running on 8080
  1. Go back and edit the Axis2TomcatHelloworldClient.java. Add the URL as the parameter to the constructor,
    originalAxis2TomcathelloworldStub stub = new Axis2TomcathelloworldStub();
    modifiedAxis2TomcathelloworldStub stub =
    new Axis2TomcathelloworldStub("http://127.0.0.1:8081/axis2/services/axis2tomcathelloworld.axis2tomcathelloworldHttpSoap12Endpoint/");

  2. Compile the code as explained previously.
  3. Open up another seprate command prompt and start up tcpmon,

    ...\anywhere>java -cp D:\downloads\axis-bin-1_4\axis-1_4\lib\axis.jar org.apache.axis.utils.tcpmon
    Please refer to the final section in the Setting up Axis2 on Tomcat for more details on this step and why we are using the axis.jar core from Axis 1. This should startup tcpmon.
  4. In the tcpmon gui, in the listen port type in 8081 and press add.
  5. Go to the 8081 tab at the top.
  6. Now open up a command prompt and run the recompiled client as explained in the previous section- You should see SOAP messages send back and forth.