Wednesday, July 25, 2012

BeanFace WebService - Dynamic Class Invocation

Before we go further, I will cover a couple of important things for the dynamic class invocation in BeanFace Web Service.

1. com.wwlee.utils.DynamicClassInstanceInvocation Class in BeanFace.jar file   
    public Object getInstance(String objectKey) throws BeanFaceException
  - This utility class returns Java Object instance based on objectKey. The information should be defined in the properties file as the key and value format. 


2. Property File for DynamicClassInstanceInvocation 
This properties file contains the Business Logic Transformation Implementation java information. The format will be like the below sample with key=value pair.
DynamicTransformation=com.wwlee.beanface.webservice.transform.example.DynamicTransformation
key can be any meaningful string. In the example, I use key as part of soapAction value.
value will be the actual implementation java class name with full package.

Where to place the property file?

 There are two simple ways to place this property files.
One is to find where the current directory location is. Use the following example to find it.
File file = new File(".");
System.out.println("Current Directory Location Full Path : " + file.getAbsolutePath());
--> For the glassfish server, this path is '~/appserver/domains/$DomainName/config'. Depending on your runtime sever, this value will be different.
In this example, I created BeanFaceProperties directory under config directory and placed DynamicTransformationInvocation.properties file which is in com.wwlee.beanface.webservice.transform.example package.
The second way is just to provide absolute property file name path, just like '/a/b/c/BeanFaceProperties/DynamicTransformationInvocation.properties'.

If you want to change this property file location, open 'BeanFaceWebServiceDynamicTransformation.java' in  com.wwlee.beanface.webservice.server.impl.example package, and change it.

3. Abstract Class : com.wwlee.beanface.webservice.server.WebServiceTransformation
    public abstract void receive() throws BeanFaceException;
    public abstract int reply() throws BeanFaceException;
    public abstract void transform() throws BeanFaceException;
-Every actual implementation class for Dynamic Invocation, need to implement these three methods.
In our examples, DynamicTransformation.java in com.wwlee.beanface.webservice.transform.example package has the sample. I think if you want to add more implmentation classes, just modify transform() method based on your requirement.

4. com.wwlee.beanface.webservice.server.impl.example.BeanFaceWebServiceServerRouter
   public WebServiceTransformation getInstance(String objectKey) throws BeanFaceException 
- This class extends DynamicClassInstanceInvocation  class and return actual implemented transformation class instance which implements WebServiceTransformation class instance.

5.com.wwlee.beanface.webservice.server.BeanFaceWebServiceInfo Class in BeanFace.jar file
- This class provides all of convenient methods to get or set request and response SOAP message. 


In the next blog, I will cover the actual sample to utilize the above concepts including Dynamic Class Instance Invocation and properties file. 


To fully use BeanFace and its Web Service, you need to download the followings.
1. BeanFace.jar - BeanFace Core API
2. BeanFaceExample.zip - Include all of the example source codes including Web Service Clients
3. BeanFaceWebService.zip - Include all of the sample java source for Web Service Server sides.  

No comments:

Post a Comment