soap tutorial

adriani.jws.template.service
Class ServiceLogic

java.lang.Object
  extended by adriani.jws.template.service.GeneralService
      extended by adriani.jws.template.service.ServiceLogic

public class ServiceLogic
extends GeneralService

The "interface" class, implementing the high level behavior of the service. Preparation of the parameters for the DAO layer should not be handled here, but should be delegated to the ServiceMacro instead.
Using this class it should be possible to implement the service's skeleton just adding a code-block like this:


        ServiceLogic logic          = new ServiceLogic() ;
        WrapperXXXIn input          = new WrapperXXXIn(adbBean) ;
        WrapperXXXOut output        = (WrapperXXXOut) logic.getOutput(input) ;
        ADBBean element             = output.getElement() ;
 

Hence this class should implement one method for each method offered by the service skeleton: it's suggested to name such method using the SOAP method's name. Each ServiceLogic method reflecting a SOAP method should return the proper WrapperXXXOut, i.e. a custom subclass of the WrapperOut class.


Field Summary
protected static java.lang.String command_pwd
          The hard-coded pattern used to recognize remote manager commands (i.e. "000000").
protected static int ERROR
          The static value used to identify the ERROR empty response.
static int FORMAT_DATE
          Static value identifying the 2nd web service method.
static int GET_INFORMATION
          Static value identifying the 1st web service method.
protected  java.lang.String header_value
          The header value as retrieved from the SOAP's request (depending by the project).
protected static int INFO
          The static value used to identify the INFO empty response.
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).
protected  ServiceMacro serviceMacro
          A reference to the ServiceMacro managing all the calls the necessary DAO's.
protected static int SILENT
          The static value used to identify the INFO empty response.
protected static int WARN
          The static value used to identify the WARNING empty response.
 
Fields inherited from class adriani.jws.template.service.GeneralService
benchLogger, serviceAnalyzer
 
Constructor Summary
ServiceLogic()
          Constructor, creating also the ServiceMacro object and storing it as class attribute.
ServiceLogic(boolean macro)
          Constructor, creating also the ServiceMacro object and storing it as class attribute.
ServiceLogic(java.lang.String value)
          Constructor, creating also the ServiceMacro object and storing it as class attribute.
 
Method Summary
 WrapperOut checkAuthentication(int method)
          Checking for authentication, comparing authentication from the SOAP's header with authentication data from the properties file.
protected  WrapperOut getEmptyResponse(int method, int level, int state)
          Prepare a valid WrapperOut object when it's not possible to produce a valid result.
 WrapperDateOut getFormatDate(WrapperDateIn input)
          This is main business logic for the web service.
 WrapperInformationOut getInformation(WrapperInformationIn input)
          This is main business logic for the web service.
 ServiceMacro getServiceMacro()
          Return the instance of the serviceMacro used by this class.
static WrapperOut getWrapperOut(int method)
          The factory creating the proper WrapperXXXOut object that will be returned by the corresponding getOutputXXX() method.
protected  WrapperOut handleMacroError(int method, java.lang.Exception exception, boolean last)
          Prepare a valid WrapperOut subclass when the exception comes from a lower level, like the ServiceMacro class or the ServiceDBA class.
protected  WrapperOut handleNoValidation(WrapperOut wrapper, java.lang.Exception e)
          Prepare a valid WrapperOut subclass when we fail validation of the original WrapperOut object produced by the main logic.
 WrapperOut invokeMethod(int method, WrapperIn input)
          General purpose service layer for all the web service's methods.
protected  boolean manageService(WrapperIn input)
          Allow to configure the service dynamically, without reloading the AAR package on the application server.
protected  void showConfiguration()
          Prints in the LOG file some information about the service configuration.
 
Methods inherited from class adriani.jws.template.service.GeneralService
compareSB, delay, finalize, getCommandsList, getServiceAnalyzer, loadBundle, loadBundle, loadProperties, logIntrospection, manageService, showJavaProperties, showRuntime, valueOfString
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serviceMacro

protected ServiceMacro serviceMacro
A reference to the ServiceMacro managing all the calls the necessary DAO's.


header_value

protected java.lang.String header_value
The header value as retrieved from the SOAP's request (depending by the project).


GET_INFORMATION

public static final int GET_INFORMATION
Static value identifying the 1st web service method.

See Also:
Constant Field Values

FORMAT_DATE

public static final int FORMAT_DATE
Static value identifying the 2nd web service method.

See Also:
Constant Field Values

SILENT

protected static final int SILENT
The static value used to identify the INFO empty response.

See Also:
Constant Field Values

INFO

protected static final int INFO
The static value used to identify the INFO empty response.

See Also:
Constant Field Values

WARN

protected static final int WARN
The static value used to identify the WARNING empty response.

See Also:
Constant Field Values

ERROR

protected static final int ERROR
The static value used to identify the ERROR empty response.

See Also:
Constant Field Values

command_pwd

protected static final java.lang.String command_pwd
The hard-coded pattern used to recognize remote manager commands (i.e. "000000").

See Also:
Constant Field Values

leadingName

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


logger

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

Constructor Detail

ServiceLogic

public ServiceLogic()
Constructor, creating also the ServiceMacro object and storing it as class attribute.


ServiceLogic

public ServiceLogic(java.lang.String value)
Constructor, creating also the ServiceMacro object and storing it as class attribute. This constructor should be used when we need to retrieve (and store here) some data from the SOAP's header.

Parameters:
value - the value retrieved from the SOAP's header

ServiceLogic

public ServiceLogic(boolean macro)
Constructor, creating also the ServiceMacro object and storing it as class attribute.

NOT USED AT THE MOMENT!

Parameters:
macro - the ServiceMacro it's instantiated only if this parameter is true
Method Detail

checkAuthentication

public WrapperOut checkAuthentication(int method)
Checking for authentication, comparing authentication from the SOAP's header with authentication data from the properties file. To use this feature the client should specify the proper value in the header, for example:

<tns:psk xmlns:tns="http://adriani.altervista.org/namespaces/template">foo</tns:psk> For further details see the "how2use.txt" file.

See Also:
SoapHandler, SoapElements

invokeMethod

public WrapperOut invokeMethod(int method,
                               WrapperIn input)
General purpose service layer for all the web service's methods. When the service is invoked the invokeBusinessLogic() method of the XXXMessageReceiverInOut class forwards the action to XXXSkeleton.operation(), which can call this method.

This method can be used by all methods using a "standard pattern", e.g. by calling:

 return (WrapperXXXOut) invokeMethod(METHOD_NAME, input) ;
 

Parameters:
method - the static integer reference to the method to be invoked
input - the input ADBBean wrapped by the WrapperIn class
Returns:
the full output data wrapped by the proper WrapperOut class

getInformation

public WrapperInformationOut getInformation(WrapperInformationIn input)
This is main business logic for the web service. When the service is invoked the invokeBusinessLogic() method of the XXXMessageReceiverInOut class forwards the action to XXXSkeleton.operation(), which should just calls this method.

Parameters:
input - the input ADBBean wrapped by the WrapperInformationIn class
Returns:
the full output data wrapped by the WrapperInformationOut class

getFormatDate

public WrapperDateOut getFormatDate(WrapperDateIn input)
This is main business logic for the web service. When the service is invoked the invokeBusinessLogic() method of the XXXMessageReceiverInOut class forwards the action to XXXSkeleton.operation(), which should just calls this method.

Parameters:
input - the input ADBBean wrapped by the WrapperDateIn class
Returns:
the full output data wrapped by the WrapperDateOut class

getWrapperOut

public static WrapperOut getWrapperOut(int method)
The factory creating the proper WrapperXXXOut object that will be returned by the corresponding getOutputXXX() method. Every possible WrapperXXXOut class must extend the parent WrapperOut class.
This factory should return the proper WrapperXXXOut object corresponding to the input method parameter, which describes one of the operations offered by the skeleton (listed using static integer values defined as class fields).

In current implementation this factory is accessed only the the getEmptyResponse() method.

Parameters:
method - the logic method that invoked this method (see class fields)
Returns:
the proper WrapperOut object for the corresponding logic method

handleMacroError

protected WrapperOut handleMacroError(int method,
                                      java.lang.Exception exception,
                                      boolean last)
Prepare a valid WrapperOut subclass when the exception comes from a lower level, like the ServiceMacro class or the ServiceDBA class. In this case the error message is obtained by reading the necessary StackTraceElement objects.

Since the macro processing has been interrupted before producing any SOAP output, here we produce a brand new WrapperOut wrapper to ensure a correct SOAP output response, containing a message like "Java Macro Error".

Parameters:
method - the logic method that invoked this method (see class fields)
exception - the Exception thrown from a lower level (null otherwise)
last - if true the getEmptyResponse() method is invoked
Returns:
a valid WrapperOut subclass with a message describing this situation

handleNoValidation

protected WrapperOut handleNoValidation(WrapperOut wrapper,
                                        java.lang.Exception e)
Prepare a valid WrapperOut subclass when we fail validation of the original WrapperOut object produced by the main logic. The output message will contain a message with a reference to all the ADBBean objects responsible for the validation error.

Parameters:
wrapper - the instance of the WrapperOut subclass wrapping the output data
e - the Exception thrown when validating the WrapperOut element
Returns:
a valid WrapperOut subclass with a message describing all the validation errors

getEmptyResponse

protected WrapperOut getEmptyResponse(int method,
                                      int level,
                                      int state)
Prepare a valid WrapperOut object when it's not possible to produce a valid result. This method can be called in many different situations, each situation corresponding to a different message to be logged while producing the empty response. These situations are identified using the state param, which should be one of the integer values mapped by the ErrorMessage class. In current implementation this method is called in following situations: COMMAND, NO_DB, NO_RESULT, ERROR_LOGIC, ERROR_MACRO.

The level parameter can be: SILENT, INFO, WARN or ERROR.
If the SILENT constant it's used when no log message must be produced here, because we assume the caller has already logged a message describing the situation. Otherwise we produce a log message with the specified level. Current implementation relies on the wrapper factory, implemented by the getWrapperOut(), to produce the proper WrapperOut method for the current method.

Parameters:
method - a reference to one the SOAP methods exposed in the WSDL (see class fields)
level - the integer value defining the level of the logged message
state - the code of the message as described by the ErrorMessage class
Returns:
a valid WrapperOut object with a message describing this situation
See Also:
getWrapperOut(int method)

getServiceMacro

public ServiceMacro getServiceMacro()
Return the instance of the serviceMacro used by this class.

Returns:
a reference to the serviceMacro used by this class

manageService

protected boolean manageService(WrapperIn input)
Allow to configure the service dynamically, without reloading the AAR package on the application server. To send a valid command the service must be invoked passing a parameter starting with a sequence of zeros followed by the command code. The number of zeros depend by the constrain defined in the WSDL for the input parameter.
For example, if the input number parameter must be at least three digit long, then a valid command code could be something like "0001", which will be interpreted as the command 1.

The actual pattern used to recognize a command is defined by the command_pwd class field, while the field containing the command is defined by the WrapperSearchIn class.

Parameters:
input - an instance of the WrapperSearchIn wrapper containing the input data
Returns:
true if the input number have been recognized as valid command code
See Also:
command_pwd, WrapperInformationIn.getCommand()

showConfiguration

protected void showConfiguration()
Prints in the LOG file some information about the service configuration.
Notice the all classes extending the GeneralService class MUST implement this method. Hence, in order to save coding this method forwards action to the showConfiguration() method of the ServiceMacro class.

Specified by:
showConfiguration in class GeneralService
See Also:
ServiceMacro.showConfiguration()

Build 19/03/2014

Morpheus Technologies - making the Zion software
Copyright © 2009-2014 Morpheus Technologies. All Rights Reserved