com.prosysopc.ua.server
Class UaServer

java.lang.Object
  extended by com.prosysopc.ua.UaApplication
      extended by com.prosysopc.ua.server.UaServer

public class UaServer
extends UaApplication

Basic implementation of the OPC UA server.

You need to create a UaServer object and call init() for it after you have specified the security settings and endpointUrls to which you wish to bind it.

The endpoints are defined either as a list of URLs or even simpler by setting the Port and ServerName. The current host name of the server where the application is run is added to the list of URLs automatically. If you define UseLocalhost, the URL with the 'localhost' host name is also added to the list of Urls.

Note: Because the java stack currently only supports the OPC Binary protocol, you cannot define a port for the HTTP protocol.

By default, the server will contain a SessionManager, AttributeManager, SubscriptionManager and NodeManagerTable, which contains the NodeManagerRoot and the NodeManagerServer.

Use addNodeManager to add your own nodes into the server: do not add nodes to the NodeManagerRoot or NodeManagerServer.

You can also use addServiceHandler to add handlers for services that are not handled by the default implementation. However, you should take care that each service only has one handler in the server.

If you wish to replace the service handlers with your custom implementation, you must derive your own version of the server and override initServiceHandlers.

After you have finished with all initializations, call start() to make the server available for client connections, and to start the managers.


Nested Class Summary
 class UaServer.DiscoveryServer
          Service handler that serves onFindServers & onRegisteredServer requests. onGetEndpoint request is handled by a default EndpointDiscoveryService.
 class UaServer.NodeManagerUaServer
          Server internal namespace (NamespaceIndex 1)
 
Nested classes/interfaces inherited from class com.prosysopc.ua.UaApplication
UaApplication.a, UaApplication.DiagnosticMask, UaApplication.Protocol
 
Field Summary
protected  ApplicationIdentity applicationIdentity
           
protected  ServiceHandler attributeServiceHandler
           
protected  DiagnosticsManager diagnosticsManager
           
protected  Set<String> discoveryUris
           
protected  ScheduledExecutorService executor
           
protected  Set<String> httpsUris
           
protected  UaServerListener listener
           
protected  NodeManagerRoot nodeManagerRoot
           
protected  NodeManagerTable nodeManagerTable
           
protected  UaServer.NodeManagerUaServer nodeManagerUaServer
           
protected  NodeManagementServiceHandler nodeServiceHandler
           
protected  org.opcfoundation.ua.transport.security.SecurityMode[] securityModes
           
protected  Set<String> serverUris
           
protected  SessionManager sessionManager
           
protected  SessionManagerListener sessionManagerListener
           
protected  SessionServiceHandler sessionServiceHandler
           
protected  SubscriptionManager subscriptionManager
           
protected  SubscriptionServiceHandler subscriptionServiceHandler
           
 
Constructor Summary
UaServer()
          Creates a new UA Server.
 
Method Summary
 void addEndpoint(String uri, org.opcfoundation.ua.transport.security.SecurityMode securityMode, org.opcfoundation.ua.core.UserTokenPolicy... userTokenPolicies)
          Add an endpoint definition for a specific URI, SecurityMode & UserTokenPolicies combination

You should call addEndpoint after init() has been called.

 String[] addEndpointHost(String hostName)
          Add a specific hostName to the list of server URIs, in addition to what the default properties define.
 void addLocale(Locale locale)
           
 void addServiceHandler(Object serviceHandler)
          Add a custom serviceHandler.
 void addToServerArray(String uri)
          Add a server description to the serverArray.
 void addUserTokenPolicy(org.opcfoundation.ua.core.UserTokenPolicy policy)
           
 void close()
           
protected  AttributeServiceHandler createAttributeServiceHandler()
           
protected  DiagnosticsManager createDiagnosticsManager()
           
protected  ScheduledExecutorService createExecutor()
          This is called when a executor would be created for the UaServer.
protected  NodeManager createNewNodeManager(ServiceContext serviceContext, String namespaceUri)
          Creates a new node manager as a response to an AddNodes request with a NodeId that is not managed by any node managers, yet.
protected  NodeManagementServiceHandler createNodeManagementServiceHandler()
           
protected  SessionManager createSessionManager()
           
protected  SessionServiceHandler createSessionServiceHandler()
           
protected  SubscriptionManager createSubscriptionManager()
           
protected  SubscriptionServiceHandler createSubscriptionServiceHandler()
           
 NodeManagerTable getAddressSpace()
           
 ApplicationIdentity getApplicationIdentity()
           
 ServiceHandler getAttributeServiceHandler()
           
 Set<InetAddress> getBindAddresses()
           
 Set<InetAddress> getBindAddresses(UaApplication.Protocol protocol)
          Get the addresses to bind the server endpoints that use a specific protocol.
 DiagnosticsManager getDiagnosticsManager()
           
protected  UaServer.DiscoveryServer getDiscoveryServer()
           
 UaAddress getDiscoveryServerAddress()
           
 long getDiscoveryServerRegistrationPeriod()
          The period used for re-registering to the Discovery Server.
 org.opcfoundation.ua.transport.security.SecurityMode getDiscoveryServerRegistrationSecurityMode()
           
 String getDiscoveryServerUrl()
           
protected  String getDiscoveryUriOf(String uri)
           
 org.opcfoundation.ua.encoding.EncoderContext getEncoderContext()
           
 org.opcfoundation.ua.core.EndpointDescription getEndpoint(String uri, org.opcfoundation.ua.transport.security.SecurityMode securityMode)
          Find an endpoint definition for a specific URI & SecurityMode combination
 org.opcfoundation.ua.core.EndpointConfiguration getEndpointConfiguration()
           
 org.opcfoundation.ua.core.EndpointDescription[] getEndpoints()
          Get the list of endpoints.
 org.opcfoundation.ua.core.EndpointDescription[] getEndpoints(String uri)
          Find all endpoint definitions for a specific URI
static org.opcfoundation.ua.builtintypes.UnsignedByte getEndpointSecurityLevel(org.opcfoundation.ua.transport.security.SecurityMode sm)
          Calculate the SecurityLevel of the SecurityMode.
protected  ScheduledExecutorService getExecutor()
           
 String[] getHostNames()
           
protected  int getHttpsPort()
           
protected  org.opcfoundation.ua.transport.security.HttpsSecurityPolicy[] getHttpsSecurityPolicies()
           
 org.opcfoundation.ua.transport.https.HttpsSettings getHttpsSettings()
           
 int getHttpsWorkerThreadCount()
           
 UaServerListener getListener()
           
 Locale[] getLocales()
           
 NodeManagementServiceHandler getNodeManagementServiceHandler()
           
 NodeManagerRoot getNodeManagerRoot()
           
 NodeManagerTable getNodeManagerTable()
          Deprecated. Use getAddressSpace()
 UaServer.NodeManagerUaServer getNodeManagerUaServer()
           
 int getPort()
          The port in which the server is listening to the OPC Binary protocol.
 int getPort(UaApplication.Protocol protocol)
          Get the protocol specific TCP/IP port number.
 org.opcfoundation.ua.transport.security.SecurityMode[] getSecurityModes()
           
protected  org.opcfoundation.ua.application.Server getServer()
           
 String getServerName()
           
 String getServerName(UaApplication.Protocol protocol)
          Get the protocol specific serverName definition.
 String[] getServerUris()
          The endpoint URIs to which the server listens to.
 SessionManager getSessionManager()
           
 SessionServiceHandler getSessionServiceHandler()
           
 SubscriptionManager getSubscriptionManager()
           
 SubscriptionServiceHandler getSubscriptionServiceHandler()
           
 org.opcfoundation.ua.core.UserTokenPolicy[] getUserTokenPolicies()
           
 void init()
          Initializes the server.
protected  void initAggregateFunctions()
          Initialize the Aggregate Functions under the ServerCapabilities node, from the AggregateCalculator.
protected  void initServerArray()
           
protected  void initServiceHandlers()
           
 boolean isDiscoveryEndpointEnabled()
           
 boolean isEnableIPv6()
          Returns true if IPv6 networking is enabled or false otherwise.
 boolean isFailOnBindError()
           
 boolean isRunning()
           
 boolean isUseAllIpAddresses()
          Deprecated. 
 boolean isUseCanonicalHostName()
          Deprecated. 
 boolean isUseHostName()
          Deprecated. 
 boolean isUseLocalhost()
          Deprecated. 
protected  void logRegisterServerError(String discoveryServerUrl, boolean isOnline, UaServerException e)
           
 void registerAndLoadModel(ServerCodegenModel codegenModel, URI nodeSetXml)
          Specify an information model to use in the application.
 void registerModel(ServerCodegenModel codegenModel)
          Register an information model to use in the application.
 boolean registerServer(boolean isOnline)
          Register the server on the DiscoveryServer at getDiscoveryServerUrl().
 void registerServer(String discoveryUrl, boolean isOnline)
          Register the server on a discovery server with RegisterServer2 and then with RegisterServer if RegisterServer2 fails.
 void removeEndpoint(String uri, org.opcfoundation.ua.transport.security.SecurityMode securityMode)
          Remove an endpoint definition for a specific URI & SecurityMode combination

You should call addEnpoint after init() has been called.

 void removeEndpointHost(String uri)
          Removes all endpoints that have the given endpointUrl.
 void removeLocale(Locale locale)
           
 void removeUserTokenPolicy(org.opcfoundation.ua.core.UserTokenPolicy policy)
           
 boolean requestServerStateChange(ServiceContext serviceContext, org.opcfoundation.ua.core.ServerState state, org.opcfoundation.ua.builtintypes.DateTime estimatedReturnTime, org.opcfoundation.ua.builtintypes.UnsignedInteger secondsTillShutdown, org.opcfoundation.ua.builtintypes.LocalizedText reason, Boolean restart)
          Request a change in server state (shutdown or restart server).
 void setApplicationIdentity(ApplicationIdentity identity)
          Define the application identity of the server.
 void setBindAddresses(Set<InetAddress> bindAddresses)
          Define the InetAddresses the server endpoints should be bound to.
 void setBindAddresses(UaApplication.Protocol protocol, Set<InetAddress> bindAddresses)
          Define the InetAddresses the server endpoints should be bound to.
 void setDiscoveryEndpointEnabled(boolean discoveryEndpointEnabled)
          If this is set to false, the internal discovery server is not created and this server does not offer any Discovery Services, e.g. clients cannot make FindServers requests.
 void setDiscoveryServerAddress(UaAddress discoveryServerAddress)
          Set DiscoveryServer address, same as setDiscoveryServerUrl, but this method does not throw exception as UaAddress instances have valid syntax.
 void setDiscoveryServerRegistrationPeriod(long discoveryServerRegistrationPeriod)
          Define the period used for re-registering to the Discovery Server.
 void setDiscoveryServerRegistrationSecurityMode(org.opcfoundation.ua.transport.security.SecurityMode discoveryServerRegistrationSecurityMode)
          Define the SecurityMode to use when registering to the Discovery Server.
 void setDiscoveryServerUrl(String discoveryServerUrl)
          Define the discovery server in which the server is registered automatically.
 void setEnableIPv6(boolean enableIPv6)
          Define whether to use IPv6 addresses.
 void setEndpointConfiguration(org.opcfoundation.ua.core.EndpointConfiguration endpointConfiguration)
          Define the EndpointConfiguration to use for all default endpoints.
 void setFailOnBindError(boolean failOnBindError)
          Define whether the server start() should fail, if any of the endpoint bindings fail.
protected  void setHttpsPort(int httpsPort)
          Defines the IP port number to use for the HTTPS connection.
 void setHttpsSecurityPolicies(org.opcfoundation.ua.transport.security.HttpsSecurityPolicy... httpsSecurityPolicies)
          Define the security policies used for the HTTPS protocol.
 void setHttpsSettings(org.opcfoundation.ua.transport.https.HttpsSettings httpsSettings)
           
 void setHttpsWorkerThreadCount(int httpsWorkerThreadCount)
          The number of worker threads to use for the HTTPS server.
 void setListener(UaServerListener listener)
           
 void setPort(int port)
          The port in which the server is listening to the OPC Binary protocol.
 void setPort(UaApplication.Protocol protocol, int port)
          Define the TCP/IP port number for a specific protocol.
 void setSecurityModes(org.opcfoundation.ua.transport.security.SecurityMode[] securityModes)
          Define the supported SecurityModes.
 void setServerName(String serverName)
          Define the default server name.
 void setServerName(UaApplication.Protocol protocol, String serverName)
          Define the server name for a specific protocol.
 void setUseAllIpAddresses(boolean useAllIpAddresses)
          Deprecated. The server is no longer defining endpoints for different IP addresses. Use setBindAddresses(Set) instead to define to which actual addresses the endpoints are bound to.
 void setUseCanonicalHostName(boolean useCanonicalHostName)
          Deprecated. The server is no longer defining endpoints for different host names. Use setBindAddresses(Set) instead to define to which actual addresses the endpoints are bound to.
 void setUseHostName(boolean useHostName)
          Deprecated. The server is no longer defining endpoints for different host names. Use setBindAddresses(Set) instead to define to which actual addresses the endpoints are bound to.
 void setUseLocalhost(boolean useLocalhost)
          Deprecated. 
 void setUserTokenPolicies(org.opcfoundation.ua.core.UserTokenPolicy... userTokenPolicies)
          Define the supported UserTokenPolicies.
 void setUserValidator(UserValidator userValidator)
          Define your custom user validator to check the users that are logging in to the server.
 void shutdown(int secondsTillShutdown, org.opcfoundation.ua.builtintypes.LocalizedText shutdownReason)
          Shutdown the server.
 void shutdown(int secondsTillShutdown, org.opcfoundation.ua.builtintypes.LocalizedText shutdownReason, boolean closeServer)
          Shutdown the server.
 void shutdown(int secondsTillShutdown, String shutdownReason)
          Shutdown the server.
 void shutdown(int secondsTillShutdown, String shutdownReason, boolean closeServer)
          Shutdown the server.
protected  void shutdownBegin(int secondsTillShutdown, org.opcfoundation.ua.builtintypes.LocalizedText shutdownReason)
          Begin server shutdown process
protected  void shutdownEnd(boolean closeServer)
          Complete the shutdown process
protected  void shutdownSleep(int secondsTillShutdown)
          Wait before completing shutdown
 void start()
          Starts the server using the current configuration.
protected static org.opcfoundation.ua.core.RegisteredServer toRegisteredServer(String semaphoreFilePath, boolean isOnline, UaServer uaServer)
           
protected  void updateNamespaceArray()
           
protected  void updateServerArray()
           
protected  void validateUserError(Session session, org.opcfoundation.ua.core.UserIdentityToken userToken, Exception e)
           
protected  boolean validateUserIdentity(Session session, ServerUserIdentity userIdentity)
           
 
Methods inherited from class com.prosysopc.ua.UaApplication
formatUri, getAggregateCalculator, getCertificateValidator, getKnownDataTypeDictionary, getNamespaceTable, getOperationLimits, getRegisteredClasses, getSdkVersion, getVersion, registerClass, registerClass, registerClass, registerClasses, registerModelInternal, setCertificateValidator, setOperationLimits, validateApplicationCertificate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applicationIdentity

protected ApplicationIdentity applicationIdentity

attributeServiceHandler

protected ServiceHandler attributeServiceHandler

discoveryUris

protected Set<String> discoveryUris

httpsUris

protected Set<String> httpsUris

listener

protected UaServerListener listener

nodeManagerRoot

protected NodeManagerRoot nodeManagerRoot

nodeManagerTable

protected NodeManagerTable nodeManagerTable

nodeManagerUaServer

protected UaServer.NodeManagerUaServer nodeManagerUaServer

nodeServiceHandler

protected NodeManagementServiceHandler nodeServiceHandler

securityModes

protected org.opcfoundation.ua.transport.security.SecurityMode[] securityModes

serverUris

protected Set<String> serverUris

sessionManager

protected SessionManager sessionManager

executor

protected ScheduledExecutorService executor

sessionManagerListener

protected final SessionManagerListener sessionManagerListener

sessionServiceHandler

protected SessionServiceHandler sessionServiceHandler

subscriptionManager

protected SubscriptionManager subscriptionManager

subscriptionServiceHandler

protected SubscriptionServiceHandler subscriptionServiceHandler

diagnosticsManager

protected DiagnosticsManager diagnosticsManager
Constructor Detail

UaServer

public UaServer()
Creates a new UA Server. Use setPort (and setServerName) or setUri to define the server endpointUrl. Also use setIdentity to define the server identity, including the certificate.

Method Detail

getEndpointSecurityLevel

public static org.opcfoundation.ua.builtintypes.UnsignedByte getEndpointSecurityLevel(org.opcfoundation.ua.transport.security.SecurityMode sm)
Calculate the SecurityLevel of the SecurityMode. Returns a value that is used to define the securityLevel of an endpoint.

The value is calculated from MessageSecurityMode and SecurityPolicy: MessageSecurityMode.SignAndEncrypt gives the highest values.

You can use this if you are defining the endpoints yourself.

Parameters:
sm -
Returns:

toRegisteredServer

protected static org.opcfoundation.ua.core.RegisteredServer toRegisteredServer(String semaphoreFilePath,
                                                                               boolean isOnline,
                                                                               UaServer uaServer)

addEndpoint

public void addEndpoint(String uri,
                        org.opcfoundation.ua.transport.security.SecurityMode securityMode,
                        org.opcfoundation.ua.core.UserTokenPolicy... userTokenPolicies)
                 throws UaServerException
Add an endpoint definition for a specific URI, SecurityMode & UserTokenPolicies combination

You should call addEndpoint after init() has been called.

Cannot be modified after calling start(), i.e. when the server isRunning().

Parameters:
uri - the server URI. Use UaApplication.formatUri(Protocol, String, int, String) to compose one.
securityMode - The security mode of the endpoint
userTokenPolicies - Supported user token policies
Throws:
UaServerException - if the server is running, i.e start has been called
See Also:
removeEndpoint(String, SecurityMode)

addEndpointHost

public String[] addEndpointHost(String hostName)
                         throws UaServerException
Add a specific hostName to the list of server URIs, in addition to what the default properties define.

This is a "light-weight" alternative to defining the endpoints yourself, if you wish to use the same security mode for every URI.

The method must be used after init() and before start() is called.

Parameters:
hostName -
Returns:
the endpointUrl that is defined by the hostName
Throws:
UaServerException

addLocale

public void addLocale(Locale locale)
               throws UaServerException
Parameters:
locale -
Throws:
UaServerException

addServiceHandler

public void addServiceHandler(Object serviceHandler)
Add a custom serviceHandler. You should take care that each service only has one handler in the server.

Parameters:
serviceHandler -

addToServerArray

public void addToServerArray(String uri)
                      throws StatusException
Add a server description to the serverArray. The ServerArray is available from the namespace.

Parameters:
uri - the URI of the server to add.
Throws:
StatusException

addUserTokenPolicy

public void addUserTokenPolicy(org.opcfoundation.ua.core.UserTokenPolicy policy)
                        throws UaServerException
Parameters:
policy -
Throws:
UaServerException

close

public void close()

getAddressSpace

public NodeManagerTable getAddressSpace()
Specified by:
getAddressSpace in class UaApplication
Returns:
the AddressSpace, which provides access to the UA nodes.

getApplicationIdentity

public ApplicationIdentity getApplicationIdentity()
Returns:
the identity

getAttributeServiceHandler

public ServiceHandler getAttributeServiceHandler()

getBindAddresses

public Set<InetAddress> getBindAddresses()
Returns:
the InetAddresses the server should be bound to listen. By default gives all available addresses, as given by EndpointUtil.getInetAddresses(boolean enableIPv6), using the current value of isEnableIPv6().

getBindAddresses

public Set<InetAddress> getBindAddresses(UaApplication.Protocol protocol)
Get the addresses to bind the server endpoints that use a specific protocol. Returns getBindAddresses(), if no protocol specific values are defined with #setBindAddresses(Protocol, Set).

Parameters:
protocol -
Returns:
the inet addresses the server should be bound to.
Throws:
SocketException

getDiagnosticsManager

public DiagnosticsManager getDiagnosticsManager()

getDiscoveryServerAddress

public UaAddress getDiscoveryServerAddress()
Returns:
the address to use when registering the server to the (Local) Discovery Server.

getDiscoveryServerRegistrationPeriod

public long getDiscoveryServerRegistrationPeriod()
The period used for re-registering to the Discovery Server.

Returns:
the discoveryServerRegistrationPeriod in minutes

getDiscoveryServerRegistrationSecurityMode

public org.opcfoundation.ua.transport.security.SecurityMode getDiscoveryServerRegistrationSecurityMode()
Returns:
the security mode to use for registering the server to getDiscoveryServerAddress()
See Also:
setDiscoveryServerRegistrationSecurityMode(SecurityMode)

getDiscoveryServerUrl

public String getDiscoveryServerUrl()
Returns:
the address to use when registering the server to the (Local) Discovery Server. Equals to getDiscoveryServerAddress().getAddress()

getEncoderContext

public org.opcfoundation.ua.encoding.EncoderContext getEncoderContext()
Specified by:
getEncoderContext in class UaApplication
Returns:
the encoder context, which is used for mapping namespaces and nodeIds in the stack layer.

getEndpoint

public org.opcfoundation.ua.core.EndpointDescription getEndpoint(String uri,
                                                                 org.opcfoundation.ua.transport.security.SecurityMode securityMode)
Find an endpoint definition for a specific URI & SecurityMode combination

Parameters:
uri - the server URI. Use UaApplication.formatUri(Protocol, String, int, String) to compose one.
securityMode - The security mode of the endpoint
Returns:
the endpoint that matches the request or null if there is no match

getEndpointConfiguration

public org.opcfoundation.ua.core.EndpointConfiguration getEndpointConfiguration()
Returns:
the EndpointConfiguration used for all default endpoints.

getEndpoints

public org.opcfoundation.ua.core.EndpointDescription[] getEndpoints()
Get the list of endpoints. The endpoints is filled in when you call init(), and they are bound when you call start(). Between those calls, you can modify the list according to your needs using addEndpoint(String, SecurityMode, UserTokenPolicy...) and removeEndpoint(String, SecurityMode).

Returns:
all defined endpoints

getEndpoints

public org.opcfoundation.ua.core.EndpointDescription[] getEndpoints(String uri)
Find all endpoint definitions for a specific URI

Parameters:
uri - the server URI. Use UaApplication.formatUri(Protocol, String, int, String) to compose one.
Returns:
the endpoints that match the request or an empty array if there are none

getHostNames

public String[] getHostNames()
Returns:
all HostNames of the server, corresponding to the ServerUris.

getHttpsSettings

public org.opcfoundation.ua.transport.https.HttpsSettings getHttpsSettings()
Returns:
the httpsSettings

getHttpsWorkerThreadCount

public int getHttpsWorkerThreadCount()
Returns:
the current httpsWorkerThreadCount
See Also:
setHttpsWorkerThreadCount(int)

getListener

public UaServerListener getListener()
Returns:
the listener

getLocales

public Locale[] getLocales()
Returns:
See Also:
Application.getLocales()

getNodeManagementServiceHandler

public NodeManagementServiceHandler getNodeManagementServiceHandler()
Returns:
the NodeServiceHandler

getNodeManagerRoot

public NodeManagerRoot getNodeManagerRoot()
Returns:

getNodeManagerTable

@Deprecated
public NodeManagerTable getNodeManagerTable()
Deprecated. Use getAddressSpace()

Returns:
the NodeManagerTable, which contains all the NodeManager's of the server and in effect makes up the server address space.

getNodeManagerUaServer

public UaServer.NodeManagerUaServer getNodeManagerUaServer()
Returns:

getPort

public int getPort()
The port in which the server is listening to the OPC Binary protocol.

Equals to calling #getPort(Protocol) with Protocol.Opc.

Returns:
the port

getPort

public int getPort(UaApplication.Protocol protocol)
Get the protocol specific TCP/IP port number.

Parameters:
protocol - the protocol whose port you want
Returns:
the defined value - if 0, the protocol is not in use.

getSecurityModes

public org.opcfoundation.ua.transport.security.SecurityMode[] getSecurityModes()
Returns:
the securityMode

getServerName

public String getServerName()
Returns:
the serverName

getServerName

public String getServerName(UaApplication.Protocol protocol)
Get the protocol specific serverName definition.

Parameters:
protocol - the protocol whose serverName you want
Returns:
the specific serverName or the default one given by getServerName() if no specific value is deifned.

getServerUris

public String[] getServerUris()
                       throws UaServerException
The endpoint URIs to which the server listens to.

The list is made up of all the possible "hostnames" defined for the current computer. See the setters in the 'see also' part - these are ultimately defining the set.

Returns:
an array of all endpoint URI strings, which the server uses.
Throws:
UaServerException - if the local hostname or all IP addresses cannot be resolved
See Also:
setUseLocalhost(boolean), setUseHostName(boolean), setUseAllIpAddresses(boolean), setPort(int), setServerName(String)

getSessionManager

public SessionManager getSessionManager()
Returns:
The SessionManager that handles client sessions to the server.

getSessionServiceHandler

public SessionServiceHandler getSessionServiceHandler()
Returns:
the SessionServiceHandler

getSubscriptionManager

public SubscriptionManager getSubscriptionManager()
Returns:

getSubscriptionServiceHandler

public SubscriptionServiceHandler getSubscriptionServiceHandler()
Returns:
the SubscriptionServiceHandler

getUserTokenPolicies

public org.opcfoundation.ua.core.UserTokenPolicy[] getUserTokenPolicies()
Returns:
the configured user token policies
See Also:
addUserTokenPolicy(UserTokenPolicy), removeUserTokenPolicy(UserTokenPolicy)

init

public void init()
          throws UaServerException
Initializes the server. You should call init before doing your own server initializations. After you have finished with all initializations, call start().

Throws:
UaServerException - if the initialization fails

isDiscoveryEndpointEnabled

public boolean isDiscoveryEndpointEnabled()
Returns:
true if DiscoveryEndpoint should be created when the server is started, default is true
See Also:
setDiscoveryEndpointEnabled(boolean)

isEnableIPv6

public boolean isEnableIPv6()
Returns true if IPv6 networking is enabled or false otherwise. Can be set with setEnableIPv6(boolean). Default value is false.

Returns:
the enableIPv6

isFailOnBindError

public boolean isFailOnBindError()
Returns:
the failOnBindError
See Also:
setFailOnBindError(boolean)

isRunning

public boolean isRunning()
Returns:
true when the server is running and accepts connections.
See Also:
start(), shutdown(int, LocalizedText)

isUseAllIpAddresses

@Deprecated
public boolean isUseAllIpAddresses()
Deprecated. 

Returns:

isUseCanonicalHostName

@Deprecated
public boolean isUseCanonicalHostName()
Deprecated. 

Define whether InetAddress.getLocalHost().getCanonicalHostName() is added to the endpoints (getServerUris()).

Default: true

Returns:
the useCanonicalHostName
See Also:
isUseHostName()

isUseHostName

@Deprecated
public boolean isUseHostName()
Deprecated. 

Define whether InetAddress.getLocalHost().getHostName() is added to the endpoints (getServerUris()).

Default: true

Returns:
the useHostName
See Also:
isUseCanonicalHostName()

isUseLocalhost

@Deprecated
public boolean isUseLocalhost()
Deprecated. 

Define whether 'localhost' is added to the endpoints ( getServerUris()).

Default: true

Returns:
the useLocalhost

registerAndLoadModel

public void registerAndLoadModel(ServerCodegenModel codegenModel,
                                 URI nodeSetXml)
                          throws SAXException,
                                 IOException,
                                 ModelException,
                                 ServiceException
Specify an information model to use in the application. The model is registered for node creation and the respective types are also loaded to the type address space from the UA Nodeset XML.

Uses registerModel(com.prosysopc.ua.server.ServerCodegenModel) and NodeManagerTable.loadModel(URI).

Parameters:
codegenModel - the InformationModel generated by the Code Generator
nodeSetXml - the XML definition of the information model in NodeSet2.xml format
Throws:
ServiceException - if the mode cannot be loaded into the server
ModelException
IOException
SAXException

registerModel

public void registerModel(ServerCodegenModel codegenModel)
Register an information model to use in the application. All the types in the model are then available for the application, when it constructs new instances.

Parameters:
codegenModel - the model created by the codegen.

registerServer

public boolean registerServer(boolean isOnline)
Register the server on the DiscoveryServer at getDiscoveryServerUrl().

Also if isDiscoveryEndpointEnabled() is true it registers the server in the internal DiscoveryServer, which is available from the same port as the server.

The method does not raise any exceptions, contrary to registerServer(String, boolean), which does not use discoveryServerUrl.

The method is called automatically from init(), start() and shutdown(int, LocalizedText).

Parameters:
isOnline - whether to register the server online or offline
Returns:
true if the registration succeeds, false if it fails or is skipped (DiscoveryServerUrl is not defined)

registerServer

public void registerServer(String discoveryUrl,
                           boolean isOnline)
                    throws UaServerException
Register the server on a discovery server with RegisterServer2 and then with RegisterServer if RegisterServer2 fails.

Note that you can also define the discoveryServerUrl to make the server register itself automatically on a discovery server.

Parameters:
discoveryUrl - the URL of the discovery server
isOnline - whether to register online (server running) or offline
Throws:
UaServerException
See Also:
setDiscoveryServerUrl(java.lang.String)

removeEndpoint

public void removeEndpoint(String uri,
                           org.opcfoundation.ua.transport.security.SecurityMode securityMode)
Remove an endpoint definition for a specific URI & SecurityMode combination

You should call addEnpoint after init() has been called.

If you modify the list after calling start(), your list will not be up to date according to what is actually in use in the server.

Parameters:
uri - the server URI. Use UaApplication.formatUri(Protocol, String, int, String) to compose one.
securityMode - The security mode of the endpoint
See Also:
addEndpoint(String, SecurityMode, UserTokenPolicy...)

removeEndpointHost

public void removeEndpointHost(String uri)
Removes all endpoints that have the given endpointUrl. Note that this method should be called after init(), otherwise it wont do anything. Also calling this after start() does not have effect on the bound endpoints.

Parameters:
uri - the given endpointUrl

removeLocale

public void removeLocale(Locale locale)
                  throws UaServerException
Parameters:
locale -
Throws:
UaServerException

removeUserTokenPolicy

public void removeUserTokenPolicy(org.opcfoundation.ua.core.UserTokenPolicy policy)
                           throws UaServerException
Parameters:
policy -
Throws:
UaServerException

requestServerStateChange

public boolean requestServerStateChange(ServiceContext serviceContext,
                                        org.opcfoundation.ua.core.ServerState state,
                                        org.opcfoundation.ua.builtintypes.DateTime estimatedReturnTime,
                                        org.opcfoundation.ua.builtintypes.UnsignedInteger secondsTillShutdown,
                                        org.opcfoundation.ua.builtintypes.LocalizedText reason,
                                        Boolean restart)
                                 throws StatusException
Request a change in server state (shutdown or restart server).

Parameters:
serviceContext - calling context, including the session information, which defines the userIdentity
state - the state in which the server will be
estimatedReturnTime - the time in which the server is expected to be in running state
secondsTillShutdown - the number of seconds until shutdown
reason - reason for the request
restart - a flag indicating whether the server will be restarted after shutdown
Returns:
a boolean value indicating whether the state change is allowed
Throws:
StatusException - StatusCodes.Bad_UserAccessDenied if the user is not authorized to request the state change

setApplicationIdentity

public void setApplicationIdentity(ApplicationIdentity identity)
Define the application identity of the server. The identity should have the certificate initialized (for example, by creating the identity using ApplicationIdentity.loadOrCreateCertificate(org.opcfoundation.ua.core.ApplicationDescription, java.lang.String, java.lang.String, java.io.File, boolean, java.lang.String...)). Also make sure the the ApplicationDescription is set in the identity.

Parameters:
identity -

setBindAddresses

public void setBindAddresses(UaApplication.Protocol protocol,
                             Set<InetAddress> bindAddresses)
Define the InetAddresses the server endpoints should be bound to. By default, the server is bound to all addresses as given by EndpointUtil.getInetAddresses(boolean enableIPv6), using the current value of isEnableIPv6().

Use the method to make the server respond in only some of the available network interfaces.

Default: Use what is available from EndpointUtil.getInetAddresses(boolean enableIPv6), using the current value of isEnableIPv6().

Parameters:
protocol - the protocol to which these addresses are used. Must not be null
bindAddresses - the bindAddresses to set. If null, the protocol specific values are not to be used. The common values available from getBindAddresses() are to be used then.

setBindAddresses

public void setBindAddresses(Set<InetAddress> bindAddresses)
Define the InetAddresses the server endpoints should be bound to. By default, the server is bound to all addresses as given by EndpointUtil.getInetAddresses(boolean enableIPv6), using the current value of isEnableIPv6().

Use the method to make the server respond in only some of the available network interfaces.

Default: Use what is available from EndpointUtil.getInetAddresses(boolean enableIPv6), using the current value of isEnableIPv6().

Parameters:
bindAddresses - the bindAddresses to set. Use null to reset to default value.

setDiscoveryEndpointEnabled

public void setDiscoveryEndpointEnabled(boolean discoveryEndpointEnabled)
If this is set to false, the internal discovery server is not created and this server does not offer any Discovery Services, e.g. clients cannot make FindServers requests. Default value is true, i.e. the internal DiscoveryServer is created.

Parameters:
discoveryEndpointEnabled -

setDiscoveryServerAddress

public void setDiscoveryServerAddress(UaAddress discoveryServerAddress)
Set DiscoveryServer address, same as setDiscoveryServerUrl, but this method does not throw exception as UaAddress instances have valid syntax.

Parameters:
discoveryServerAddress - the address
See Also:
setDiscoveryServerUrl(java.lang.String)

setDiscoveryServerRegistrationPeriod

public void setDiscoveryServerRegistrationPeriod(long discoveryServerRegistrationPeriod)
Define the period used for re-registering to the Discovery Server.

If the discoveryServerUrl is not defined or the period is set to 0, no periodic registration will take place.

Default: 10 minutes

Parameters:
discoveryServerRegistrationPeriod - the period to set in minutes
See Also:
registerServer(boolean), setDiscoveryServerUrl(java.lang.String)

setDiscoveryServerRegistrationSecurityMode

public void setDiscoveryServerRegistrationSecurityMode(org.opcfoundation.ua.transport.security.SecurityMode discoveryServerRegistrationSecurityMode)
Define the SecurityMode to use when registering to the Discovery Server.

Note that according to the OPC UA specification, only secure connections are enabled, but the actual mode to use may be configurable, depending on the actual Discovery Server installation.

Default: SecurityMode.BASIC128RSA15_SIGN_ENCRYPT

Parameters:
discoveryServerRegistrationSecurityMode - the discoveryServerRegistrationSecurityMode to set

setDiscoveryServerUrl

public void setDiscoveryServerUrl(String discoveryServerUrl)
                           throws URISyntaxException
Define the discovery server in which the server is registered automatically. Normally, this is the Local Discovery Server, at 'opc.tcp://localhost:4840'

Parameters:
discoveryServerUrl - the discoveryServerUrl to set
Throws:
URISyntaxException - if the url is not valid
See Also:
registerServer(boolean), setDiscoveryServerRegistrationPeriod(long), setDiscoveryServerAddress(com.prosysopc.ua.UaAddress)

setEnableIPv6

public void setEnableIPv6(boolean enableIPv6)
Define whether to use IPv6 addresses. Windows requires Java 7 or newer in order to use IPv6. Default value false.

Parameters:
enableIPv6 - set true to enable or false to disable IPv6 networking.

setEndpointConfiguration

public void setEndpointConfiguration(org.opcfoundation.ua.core.EndpointConfiguration endpointConfiguration)
Define the EndpointConfiguration to use for all default endpoints.

Parameters:
endpointConfiguration - the value to set. Use null to reset back to EndpointConfiguration.defaults().

setFailOnBindError

public void setFailOnBindError(boolean failOnBindError)
Define whether the server start() should fail, if any of the endpoint bindings fail.

The property can be used to overcome problems in some hostname/IP address problems, in case the server tries to bind to invalid addresses, for example.

The draw back is that if there is a server already bound to the address, the new one will start up, but never runs.

Default: true

Parameters:
failOnBindError - the failOnBindError to set

setHttpsSecurityPolicies

public void setHttpsSecurityPolicies(org.opcfoundation.ua.transport.security.HttpsSecurityPolicy... httpsSecurityPolicies)
                              throws UaServerException
Define the security policies used for the HTTPS protocol.

Default: HttpsSecurityPolicy.ALL

Parameters:
httpsSecurityPolicies - the httpsSecurityPolicies to set
Throws:
UaServerException - if the server is running

setHttpsSettings

public void setHttpsSettings(org.opcfoundation.ua.transport.https.HttpsSettings httpsSettings)
Parameters:
httpsSettings - the httpsSettings to set

setHttpsWorkerThreadCount

public void setHttpsWorkerThreadCount(int httpsWorkerThreadCount)
The number of worker threads to use for the HTTPS server. Defines how many worker threads are initialized to handle incoming HTTPS requests. Note that this does not limit the number of UA sessions, since all sessions will share these threads. The value must be defined before init() is called.

Default: 10

Parameters:
httpsWorkerThreadCount - the httpsWorkerThreadCount to set

setListener

public void setListener(UaServerListener listener)
Parameters:
listener - the listener to set

setPort

public void setPort(int port)
             throws UaServerException
The port in which the server is listening to the OPC Binary protocol.

The method equals to calling #setPort(Protocol, int) with Protocol.Opc.

Parameters:
port - The binary port number. If 0, the binary protocol is disabled. Do not use any of the standard port numbers used by well-known TCP/IP services. Recommended numbers start from 1024. 4840 is reserved for the Local Discovery Server, but if you do not intend to run one, you can bind your server in there.
Throws:
UaServerException - if the server isRunning already

setPort

public void setPort(UaApplication.Protocol protocol,
                    int port)
             throws UaServerException
Define the TCP/IP port number for a specific protocol. This is used to initialize the endpoint URL. So the endpoint URLs are of the form "://:/".

It is also used to define which protocols are enabled in the server. If the value is 0, the specific protocol is disabled. By default the protocols are not defined.

Parameters:
protocol - the UA protocol for which the name is applied to
port - the port number to set. If 0, the specific protocol is not enabled in the server.
Throws:
UaServerException - if the server isRunning already

setSecurityModes

public void setSecurityModes(org.opcfoundation.ua.transport.security.SecurityMode[] securityModes)
                      throws UaServerException
Define the supported SecurityModes.

Parameters:
securityModes - the securityMode to set
Throws:
UaServerException - if the server isRunning already

setServerName

public void setServerName(UaApplication.Protocol protocol,
                          String serverName)
                   throws UaServerException
Define the server name for a specific protocol. This is appended to the endpoint URLs, in addition to the host name and port. So the endpoint URLs are of form "://:/".

Parameters:
protocol - the UA protocol for which the name is applied to
serverName - the serverName to set. If null, then the specific value is reset and the default will be used.
Throws:
UaServerException - if the server isRunning already
See Also:
setServerName(String)

setServerName

public void setServerName(String serverName)
                   throws UaServerException
Define the default server name. This is appended to the endpoint URLs, in addition to the host name and port. So the endpoint URLs are of form "://:/".

The default value is used for all protocols, unless specific values are defined with #setServerName(Protocol, String)

Parameters:
serverName - the serverName to set
Throws:
UaServerException - if the server isRunning already
See Also:
setServerName(String)

setUseAllIpAddresses

@Deprecated
public void setUseAllIpAddresses(boolean useAllIpAddresses)
Deprecated. The server is no longer defining endpoints for different IP addresses. Use setBindAddresses(Set) instead to define to which actual addresses the endpoints are bound to.

Define that an endpoint URL should be defined for every IP Address defined for the server. By default the host name of the server is used in the endpoints only.

Default: false.

Parameters:
useAllIpAddresses - if true, all IP addresses are added to endpointUrls
See Also:
setUseHostName(boolean), setUseCanonicalHostName(boolean), setUseLocalhost(boolean)

setUseCanonicalHostName

@Deprecated
public void setUseCanonicalHostName(boolean useCanonicalHostName)
Deprecated. The server is no longer defining endpoints for different host names. Use setBindAddresses(Set) instead to define to which actual addresses the endpoints are bound to.

Define whether InetAddress#getLocalHost().getCanonicalHostName() is added to the endpoints (getServerUris()).

Depending on the Operating system, CanonicalHostName can contain the domain part of the host name or be without it.

Default: true

Parameters:
useCanonicalHostName - the useCanonicalHostName to set
See Also:
setUseAllIpAddresses(boolean), setUseHostName(boolean), setUseLocalhost(boolean)

setUseHostName

@Deprecated
public void setUseHostName(boolean useHostName)
Deprecated. The server is no longer defining endpoints for different host names. Use setBindAddresses(Set) instead to define to which actual addresses the endpoints are bound to.

Define whether InetAddress.getLocalHost().getHostName() is added to the endpoints (getServerUris()).

Depending on the Operating system, HostName can contain the domain part of the host name or be without it.

Default: true

Parameters:
useHostName - the useHostName to set
See Also:
setUseAllIpAddresses(boolean), setUseCanonicalHostName(boolean), setUseLocalhost(boolean)

setUseLocalhost

@Deprecated
public void setUseLocalhost(boolean useLocalhost)
                     throws UaServerException
Deprecated. 

Add 'localhost' to the list of endpoints (getServerUris()).

Default: false

Parameters:
useLocalhost - if true, 'localhost' will be added to the list of endpoints.
Throws:
UaServerException - if the server isRunning already
See Also:
setUseAllIpAddresses(boolean), setUseCanonicalHostName(boolean), setUseHostName(boolean)

setUserTokenPolicies

public void setUserTokenPolicies(org.opcfoundation.ua.core.UserTokenPolicy... userTokenPolicies)
                          throws UaServerException
Define the supported UserTokenPolicies.

Parameters:
userTokenPolicies - the securityMode to set
Throws:
UaServerException - if the server isRunning already

setUserValidator

public void setUserValidator(UserValidator userValidator)
Define your custom user validator to check the users that are logging in to the server.

Parameters:
userValidator - the validator to use. Set to null to accept all users.

shutdown

public void shutdown(int secondsTillShutdown,
                     org.opcfoundation.ua.builtintypes.LocalizedText shutdownReason)
Shutdown the server. The clients are notified about the shutdown via ServerStatus. The method waits for secondsTillShutdown and then closes down all service managers and returns.

Parameters:
secondsTillShutdown - the delay after notifying the clients about the shutdown
shutdownReason - the shutdown reason message provided for the clients

shutdown

public void shutdown(int secondsTillShutdown,
                     org.opcfoundation.ua.builtintypes.LocalizedText shutdownReason,
                     boolean closeServer)
Shutdown the server. The clients are notified about the shutdown via ServerStatus. The method waits for secondsTillShutdown and then closes down all service managers and returns.

Parameters:
secondsTillShutdown - the delay after notifying the clients about the shutdown
shutdownReason - the shutdown reason message provided for the clients
closeServer - determine whether the server is also closed at the same. Use 'false' if you intend to restart the server again, by calling start(). It will leave the node managers intact, and they will not need to be re-initialized. Default is true.

shutdown

public void shutdown(int secondsTillShutdown,
                     String shutdownReason)
Shutdown the server. The clients are notified about the shutdown via ServerStatus. The method waits for secondsTillShutdown and then closes down all service managers and returns.

Parameters:
secondsTillShutdown - the delay after notifying the clients about the shutdown
shutdownReason - the shutdown reason message provided for the clients (without any locale information)

shutdown

public void shutdown(int secondsTillShutdown,
                     String shutdownReason,
                     boolean closeServer)
Shutdown the server. The clients are notified about the shutdown via ServerStatus. The method waits for secondsTillShutdown and then closes down all service managers and returns.

Parameters:
secondsTillShutdown - the delay after notifying the clients about the shutdown
shutdownReason - the shutdown reason message provided for the clients (without any locale information)
closeServer - determine whether the server is also closed at the same. Use 'false' if you intend to restart the server again, by calling start(). It will leave the node managers intact, and they will not need to be re-initialized. Default is true.

start

public void start()
           throws UaServerException
Starts the server using the current configuration. Calls init(), if it is not called. generally, you should call init, initialize your own server stuff, and call start.

Throws:
UaServerException - if the server fails to start.
See Also:
init(), close()

createAttributeServiceHandler

protected AttributeServiceHandler createAttributeServiceHandler()
Returns:
the AttributeServiceHandler to use for the server. You can override the method to provide your own version of the handler.

createDiagnosticsManager

protected DiagnosticsManager createDiagnosticsManager()

createExecutor

protected ScheduledExecutorService createExecutor()
This is called when a executor would be created for the UaServer. This can be overrided to change the default behavior that uses Executors.newSingleThreadScheduledExecutor().

Returns:
an executor

createNewNodeManager

protected NodeManager createNewNodeManager(ServiceContext serviceContext,
                                           String namespaceUri)
                                    throws StatusException
Creates a new node manager as a response to an AddNodes request with a NodeId that is not managed by any node managers, yet.

It will call getListener().onCreateNewNodeManager() unless it is not set, in which case a new NodeManagerUaNode is created.

Parameters:
serviceContext -
namespaceUri -
Returns:
the new NodeManager
Throws:
StatusException - if the operation is not allowed.

createNodeManagementServiceHandler

protected NodeManagementServiceHandler createNodeManagementServiceHandler()
Returns:
the NodeManagementServiceHandler to use for the server. You can override the method to provide your own version of the handler.

createSessionManager

protected SessionManager createSessionManager()
Throws:
StatusException

createSessionServiceHandler

protected SessionServiceHandler createSessionServiceHandler()
Returns:
the SessionServiceHandler to use for the server. You can override the method to provide your own version of the handler.

createSubscriptionManager

protected SubscriptionManager createSubscriptionManager()
Returns:
the SubscriptionManager to use for the server. You can override the method to provide your own version of the handler.

createSubscriptionServiceHandler

protected SubscriptionServiceHandler createSubscriptionServiceHandler()
Returns:
the SubscriptionServiceHandler to use for the server. You can override the method to provide your own version of the handler.

getDiscoveryServer

protected UaServer.DiscoveryServer getDiscoveryServer()
Returns:

getDiscoveryUriOf

protected String getDiscoveryUriOf(String uri)
                            throws URISyntaxException
Parameters:
uri -
Returns:
Throws:
URISyntaxException

getExecutor

protected ScheduledExecutorService getExecutor()

getHttpsPort

protected int getHttpsPort()
Returns:
the httpsPort

getHttpsSecurityPolicies

protected org.opcfoundation.ua.transport.security.HttpsSecurityPolicy[] getHttpsSecurityPolicies()
Returns:
the httpsSecurityModes used for the HTTPS protocol

getServer

protected org.opcfoundation.ua.application.Server getServer()
Returns:
the server

initAggregateFunctions

protected void initAggregateFunctions()
Initialize the Aggregate Functions under the ServerCapabilities node, from the AggregateCalculator.


initServerArray

protected void initServerArray()
                        throws UaServerException
Throws:
UaServerException

initServiceHandlers

protected void initServiceHandlers()
                            throws UaServerException
Throws:
UaServerException

logRegisterServerError

protected void logRegisterServerError(String discoveryServerUrl,
                                      boolean isOnline,
                                      UaServerException e)
Parameters:
isOnline -
discoveryServerUrl -
e -

setHttpsPort

protected void setHttpsPort(int httpsPort)
                     throws UaServerException
Defines the IP port number to use for the HTTPS connection. If the value is not set, then HTTPS will not be available.

The standard Internet port number for HTTPS is 443, but you should probably normally use a custom port number for the UA Server, unless you know that there is no other HTTPS server installed on the same computer.

Parameters:
httpsPort - the httpsPort to set
Throws:
UaServerException

shutdownBegin

protected void shutdownBegin(int secondsTillShutdown,
                             org.opcfoundation.ua.builtintypes.LocalizedText shutdownReason)
Begin server shutdown process

Parameters:
secondsTillShutdown - seconds to wait until shutdown
shutdownReason - reason for shutdown

shutdownEnd

protected void shutdownEnd(boolean closeServer)
Complete the shutdown process

Parameters:
closeServer - whether the server is closed

shutdownSleep

protected void shutdownSleep(int secondsTillShutdown)
Wait before completing shutdown

Parameters:
secondsTillShutdown - seconds to wait

updateNamespaceArray

protected void updateNamespaceArray()

updateServerArray

protected void updateServerArray()
                          throws StatusException
Throws:
StatusException

validateUserError

protected void validateUserError(Session session,
                                 org.opcfoundation.ua.core.UserIdentityToken userToken,
                                 Exception e)
Parameters:
session -
userToken -
e -

validateUserIdentity

protected boolean validateUserIdentity(Session session,
                                       ServerUserIdentity userIdentity)
                                throws StatusException
Parameters:
session -
userIdentity -
Returns:
true if the user is valid.
Throws:
StatusException


Copyright © 2018. All rights reserved.