Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, January 28, 2010

VXML

VoiceXML is a markup language for creating voice-user interfaces. It uses speech recognition and/or touchtone (DTMF keypad) for input and pre-recorded audio and text-to-speech synthesis (TTS) for output. It is based on the Worldwide Web Consortium's (W3C's) Extensible Markup Language (XML) and leverages the web paradigm for application development and deployment. By having a common language application developers platform vendors and tool providers all can benefit from code portability and reuse

Saturday, November 28, 2009

JMeter

JMeter

It is an open source software to perform load testing the functional and behavioral and measuring the performance.

http://jakarta.apache.org/jmeter/ 

Putty and CVS

PuTTY is a terminal emulator application which can act as a client for the SSH, Telnet, rlogin, and raw TCP computing protocols. An open source telnet and SSH Client for the Windows and Unix platforms. Includes FAQ, documentation and contact information.

Download link for PuTTY http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

To configure CVS using putty, install putty and enter the host name where CVS repository is located. Command prompt pops up asking to authenticate. Once authenticated you will be able to access CVS repository from your local machine.

You can also configure CVS with Eclipse. In the fast view of eclipse select CVS and go to CVS repository.
Configure the CVS by specfying the parameters requested. CVS will be integrated with the local machine. Now, we can checkout the projects into the repository. This helps in maintaining all the applications at a single repository. Also it will be helpful for all the team members to work on the same version of code.

Useful links for writting web services

Here are a few links to get started with webservices using axis2 and also installing and setting up the environment. I suggest to follow one of the links for clarity [do not follow all, you will be confused] depending on what you are looking for.

[1] Developing webservices using JAX-WS and weblogic http://download.oracle.com/docs/cd/E12840_01/wls/docs103/webserv/setenv.html

[2] Developing web services with handler http://www.developer.com/services/article.php/3503766/Processing-RequestResponse-Messages-of-a-Web-Service-Using-Handler-Chain.htm

[3]  Configuration files while using AXIS2. http://ws.apache.org/axis2/1_3/axis2config.html

[4] Sample example for writing web service handlers http://docs.huihoo.com/apache/axis2-1.0-docs/xdocs/1_0/userguide4.html

[5] Learning how to develop and deploy applications using AXIS2 [beginner's guide] http://docs.huihoo.com/apache/axis2-1.0-docs/xdocs/1_0/userguide1.html

[6] How to install and configure axis2 with tomcat or weblogic http://www.aniltj.com/blog/2006/02/06/InstallAndConfigureApacheTomcatAxisForWebServiceDevelopmentOnWindowsXPSP2.aspx

[7] Demonstration of simple web service http://lkamal.blogspot.com/2008/07/web-service-axis-tutorial-client-server.html

[8] Developing POJO web service using Axis2. http://ws.apache.org/axis2/1_1/pojoguide.html#pojows

[9] Hello world with AXIS2. http://people.apache.org/~ruchithf/hw-axis2/

Thursday, November 26, 2009

Web Service Examples

I would like to share a few web service examples, firstly I will walk through the process of developing and publishing web services using JAX-RPC and AXIS2 on Tomcat.
Step 1
Install AXIS2 and verify its working, Step by step instructions in installing AXIS2 is given in http://ws.apache.org/axis2/1_1/installationguide.html
Step 2
Develop a simple Hello world example using AXIS2 and deploy on tomcat to demonstrate its working. http://people.apache.org/~ruchithf/hw-axis2/

Lets now see a simple temperature conversion web service without handlers.

Setup:
Download axis2.war unzip it.
Download weblogic 10.0 and install it.
Copy the contents of axis2.war into deploy directory of weblogic i.e wlserver_10.0 for weblogic 10.0
we can verify whether axis has been successfully deployed by starting the admin console and going to the url http:localhost:7001/axis2.
You should see axis2 welcome page.

Step 1 : Write a simple Java class with temperature conversion methods:

package weather;
public class TC {
/**
* util method to convert celsius to fahrenheit
* @param cValue : double value of celsius
* @return calculated value of fahrenheit
*/
public double c2fConvertion(double cValue) {
return ((cValue * 9.0)/5.0 )+ 32.0;
}

/**
* util method to convert fahrenheit to celsius
* @param fValue : double value of fahrenheit
* @return calculated value of celsius
*/
public double f2cConvertion(double fValue) {
return ((fValue - 32.0) * 5.0) / 9.0;
}
}

Include services.xml file in the META-INF folder, which is to be placed in the root.
<service name="BalanceEnquiryService">
    <description>
    This is a sample Web Service with a logging module engaged.
    </description>
     <parameter name="ServiceClass" locked="xsd:false">BalanceEnquiryService</parameter>
    <operation name="getBalance">
    <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"
    class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
     </operation>
 </service>

Step 2 :Compile the Program and make a aar file and deploy on axis2 which is deployed onto weblogic or tomcat.

Step 3: Successful deployment of web service will generate a WSDL file. Copy the url and save the file with .wsdl extension. paste the file into the client project.

Step 4 : At command prompt, go to the project where we copied the wsdl and type the command. WSDL2JAVA -uri .\****.wsdl -p client -d adb

Step 5: Stub would be generated at the package client in the project. Write a client test class to test the web service.

package weatherclient;

import java.rmi.RemoteException;

import weatherclient.TCStub.C2FConvertionResponse;

public class TCTest {

public static void main(String args[]) {
try {
TCStub abc = new TCStub("http://localhost:7001/axisnew/services/TC.TCHttpSoap12Endpoint");
weatherclient.TCStub.C2FConvertion req= new weatherclient.TCStub.C2FConvertion();
req.setArgs0(20);
C2FConvertionResponse res = abc.c2FConvertion(req);
System.out.print("converted value is " + res.get_return());
} catch(Exception e){
e.printStackTrace();
}
}
}


We can view the temperature on the console. Similarly we can include any business methods in our web service and the client can class them.

Now, lets see a web service example which uses Handlers.
The installation and deployment steps are similar to the web service described above.

Step 1: Write a service class as mentioned above and include services.xml. The services.xml file here would contain a module reference which points to the handler.

<service name="BalanceEnquiryService">
    <description>
    This is a sample Web Service with a logging module engaged.
    </description>
    <module ref="authentication"/>
     <parameter name="ServiceClass" locked="xsd:false">BalanceEnquiryService</parameter>
    <operation name="getBalance">
    <messageReceiver  mep="http://www.w3.org/2004/08/wsdl/in-out"
    class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
     </operation>
   </service>
     

Step 2: Write a module with the handler information and include a module.xml file which contains all the operations to be performed by the module.

The module class would contain the handler operations.

import org.apache.axis2.AxisFault;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisDescription;
import org.apache.axis2.description.AxisModule;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.modules.Module;
import org.apache.neethi.Assertion;
import org.apache.neethi.Policy;
public class AuthenticationModule implements Module {


// initialize the module
public void init(ConfigurationContext configContext, AxisModule module) throws AxisFault {
}

public void engageNotify(AxisDescription axisDescription) throws AxisFault {
}

// shutdown the module
public void shutdown(ConfigurationContext configurationContext) throws AxisFault {
}

public String[] getPolicyNamespaces() {
return null;
}

public void applyPolicy(Policy policy, AxisDescription axisDescription) throws AxisFault {
}

public boolean canSupportAssertion(Assertion assertion) {
return true;
}
}


Module.xml for the above handler class is as follows.


<?xml version="1.0" encoding="UTF-8"?>
<module name="authentication" class="AuthenticationModule">
  
   <InFlow>
         <handler name="InFlowLogHandler" class="AuthenticationHandler">
            <order phase="authentication"/>
        </handler>
    </InFlow>

    <OutFlow>
        <handler name="OutFlowLogHandler" class="AuthenticationHandler">
            <order phase="authentication"/>
        </handler>
    </OutFlow>

    <OutFaultFlow>
        <handler name="FaultOutFlowLogHandler" class="AuthenticationHandler">
            <order phase="authentication"/>
        </handler>
    </OutFaultFlow>

    <InFaultFlow>
         <handler name="FaultInFlowLogHandler" class="AuthenticationHandler">
            <order phase="authentication"/>
        </handler>
    </InFaultFlow>
</module>

Make a .mar file of module class and module.xml and deploy it into the modules folder of axis2 in our application server. Upon successful deployment we can view the module in the axis2 page under modules sub directory.

Step3: Engage the module for our service. Also engage the operations for the module.
Step4: Similar to the web services mentioned above, ie. verify wsdl, generate stub, write test case and demonstrate the working of the application.

Web Services

Service Oriented Architecture
It is an evolution of the fundamentals governing a component based development. Component based development provides an opportunity for greater code reuse than what is possible with object oriented principles.

Web Service -- It is an implementation technology and one of the ways to implement SOA. We can build SOA based applications without using Web Services for example Java RMI, EJB, JMS. But what Web Services offer is the standard based and platform-independant service via HTTP, XML, SOAP, WSDL and UDDI, thus allowing interoperability between heterogenous technologies like J2EE and .Net. Web Services support loosely coupled connections. The interface of the Web service provides a layer of abstraction between the client and the server. The loosely coupled applications reduce the cost of maintenance and increases reusability. esent a new form of middleware based on XML and Web. Web services are language and platform independent. You can develop a Web service using any language and deploy it on to any platform, from small
device to the largest supercomputer. Web service uses language neutral protocols such as HTTP and communicates between disparate applications by passing XML messages to each other via a Web API.

SOAP stands for Simple Object Access Protocol. It is an XML based lightweight protocol, which allows software components and application components to communicate, mostly using HTTP (can use SMTP etc). SOAP sits on top of the HTTP protocol. SOAP is nothing but XML message based document with pre-defined format. SOAP is designed to communicate via the Internet in a platform and language neutral manner and allows you to get around firewalls as well. Let’s look at thr structure of a SOAP messages:
A SOAP message MUST be encoded using XML.
A SOAP message MUST use the SOAP Envelope namespace.
A SOAP message MUST use the SOAP Encoding namespace.
A SOAP message must NOT contain a DTD reference.
A SOAP message must NOT contain XML Processing Instruction.

WSDL stands for Web Services Description Language. A WSDL document is an XML document that describes how the messages are exchanged. Let’s say we have created a Web service. Who is going to use that and how does the client know which method to invoke and what parameters to pass? There are tools that can generate WSDL from the Web service. Also there are tools that can read a WSDL document and create the necessary code to invoke the Web service. So the WSDL is the Interface Definition Language (IDL) for Web services.

UDDI stands for Universal Description Discovery and Integration. UDDI provides a way to publish and discover information about Web services. UDDI is like a registry rather than a repository. A registry contains only reference information like the JNDI, which stores the EJB stub references. UDDI has white pages, yellow pages and green pages. If the retail industry published a UDDI for a price check standard then all the retailers can register their services into this UDDI directory. Shoppers will search the UDDI directory to find the retailer interface. Once the interface is found then the shoppers can communicate with the services immediately.

Now, we have some java related API's for web services. The J2EE 1.4 platform provides comprehensive support for Web services through the JAX-RPC (Java API for XML based RPC Remote PCall)) and JAXR (Java API for XML Registries). In the J2EE 1.4 platform you can but the above mentioned XML based standards and protocols. A Web service client accesses the EJB container.

JAX-RPC (Java API for XML based RPC) supports XML based RPC for Java and J2EE platforms. JAX-RPC provides an easy to develop programming model to develop Web services. As shown in the diagram above, a JAX-RPC runtime system and API abstracts the complexities of SOAP protocol by :
Providing a standard way of marshalling Java to XML and Java to WSDL and unmarshalling XML to Java and WSDL to Java.
Standardizing the creation of SOAP requests and responses.
Supporting and dispatching SOAP requests to methods on JAX-RPC Service Endpoint classes in the Web Container.
Specifying a standard way to plug in SOAP message handlers, allowing both pre and post processing of SOAP requests and responses.

The JAX-RPC message handlers are similar to servlet filters. They provide additional message-
handling facilities to Web service endpoints (both client and server) as extensions to the basic service implementation logic by providing logging, auditing, encryption, decryption etc.

Apache AXIS is a Web services tool kit, which enables you to expose a functionality you have as a Web service without having to learn everything there is to know about the underlying platform. It hides all the complexities from the developer and improves productivity.

Friday, November 6, 2009

Maven

Maven is a tool used to build our applications. It is written in xml format in the file pom.xml. http://maven.apache.org/ will guide in understanding maven.

Working with maven for the first time.

1. Download Apache Maven(bin) from http://maven.apache.org/download.html.
2. Unzip into C:/Maven
3. Set Path M2_HOME pointing to the home directory and M2_Repo pointing to a repository what we created inside maven.
4. Set the path to M2\bin so that maven gets included into the path.
5. Run the commands given the http://maven.apache.org/ link. [go to the maven home directory and create repository]
6. While running for the first time maven will download all the necessary files.
7. Run the sample test program given in the my-app(this will be created when we run the create project command from the above link) directory.
8. pom.xml is the build file containing the build commands and dependencies.
9. From command prompt just go to the directory of pom.xml in the workspace and run the commands.