javawaveblogs-20

Monday, December 3, 2007

Spring - Part I

Here is the simple example to start up with spring,

To write a simple spring application we need one interface, one implementation of that interface and a test client to test the implementation. Apart form that we also need a configuration XML file.

One interface --> Hello.java
One implementation --> HelloImpl.java
One Test Client --> HelloClient.java
One Spring XML File --> Hello.xml (Should be in the classpath).

Now let us see the interface Hello.java.


package com.javawave.spring.cli;

/**
* @author dhanago
*/
public interface Hello
{
/**
* This method will return the salutation for the name passed as input
* param to it.
*
* @param name
* @return
*/
public String sayHello( String name );
}


The above interface has only one method to say hello. This method has to be implemented in the implementation class "HelloImpl.java"


package com.javawave.spring.cli;

/**
* @author dhanago
*/
public class HelloImpl implements Hello
{

private String greet;

/**
* zero-arg constructor
*/
public HelloImpl()
{

}

/**
* @param greet
*/
public HelloImpl( String greet )
{
this.greet = greet;
}

/*
* (non-Javadoc)
*
* @see com.javawave.spring.cli.Hello#sayHello(java.lang.String)
*/
public String sayHello( String name )
{

return this.greet + name;
}

/**
* @param greet the greet to set
*/
public void setGreet( String greet )
{
this.greet = greet;
}

}

The Impl class has a property called greet. This also has a setter method "setGreet" to set the value for this property.

Now let us see the spring xml. This XML file will be used for creating the objects in spring framework. This XML is also called wiring xml. Through this XML we will set the greet property of the HelloImpl class.

Hello.XML
~~~~~~~~~


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="hello"
class="com.javawave.spring.cli.HelloImpl">
<property name="greet">
<value>Good Morning!...</value>
</property>
</bean>
</beans>

Here in the XML you can see the tag called bean which will map to the bean what you are using in the application. It has an attribute called "id" and a attribute called "class". The "class" attribute maps to the HelloImpl.java in our case. The property tag inside the bean tag maps to the property inside the bean class. Here in our case it is the "greet" property. The value for the property is given in the value element inside the property element. This is the value passed to the bean's property "greet" . This is how spring does the dependency injection (DI). Here what you are doing is injecting dependency through setter method. This is also called Setter Injection.

Now we will see the client application "HelloClient.java" to test the "HelloImpl.java".

/**
*
*/
package com.javawave.spring.cli;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

/**
* @author dhanago
*/
public class HelloClient
{

/**
* @param args
*/
public static void main( String[] args )
{
try
{
System.out.println( "Inside main of HelloClient.." );
Resource resource = new ClassPathResource(
"com/javawave/spring/cli/Hello.xml" );
BeanFactory factory = new XmlBeanFactory( resource );
Hello hello = (Hello) factory.getBean( "hello" );
String result = hello.sayHello( "Man" );
System.out.println( result );
}
catch (Exception e)
{
System.out.println( "Exception/Error:" + e.toString() );
}
}
}

This client application uses ClassPathResource to load the resource. In our case Hello.xml and it creates the factory via XmlBeanFactory. factory class has getBean method which will return a object. Here we get Hello object. So from that we can call sayHello method as shown in the above code and get the result.

The Jars used for this application is:
spring.jar
commons-logging.jar

The Output is shown below:

Inside main of HelloClient..
Good Morning!...Man
Dec 3, 2007 1:59:01 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [com/javawave/spring/cli/Hello.xml]

Friday, November 30, 2007

Comparing two Value Objects in Java

In Java comparing two value object is not straight forward. Here we will see how we can compare two value objects in Java.

For that first we will create a value object called "MyValueObject". This value object contains two properties. 1) firstName 2) lastName. Both the properties are of type string.

In the same class we also have a overridden method which does the comparison for us. This method "public boolean equals(Object obj)" takes the properties and compare them individually. if the properties values are all equal then it returns true or it will return false. By doing this our test class will just call the equals method on the object to make sure if the objects are equal or not.

Code is listed below.

/*
*/
package com.blogspot.javawave;

/**
*
* @author dhanago
*/
public class MyValueObject
{

private String firstName;
private String lastName;

/**
* This constructor is used to set the two properties values in the class.
*
* @param firstName
* @param lastName
*/
public MyValueObject(String firstName,
String lastName)
{
this.firstName = firstName;
this.lastName = lastName;
}

@Override
public boolean equals(Object obj)
{
boolean isEqual = false;
if (this.getClass() == obj.getClass())
{
MyValueObject myValueObject = (MyValueObject) obj;
if ((myValueObject.firstName).equals(this.firstName) &&
(myValueObject.lastName).equals(this.lastName))
{
isEqual = true;
}
}

return isEqual;
}
}

Test class is given below:

/*
*/
package com.blogspot.javawave;

/**
*This class is used to test compare the value object.
*
* @author dhanago
*/
public class TestCompareValueObject
{

/**
* This is the main method used to test compare the value object.
* @param arg
*/
public static void main(String[] arg)
{
MyValueObject obj1 = new MyValueObject("Muthu", "Kumar");
MyValueObject obj2 = new MyValueObject("Muthu", "Kumar");

if (obj1.equals(obj2))
{
System.out.println("Both the objects are equal");
}
else
{
System.out.println("Both the objects are not equal");
}
}
}

This one of the way we can easily compare the value objects in Java

Tuesday, November 13, 2007

SOA principles

SOA principles

The following guiding principles define the ground rules for development, maintenance, and usage of the SOA[8]

  • Reuse, granularity, modularity, composability, componentization, and interoperability
  • Compliance to standards (both common and industry-specific)
  • Services identification and categorization, provisioning and delivery, and monitoring and tracking

The following specific architectural principles for design and service definition focus on specific themes that influence the intrinsic behaviour of a system and the style of its design:

  • Service Encapsulation - A lot of existing web-services are consolidated to be used under the SOA Architecture. Many a times, such services have not been planned to be under SOA.
  • Service Loose coupling - Services maintain a relationship that minimizes dependencies and only requires that they maintain an awareness of each other
  • Service contract - Services adhere to a communications agreement, as defined collectively by one or more service description documents
  • Service abstraction - Beyond what is described in the service contract, services hide logic from the outside world
  • Service reusability - Logic is divided into services with the intention of promoting reuse
  • Service composability - Collections of services can be coordinated and assembled to form composite services
  • Service autonomy – Services have control over the logic they encapsulate
  • Service optimization – All else equal, high-quality services are generally considered preferable to low-quality ones
  • Service discoverability – Services are designed to be outwardly descriptive so that they can be found and assessed via available discovery mechanisms[9]

In addition, the following factors should also be taken into account when defining a SOA implementation:

  • SOA Reference Architecture covers the SOA Reference Architecture, which provides a worked design of an enterprise-wide SOA implementation with detailed architecture diagrams, component descriptions, detailed requirements, design patterns, opinions about standards, patterns on regulation compliance, standards templates etc.[10]
  • Life cycle management SOA Practitioners Guide Part 3: Introduction to Services Lifecycle introduces the Services Lifecycle and provides a detailed process for services management though the service lifecycle, from inception through to retirement or repurposing of the services. It also contains an appendix that includes organization and governance best practices, templates, comments on key SOA standards, and recommended links for more information.
  • Efficient use of system resources
  • Service maturity and performance
  • EAI Enterprise Application Integration

Friday, November 2, 2007

What is WSDL?

Saturday, October 13, 2007

Java Excel API

Where to get the jexcelapi?


Get the API download form --> http://jexcelapi.sourceforge.net/

What is jexcelapi ?

A Java API to read, write, and modify Excel spreadsheets.

Now java developers can read Excel spreadsheets, modify them with a convenient and

simple API, and write the changes to any output stream (e.g. disk, HTTP, database, or

any socket).


Because it is Java, the API can be invoked from within a servlet, thus giving access to

Excel spreadsheets over internet and intranet web applications.


Features of jexcelapi

Reads data from Excel 95, 97, 2000, XP, and 2003 workbooks
Reads and writes formulas (Excel 97 and later only)
Generates spreadsheets in Excel 2000 format Supports font, number and date formatting Supports shading, bordering, and coloring of cells Modifies existing worksheets Is internationalized, enabling processing in almost any locale, country, language, or character encoding (formulas are currently only supported in English, French, Spanish, and German, but more can be added if translated) Supports copying of charts Supports insertion and copying of images into spreadsheets Supports logging with Jakarta Commons Logging, log4j, JDK 1.4 Logger, etc ...and much more.

Technical notes ==> http://www.andykhan.com/jexcelapi/technotes.html

JExcelApi JavaDoc ==> http://jexcelapi.sourceforge.net/resources/javadocs/index.html



Pre-Requirements:
  • Should be knowing basic concepts of Java.
  • Should know how to set class path to use third party Api's.


Now we will see how to read a spread sheet using this API:


First of all we will create a spread sheet like the one below and store it in our local folder.

I am saving this file in "D:testmyFile.xls"



To read the spread sheet content using jxl Api, first we have to create an object called
Workbook. Once you create the Workbook then you will get access to individual sheets.
Note that these sheets are Zero indexed.
So you have to use some thing like workbook.getSheet(0);

Once you get the sheet then you can easily get the cells and their content as string.
If you want it is also possible to get the data with out changing the type as it is.

See the sample code below (SpreadsheetReader.java).

package com.jxl.dhanago;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
* This Java program is used to read the spread sheet and print it in
* console output.
*
* @author dhanago
*/
public class SpreadsheetReader
{

/**
* This method is used to read a spread sheet and print it in console.
*
* @param xlsPath
*/
public void readSpreadSheet( String xlsPath )
{
try
{
/*
* To read the spread sheet , first we have to create a workbook
* object like one shown below.
*/
Workbook workbook = Workbook.getWorkbook( new File( xlsPath ) );
/*
* then get the sheet index 0. Note the index starts with 0.
*/
Sheet sheet = workbook.getSheet( 0 );
/*
* get the cell form the sheet object like below.
*/
Cell cell00 = sheet.getCell( 0, 0 );
Cell cell01 = sheet.getCell( 0, 1 );
Cell cell02 = sheet.getCell( 0, 2 );

/*
* now we will display the cell values as string in console output.
*/
System.out.println( "Cell00 value: " + cell00.getContents() );
System.out.println( "Cell01 value: " + cell01.getContents() );
System.out.println( "Cell02 value: " + cell02.getContents() );
// free up memory
workbook.close();
}
catch (BiffException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}

/**
* This is the main executable method used to test the spread sheet
* reader.
*
* @param args
*/
public static void main( String[] args )
{
SpreadsheetReader readSpreadsheet = new SpreadsheetReader();
String xlsPath = "D:\test\myFile.xls";
readSpreadsheet.readSpreadSheet( xlsPath );
}
}

OutPut for the above code:

Cell00 value: Name
Cell01 value: Muthukumar Dhanagopal
Cell02 value: Krish

The above code displays the cell values as string. How to get the same
data type and display them with out converting them to string. Is that
possible using this API?

Yes, it is possible.
Here is the code which does the same for you.
It checks the cell type for LABEL, NUMBER or DATE and then gets the value from
the cell type cast the value to that particular data type and displays it on the console.

package com.jxl.dhanago;

import java.io.File;
import java.io.IOException;

import jxl.Cell;
import jxl.CellType;
import jxl.DateCell;
import jxl.LabelCell;
import jxl.NumberCell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

/**
* This java program is used to get and display the xls data according to
* the type.
*
* @author dhanago
*/
public class ReadXLWithExactDataType
{

/**
* This method is used to display the xls data with exact type.
*
* @param xlsPath
*/
public void readDataWithType( String xlsPath )
{
try
{
/*
* To read the spread sheet , first we have to create a workbook
* object like one shown below.
*/
Workbook workbook = Workbook.getWorkbook( new File( xlsPath ) );
/*
* then get the sheet index 0. Note the index starts with 0.
*/
Sheet sheet = workbook.getSheet( 0 );
/*
* get the cell form the sheet object like below.
*/
Cell cell00 = sheet.getCell( 0, 0 );

if (cell00.getType() == CellType.LABEL)
{
System.out.println( "Type LABEL" );
LabelCell labelCell = (LabelCell) cell00;
System.out.println( "Label Cell: " + labelCell.getString() );
}
else if (cell00.getType() == CellType.NUMBER)
{
System.out.println( "Type NUMBER" );
NumberCell numberCell = (NumberCell) cell00;
System.out.println( "Number Cell: " + numberCell.getValue() );
}
else if (cell00.getType() == CellType.DATE)
{
System.out.println( "Type DATE" );
DateCell dateCell = (DateCell) cell00;
System.out.println( "Date Cell: " + dateCell.getDate() );
}
else
{
System.out.println( "Type not supported." );
}

/*
* now we will display the cell values as string in console output.
*/
System.out.println( "Cell00 value: " + cell00.getContents() );
// free up memory
workbook.close();
}
catch (BiffException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}

/**
* This is the main executable method used to test the spread sheet
* reader.
*
* @param args
*/
public static void main( String[] args )
{
ReadXLWithExactDataType readXL = new ReadXLWithExactDataType();
String xlsPath = "D:\test\myFile.xls";
readXL.readDataWithType( xlsPath );
}

}

The Output for the above code is:
Type LABEL
Label Cell: Name
Cell00 value: Name


Wednesday, October 10, 2007

Rule Engine - Drools

What is a Rule Engine?

Artificial Intelligence (A.I.) is a very broad research area that focuses on "Making computers think like people" and includes disciplines such as Neural Networks, Genetic Algorithms, Decision Trees, Frame Systems and Expert Systems. Knowledge representation is the area of A.I. concerned with how knowledge is represented and manipulated. Expert Systems use Knowledge representation to facilitate the codification of knowledge into a knowledge base which can be used for reasoning - i.e. we can process data with this knowledge base to infer conclusions. Expert Systems are also known as Knowledge-based Systems and Knowledge-based Expert Systems and are considered 'applied artificial intelligence'. The process of developing with an Expert System is Knowledge Engineering. EMYCIN was one of the first "shells" for an Expert System, which was created from the MYCIN medical diagnosis Expert System. Where-as early Expert Systems had their logic hard coded, "shells" separated the logic from the system, providing an easy to use environment for user input. Drools is a Rule Engine that uses the Rule Based approached to implement an Expert System and is more correctly classified as a Production Rule System.

The term "Production Rule" originates from formal grammar - where it is described as "an abstract structure that describes a formal language precisely, i.e., a set of rules that mathematically delineates a (usually infinite) set of finite-length strings over a (usually finite) alphabet" (wikipedia).

For more information visit the following URL
https://hudson.jboss.org/hudson/job/drools/lastSuccessfulBuild/artifact/trunk/target/docs/html/ch02.html



JBoss server in Eclipse

Defining JBoss server in Eclipse:

Step 1 : Open Eclipse WTP all in one pack in a new work space.

Step 2 : Change the perspective to J2EE Perspective if it is not currently in J2EE Perspective.

Step 3 : Once the Perspective is changed to J2EE, you can see a tab called Servers in the bottom right panel along with Problems, Tasks, Properties.

Step 4 : If the Servers tab is not found. Go to Eclipse menu : Windows > Show view and click on Servers, so that Server tab will be displayed.

Step 5 : Go to Servers tab window and right click the mouse. You will get a pop up menu called "New".

Step 6 : Clicking on the New menu you will get one more pop up called "Server". Click on it.

Step 7 : Now you will get Define New Server Wizard.

Step 8 : In the wizard there are options to define many servers. One among them is JBoss. Click on JBoss and Expand the tree.

Step 9 : Select JBoss v 4.0 and click next.

Step 10 : Now give the JDK directory and JBoss home directory. Click Next.

Step 11 : Now the wizard will show you the default Address, port, etc., Leave it as it is and click on Next.

Step 12 : Click on finish.

Step 13 : Now you can see the JBoss server listed in the Servers window and the status is Sopped.

Step 14 : JBoss server is now defined in Eclipse now and its ready to use from with in Eclipse IDE.

Monday, October 8, 2007

DOM parsing technique

This class follows the DOM parsing technique and does the following.

1.Parse the demoxml.xml file.
2.Search for the xml node by the name "parent1" from the xml.
3.Create a new child node by the name "newChild"
4.Create a text("new child of the parent1") to the "newChild" node
5.Append the "newChild" node to "parent1" node.
6.Save the changes (transform) to the xml.


Sample Code: (
DOMParser.java)
package com.dom.dhanago;

/*
* This class follows the DOM parsing technique and does the following.
* 1.Parse the demoxml.xml file. 2.Search for the xml node by the name
* "parent1" from the xml. 3.Create a new child node by the name "newChild"
* 4.Create a text("new child of the parent1") to the "newChild" node
* 5.Append the "newChild" node to "parent1" node. 6.Save the changes
* (transform) to the xml.
*/

import java.io.File;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class DOMParser
{

public static void main( String[] args )
{
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document;
document = builder.parse( new File( "C:\\demoxml.xml" ) );
/*
* You can pass either xml file or string.To fetch the root element
* of the xml document.
*/
Element rootEle = document.getDocumentElement();
/*
* To fetch all the child nodes of the root element.
*/
NodeList childNodes = rootEle.getChildNodes();
/*
* To search an element from the whole document.
*/
NodeList parentNode = document.getElementsByTagName( "parent1" );
/*
* To create a new child element by the name "newChild".
*/
Element newChild = document.createElement( "newChild" );
/*
* Adding text data to "newChild".
*/
newChild.appendChild( document
.createTextNode( "new Child of the parent1 node" ) );

/*
* To append the "newChild" ,created above.
*/
parentNode.item( 0 ).appendChild( newChild );

TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();

/*
* Preparing the source which is the document created above.
*/
Source srcDocument = new DOMSource( document );
/*
* Destination will be same different xml.
*/
Result destxml = new StreamResult( new File( "C:\\demoxml.xml" ) );
/*
* Transforming document to destination xml.
*/
aTransformer.transform( srcDocument, destxml );
System.out.println( "Successfully transformed" );
}
catch (Exception e)
{
System.out.println( "exec " + e );
}
}
}

Friday, October 5, 2007

Code to convert from Xml-String to Document and Document to String

package ora.in;

import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* Code to convert from Xml-String to Document and Document to String.
*
* @author Muthu
*/
public class S2DandD2S
{
public static Document loadXmlFileToDocument( String strXml,
boolean ignoreComments )
{
Document docRet = null;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory
.newInstance();
factory.setIgnoringComments( ignoreComments );
DocumentBuilder docBuilder = factory.newDocumentBuilder();
docRet = docBuilder.parse( new InputSource( new StringReader(
strXml ) ) );
}
catch (SAXException e)
{
System.out.println( "SAXException" );
}
catch (IOException e)
{
System.out.println( "IOException" );
}
catch (ParserConfigurationException e)
{
System.out.println( "ParserConfigurationException" );
}
catch (FactoryConfigurationError e)
{
System.out.println( "FactoryConfigurationError" );
}
return docRet;
}

/**
* @param args
*/
public static void main( String[] args )
{
try
{
String xml = "Some exception file as string";

Document document = loadXmlFileToDocument( xml, false );
TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();

Source srcDocument = new DOMSource( document );

// Preparing the source which is the document created above.
StringWriter writer = new StringWriter();
Result destxml = new StreamResult( writer );

// Transformingdocument to destination xml.
aTransformer.transform( srcDocument, destxml );

System.out.println( writer.toString() );
System.out.println( "Successfully transformed" );
}
catch (Exception e)
{
System.out.println( "exec " + e );
}
}
}

Parsing Java InputStream To Text and Vice Versa

Here are couple of useful methods to convert from InputStream to String
and vice versa.

Input Stream to String


public String parseISToString(java.io.InputStream is){
java.io.DataInputStream din = new java.io.DataInputStream(is);
StringBuffer sb = new StringBuffer();
try{
String line = null;
while((line=din.readLine()) != null){
sb.append(line+"\n");
}
}catch(Exception ex){
ex.getMessage();
}finally{
try{
is.close();
}catch(Exception ex){}
}
return sb.toString();
}

String to InputStream


public java.io.InputStream parseStringToIS(String xml){
if(xml==null) return null;
xml = xml.trim();
java.io.InputStream in = null;
try{
in = new java.io.ByteArrayInputStream(xml.getBytes("UTF-8"));
}catch(Exception ex){
}
return in;
}

Friday, September 21, 2007

Happy Axis

Introduction

Axis is a web service engine. It is the third generation of apache soap.
To know about webservices it is mandatory to know about SOAP.

This artical will gives you the brief introduction on SOAP.

Then it will introduce you to Apache Axis 1.4. Then we will also tell about the diffrent styles

of webservices in brief.

The article will conclude by giving a sample application, explaining how to deploy webservice

in axis? How to call the deployed webservice?

Pre-Requesties

  • This artical assumes that you already know how to write a java code, compile and run.
  • You should also have a servlet engine or an application server already configured.
  • You should be familiar with web application deployment scenarios and how to start and
stop the server.
  • We recommend Jakarta Tomcat. [If you are installing Tomcat, get the latest 4.1.x version,
and the full distribution, not the LE version for Java 1.4, as that omits the Xerces XML parser].
Other servlet engines are supported, provided they implement version 2.2 or greater of the
servlet API.
  • Make sure you have the latest version of JDK installed in your system and JAVA_HOME is set.
  • Note also that Axis client and server requires Java 1.3 or later.


Things to know before diving into Web Service

  • Core Java and concepts of java.
  • How to diagnose trouble from exception traces.
  • What is a web application? what is the folder structure of web application? how to pack
libraries to web application? how to make a war file? to deploy web application to the application
server. Should also have knowledge on servlets.
  • Basic knowledge about XML. [XML parsing not mandatary]
  • Should also have knowledge about HTTP, TCP/IP


Software used in this artical

  • Apache Axis 1.4
  • JDK 1.5.x
  • Jakarta Tomcat 5.x
  • Netbeans 5.5.1 for java coding.

SOAP

SOAP is an XML-based communication protocol and encoding format for inter-application

communication. The current spec is version, SOAP 1.2, though version1.1 is more widespread.

SOAP is the backbone of Web Services.

Below shown is the sample SOAP request message.

						
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SOAP-ENV:Body>
<ns1:echoString xmlns:ns1="http://javawave.net/">
<arg0 xsi:type="xsd:string">Hi There!</arg0>
</ns1:echoString>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Web Service

Web service is a new generation cross-platform, cross-language distributed computing

applications.

Apache Axis

Axis is a SOAP engine. It is a SOAP processer framework. The current version of Axis if written

fully in Java.

Axis has full support for the Web Service Description Language(WSDL). It has tools to generate

java code (Client stubs) from WSDL as well as generate WSDL automatically from java code.

Axis also has a simple stand alone server. It also has a server which plugs in to other servlet

engins, like Tomcat.

Axis also has a monitoring tool to monitor TCP/IP packets.

Please note that this is an open-source effort. And in case you're wondering what Axis stands

for, it's Apache EXtensible Interaction System - a fancy way of implying it's a very configurable

SOAP engine.

Axis is compiled in the JAR file axis.jar; it implements the JAX-RPC API declared in the JAR files

jaxrpc.jar and saaj.jar. It needs various helper libraries, for logging, WSDL processing and

introspection. All these files can be packaged into a web application, axis.war, that can be

dropped into a servlet container.

Diffrent Style of Web Services in Axis

There are four style of web services axis supports. They are:

  • RPC
  • Document
  • Wrapped, and
  • Message

we will take about these services after we see how to write deployment descriptor's to deploy

a service

Installing Axis

  • Download the latest version of Axis. Here we are using Axis version 1.4
  • Unzip the package downloaded to a folder say "myAxis".
  • Inside the unpacked folder, we can see a folder by name "axis".(<myAxis>axis-1_4webapps)
  • Copy the folder to tomcat webapps folder.(this article uses tomcat and we assume that your
tomcat is up and running in port 8080, if it is not running in 8080 please configure your tomcat to
run on 8080 if you are using some other application servers please see the reference document on
deploying web application in the server you are using)
  • The folder name "axis" can be renamed if you want diffrent context name. The rest of this
document assumes that the default webapp name, "axis" has been used; rename these references
if appropriate.
  • Axis needs a xml parser to work. If your application server does not provide one, please download
xml-xerces distribution (http://xml.apache.org/dist/xerces-j/) and add the parser libraries to
axis/WEB-INF/lib.
  • Axis also needs jaxrpc.jar and saaj.jar in the application path. jaxrpc.jar and saaj.jar contain
javax packages, so they may not get picked up. Copy them from
axis/WEB-INF/lib to CATALINA_HOME/common/lib and restart Tomcat.
  • Now we are ready to go... :)

Validating the Installation

  • Make sure tomcat is running. Navigate to http://127.0.0.1:8080/axis/, if you have changed the
context name or the port change it accordingly in your URL. Now you should see the Apache-Axis start
page. If you are not able to see the page then probably your web application is not deployed properly.
  • Click on the validate link on the Apache Axis start page. This will lead you to happyaxis.jsp.
This is the test page that checks if the needed libraries and optional libraries are present or not.
  • If any of the needed libraries are missing, Axis will not work, then first you have to fix it and then
proceed.
  • Optional components are optional; install them as your need arises. If you see nothing but an internal
server error and an exception trace, then you probably have multiple XML parsers on the CLASSPATH,
and this is causing version confusion. Eliminate the extra parsers, restart the app server and try again.
  • Once the happyaxis page is happy. Navigate to the Apache-Axis start page
(http://127.0.0.1:8080/axis/). Select view list of deployed web services link. This will lead to a page
which will list all the deployed web services. On this page, You should be able to click on (wsdl) for
each deployed Web service to make sure that your web service is up and running.

Deploying new Web Services

New Web services installation process

  • Get the classes and libraries of your new service into the Axis WAR directory tree, and
  • Tell the AxisEngine about the new file. The latter is done by submitting an XML deployment descriptor
to the service via the Admin web service, which is usually done with the AdminClient program. AdminClient
run the Axis SOAP client to talk to the Axis adminstration service, which is a SOAP service in its own right.
It's also a special SOAP service.

Implementing the process

Prepare a batch file which will set all the axis related jar files to the classpath.
Here is the list of jars needed to set in the class path

  • axis-ant.jar
  • axis.jar
  • commons-discovery-0.2.jar
  • commons-logging-1.0.4.jar
  • jaxrpc.jar
  • log4j-1.2.8.jar
  • saaj.jar
  • wsdl4j-1.5.1.jar
  • xml-apis.jar(download this jar)
  • xercesImpl.jar(download this jar)

First we will write a simple java code like below

                            
/*
* HappyAxis.java
*
* Created on 9 Aug, 2007, 7:16:36 PM
*
*/

package myapp;

/**
*
* @author Muthukumar Dhanagopal
*/
public class HappyAxis
{

public HappyAxis()
{
}

public String sayHello(String name)
{
return "Hello " + name;
}

}


Compile the code and make a jar file. Here we created the jar file by name myApp.jar which contains

the above code.

Once myApp.jar is created, drop the jar inside axisWEB-INFlib folder in inside your application server.

Now it is time to write a deployment descriptor file to deploy our service in axis.

Web Service Deployment descriptor is nothing but a xml file with .wsdd extention. You can find a

sample deployment descriptor below, which is used to deploy our example service HappyAxis packed

into myApp.jar library.

                            
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="MyService" provider="java:RPC">
<parameter name="className" value="myapp.HappyAxis"/>
<parameter name="allowedMethods" value="*"/>
</service>

</deployment>

The service element has a name attribute which will contain the service name you want to expose.

provider attribute will contain the provider used for the service. here we are using the java:RPC

provider. Insted of provider attribute we can also use style attribute where we can define the

style of webservice like document or messaging style. Our service name we defined here is "MyService".

service element has two child element named parameter. The first parameter element's name attribute

will hold the value className and the value attribute will contain the exact class name including the

package. Here our value is "myapp.HappyAxis". In the next parameter tag you can specify all the

methods you like to expose in that class. If you want to expose all the methods in the class specify * in

the value attribute. If you want to specify only one method or couple of methods, then specify the

method name seperated by space.

Save the above deployment descriptor as deploy.wsdd.

Run the bath file which we prepared earlier to set classpath. Execute the following command from the

directory where you have saved the deploy.wsdd. If you are not in this directory you will get a

"java.io.FileNotFoundException: deploy.wsdd (The system cannot find the file specified)" exception

java org.apache.axis.client.AdminClient 
-lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

If you get some java client error (like ClassNotFoundException), then you haven't set up your

CLASSPATH variable right, mistyped the classname, or did some other standard error. Tracking down

such problems are foundational Java development skills--if you don't know how to do these things,

learn them now!

If you don't get any error then that means you have successfully deployed your web service.

Now visit the Apache-Axis start page and navigate to the web service listing page. Here you can

see your service getting displayed. Just click on the WSDL link, Axis will automaticly generate

WSDL for your deployed service.

Now we will see the styles of webservices possible in Axis

As we have already seen there are four types of webservices supported in Axis.

They are RPC(1), Document(2), Wrapped(3) and Message(4)

RPC services

RPC services are the default in Axis. They are what you get when you deploy services with

<service ... provider="java:RPC"> or <service ... style="RPC">.

RPC services follow the SOAP RPC and encoding rules. Axis will deserialize XML into Java objects which

can be fed to your service, and will serialize the returned Java object(s) from your service back into XML.

Since RPC services default to the soap section 5 encoding rules, objects will be encoded via "multi-ref"

serialization, which allows object graphs to be encoded.

Document / Wrapped service

Document and Wrapped services are similar, both use SOAP encoding for data.(means its plain xml schema).

Axis binds java objects for the xml schema here. so in the end you will end up using java objects. You will

not use the xml directly here.

The document or wrapped style is indicated in WSDD as follows:


<service ... style="document"> for document style
<service ... style="wrapped"> for wrapped style

Message service

Message service should be used when you want Axis to step back and let your code at the actual XML

instead of turning it into Java objects. There are four valid signatures for your message-style service methods:


public Element [] method(Element [] bodies);
public SOAPBodyElement [] method (SOAPBodyElement [] bodies);
public Document method(Document body);
public void method(SOAPEnvelope req, SOAPEnvelope resp);

Consuming the deployed Web Services

Basic simple way to consume a Web Service

First we will see the basic way of calling a web service with out generating stubs from WSDL

The code below is used to call our deployed web service "MyService"

                        
/*
* TestClient.java
*
* Created on 9 Aug, 2007, 9:05:40 PM
*/

package myapp;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

/**
*
* @author Muthukumar Dhanagopal
*/
public class TestClient
{

public TestClient()
{
}

public static void main(String[] args)
{
try
{
String endpoint = "http://localhost:8080/axis/services/MyService";

Service service = new Service();
Call call = (Call) service.createCall();

call.setTargetEndpointAddress(new java.net.URL(endpoint));
call.setOperationName(new QName("http://javawave.blogspot.com/", "sayHello"));

String ret = (String) call.invoke( new Object[] { "Hello!" } );

System.out.println("Sent 'Hello!', got '" + ret + "'");
}
catch (Exception e)
{
System.err.println(e.toString());
}
}
}


The program can be run as follows

                        
java myapp.TestClient
Sent 'Hello', got 'Hello Hello'

Consume a Web Service by creating stubs from WSDL

Before getting into creating stubs, we will have a quick look at what is WSDL?

The Web Service Description Language is a specification authored by IBM and Microsoft,

and supported by many other organizations. WSDL serves to describe Web Services in

a structured way. A WSDL description of a service tells us, in a machine-understandable

way, the interface to the service, the data types it uses, and where the service is located.

Axis supports WSDL in three ways:

  • After you deploy the web service, you can access the URL with a web browser
appending ?wsdl to end of it. Then Axis will automatically generate a wsdl document for you.
  • Axis provides a WSDL2Java tool which will generate proxy stubs and skeletons for
service with WSDL description.
  • Axis also provides Java2WSDL tool which will generate WSDL from a Java code.

With this information, Now we will see how to build stubs from WSDL to call our deployed

web service

Client-side binding

Axis provides WSDL-to-Java tool in org.apache.axis.wsdl.WSDL2Java. The basic invocation looks

like this:

java org.apache.axis.wsdl.WSDL2Java (WSDL file URL)

This command will generate the java stubs with those bindings necessary for the client.

Axis follows JAX-RPC specification when generating the client binding from WSDL description.

For our client stub generation, First we will save the wsdl to a perticular location. Then

we will invoke the following command as this:

java org.apache.axis.wsdl.WSDL2Java MyService.wsdl

Once this invocation happens, then we can see the stubs getting generated in the same

directory from where we invocked the command. Now we are ready to go. Just compile

the stubs and write a CLI (Command Line Interface) which will make use of the generated

stub and calls the web service.

Conclusion

So we came across Axis webservices by touching on some of the features of axis. We do

came across a sample webservice wich uses RPC style. We also saw how to generate the

stubs and call the web service. Here I whould say we just had a dip in to the sea of

webservice by just going through a sample application deployment in axis. There are lot

to learn about it. Please dive deep in to the sea called webservice for the treasure of

knowledge about it.

Happy Axis.. :)

Thursday, September 20, 2007

Object Type - Class

In Java we have a class called Class. Type Class is in the package java.lang

What is Class and class? (Please note the second one is with a small 'c')
The one with small 'c' ie., class is a keyword used to declare Java classes.
The one with upper case 'C' is a Type inside java.lang package.
Type Class describes other objects. Class does not have a constructor.
It helps a Java program to get information about other Java objects.
The Class class provides the basis for Java Reflection and Introspection.

If it is not having a constructor, then how to obtain the object of type Class?

The method getClass() is defined in the Java Object class.

An object of type Class can be obtained by calling the getClass() method on a particular Java object.

The following code will give us the object of type Class for Object obj
Class objClass = obj.getClass();
The Class class offers several useful methods like below:
//is used to return class constructors
public Constructor[] getConstructors()

//is used to
return class methods
public Method[] getMethods()

//is used to return class fields
public Field[] getFields()

//is used to return the superclass
public Class getSuperClass()

Wednesday, September 19, 2007

NetBeans 6.0 Keyboard Shortcuts

Finding, Searching, and Replacing

Ctrl-F3 Search word at insert point
F3/Shift-F3 Find next/previous in file
Ctrl-F/H Find/Replace in file
Alt-F7 Find usages
Ctrl-Shift-P Find/replace in projects
Alt-Shift-U Find usages results
Alt-Shift-H Turn off search result

highlights

Alt-Left Next in jump list
Alt-Right Previous in jump list
Ctrl-R Rename
Ctrl-U, then U Convert selection to

uppercase
Ctrl-U, then L Convert selection to

lowercase
Ctrl-U, then S Toggle case of selection
Alt-Shift-V Paste formatted

Navigating through Source Code
Ctrl-O/Alt-Shift-O Go to type/file
Ctrl-Shift-T Go to JUnit test
Alt-O Go to source
Ctrl-B Go to declaration
Ctrl-G Go to line
Ctrl-Shift-M Toggle add/remove

bookmark
Ctrl-Shift-Next/previous bookmark
Period/Comma
Ctrl-Next/previous
Period/Comma usage/compile error
Ctrl-Shift-1/2/3 Select in

Projects/Files/Favorites
Ctrl-[ Move caret to matching
bracket
Ctrl-K/Ctrl-Shift KNext/previous word match

Coding in Java

Alt-Insert Generate code
Ctrl-Shift-I Fix all class imports
Alt-Shift-I Fix selected class's import
Alt-Shift-F Reformat selection
Alt-Shift-Shift tab to the left/right
Left/Right
Ctrl-/ Add/remove comment lines
Ctrl/Alt-F12 Inspect members/hierarchy
Ctrl-E Delete current line

Compiling, Testing, and Running

F9 Compile package/ file
F11 Build main project
Shift-F11 Clean & build main project
Ctrl-Q Set request parameters
Ctrl-Shift-U Create JUnit test
Ctrl-F6/Alt-F6 Run JUnit test on file/project
F6/Shift-F6 Run main project/file

Opening and Toggling betweenViews

Ctrl-Tab (Ctrl-`) Toggle between open

documents
Shift-Escape Maximize window (toggle)
Ctrl-F4/Ctrl-W Close currently selected

window
Ctrl-Shift-F4 Close all windows
Shift-F10 Open contextual menu
Alt-Shift-D Undock window

Debugging

Ctrl-F5 Start debugging main project
Ctrl-Shift-F5 Start debugging current file
Ctrl-Shift-F6 Start debugging test for file

(JUnit)
Shift-F5/F5 Stop/Continue debugging

session
F4 Run to cursor location in file
F7/F8 Step into/over
Ctrl-F7 Step out
Ctrl-Alt-Up Go to called method
Ctrl-Alt-Down Go to calling method
Ctrl-F9 Evaluate expression
Ctrl-F8 Toggle breakpoint
Ctrl-Shift-F8 New breakpoint
Ctrl-Shift-F7 New watch

When typing in the Source Editor, you can generate the
text in the right-column of the following list by typing
the abbreviation that is listed in the left-column and
then pressing Tab.

Java Editor Code Templates

En
Enumeration

Ex
Exception

Ob Object
Psf public static final

Psfb
public static final boolean

Psfi
public static final int

Psfs
public static final String

St
String

ab abstract
bo boolean

br break
ca catch (
cl class

cn continue
df default:

dowhile
do {
} while (condition);

eq
equals

ex extends
fa false

fi final
fl float

forc for (Iterator it = collection.iterator();
it.hasNext();) {
Object elem = (Object) it.next();
}
fore for (Object elem : iterable) {
}
fori for (int i = 0; i < arr.length; i++) {
}

fy
finally

ie
interface

ifelse if (condition){}else {
}
im implements
iof instanceof

ir
import

le
length

newo
Object name = new Object(args);

pe
protected

pr private
psf private static final
psfb private static final boolean
psfi private static final int
psfs private static final String
pst printStackTrace();

psvm
public static void main(String[] args){

}
pu public
re return
serr System.err.println ("|");
sout System.out.println ("|");
st static
sw switch (
sy synchronized
tds Thread.dumpStack();
th throws
trycatch try {}

catch (Exception e) {}
tw throw
twn throw new
wh while (
whilei while (it.hasNext()) {

Object elem = (Object) it.next();
}

Java 5 new features

Several useful features were introduced in Java 5.

The compiler is also updated and all translate to already defined Java bytecode,
meaning that virtual machines can execute these features with no need for an update.
These features make writing Java code easier, cleaner, and faster.
Even if you choose not to take advantage of these features, familiarity with them is vital.

The new features of Java5 are listed below:

Generics: A way to make classes type-safe. this helps us in narrowing an instance
of a collection to hold a specific object type and eliminating the need to cast
objects when taking an object out of the collection.

Enhanced for loop: Less error-prone and cleaner for loop for use with iterators.

Variable arguments: For passing an arbitrary number of parameters to a method.

Boxing/unboxing: Support for automatic conversion between primitive types and their
reference types.

Type-safe enumerations: Clean syntax for defining and using enumerations, supported
at the language level.

Static import: Ability to access static members from a class without need to qualify
them with a class name.

Metadata: Coupled with new tools developed by third-party companies, saves developers the
effort of writing boilerplate code by automatically generating the code.

Tuesday, September 18, 2007

NetBeans IDE 6.0

NetBeans IDE 6.0

The NetBeans IDE is a modular, standards-based, integrated development environment (IDE) written in the Java programming language. The NetBeans project consists of an open source IDE and an application platform, which can be used as a generic framework to build any kind of application.

for more information: http://www.netbeans.org/index.html

Working with Netbeans and ubuntu

1) Download JDK example: jdk1.6.0-beta2.bin into your home folder.

2) In terminal run : ./jdk1.6.0-beta2.bin
(make sure to chmod +x so that it can actually run)
result : you will get a folder in home such as jdk1.6.0/

3) In terminal run : sudo mv jdk1.6.0 /opt
result : you just moved jdk1.6.0 into /opt folder.
So now /opt/jdk1.6.0 is the location of the jdk.

4) In terminal run : sudo rm /usr/bin/java
result: remove any link that is in your system path for java.
So you can replace it with the jdk in /opt

5) In terminal run : sudo ln -s /opt/jdk1.6.0/jre/bin/java /usr/bin
result : made a link to your new jdk.
So that it is easy to be found by other programs

6) Dowload the latest snapshot of netbeans ex. nebeans 6.0

7) In terminal run : ./nebeans6.0-xxxx.bin
result : netbeans installer will find you jdk and will use it
for installation of the IDE.
At the end of installation you should have an icon on your desktop
for nebeans that uses java JDK that you placed in your /opt/jdk1.6.0 folder.

In netbeans folder structure you can find a file ~/netbeans6/etc/netbeans.conf
in there you can also point to a jdk of your choosing
like this : netbeans_jdkhome="/opt/jdk1.6.0"

Installing Java on Ubuntu

Update the apt repository with the following lines.

deb http://us.archive.ubuntu.com/ubuntu dapper main restricted
deb http://us.archive.ubuntu.com/ubuntu dapper universe multiverse

After this have apt updates its repository

Run the following command
sudo apt-get update

Once the above command is run. Its time to install java.
Run the following command to install java.
sudo apt-get install sun-java5-jdk

Installing MySQL on Ubuntu

It is very very easy to install mysql-server on ubuntu. All you have to do is run the following command.

To install
sudo apt-get install mysql-server

To run
mysql -u root -p -h localhost

Monday, September 17, 2007

Client Interaction -- Tips

1. Do not write "the same" in an email - it makes little sense to them.
Example - I will try to organize the project artifacts and inform you of the same when it is done.
This is somewhat an Indian construct. It is better written simply as:
I will try to organize the project artifacts and inform you when that is done

2. Do not write or say, "I have some doubts on this issue"
The term "Doubt" is used in the sense of doubting someone - we use this term because in Indian languages, the word for a "doubt"
and a "question" is the same.
The correct usage (for clients) is:
I have a few questions on this issue


3. The term "regard" is not used much in American English. They usually do not say "regarding this issue" or "with regard to this".
Simply use, "about this issue".


4. Do not say "Pardon" when you want someone to repeat what they said. The word "Pardon" is unusual for them and is somewhat
formal. You can say, ‘Please come again or could y ou please repeat.’


5. Americans do not understand most of the Indian accent immediately - They only understand 75% of what we speak and then interpret the rest. Therefore try not to use shortcut terms such as "Can't" or "Don't". Use the expanded "Cannot" or "Do not".


6. Do not use the term "screwed up" liberally. If a situation is not good, it is better to say, "The situation is messed up". Do not use words such as "shucks", or "pissed off".

7. As a general matter of form, Indians interrupt each other constantly in meetings - DO NOT interrupt a client when they are speaking.
Over the phone, there could be delays - but wait for a short time before responding.

8. When explaining some complex issue, stop occasionally and ask "Does that make sense?".
This is preferrable than "Do you understand me?"

9. In email communications, use proper punctuation. To explain something, without breaking your flow, use semicolons, hyphens or
paranthesis. As an example:
You have entered a ne w bug (the popup not showing up) in the defect tracking system; we could not reproduce it - although,
a screenshot would help.
Notice that a reference to the actual bug is added in paranthesis so that the sentence flow is not broken. Break a long sentence
using such punctuation.


10. In American English, a mail is a posted letter. An email is electronic mail.
When you say "I mailed the information to you", it means you sent an actual letter or package through the postal system.
The correct usage is: "I emailed the information to you"

11. To "prepone" an appointment is an Indian usage. There is no actual word called prepone. You can "advance" an appointment.

12. In the term "N-tier Architecture" or "3-tier Architecture", the word "tier" is NOT pronounced as "Tire". I have seen many people pronounce it this way. The correct pronunciation is "tea-yar". The "ti" is pronounced as "tea".


13. The usages "September End", "Month End", "Day End" are not understood we ll by Americans. They use these as "End of September",
"End of Month" or "End of Day".


14. Americans have weird conventions for time - when they say the time is "Quarter Of One", they mean the time is 1:15. Better to ask them the exact time.


15. Indians commonly use the terms "Today Evening", "Today Night". These are not correct; "Today" means "This Day" where the Day stands
for Daytime. Therefore "Today Night" is confusing. The correct usages are: "This Evening", "Tonight".
That applies for "Yesterday Night" and "Yesterday Evening". The correct usages are: "Last Night" and "Last Evening".


16. When Americans want to know the time, it is usual for them to say, "Do you have the time?". Which makes no sense to an indian.

17. There is no word called "Updation". You update somebody. You wait for updates to happen to the database. Avoid saying "Updation".

18. When you talk with someone for the first time, refer to them as they refer to you - in America, the first conversation usually starts by
using the first name. Therefore you can use the first name of a client. Do not say "Sir". Do not call women "Madam".


19. It is usual convention in initial emails (particularly technical) to expand abbreviations, this way:
We are planning to use the Java API for Registry (JAXR).
After mentioning the expanded form once, subsequently you can use the abbreviation.


20. Make sure you always have a subject in your emails and that the subject is relevant.
Do not use a subject line such as HI.


21. Avoid using "Back" instead of "Back" Use "ago". Back is the worst word for American. (for Days use "Ago", for hours use "before")

22. Avoid using "but" instead of "But" Use "However".

23. Avoid using "Yesterday" hereafter use "Last day".

24. Avoid using "Tomorrow" hereafter use "Next day".







Sunday, September 16, 2007

UDDI Clients and Servers

UDDI clients


uddi4j: UDDI for Java
UDDI.NET SDK: UDDI for Microsoft .NET
uddi4r: UDDI for Ruby
uddi4py: UDDI for Python
UDDI::Lite: UDDI for Perl

UDDI servers


Apache jUDDI: Open-Source UDDI Server
BEA Aqualogic Service Registry
Novell nSure UDDI Server: Open-Source UDDI Server
Microsoft Enterprise UDDI Server: Part of Windows 2003 Server
Systinet Registry
Oracle Service Registry
Software AG CentraSite
SAP Enterprise SOA PI7.1

Thursday, August 2, 2007

STEPS TO CONFIGURE JUDDI + JBOSS AND MY SQL




UDDI needs persistent storage as mentioned in above section.

Here we use MySQL for persistents.

Step 1:

Download MySQL-5.0.26 and install MySQL.

Set the root password to "password".

Step 2:

Install Jboss application server.

Jboss version 4.0.5 is used here

Step 3:

MySQL driver installation:

Download the corresponding drivers from the Internet and

place it in \server\default\lib folder.
Driver used here is mysql-connector-java-5.0.4-bin.jar.


Step 4:


jUDDI Deployment:


Download JUDDI version 0.9rc4

Unzip the file to some folder, say JUDY.
There will be a folder inside the unzipped package named juddi.
This folder has the folder structure as of web applications.
Copy the folder and place it inside <JBOSS_HOME>\server\default\deploy.
Rename the folder to juddi.war.

Inside JUDY where we have unzipped juddi download
there is a folder called “sql”.
There we can find the sql scripts for many databases.
In that we do have sql script for creating juddi schema for MySQL.
Run that script in installed MySQL and create the database and the tables.

Create juddi.xml: Create a file named juddi.xml in the folder

<JBOSS_HOME>\server\default\conf and with in that copy and past the following code. The password in the following code should be set to the MySQL database password.

<? Xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application
6.0//EN"  "http://www.bea.com/servers/wls600/dtd/weblogic-web-jar.dtd">
<Context path="/juddi" docBase="juddi" debug="5" reloadable="true"
crossContext="true">
<Logger className="org.apache.catalina.logger.FileLogger"
prefix="localhost_juddiDB_log" suffix=".txt" timestamp="true"/>
<Resource name="jdbc/juddiDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000" username="juddi"
password="password" driverClassName="org.gjt.mm.mysql.Driver"
url="jdbc: mysql://localhost:3306/juddi?autoReconnect=true" />
</Context>

Edit juddi.properties file located at <JBOSS_HOME>\server\default\deploy\juddi.war\web-inf\juddi.properties. Match the email address used with in the insert-publisher.sql. This should match the domine name used for the email address with in JUDDI's insert-publisher.sql file

juddi.operatorEmailAddress = yourEmail@aDomain.com


Create juddi-da.xml and place it in <JBOSS_HOME>\server\default\deploy.
Copy the following code to it and save the file.


<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>juddiDB</jndi-name>
<connection-url>jdbc:mysql://localhost:3306/juddi</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>root</user-name>
<password>password</password>
<min-pool-size>1</min-pool-size>
<max-pool-size>50</max-pool-size>
</local-tx-datasource>
</datasources>



Edit juddi-user.xml file located at <JBOSS_HOME>\server\default\deploy\juddi.war\web-inf\juddi-user.xml and change the password for the user juddi to MySQL root password (i.e., password)

Run Jboss.
Enter the URL http://<hostname>:8080/juddi/.
We will get the juddi home page. Click on validate link.
If there are any errors found in the validation page, Please follow all the steps above and validate again.
If there are no errors then it means juddi is configured successfully.



Wednesday, August 1, 2007

Design patterns

Design patterns helps us solve the problem we face in designing the application. It gives us many possible ways to solve a problem during object-oriented design. We can call it as a repatable solution to a commonly occuring problem.

Design patterns are categorized to following 3 groups:
1. Creational
2. Structural and
3. Behavioral.

diggthis