org.benow.service
Class SimpleServiceClient

java.lang.Object
  extended by org.benow.service.SimpleServiceClient

public class SimpleServiceClient
extends java.lang.Object

The SimpleServiceClient is a simple accessor to services. It can be used as a standalone application (benow-service-client.jar) or within an application as an accessor to a remote system running the BeNOW services over http (BeNOW web framework).

Author:
andy

Nested Class Summary
 class SimpleServiceClient.RemoteError
           
 
Constructor Summary
SimpleServiceClient(java.lang.String urlStr)
          Create a new client connecting to given service url, in the format

[protocol]://[user:pass:]host[:port]/[prefix]

such as

http://localhost:8880/svc

If no username or password is given, then the user and pass from the runtime (Security.getCurrentUser()) is used, if there is any.

SimpleServiceClient(java.lang.String host, int port)
          Create client to given host, connect url constructed is http://[host]:[port]/svc.
SimpleServiceClient(java.lang.String protocol, java.lang.String host, int port, java.lang.String file)
           
SimpleServiceClient(java.net.URL url)
          Create a new client connecting to given service url, in the format

[protocol]://[user:pass:]host[:port]/[prefix]

such as

http://localhost:8880/svc

If no username or password is given, then the user and pass from the runtime (Security.getCurrentUser()) is used, if there is any.

 
Method Summary
static java.lang.String elementToString(org.w3c.dom.Element elem)
          Converts an element to a xml string.
 java.lang.Object exec(java.lang.String className, java.lang.String methodSig, java.lang.Object... params)
          Exec a service method with parameters, returning a result as an object.
 byte[] execData(java.lang.String className, java.lang.String methodSig, java.lang.Object... params)
          Runs a given method and returns the raw returned data.
 java.lang.String execString(java.lang.String className, java.lang.String methodSig, java.lang.Object... params)
          Runs a given method and returns the full returned value in string format.
 org.w3c.dom.Document execXML(java.lang.String className, java.lang.String methodSig, java.lang.Object... params)
          Call, returning xml document.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleServiceClient

public SimpleServiceClient(java.lang.String urlStr)
                    throws java.net.MalformedURLException
Create a new client connecting to given service url, in the format

[protocol]://[user:pass:]host[:port]/[prefix]

such as

http://localhost:8880/svc

If no username or password is given, then the user and pass from the runtime (Security.getCurrentUser()) is used, if there is any. This is inspected via reflection, so if the security classes are not on the classpath, there is no error. If no current user (not found or anonymous) no user is used for connect. The user may be given in inline format:

http://me:mypass@somehost/svc

Parameters:
urlStr -
Throws:
java.net.MalformedURLException

SimpleServiceClient

public SimpleServiceClient(java.net.URL url)
                    throws java.net.MalformedURLException
Create a new client connecting to given service url, in the format

[protocol]://[user:pass:]host[:port]/[prefix]

such as

http://localhost:8880/svc

If no username or password is given, then the user and pass from the runtime (Security.getCurrentUser()) is used, if there is any. This is inspected via reflection, so if the security classes are not on the classpath, there is no error. If no current user (not found or anonymous) no user is used for connect. The user may be given in inline format:

http://me:mypass@somehost/svc

If a user is given, authentication is performed immediately. No consideration is currently made for session expiry.

Parameters:
urlStr -
Throws:
java.net.MalformedURLException

SimpleServiceClient

public SimpleServiceClient(java.lang.String host,
                           int port)
                    throws java.net.MalformedURLException
Create client to given host, connect url constructed is http://[host]:[port]/svc. Authentication grabbed from run user, if any.

Parameters:
host -
Throws:
java.net.MalformedURLException

SimpleServiceClient

public SimpleServiceClient(java.lang.String protocol,
                           java.lang.String host,
                           int port,
                           java.lang.String file)
                    throws java.net.MalformedURLException
Throws:
java.net.MalformedURLException
Method Detail

execData

public byte[] execData(java.lang.String className,
                       java.lang.String methodSig,
                       java.lang.Object... params)
                throws SimpleServiceClient.RemoteError,
                       java.lang.RuntimeException
Runs a given method and returns the raw returned data.

Parameters:
className -
methodSig -
params -
Returns:
Throws:
SimpleServiceClient.RemoteError - on something wrong remotely
java.lang.RuntimeException

exec

public java.lang.Object exec(java.lang.String className,
                             java.lang.String methodSig,
                             java.lang.Object... params)
Exec a service method with parameters, returning a result as an object.

Parameters are converted for http transport as appropriate:

The object returned is determined by

Parameters:
className -
methodSig -
params -
Returns:

execString

public java.lang.String execString(java.lang.String className,
                                   java.lang.String methodSig,
                                   java.lang.Object... params)
Runs a given method and returns the full returned value in string format.

Parameters:
className -
methodSig -
params -
Returns:
Throws:
SimpleServiceClient.RemoteError - on something wrong remotely
java.lang.RuntimeException

execXML

public org.w3c.dom.Document execXML(java.lang.String className,
                                    java.lang.String methodSig,
                                    java.lang.Object... params)
Call, returning xml document.

Parameters:
className -
methodSig -
params -
Returns:

elementToString

public static java.lang.String elementToString(org.w3c.dom.Element elem)
                                        throws java.io.IOException
Converts an element to a xml string. Useful when inspecting element results.

Parameters:
elem -
Returns:
Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)