Dispatcher Policy

If the RM provided Message Dispatcher Policies are not satisfactory, a custom Message Dispatcher Policy can be provided. The following interface should be implemented and registered as an OSGi Service:

com.prosyst.mprm.net.nio.http.message.MessageDispatcherPolicy

An example implementation is given below:

...
 
public class MessageDispatcherPolicyImpl implements BundleActivator, MessageDispatcherPolicy {
private ServiceRegistration reg;
public void start(BundleContext bc) throws Exception {
reg = bc.registerService(MessageDispatcherPolicy.class.getName(), this, null);
}
public void stop(BundleContext bc) throws Exception {
if (reg != null) {
reg.unregister();
reg = null;
}
}
 
public boolean isTunnelingRequest(RequestHeader header) {
/* Return true if this request should be redirected to a device, or false otherwise */
return false;
}
 
public MessageTargetResolution resolveTarget(RequestHeader header) {
String deviceID = null;
/* Initialize the deviceID to point to the device this request should be forwarded to
return MessageTargetResolution.getSuccess(deviceID) if the request should be forwarder to the device
return MessageTargetResolution.getError(String message, int code) if the request should be rejected and
not forwarded to a device or if the caller has no access rights to the device this request is targeted for
*/
return MessageTargetResolution.getSuccess(deviceID);
}
 
}

Request Interceptor

A Request Interceptor can be used to intercept incoming requests, thus allowing additional access control for the remote requests. Bundles, that have to intercept HTTP tunneling requests, can implement and register as an OSGi service the following interface:

com.prosyst.mprm.net.tunnel.interceptor.TunnelRequestInterceptor

The Request Interceptor can intercept predefined requests or all incoming requests. To implement targeted requests interceptor, it has to be registered with the following registration property:

TunnelRequestInterceptor.TARGET,

If the Request Interceptor is to be implemented for all incoming traffic then no target should be specified. An example implementation is given below:

...
 
public class TunnelRequestInterceptorImpl implements BundleActivator, TunnelRequestInterceptor {
 
private ServiceRegistration reg;
public void start(BundleContext bc) throws Exception {
Hashtable<String, String> properties = new Hashtable<String, String>(1);
properties.put(TunnelRequestInterceptor.TARGET, "http.tunnel.myInterceptor");
reg = bc.registerService(TunnelRequestInterceptor.class.getName(), this, properties);
}
public void stop(BundleContext bc) throws Exception {
if (reg != null) {
reg.unregister();
reg = null;
}
}
 
public InterceptorResolution validateRequest(String targetDeviceId, HttpRequestHeader header) {
InterceptorResolution resolution = null;
/* Implement here the validation taking into account the target device and the request information */
return resolution;
}
}

Custom Device ID Resolver

The HTTP tunnel by default supports Device ID resolution through the HTTP header or URL. Due to security concerns such scheme might not be desirable in all use cases. For such situation the Custom Device ID Resolver interface can be used. It allows the resolution to be done based on a session ID or some kind of access key, for example. To use this functionality, implement and register as an OSGi service the following interface:

com.prosyst.mprm.net.tunnel.resolution.DeviceIdResolver

This interface uses the key to map it to a known RM device ID.
An example implementation of the com.prosyst.mprm.net.tunnel.resolution.DeviceIdResolver is given below:

...
 
public class DeviceIdResolverImpl implements BundleActivator, DeviceIdResolver {
 
private ServiceRegistration reg;
public void start(BundleContext bc) throws Exception {
Hashtable<String, String> properties = new Hashtable<String, String>(1);
properties.put(DeviceIdResolver.TARGET, "http.tunnel.myIDResolver");
reg = bc.registerService(DeviceIdResolver.class.getName(), this, properties);
}
public void stop(BundleContext bc) throws Exception {
if (reg != null) {
reg.unregister();
reg = null;
}
}
 
public String resolveToDeviceId(String key) {
String deviceID = null;
/* Implement here the key to device ID mapping and return the device ID mapped to the key passed as parameter to this method */
return deviceID;
}
}