com.wm.app.b2b.server
Class ServerAPI

java.lang.Object
  extended by com.wm.app.b2b.server.ServerAPI

public class ServerAPI
extends java.lang.Object

Central point of access for internal server functionality. This includes:


Constructor Summary
ServerAPI()
           
 
Method Summary
static boolean checkAcl(java.lang.String aclName, java.lang.String userName)
          Returns true if the user belongs to a group that is a member of the specified ACL.
static ContentHandler getContentHandler(java.lang.String content_type)
          Returns a new ContentHandler for the specified content type.
static int getCurrentPort()
          Returns the port number associated with the current thread of execution.
static java.lang.String[] getEnabledPackages()
          Returns an array of String objects representing all enabled packages.
static LogOutputStream getLogStream(java.lang.String logfile)
          Opens a log file in the server's default logs directory.
static java.io.File getPackageConfigDir(java.lang.String pkgname)
          Returns a File object representing the path name for the given package's configuration directory.
static java.lang.String[] getPackages()
          Returns an array of String objects representing all packages.
static java.io.File getServerConfigDir()
          Returns a File object for the server's config directory.
static java.lang.String getServerName()
          Returns the server's host name.
static void logError(java.lang.Throwable t)
          Logs the specified error to the server's default log file.
static void logError(Values v)
          Logs the specified error to the server's default log file.
static void registerContentHandler(java.lang.String content_type, ContentHandlerFactory factory)
          Registers a new content-type with the server.
static void registerFlowService(java.lang.String pkgname, NSName svcname, FlowRoot root, NSSignature sig)
          Registers a Flow service.
static void registerFlowService(java.lang.String pkgname, NSName svcname, FlowRoot root, NSSignature sig, Values vals)
          Registers a Flow service.
static void registerService(java.lang.String pkgname, NSName svcname, boolean validate, int type, java.lang.String classname, java.lang.String methodname, Values vals)
          Registers a service.
static void removeContentHandler(java.lang.String content_type)
          Deregisters a content type from the server.
static void sendMail(java.lang.String to, java.lang.String from, java.lang.String subject, java.lang.String body)
          Sends an e-mail message to the specified recipient.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerAPI

public ServerAPI()
Method Detail

registerContentHandler

public static void registerContentHandler(java.lang.String content_type,
                                          ContentHandlerFactory factory)
Registers a new content-type with the server. ContentHandler objects are invoked to process input of their particular MIME type. A ContentHandlerFactory can be used to register several different MIME types.

Parameters:
content_type - A String specifying the new MIME content type to be supported (for example, "text/xml").
factory - A ContentHandlerFactory that will process requests for the new MIME type.
See Also:
ContentHandler, ContentHandlerFactory

removeContentHandler

public static void removeContentHandler(java.lang.String content_type)
Deregisters a content type from the server. The default content handler will be associated with this content type.

Parameters:
content_type - A String specifying the MIME content type to deregistered.

getContentHandler

public static ContentHandler getContentHandler(java.lang.String content_type)
Returns a new ContentHandler for the specified content type.

Parameters:
content_type - A String specifying a MIME content-type.
Returns:
A ContentHandler for the specified content type.

logError

public static void logError(java.lang.Throwable t)
Logs the specified error to the server's default log file. The name of the default log is usually "error.log" in the server's logs directory.
Note: Service.throwError method logs subclasses of java.lang.RuntimeException by default. Be careful not to double-log your errors.

Parameters:
t - A Throwable object specifying the error to be logged.
See Also:
logError(Values), Service.throwError(java.lang.Throwable)

logError

public static void logError(Values v)
Logs the specified error to the server's default log file. The name of the default log is usually "error.log" in the server's logs directory.
Note: Service.throwError method logs subclasses of java.lang.RuntimeException by default. Be careful not to double-log your errors.

Parameters:
v - A Values object specifying the error to be logged.
See Also:
logError(Throwable), Service.throwError(java.lang.Throwable)

getLogStream

public static LogOutputStream getLogStream(java.lang.String logfile)
Opens a log file in the server's default logs directory. This should only be used to obtain handles to new log files for app-specific logging purposes. By convention, the name should be something like “myapp.log".

Parameters:
logfile - A String specifying the name of the new log file.
Returns:
The LogOutputStream which is used to write to the new log file.

sendMail

public static void sendMail(java.lang.String to,
                            java.lang.String from,
                            java.lang.String subject,
                            java.lang.String body)
Sends an e-mail message to the specified recipient. This method is usually called on behalf of a service that's failing. The SMTP server must be set in the configuration file, watt.server.smtpServer, for this method to work properly.

Parameters:
to - A String specifying the recipient of the message.
from - A String specifying the return address.
subject - A String specifying the subject line of the message.
body - A String specifying the body of the message.

getServerConfigDir

public static java.io.File getServerConfigDir()
Returns a File object for the server's config directory. This contains all the server-wide configuration files, like "server.cnf".

Returns:
a File object pointing to SERVERHOME/config directory.

getPackageConfigDir

public static java.io.File getPackageConfigDir(java.lang.String pkgname)
Returns a File object representing the path name for the given package's configuration directory. This configuration directory contains all the settings files for initializing services in that package.

Parameters:
pkgname - A String specifying the name of the package whose configuration directory is desired.
Returns:
A File object representing the path name to the SERVERHOME/packages/pkgname/config directory.

getPackages

public static java.lang.String[] getPackages()
Returns an array of String objects representing all packages.

Returns:
A String [] of all packages.

getEnabledPackages

public static java.lang.String[] getEnabledPackages()
Returns an array of String objects representing all enabled packages.

Returns:
A String [] of all enabled packages.

registerFlowService

public static void registerFlowService(java.lang.String pkgname,
                                       NSName svcname,
                                       FlowRoot root,
                                       NSSignature sig)
                                throws ServiceSetupException
Registers a Flow service.

Parameters:
pkgname - A String specifying the package in which the service will reside.
svcname - A NSName specifying the service to be registered.
root - A FlowRoot object specifying the Flow in which the service will be placed.
sig - A NSSignature specifying the signature of the service.
Throws:
ServiceSetupException - If an error occurs while registering the Flow service.

registerFlowService

public static void registerFlowService(java.lang.String pkgname,
                                       NSName svcname,
                                       FlowRoot root,
                                       NSSignature sig,
                                       Values vals)
                                throws ServiceSetupException
Registers a Flow service.

Parameters:
pkgname - A String specifying the package in which the service will reside.
svcname - A NSName specifying the service to be registered.
root - A FlowRoot object specifying the Flow in which the service will be placed.
sig - A NSSignature specifying the signature of the service.
vals - A Values object (information from namespace node definition file)
Throws:
ServiceSetupException - If there is an error registering the Flow service.

registerService

public static void registerService(java.lang.String pkgname,
                                   NSName svcname,
                                   boolean validate,
                                   int type,
                                   java.lang.String classname,
                                   java.lang.String methodname,
                                   Values vals)
                            throws ServiceSetupException
Registers a service.

Parameters:
pkgname - A String specifying the package.
svcname - A NSName specifying the service name.
validate - A boolean value (true: attempt to load service)
type - An int value specifying the type of the service (from NSService).
classname - A String (if Java service), null otherwise.
methodname - A String (if Java service), null otherwise.
vals - A Values object (information from namespace node definition file).
Throws:
ServiceSetupException - If an error occurs while registering the service.
ServiceSetupException

getServerName

public static java.lang.String getServerName()
Returns the server's host name. If the server’s host name cannot be resolved then null is returned.

Returns:
A String representation of the server name; null otherwise.

getCurrentPort

public static int getCurrentPort()
Returns the port number associated with the current thread of execution. The current thread of execution has an associated InvokeState object which encapsulates the information describing every service invocation (for example, the service being invoked, the user invoking the service, inputs to the service, etc). If the InvokeState object associated with the current thread of execution cannot resolve the port number, then –1 is returned.

Returns:
An int value representing the port number associated with the current thread of execution; negative one (-1) otherwise.
See Also:
InvokeState

checkAcl

public static boolean checkAcl(java.lang.String aclName,
                               java.lang.String userName)
Returns true if the user belongs to a group that is a member of the specified ACL.

Parameters:
aclName - A string specifying an ACL name
userName - A string specifying a user name
Returns:
true if the user belongs to a group that is a member of the specified ACL; false otherwise.