public class HttpServer
extends java.lang.Object
implements java.lang.AutoCloseable
ESB
class
for processing. This base class also stores information on the exact address
that the server is running on and controls both the blocking and non-blocking
request threads that receive any remotely sent messages.
NOTE: when this is created it also adds a keystore with a default (untrusted) licas certificate.
Modifier and Type | Field and Description |
---|---|
protected static HttpServer |
httpServer
The http server
|
protected PasswordHandler |
passwordHandler
This stores and compares all passwords used by this service
|
protected static ServerConfig |
serverConfig
The server config or setup info
|
protected boolean |
shutDown
True if shutdown the service thread
|
protected java.lang.String |
uuid
This is the ID of the component
|
Modifier | Constructor and Description |
---|---|
protected |
HttpServer(ServerConfig theServerConfig)
Construct http server object.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canAccess(java.lang.String thePassword,
java.lang.reflect.Method theMethod)
Return true if the password allows the calling component to access this component.
|
boolean |
canAccess(java.lang.String thePassword,
java.lang.String methodName)
Return true if the password allows the calling component to access this component.
|
protected boolean |
checkAddress(java.lang.String host,
int port)
Return true if the ip address and port compares to the address the server is running on.
|
void |
close()
Clean-up before shutting down the service.
|
protected java.lang.String |
contactInfo()
Get a server administrator contact address, email or something.
|
protected ServiceWrapperDef |
createServiceWrapper(Auto theService,
java.lang.String serviceName,
java.lang.String serviceType,
java.util.ArrayList<java.lang.String> jarFiles,
org.licas_xml.abs.Element adminXml)
Create a service wrapper suitable for storing the service object.
|
java.lang.Object |
execute(MethodInfo methodInfo)
Execute the specified method and return the result.
|
protected java.lang.Object |
executeServer(MethodInfo methodInfo)
Execute the specified method and return the result.
|
protected ESB |
getESB(java.lang.String adminKey)
Return the Enterprise Service Bus stored in this server.
|
Link_NM |
getFaultsTree(java.lang.String adminKey)
Get the faults list tree.
|
protected static HttpServer |
getHttpServer(java.lang.String adminKey)
Retrieve the static instance of the http server.
|
protected FileObject |
getJarForService(java.lang.String jarName)
Load a jar file into a file object and return.
|
java.lang.String |
getPassword(java.lang.String clientID,
Contract clientContract)
Get this service's password, depending on the calling component's contract description.
|
protected java.util.ArrayList<java.lang.String> |
getPrivateMethods()
Get the list of public-level methods that should not be invoked externally, maybe from an interface.
|
protected java.util.ArrayList<java.lang.String> |
getPublicMethods()
Get the list of methods that can be freely called on a Service in general,
without even requiring a password.
|
protected java.util.ArrayList<java.lang.String> |
getServerMethods()
Return true if the method can be freely called without a password.
|
protected java.lang.String |
getServerPassword()
Get the local server password, which is the ESB password as well.
|
protected static java.lang.String |
getServerURL()
Return the http address of the static http server.
|
protected ServiceWrapperDef |
getServiceWrapper(java.lang.String serviceName,
java.lang.String thePassword,
java.lang.String adminKey)
Return the service wrapper for the related service name.
|
protected boolean |
getThisShutDown()
Return a value indicating if this server should be shut down.
|
java.lang.String |
getUUID()
Get the ID value.
|
protected boolean |
hasJarFactory(java.lang.String thePassword)
Return true if this server is running a jar factory.
|
protected boolean |
isAdminKey(java.lang.String theAdminKey)
Return true if the key passed in is this service's admin key.
|
protected boolean |
isLocalIPAddress(java.lang.String theIPAddress)
Return true if the ip address represents a local server.
|
protected boolean |
isPrivateMethod(java.lang.String methodName)
Return true if the method is a public-level method that should not be accessed externally.
|
boolean |
isPublicMethod(java.lang.String methodName)
Return true if the method is a public method that can be freely called.
|
boolean |
isRunning()
Return true if an enterprise service bus is stored and running in this server.
|
void |
notifyOfFault(FaultDetails fault,
java.lang.String adminKey)
This method should be called to notify the server about a problem or fault.
|
boolean |
setESB(java.lang.String serviceName,
java.lang.String serviceType,
java.util.ArrayList<java.lang.String> jarFile,
java.lang.String className,
java.util.ArrayList<java.lang.Object> params)
Set the ESB and update with the config values.
|
boolean |
setESB(java.lang.String serviceName,
java.lang.String serviceType,
org.licas_xml.abs.Element adminXml)
Set the ESB and update with the config values.
|
static boolean |
setHttpServer(ServerConfig theServerConfig)
Create an instance of the http server.
|
void |
setShutDown(java.lang.String thisAdminKey)
Set the shutdown variable to indicate that the thread should be stopped.
|
void |
setUUID(java.lang.String thisUUID)
Set the ID value, but only if it is null, otherwise it is not changed.
|
protected void |
shutDown()
Set the shut down variable to true
|
protected boolean |
shutDown(java.lang.String theAdminKey)
Shut down the server and stop the request thread.
|
protected void |
startRequestThread()
Start the request thread.
|
protected java.lang.String uuid
protected PasswordHandler passwordHandler
protected boolean shutDown
protected static ServerConfig serverConfig
protected static HttpServer httpServer
protected HttpServer(ServerConfig theServerConfig) throws java.lang.Exception
theServerConfig
- the server config or setup info.java.lang.Exception
- any error.public static boolean setHttpServer(ServerConfig theServerConfig) throws java.lang.Exception
theServerConfig
- the server config or setup info.java.lang.Exception
- any errorprotected static HttpServer getHttpServer(java.lang.String adminKey)
adminKey
- the server admin key.public boolean isRunning()
public boolean setESB(java.lang.String serviceName, java.lang.String serviceType, org.licas_xml.abs.Element adminXml)
serviceName
- the service name.serviceType
- the service type.adminXml
- the admin script.public boolean setESB(java.lang.String serviceName, java.lang.String serviceType, java.util.ArrayList<java.lang.String> jarFile, java.lang.String className, java.util.ArrayList<java.lang.Object> params)
serviceName
- the name of the service.serviceType
- the type of the service.jarFile
- the jar files for a remote loading. Values are jar paths
of type String.className
- the name of the service class.params
- a list of initialisation parameters.protected ESB getESB(java.lang.String adminKey)
adminKey
- the admin key for this server.protected boolean hasJarFactory(java.lang.String thePassword)
thePassword
- the password for this server.protected java.lang.String getServerPassword() throws java.lang.Exception
java.lang.Exception
- any error.protected ServiceWrapperDef createServiceWrapper(Auto theService, java.lang.String serviceName, java.lang.String serviceType, java.util.ArrayList<java.lang.String> jarFiles, org.licas_xml.abs.Element adminXml) throws java.lang.Exception
theService
- the service that is wrapped and managed. Must be Auto
-derived.serviceName
- the name of the service.serviceType
- the type of the service.jarFiles
- the jar files for a remote loading. Values are jar paths
of type String.adminXml
- an admin document describing the service wrapper. This is
probably null, but might be a config and policy script, for example.java.lang.Exception
- any error.public void notifyOfFault(FaultDetails fault, java.lang.String adminKey)
fault
- a description of the fault.adminKey
- server admin key. If this is incorrect, then the fault is not recorded.public Link_NM getFaultsTree(java.lang.String adminKey)
adminKey
- server admin key.public boolean canAccess(java.lang.String thePassword, java.lang.String methodName)
thePassword
- the password to use.methodName
- the method name that needs to be called.public boolean canAccess(java.lang.String thePassword, java.lang.reflect.Method theMethod)
thePassword
- the password to use.theMethod
- the method that needs to be called.protected void startRequestThread()
protected boolean getThisShutDown()
protected void shutDown()
protected boolean shutDown(java.lang.String theAdminKey)
theAdminKey
- the unique key to protect loading/removal of the server.protected java.lang.String contactInfo()
protected ServiceWrapperDef getServiceWrapper(java.lang.String serviceName, java.lang.String thePassword, java.lang.String adminKey) throws ServiceException, java.lang.Exception
serviceName
- the name of the service you want to retrieve.thePassword
- the password to access the service you want to retrieve.adminKey
- the admin key for the service you want to retrieve.ServiceException
- for service specific error.java.lang.Exception
- any other error.public java.lang.String getPassword(java.lang.String clientID, Contract clientContract) throws java.lang.Exception
clientID
- the clientID of the calling component.clientContract
- the description of the calling component's contract proposal.ESB
object
that also uses the same password set. The server by default will always or
never return its password.java.lang.Exception
- any error.protected FileObject getJarForService(java.lang.String jarName) throws java.lang.Exception
jarName
- the name of the jar file.java.lang.Exception
- any error.public java.lang.Object execute(MethodInfo methodInfo) throws java.lang.Exception
methodInfo
- the method call description with all of the required information.java.lang.Exception
- any error.protected java.lang.Object executeServer(MethodInfo methodInfo) throws MethodNotFoundException, java.lang.Exception
methodInfo
- the method call description with all of the required information.MethodNotFoundException
- for a method declaration mismatch.java.lang.Exception
- any other error.protected boolean isAdminKey(java.lang.String theAdminKey)
theAdminKey
- the key to check.public void setUUID(java.lang.String thisUUID)
thisUUID
- the ID.public java.lang.String getUUID()
public boolean isPublicMethod(java.lang.String methodName)
methodName
- the name of the method.protected boolean isPrivateMethod(java.lang.String methodName)
methodName
- the name of the method.protected java.util.ArrayList<java.lang.String> getServerMethods()
isPublicMethod
.protected java.util.ArrayList<java.lang.String> getPublicMethods()
protected java.util.ArrayList<java.lang.String> getPrivateMethods()
public void setShutDown(java.lang.String thisAdminKey)
thisAdminKey
- the service key of this service.protected boolean checkAddress(java.lang.String host, int port) throws java.lang.Exception
host
- the host address. Can include 'localhost' or '127.0.0.1'.port
- the port.java.lang.Exception
- any error.protected boolean isLocalIPAddress(java.lang.String theIPAddress) throws java.lang.Exception
theIPAddress
- the ip address to compare, 127.0.0.1, for example.java.lang.Exception
- any error.protected static java.lang.String getServerURL()
public void close()
close
in interface java.lang.AutoCloseable