The SHS is not a full featured HTTP Server. It supports only the functionality needed to create WebSockets.
The Bosch IoT Gateway Software WebSockets Server supports the creation of SHS by using the OSGi configuration.
To create a new SHS a new proper OSGi configuration must be created.
To update an existing SHS, the corresponding OSGi configuration must be properly updated
To delete on existing SHS, the corresponding OSGi configuration must be deleted
If an OSGi configuration is not properly created/updated (for example the port already is in use), an exception will be thrown and the operation will be unsuccessful.
When the Bosch IoT Gateway Software WebSockets module is installed and started and the mbs.mtp.osgi.createConfigs System property is not explicitly set to false an OSGi configuration for SHS is created. It will attempt to start a SHS at port 8082 (if the configuration is correct the SHS will be started, otherwise an exception is thrown and the SHS won't start.) Setting the mbs.mtp.osgi.createConfigs property to false will disable all default OSGi configurations, which may lead to unexpected behavior in other Bosch IoT Gateway Software components. If the SHS is not needed, the safest solution to delete the server is to manually delete the corresponding OSGi configuration after every clean start of the Bosch IoT Gateway Software.
Standalone HTTP Server Configuration Properties
All of the Server properties can be changed once the it is started. They are as follows:
port - indicates the port at which the server is started. if the port is already taken then the server cannot start and has to be started manually when the port is freed (you must do a change to some of the properties in order to start it once you free the port). The port is in the range of [1025, 65535] (inclusive), a ConfigurationException will be thrown if you leave those bounds
filter - indicates if the server will be secure or non-secure, by default servers are non-secure. An LDAP filter is used.
soTimeout - defines the default socket timeout (SO_TIMEOUT) in seconds which is the timeout for waiting for data. A timeout value of zero is interpreted as an infinite timeout.
backlog - the maximum queue length for incoming connection indications (a request to connect). If a connection indication arrives when the queue is full, the connection is refused. The minimum length has to be a number greater than 0, if it's not the the default maximum queue length is used. By default the maximum queue length is 100.
host - defines the local InetAddress which the server will bind to
scope - provide a way for restricting the WebSocketApplication visibility to a predetermined running HTTP server or servers (Bosch IoT Gateway Software HTTP or Standalone Servers)
restart - the default value is false (the SHS will not stop). If set to true the SHS will stop and try to start again until a SSLServerSocketFactory OSGi service is found.
stopConnectedWebSockets - Is dependent on the restart property. If the restart property is set to falsethenstopConnectedWebSockets MUST be set to false. If restart is set to true and stopConnectedWebSockets is set to false the current WebSocket connections will not be closed. If both restart and stopConnectedWebSockets are set to true the current WebSocket connections will be closed.
Securing the Standalone HTTP Server
To make a SHS secure you need a custom SSLServerSocketFactory implementation. If you have one you must register it as an OSGi Service with the corresponding Service PID.
Once a configuration with a filter property is created an LDAP filter is used to track the SSLServerSocketFactory services.
In the start() method of the Activator of your SSLServerSocketFactory Service set the properties and register the service, for example if you want to register a DemoSSLSocketFactory.class which extends SSLServerSocketFactory.class, with service.pid=demo_ssl:
public void start(BundleContext context) throws Exception {
Dictionary< String, String> sslProps = new Hashtable< String, String>();
sslProps.put(Constants.SERVICE_PID, "demo_ssl");
SSLServiceRegistration = context.registerService(SSLServerSocketFactory.class, new DemoSSLSocketFactory(), sslProps);
}
If there is no SSLServerSocketFactory at the moment of the secure SHS registration, the server will be added to a queue and will be started as soon as the required SSLServerSocketFactory is registered as an OSGi Service
There is no guarantee that the Standalone Server will be secure, it is assumed so because of the SSLServerSocketFactory is used.
Standalone HTTP Server Events
The Bosch IoT Gateway Software WebSockets Server uses the OSGi EventAdmin to publish the following events:
com/prosyst/mbs/services/websockets/info/add_server - When a new SHS is started
com/prosyst/mbs/services/websockets/info/delete_server - When a SHS is deleted
com/prosyst/mbs/services/websockets/info/update_server - When a SHS is updated (when you change one of the properties of the Standalone Server configuration and save it)
When a configuration is updated a proper configurations must be provided.