Wednesday, June 4, 2008

MVC in JSF

* When a user requests a JSF page, the request goes to Faces Servlet.
* Faces Servlet is the controller which examines the user requests and calls various actions on the model.
*JSF user interface component represent the view layer.

JSF Application

Any JSF application includes the followinf pieces,

* Set of JSPs for presentation
* Java Beans
* Application configuration file whch defines navigation rules,configures beans and other custom objects.
* Web.xml
* Set of custom objects created by the developers.
* Custom tags needed for reperesenting custom objects.

Thursday, May 1, 2008

JAVAServer Faces Technology

Javaserver faces technology is a server side user interface component framework for java based web applications.
The well defined programming model and tag libraries significantly ease the burden of developing and maintaining web applications with server UIs.
One of the greatest advantage of JSF is , it provides complete separation between behavior and presentation just like client side UI architecture.

Introduction on AJAX Technology: Asynchronous JavaScript and XML

AJAX is not a new programming language, but a technology for creating better, faster, and more interactive web applications.
With AJAX, your JavaScript can communicate directly with the server, using the JavaScript XMLHttpRequest object. With this object, your JavaScript can trade data with a web server, without reloading the page.
AJAX uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole pages.

This is an excellent article on AJAX.
http://java.sun.com/developer/technicalArticles/J2EE/AJAX/

Tuesday, April 22, 2008

Command to generate client classes for wsdl using axis

Use the following task to generate the client class for the given WSDL using appache axis tool,



macro.java classname="org.apache.axis.wsdl.WSDL2Java" args="specify the wsdlname with absolute path --output specify the location where the client class shld get generated"

Out of memory error while generating client classes using WSDL

To handle this error we can generate the classed by directly using clientgen program by passing the memory limits.
Here's the command that could be used,

C:\bea\weblogic81\server\bin>java -Xms128m -Xmx1024m -Dweblogic.xml.schema.binding.verbose=true weblogic.webservice.clientgen -wsdl http://113.130.235.213:7741/webservice/SentinelWS?WSDL -packageName com.verizon.enterprise.eBosi.BOSIRepair.CMIS -clientJar CmWSClient.jar

Issues with Serialized object in webservice

Since objects communicating in webservice are serialized, any changes to the webservice would affect client application.
Esp when fields or methods are removed, then the object can't be deserialized in the client application.
Addition of fields/methods would not cause any issue during deserialization.

Creating and invoking WebService in Weblogic Server

Create the following file myRemote, myHome and myEJBClass under c:\myEJBexample .Set the path as c:\Webservicestaging.
com.example.webservices structure will be created under c:\Webservicestaging.
// myRemote.java
package com.example.webservices;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface myRemote extends EJBObject
{

public int mymethod(int i) throws RemoteException;
}

//myHome
package com.example.webservices;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface myHome extends EJBHome
{
myRemote create() throws RemoteException,CreateException;
}

//myEJBClass
package com.example.webservices;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
public class myEJBClass implements SessionBean
{
public myEJBClass(){}
public int mymethod(int i)
{
return i+5;
}

public void ejbCreate(){}
public void ejbRemove(){}
public void ejbActivate(){}
public void ejbPassivate(){}
public void setSessionContext(SessionContext sc){}
}

Compile the EJB as below
C:\myEJBexample>javac -d c:\staging *.java
Now class file will be generated under com.example.webservices structure in c:\ staging
Create META-INF folder in c:\ staging
Create ejb-jar.xml and weblogic-ejb-jar.xml under META-INF as below
C:\ staging>java weblogic.ant.taskdefs.ejb.DDInit c:\staging
Create myjar.jar under c:\ staging using the below command
C:\staging>jar cvf myjar.jar .
Create build.xml at C:\staging using the below script for creating an EAR file.

project name="buildWebservice" default="ear"
target name="ear"
servicegen
destEar="myear.ear"
contextURI="myServiceTest"
service
ejbJar="myjar.jar"
targetNamespace="http://www.bea.com/webservices/basic/statelesSession"
serviceName="myServiceTest"
serviceURI="/myServiceTest"
generateTypes="True"
expandMethods="True"
style="rpc"
/service
/servicegen
/target
/project

Execute the created build.xml using the below command
C:\staging\ant
Now an EAR file named myear would be created in the folder C:\staging.
Deploy myear in Weblogic server bu following the below said steps,
In the weblogic server console click Applications under Deployments.
Now Applications window will be opened in the right panel.
Click on Deploy an Application in the right panel.
In the Deploy an Application window go to C:\staging folder and select myear.ear file and select continue.
After successful deployment of myear.ear file; two files namely myjar.jar and myServiceTest would be created under myear.ear in the left panel under Applications.
Now click on myServiceTest in the left panel, and click on Testing tab in the right panel.
In the right panel under testing tab click on the link beside Launch Test Page.
In the page opened you can get the following details,
a. WSDL will be opened on click of the link Service Description
b. The method exposed in the WSDL can be tested by clicking the link myMethod.
c. Example code that invokes this service using generated stub will be given. This sample code can be used for writing out client.
d. To generate a client stub for this Web Service the ant task that needs to be used will be given.
Now create a folder named client under c:\staging to place all client related files.
Create build.xml to generate client jar using the ant task mentioned in step 8.d
Run this build.xml from c:\staging\client
Client jar containing supporting stubs will be created.
Extract the created client jar under c:\staging\client
Here is the sample client file for invoking the created the Web Service,create this file in c:\staging\client
import com.myco.myservice.client.MyServiceTest;
import com.myco.myservice.client.MyServiceTest_Impl;
import com.myco.myservice.client.MyServiceTestPort;
import com.myco.myservice.client.MyServiceTestPort_Stub;
public class myClient
{
public static void main(String args[])
{
try{
String wsdlUrl = "http://localhost:7001/myServiceTest/myServiceTest?WSDL";
MyServiceTest service = new MyServiceTest_Impl( wsdlUrl );
MyServiceTestPort port = service.getmyServiceTestPort();
int result = port.mymethod(10);
System.out.println("Result is ******** " + result);
}
catch(Exception e)
{
}
}
}
Now compile this file using the following command,
C:\staging\client>javac -d . *.java
17. Now run the generated class file to get the result.

Overview of WebLogic Web Services Architecture

Here is what happens when a client application invokes this type of WebLogic Web Service operation:
-The client application sends a SOAP message request to WebLogic Server over HTTP. Based on the URI in the request, WebLogic Server identifies the Web Service being invoked.
-The Web Service reads the SOAP message request and identifies the operation that it needs to run. The operation corresponds to a method of a stateless session EJB or a Java class, to be invoked in a later step.
-The Web Service converts the operation's parameters in the SOAP message from their XML representation to their Java representation using the appropriate deserializer class. The deserializer class is either one provided by WebLogic Server for built-in data types or a user-created one for non-built-in data types.
-The Web Service invokes the appropriate back-end component method, passing it the Java parameters.
-The Web Service converts the method's return value from Java to XML using the appropriate serializer class, and packages it into a SOAP message response.
-The Web Service sends the SOAP message response back to the client application that invoked the Web Service.

Overview of Web Services

In a typical Web services scenario, a business application sends a request to a service at a given URL using SOAP over HTTP
Web services are accessible from heterogeneous environment. They are technology and vendor independent unlike other service-oriented technologies such as RMI, COM, CORBA….

Properties of Web Services.

•Web Services are accessed over the Web.
•Web Services describe themselves using an XML-based description language.
•Web Services communicate with clients (either end-user applications or other Web Services) through XML messages that are transmitted by standard Internet protocols, such as HTTP.