com.google.api.ads.common.lib.soap
Class SoapServiceClient<T>

java.lang.Object
  extended by com.google.api.ads.common.lib.soap.SoapServiceClient<T>
Type Parameters:
T - the type of SOAP client
All Implemented Interfaces:
InvocationHandler
Direct Known Subclasses:
AdsServiceClient

public abstract class SoapServiceClient<T>
extends Object
implements InvocationHandler

The SoapServiceClient class pairs together the soapClient and soapClientHandler so that calls made through the invoke(Object, Method, Object[]) method can be dispatched and handled correctly in the SOAP layer. This class is not aware of what API it uses and relies on the soapClientHandler to determine how the SOAP framework should be used.

Author:
Adam Rogal

Constructor Summary
protected SoapServiceClient(SoapClientHandlerInterface<T> soapClientHandler, T soapClient)
          Protected constructor.
 
Method Summary
protected  SoapCallReturn callSoapClient(SoapCall<T> soapCall)
          Called from invoke(Object, Method, Object[]) if the method is intended for the SOAP client.
protected  SoapCall<T> createSoapCall(Method soapClientMethod, Object[] args)
          Creates the SoapCall from the soapClientMethod and its args.
 Object getSoapClient()
          Returns the underlying SOAP client.
protected  SoapClientHandlerInterface<T> getSoapClientHandler()
          Returns the SOAP client handler.
protected  Throwable handleException(Throwable e)
          Handles the exception.
 Object invoke(Object proxy, Method method, Object[] args)
          Wraps the underlying SOAP RPC such that first the method, by its name, is applied to the runtime class.
protected abstract  void logSoapCall(SoapCallReturn soapCallReturn)
          Logs a SOAP call.
 void setEndpointAddress(String endpointAddress)
          Sets the endpoint address of the underlying SOAP client.
protected abstract  void setHeaders()
          Sets the headers for the service client.
protected  Object unwrapSoapCallReturn(SoapCallReturn soapCallReturn)
          Unwraps a SOAP call return such that if there was an exception, it is thrown and if it was a successful call, the return value of the SOAP call is returned.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SoapServiceClient

protected SoapServiceClient(SoapClientHandlerInterface<T> soapClientHandler,
                            T soapClient)
Protected constructor.

Parameters:
soapClientHandler - the SOAP client handler
soapClient - the SOAP client
Method Detail

callSoapClient

protected SoapCallReturn callSoapClient(SoapCall<T> soapCall)
Called from invoke(Object, Method, Object[]) if the method is intended for the SOAP client. Extending classes should override this method if they wish to wrap the call, such in cases of reauthentication or exception handling. The actual SOAP call is synchronized on the SOAP client so that only one request to the SOAP client can be made with without interruption, useful for logging and exception handling.

Parameters:
soapCall - the call to send to the SOAP client
Returns:
the return value from the soapCall

invoke

public Object invoke(Object proxy,
                     Method method,
                     Object[] args)
              throws Throwable
Wraps the underlying SOAP RPC such that first the method, by its name, is applied to the runtime class. If no such method exists, it is assumed that the call is meant for the SOAP client. In this case, the SOAP client handler will invoke the SOAP client method with provided arguments.

Specified by:
invoke in interface InvocationHandler
Parameters:
proxy - the proxy class that invoke was called on
method - the method to apply to the proxy class or the underlying SOAP client
args - the method arguments
Returns:
the return from the SoapServiceClient or a SoapCallReturn object containing the result from the SOAP call
Throws:
Throwable - thrown if the SOAP call passed into this method results in an exception. The exception thrown will be not be wrapped - it will adhere to the "throws" clause of the passed in Method.
See Also:
InvocationHandler.invoke(Object, Method, Object[])

createSoapCall

protected SoapCall<T> createSoapCall(Method soapClientMethod,
                                     Object[] args)
Creates the SoapCall from the soapClientMethod and its args.


setEndpointAddress

public void setEndpointAddress(String endpointAddress)
Sets the endpoint address of the underlying SOAP client.


getSoapClient

public Object getSoapClient()
Returns the underlying SOAP client.


getSoapClientHandler

protected SoapClientHandlerInterface<T> getSoapClientHandler()
Returns the SOAP client handler.


logSoapCall

protected abstract void logSoapCall(SoapCallReturn soapCallReturn)
Logs a SOAP call.

Parameters:
soapCallReturn -

setHeaders

protected abstract void setHeaders()
                            throws ServiceException,
                                   AuthenticationException
Sets the headers for the service client.

Throws:
ServiceException - if there was a problem setting the headers
AuthenticationException - if there was a problem authenticating while setting headers

handleException

protected Throwable handleException(Throwable e)
Handles the exception.

Default behavior is to return the exception unchanged.

Parameters:
e - the exception to handle
Returns:
the exception which may have been modified (wrapped/unwrapped)

unwrapSoapCallReturn

protected Object unwrapSoapCallReturn(SoapCallReturn soapCallReturn)
                               throws Throwable
Unwraps a SOAP call return such that if there was an exception, it is thrown and if it was a successful call, the return value of the SOAP call is returned.

Parameters:
soapCallReturn - the SoapCallReturn to unwrap
Returns:
the SoapCallReturn.getReturnValue() if the call was successful
Throws:
Throwable - the exception captured in the SoapCallReturn.getException() if present


Copyright © 2012. All Rights Reserved.