com.trendmicro.grid.acl.client
Class ServiceClient

java.lang.Object
  extended by com.trendmicro.grid.acl.client.ServiceClient

public class ServiceClient
extends Object

Implements a sharable, thread safe client to connect to the JAX-WS based web services.

Author:
Juergen_Kellerer, 2010-05-16

Constructor Summary
ServiceClient()
          Creates a new service client using built-in default settings.
ServiceClient(String defaultHost, int defaultPortNumber, boolean defaultSecure)
          Creates a new service client for the given default hostname, port number and SSL option.
ServiceClient(String defaultHost, int defaultPortNumber, boolean defaultSecure, UUID apiKey)
          Creates a new service client for the given default hostname, port number and SSL option.
ServiceClient(String defaultHost, UUID apiKey)
          Creates a new service client using the given GRID ACL default host and an optional api-key.
 
Method Summary
 void configureWithSessionCookies(URLConnection urlConnection)
          Adds session cookies to the given http url connection.
static com.trendmicro.grid.acl.l0.datatypes.FileIdentifier generateFileIdentifier(File source)
          Is a utility method that generates a file identifier from the given File.
static com.trendmicro.grid.acl.l0.datatypes.FileIdentifier generateFileIdentifier(URL source)
          Is a utility method that generates a file identifier from the given URL.
 net.sf.tinyjee.ws.client.ClientServiceContext getContext()
          Returns the underlying client context instance.
 String getDefaultHost()
           
 int getDefaultPortNumber()
           
 Collection<Class<? extends com.trendmicro.grid.acl.Service>> getDefinedPorts()
          Returns all endpoint interfaces of the service definitions.
 InputStream getFromUrl(URL sourceUrl)
          Gets content from the given URL using the same session as used with web-service calls.
 void getFromUrl(URL sourceUrl, OutputStream targetStream)
          Gets content from the given URL using the same session as used with web-service calls and writes it to the provided output stream.
<T extends com.trendmicro.grid.acl.Service>
T
getPort(Class<T> endpointInterface)
          Returns a cached port (proxy) of the given endpoint interface using the specified default values for host, port-number and security.
<T extends com.trendmicro.grid.acl.Service>
T
getPort(Class<T> endpointInterface, String host)
          Returns a cached port (proxy) of the given endpoint interface.
<T extends com.trendmicro.grid.acl.Service>
T
getPort(Class<T> endpointInterface, String host, int port, boolean secure, WebServiceFeature... features)
          Returns a cached port (proxy) of the given endpoint interface.
 boolean isDefaultSecure()
           
 HttpURLConnection preparePutToUrl(URL targetUrl)
          Prepares a HttpURLConnection to PUT content to the underlying URL using the same session as used with web-service calls.
 void putToUrl(InputStream inputStream, URL targetUrl)
          Puts content to the given URI using the same session as used with web-service calls.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServiceClient

public ServiceClient()
Creates a new service client using built-in default settings.


ServiceClient

public ServiceClient(String defaultHost,
                     UUID apiKey)
Creates a new service client using the given GRID ACL default host and an optional api-key.

Parameters:
defaultHost - the default hostname to use when retrieving a port using getPort(Class).
apiKey - an optional API key to use with SOAP calls (can be set to 'null' if not relevant). If specified, connections are by default opened using a secured (SSL/TLS) connection.

ServiceClient

public ServiceClient(String defaultHost,
                     int defaultPortNumber,
                     boolean defaultSecure)
Creates a new service client for the given default hostname, port number and SSL option.

Parameters:
defaultHost - the default hostname to use when retrieving a port using getPort(Class).
defaultPortNumber - the port number of the ACL running on the given host. Use '0' to use the protocol's default port.
defaultSecure - toggles whether the service is by default accessed using a secured (SSL/TLS) connection.

ServiceClient

public ServiceClient(String defaultHost,
                     int defaultPortNumber,
                     boolean defaultSecure,
                     UUID apiKey)
Creates a new service client for the given default hostname, port number and SSL option.

Parameters:
defaultHost - the default hostname to use when retrieving a port using getPort(Class).
defaultPortNumber - the port number of the ACL running on the given host. Use '0' to use the protocol's default port.
defaultSecure - toggles whether the service is by default accessed using a secured (SSL/TLS) connection.
apiKey - an optional API key to use with SOAP calls. (can be set to 'null')
Method Detail

getContext

public net.sf.tinyjee.ws.client.ClientServiceContext getContext()
Returns the underlying client context instance.

Returns:
the underlying client context instance.

generateFileIdentifier

public static com.trendmicro.grid.acl.l0.datatypes.FileIdentifier generateFileIdentifier(URL source)
                                                                                  throws IOException
Is a utility method that generates a file identifier from the given URL.

Parameters:
source - the source to generate the file-identifier of.
Returns:
a fully qualified file identifier containing SHA1 and MD5.
Throws:
IOException - in case of reading the source failed.

generateFileIdentifier

public static com.trendmicro.grid.acl.l0.datatypes.FileIdentifier generateFileIdentifier(File source)
                                                                                  throws IOException
Is a utility method that generates a file identifier from the given File.

Parameters:
source - the source to generate the file-identifier of.
Returns:
a fully qualified file identifier containing SHA1 and MD5.
Throws:
IOException - in case of reading the source failed.

getFromUrl

public InputStream getFromUrl(URL sourceUrl)
                       throws IOException
Gets content from the given URL using the same session as used with web-service calls.

Parameters:
sourceUrl - the URL to GET.
Returns:
the input stream containing the content stream.
Throws:
IOException - in case of reading the content failed.

getFromUrl

public void getFromUrl(URL sourceUrl,
                       OutputStream targetStream)
                throws IOException
Gets content from the given URL using the same session as used with web-service calls and writes it to the provided output stream.

This method has more advanced error reporting than getFromUrl(java.net.URL) as it also evaluates HTTP response codes and error replies from the server.

Parameters:
sourceUrl - the URL to GET.
targetStream - the target to write the content to.
Throws:
IOException - In case of reading or writing the content failed.

putToUrl

public void putToUrl(InputStream inputStream,
                     URL targetUrl)
              throws IOException
Puts content to the given URI using the same session as used with web-service calls.

Parameters:
inputStream - the stream of the content to put.
targetUrl - the target URL to put the content to.
Throws:
IOException - In case of reading or writing the content failed.

preparePutToUrl

public HttpURLConnection preparePutToUrl(URL targetUrl)
                                  throws IOException
Prepares a HttpURLConnection to PUT content to the underlying URL using the same session as used with web-service calls.

Parameters:
targetUrl - the target URL to put the content to.
Returns:
a configured HttpURLConnection instance that can be used for putting the content.
Throws:
IOException - In case of reading or setting the cookies fails.

configureWithSessionCookies

public void configureWithSessionCookies(URLConnection urlConnection)
                                 throws IOException
Adds session cookies to the given http url connection.

Parameters:
urlConnection - the url connection to configure.
Throws:
IOException - in case of the configuration failed.

getDefaultHost

public String getDefaultHost()

getDefaultPortNumber

public int getDefaultPortNumber()

isDefaultSecure

public boolean isDefaultSecure()

getPort

public <T extends com.trendmicro.grid.acl.Service> T getPort(Class<T> endpointInterface)
Returns a cached port (proxy) of the given endpoint interface using the specified default values for host, port-number and security.

Look after implementations of Service to see what endpoint interfaces exist and can be used here.

Type Parameters:
T - the endpoint interface type.
Parameters:
endpointInterface - the interface describing the endpoint protocol.
Returns:
a cached port (proxy) of the given endpoint interface.

getPort

public <T extends com.trendmicro.grid.acl.Service> T getPort(Class<T> endpointInterface,
                                                             String host)
Returns a cached port (proxy) of the given endpoint interface.

Look after implementations of Service to see what endpoint interfaces exist and can be used here.

Type Parameters:
T - the endpoint interface type.
Parameters:
endpointInterface - the interface describing the endpoint protocol.
host - the hostname of the remote machine to connect to.
Returns:
a cached port (proxy) of the given endpoint interface.

getPort

public <T extends com.trendmicro.grid.acl.Service> T getPort(Class<T> endpointInterface,
                                                             String host,
                                                             int port,
                                                             boolean secure,
                                                             WebServiceFeature... features)
Returns a cached port (proxy) of the given endpoint interface.

Look after implementations of Service to see what endpoint interfaces exist and can be used here.

Type Parameters:
T - the endpoint interface type.
Parameters:
endpointInterface - the interface describing the endpoint protocol.
host - the hostname of the remote machine to connect to.
port - the port number of the remote machine to connect to.
secure - whether a secure transport should be chosen.
features - specifies additional standard or vendor specific features that may be applied to the returned port proxy.
Returns:
a cached port (proxy) of the given endpoint interface.

getDefinedPorts

public Collection<Class<? extends com.trendmicro.grid.acl.Service>> getDefinedPorts()
Returns all endpoint interfaces of the service definitions.

Returns:
all endpoint interfaces of the service definitions.