soap tutorial

adriani.jws.template
Class SimpleClient

java.lang.Object
  extended by adriani.jws.template.SimpleClient

public class SimpleClient
extends java.lang.Object

A very simple command line class offering a main() method to allow invocation of the web service methods directly on the command line.
If all the necessary environment variables are correctly defined it should be possible to run this client writing:

java -cp %CLASSPATH% adriani.jws.template.client.SimpleClient

This class can be launched specifying the input parameters for the web service, choosing between two different approaches: in the emulate mode the client will invoke the business logic directly, bypassing the ADB structure. In the actual mode the client will invoke the actual skeleton class of the service.

For details run SimpleClient -h.


Field Summary
static java.lang.String BLANK
          Static final value stored as class field to improve performances.
 java.lang.String[] default_data
          The string array containing the default hard-coded SOAP request parameters.
static java.lang.String EMPTY
          Static final value stored as class field to improve performances.
 boolean emulate
          If true invokes a method like SimpleClient.testMethodName(), which emulates the web service (without using the ADBBean classes).
 java.lang.String[] format_data
          The string array containing the default hard-coded SOAP request parameters.
 int howMany
          Number of input parameters necessary to fill the input SOAP request (for current method).
 java.lang.String[] information_data
          The string array containing the default hard-coded SOAP request parameters.
protected static java.lang.String leadingName
          Beginning of each logging message produced by this class.
protected static WSLogger logger
          Retrieving the logger instance to be used for this class (static).
static java.lang.StringBuffer NULL
          Static final value stored as class field to improve performances.
static java.lang.String ZERO
          Static final value stored as class field to improve performances.
 
Constructor Summary
SimpleClient()
           
 
Method Summary
 void formatDate(java.lang.StringBuffer[] param)
          This method is invoked only if the client is run in the actual mode.
 java.util.Calendar getCalendarValue(java.lang.StringBuffer value)
          Parse an element of the input string, returning the parsed calendar value.
 java.util.Date getDateValue(java.lang.StringBuffer value)
          Parse an element of the input string, returning the parsed date value.
 void getInformation(java.lang.StringBuffer[] param)
          This method is invoked only if the client is run in the actual mode.
 int getIntValue(java.lang.String[] string, int index)
          Parse an element of the input array, returning the parsed integer value.
 int getIntValue(java.lang.StringBuffer[] buffer, int index)
          Parse an element of the input array, returning the parsed integer value.
 java.lang.StringBuffer[] getParameters(java.lang.String[] args, int method, int start)
          Extract the SOAP parameters list from the input args string array, starting from the start index position.
static void main(java.lang.String[] args)
          Main method used to call the web service from the command line, forwarding action to the run(String[] args) method.
 void manageOptions(java.lang.String[] args)
          Manage all the possible options available from the command line.
 java.lang.StringBuffer printHelp()
          Print some help about the SimpleClient command line options on the STDOUT.
 void run(java.lang.String[] args, int method)
          If the client is run in the emulate mode the method forwards action to one the testXXX() methods, which invokes the service logic using the hard-coded input parameters.
 void testCodeBlock(java.lang.String[] buffer)
          General test, used as a place-holder to write brand new code-block.
 void testConfiguration()
          Test method used to verify that the static code block in the GeneralService class is found and correctly executed.
 void testDatabase()
          Test method used to verify that the static code block in the Database class is found and correctly executed.
 void testFormatDate(java.lang.StringBuffer[] param)
          Invokes the ServiceLogic.getFormatDate() method using the wrappers defined in the wrappers package.
 void testGetInformation(java.lang.StringBuffer[] param)
          Invokes the ServiceLogic.getInformation() method using the wrappers defined in the wrappers package.
 void testLogger()
          Test the logging system.
 void testQuery(java.lang.StringBuffer[] buffer)
          Execute a simple dummy SQL query to verify the format of the JDBC result set retrieved from the database.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

howMany

public int howMany
Number of input parameters necessary to fill the input SOAP request (for current method).


default_data

public java.lang.String[] default_data
The string array containing the default hard-coded SOAP request parameters.


information_data

public java.lang.String[] information_data
The string array containing the default hard-coded SOAP request parameters.


format_data

public java.lang.String[] format_data
The string array containing the default hard-coded SOAP request parameters.


emulate

public boolean emulate
If true invokes a method like SimpleClient.testMethodName(), which emulates the web service (without using the ADBBean classes). Otherwise, if false, invokes the actual skeleton class implementing the web service, which should be a method like SimpleClient.methodName()


EMPTY

public static final java.lang.String EMPTY
Static final value stored as class field to improve performances.

See Also:
Constant Field Values

BLANK

public static final java.lang.String BLANK
Static final value stored as class field to improve performances.

See Also:
Constant Field Values

ZERO

public static final java.lang.String ZERO
Static final value stored as class field to improve performances.

See Also:
Constant Field Values

NULL

public static final java.lang.StringBuffer NULL
Static final value stored as class field to improve performances.


logger

protected static WSLogger logger
Retrieving the logger instance to be used for this class (static).


leadingName

protected static java.lang.String leadingName
Beginning of each logging message produced by this class.

Constructor Detail

SimpleClient

public SimpleClient()
Method Detail

main

public static void main(java.lang.String[] args)
Main method used to call the web service from the command line, forwarding action to the run(String[] args) method.

Default behavior (no option at all) will launch the simple client in the actual mode, using hard-coded data and calling the first method, i.e. the getDonator() method.

Parameters:
args - the standard input string array, usually read from STDIN.
See Also:
run(String[] args, int method)

run

public void run(java.lang.String[] args,
                int method)
If the client is run in the emulate mode the method forwards action to one the testXXX() methods, which invokes the service logic using the hard-coded input parameters.
Otherwise, if the client is run in the actual mode, action is forwarded to one the actual methods (named as the WSDL methods), which calls the service skeleton passing the input parameters (as above).

Parameters:
args - the standard input string array, usually read from STDIN
method - the web service method to be invoked (if 0 we'll use the default one, usually the first method)

manageOptions

public void manageOptions(java.lang.String[] args)
Manage all the possible options available from the command line. The available test offered by the SimpleClient are executed by calling:

java -cp %CLASSPATH% adriani.jws.template.client.SimpleClient -t n

Where the n parameter select one of the following test:

0. Test the logger system offered by the WSLogger class.
1. Forces the class loader to load the GeneralService class in order to verify that the configuration and initialization sequence is executed correctly.
2. Verify database environment (driver and connection pool) and all active threads.
3. Print the list of all active threads.
4. Test a generic code-block (unit-testing during development).

Parameters:
args - the input string array

testGetInformation

public void testGetInformation(java.lang.StringBuffer[] param)
Invokes the ServiceLogic.getInformation() method using the wrappers defined in the wrappers package. This method is useful when it's necessary to test the web service logic without using the ADBBean classes produces by Axis2 wsdl2java tool.
Basically speaking, the invocation of the ServiceLogic.getOutput() method performed here should almost reflect the actual implementation of the web service, with just two differences:

1. Here the WrapperIn object is constructed using the WrapperIn.setXXX() methods, while in the skeleton class a constructor like WrapperIn(ADBBean element) is used.
2. Here we extract data from the output wrapper using the WrapperOut.getXXX() methods, in order to print these data on the STDOUT, while the skeleton class returns the whole ADBBean object given by WrapperOut.getElement().

Parameters:
param - the string buffer array containing all the input data

testFormatDate

public void testFormatDate(java.lang.StringBuffer[] param)
Invokes the ServiceLogic.getFormatDate() method using the wrappers defined in the wrappers package. This method is useful when it's necessary to test the web service logic without using the ADBBean classes produces by Axis2 wsdl2java tool.
Basically speaking, the invocation of the ServiceLogic.getOutput() method performed here should almost reflect the actual implementation of the web service, with just two differences:

1. Here the WrapperIn object is constructed using the WrapperIn.setXXX() methods, while in the skeleton class a constructor like WrapperIn(ADBBean element) is used.
2. Here we extract data from the output wrapper using the WrapperOut.getXXX() methods, in order to print these data on the STDOUT, while the skeleton class returns the whole ADBBean object given by WrapperOut.getElement().

Parameters:
param - the string buffer array containing all the input data

getInformation

public void getInformation(java.lang.StringBuffer[] param)
This method is invoked only if the client is run in the actual mode. The required input ADBBean objects are produced using the input parameters, in order to respect the structure of the input ADBBean element. In the same way, the resulting output data are retrieved from the output ADBBean object, as returned by the skeleton, then are printed on the STDOUT.

Parameters:
param - the string buffer array containing all the input data

formatDate

public void formatDate(java.lang.StringBuffer[] param)
This method is invoked only if the client is run in the actual mode. The required input ADBBean objects are produced using the input parameters, in order to respect the structure of the actual input ADBBean element. In the same way, the resulting output data are retrieved from the output ADBBean object, as returned by the skeleton, then are printed on the STDOUT.

Parameters:
param - the string buffer array containing all the input data

testLogger

public void testLogger()
Test the logging system.


testConfiguration

public void testConfiguration()
Test method used to verify that the static code block in the GeneralService class is found and correctly executed. In this way we verify that all the static configuration and initialization of the web service is executed in the right order.


testDatabase

public void testDatabase()
Test method used to verify that the static code block in the Database class is found and correctly executed. Moreover, when this method is invoked, some meta-data about the database's connections and related pools are printed on the STDOUT.


testQuery

public void testQuery(java.lang.StringBuffer[] buffer)
Execute a simple dummy SQL query to verify the format of the JDBC result set retrieved from the database.
Current implementation performs a simple SELECT query in the DB_02 database. The query to be executed is selected by the argument[1] parameter, while the input parameter used to fill the statement (if available) is specified by the argument[2] parameter. In other words this method must be called using following syntax:

SimpleClient -q n p

The value of the parameter n select of the following DAO methods:

0 : getRecord(target, label, query, 1)
1 : getRecord(target, label, query, 4)
2 : getRecord(target, label, query, 4)
3 : getRecordSet(target, label, query, 2)
4 : getFunction(target, label, query, param_1, type)
5 : getProcedure(target, label, query, param_2, 1, inout)
6 : getFunctionPipe(target, label, query, 2)

Parameters:
buffer - the input string array, converted into a StringBuffer object
See Also:
GeneralDAO.getRecord(int targetDB, String label, String query, int cols), GeneralDAO.getRecordSet(int targetDB, String label, String query, int cols), GeneralDAO.getFunction(int targetDB, String label, String query, Object[] param, int type), GeneralDAO.getProcedure(int targetDB, String label, String query, Object[] param, int cols, int[] inout), GeneralDAO.getFunctionPipe(int targetDB, String label, String query, int cols)

testCodeBlock

public void testCodeBlock(java.lang.String[] buffer)
General test, used as a place-holder to write brand new code-block. After testing, usually this code-block is moved and renamed, creating a new method in another class (or is discharged).

To test this method run the SimpleClient using the -t 4 option.

Parameters:
buffer - the input args string array

getParameters

public java.lang.StringBuffer[] getParameters(java.lang.String[] args,
                                              int method,
                                              int start)
Extract the SOAP parameters list from the input args string array, starting from the start index position. If the input array is null the default values, stored as class fields, will be used.
If the number of input parameters is less than the required number of arguments this method will complete the SOAP request using the default values.

Parameters:
args - the standard input string array, usually taken from an hard-coded array
method - index of the method which the parameters belong
start - the index of the first args element to be used as SOAP parameter
Returns:
the SOAP input parameters as a StringBuffer array

printHelp

public java.lang.StringBuffer printHelp()
Print some help about the SimpleClient command line options on the STDOUT.

Returns:
the formatted string message printed on STDOUT

getIntValue

public int getIntValue(java.lang.String[] string,
                       int index)
Parse an element of the input array, returning the parsed integer value.

Parameters:
string - the input string array, converted into a String object
index - the index of the element to be extracted
Returns:
the integer number corresponding to the index-th element of the array

getIntValue

public int getIntValue(java.lang.StringBuffer[] buffer,
                       int index)
Parse an element of the input array, returning the parsed integer value.

Parameters:
buffer - the input string array, converted into a StringBuffer object
index - the index of the element to be extracted
Returns:
the integer number corresponding to the index-th element of the array

getDateValue

public java.util.Date getDateValue(java.lang.StringBuffer value)
Parse an element of the input string, returning the parsed date value.

Parameters:
value - the input date in string format
Returns:
the parsed date

getCalendarValue

public java.util.Calendar getCalendarValue(java.lang.StringBuffer value)
Parse an element of the input string, returning the parsed calendar value.

Parameters:
value - the input date in string format
Returns:
the parsed calendar

Build 18/09/2012

Morpheus Quality Technologies - Making the Zion software
Copyright © 2009-2013 Morpheus Quality Technologies. All Rights Reserved