Improve integration of CallbackService with the sensiNact instance

Let the callbackcontext provides a sensiNact Session
diff --git a/platform/northbound/http-tools/extra-src3/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/CallbackServiceImpl.java b/platform/northbound/http-tools/extra-src3/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/CallbackServiceImpl.java
index e895012..4e1d1be 100644
--- a/platform/northbound/http-tools/extra-src3/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/CallbackServiceImpl.java
+++ b/platform/northbound/http-tools/extra-src3/test/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/test/CallbackServiceImpl.java
@@ -2,6 +2,8 @@
 
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletRequestWrapper;
 
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackContext.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackContext.java
index b91e879..ac8493e 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackContext.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackContext.java
@@ -10,6 +10,8 @@
  */
 package org.eclipse.sensinact.gateway.nthbnd.http.callback;
 
+import org.eclipse.sensinact.gateway.core.Session;
+
 /**
  * {@link RequestWrapper} and {@link ResponseWrapper} holder
  * 
@@ -18,6 +20,13 @@
 public interface CallbackContext {
 
     /**
+     * Returns an {@link Session} allowing to interact with the sensiNact instance
+     *
+     * @return an sensiNact {@link Session} instance - Null by default
+     */
+    Session getSession();
+    
+    /**
      * Returns an {@link RequestWrapper} wrapping the underlying 
      * request whatever it is an Http or a websocket one.
      *
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java
index ac6609b..8fd8768 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/CallbackService.java
@@ -60,4 +60,15 @@
      * processed and the response to be sent back to the requirer
      */
     void process(CallbackContext context);
+        
+//    /**
+//     * Returns this CallbackService's String identifier allowing to attach
+//     * an authenticated sensiNact's Session instance
+//     * 
+//     * @return this CallbackService's String identifier - Null by default 
+//     */
+//    default String getCallbackServiceIdentifier() {
+//    	return null;
+//    }
+    
 }
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/ServletCallbackContext.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/ServletCallbackContext.java
index 084c1f3..f1f21fe 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/ServletCallbackContext.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/ServletCallbackContext.java
@@ -10,6 +10,11 @@
  */
 package org.eclipse.sensinact.gateway.nthbnd.http.callback;
 
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
+import org.eclipse.sensinact.gateway.common.execution.Executable;
+import org.eclipse.sensinact.gateway.core.Core;
+import org.eclipse.sensinact.gateway.core.Session;
+
 /**
  * {@link CallbackContext} dedicated to http connection
  */
@@ -17,33 +22,46 @@
 
     private HttpRequestWrapper request;
     private HttpResponseWrapper response;
+    private Session session;
+    private Mediator mediator;
 
     /**
      * Constructor
      *
+     * @param mediator the {@link Mediator} allowing the ServletCallbackContext to be instantiated 
+     * to interact with the OSGi host environment
      * @param request {@link HttpRequestWrapper} held by the ServletCallbackContext
      * to be instantiated
      * @param response {@link HttpResponseWrapper} held by the ServletCallbackContext
      * to be instantiated
      */
-    public ServletCallbackContext(HttpRequestWrapper request, HttpResponseWrapper response) {
+    public ServletCallbackContext(Mediator mediator, HttpRequestWrapper request, HttpResponseWrapper response) {
         this.request = request;
         this.response = response;
+        this.mediator = mediator;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackContext#getRequest()
-     */
     @Override
     public HttpRequestWrapper getRequest() {
     	return request;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackContext#getResponse()
-     */
     @Override
     public HttpResponseWrapper getResponse() {
     	return response;
     }
+
+	@Override
+	public Session getSession() {
+		//TODO: allow some how to authenticate
+		if(this.session == null) {
+			this.session = mediator.callService(Core.class, new Executable<Core,Session>(){
+				@Override
+				public Session execute(Core core) throws Exception {
+					return core.getAnonymousSession();
+				}
+			});
+		}
+		return this.session;
+	}
 }
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/WebSocketCallbackContext.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/WebSocketCallbackContext.java
index 63b7246..d25bed0 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/WebSocketCallbackContext.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/WebSocketCallbackContext.java
@@ -10,6 +10,11 @@
  */
 package org.eclipse.sensinact.gateway.nthbnd.http.callback;
 
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
+import org.eclipse.sensinact.gateway.common.execution.Executable;
+import org.eclipse.sensinact.gateway.core.Core;
+import org.eclipse.sensinact.gateway.core.Session;
+
 /**
  * {@link CallbackContext} dedicated to websocket connection
  */
@@ -17,33 +22,47 @@
 
 	private WebSocketRequestWrapper request;
 	private WebSocketResponseWrapper response;
+    private Session session;
+	private Mediator mediator;
 
     /**
      * Constructor
      *
+     * @param mediator the {@link Mediator} allowing the WebSocketCallbackContext to be instantiated 
+     * to interact with the OSGi host environment
      * @param request {@link WebSocketRequestWrapper} held by the WebSocketCallbackContext
      * to be instantiated
      * @param response {@link WebSocketResponseWrapper} held by the WebSocketCallbackContext
      * to be instantiated
      */
-    public WebSocketCallbackContext(WebSocketRequestWrapper request, WebSocketResponseWrapper response) {
+    public WebSocketCallbackContext(Mediator mediator, WebSocketRequestWrapper request, WebSocketResponseWrapper response) {
         this.request = request;
         this.response = response;
+        this.mediator = mediator;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackContext#getRequest()
-     */
     @Override
     public WebSocketRequestWrapper getRequest() {
     	return this.request;
     }
 
-    /* (non-Javadoc)
-     * @see org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackContext#getResponse()
-     */
     @Override
     public WebSocketResponseWrapper getResponse() {
     	return this.response;
     }
+
+	@Override
+	public Session getSession() {
+		//TODO: allow some how to authenticate
+		if(this.session == null) {
+			this.session = mediator.callService(Core.class, new Executable<Core,Session>(){
+				@Override
+				public Session execute(Core core) throws Exception {
+					core.getAnonymousSession();
+					return null;
+				}
+			});
+		}
+		return this.session;
+	}
 }
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java
index 0e18e43..e59547a 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackFactory.java
@@ -185,7 +185,7 @@
         int callbackType = callbackService.getCallbackType();
         if((callbackType & CallbackService.CALLBACK_SERVLET) == CallbackService.CALLBACK_SERVLET) {
 	        
-        	CallbackServlet callbackServlet = new CallbackServlet(callbackService);
+        	CallbackServlet callbackServlet = new CallbackServlet(mediator, callbackService);
 
 	        Dictionary props = callbackService.getProperties();
 	        props.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, endpoint);
@@ -205,7 +205,7 @@
         	
         	WebSocketServlet webSocketServlet = new WebSocketServlet() { 			
 				private static final long serialVersionUID = 1L;	
-				private CallbackWebSocketPool pool = new CallbackWebSocketPool(callbackService);    				
+				private CallbackWebSocketPool pool = new CallbackWebSocketPool(mediator, callbackService);    				
 		        private final AtomicBoolean firstCall = new AtomicBoolean(true); 
 		    
 				private final CountDownLatch initBarrier = new CountDownLatch(1); 
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java
index 93a9b2d..c684ce6 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackServlet.java
@@ -19,6 +19,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
 import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
 import org.eclipse.sensinact.gateway.nthbnd.http.callback.HttpRequestWrapper;
 import org.eclipse.sensinact.gateway.nthbnd.http.callback.HttpResponseWrapper;
@@ -33,15 +34,19 @@
 public class CallbackServlet extends HttpServlet implements Servlet{
 	
 	private CallbackService callbackService;
+	private Mediator mediator;
 
     /**
      * Constructor
-     *
+     * 
+     * @param mediator the {@link Mediator} allowing the CallbackServlet to be 
+     * instantiated to interact with the OSGi host environment
      * @param callbackService the {@link CallbackService} allowing the
      * CallbackServlet to be instantiated to process the callback request
      */
-    public CallbackServlet(CallbackService callbackService) {
+    public CallbackServlet(Mediator mediator, CallbackService callbackService) {
         this.callbackService = callbackService;
+        this.mediator = mediator;
     }
     
     /* (non-Javadoc)
@@ -61,7 +66,7 @@
     	if (response.isCommitted()) {       	
     		return;
         }
-        final ServletCallbackContext context = new ServletCallbackContext(
+        final ServletCallbackContext context = new ServletCallbackContext(mediator,
         		new HttpRequestWrapper(request), new HttpResponseWrapper(response));
         try {
             if (CallbackServlet.this.callbackService != null) {
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketPool.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketPool.java
index d14de00..20f309a 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketPool.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketPool.java
@@ -17,6 +17,7 @@
 import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
 import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
 import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
 import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
 
 /**
@@ -29,12 +30,14 @@
 	
     private List<CallbackWebSocketServlet> sessions;
 	private CallbackService callbackService;
+	private Mediator mediator;
 
     /**
      * Constructor
      */
-    public CallbackWebSocketPool(CallbackService callbackService) {
+    public CallbackWebSocketPool(Mediator mediator, CallbackService callbackService) {
         this.callbackService = callbackService;
+        this.mediator = mediator;
         this.sessions = Collections.synchronizedList(new ArrayList<CallbackWebSocketServlet>());
     }
 
@@ -52,7 +55,7 @@
 
     @Override
     public Object createWebSocket(ServletUpgradeRequest req, ServletUpgradeResponse resp) {
-        CallbackWebSocketServlet wrapper = new CallbackWebSocketServlet(callbackService);
+        CallbackWebSocketServlet wrapper = new CallbackWebSocketServlet(mediator,callbackService);
         if (wrapper != null) {
             this.sessions.add(wrapper);
         }
diff --git a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketServlet.java b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketServlet.java
index e8c1660..fc3cce2 100644
--- a/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketServlet.java
+++ b/platform/northbound/http-tools/src/main/java/org/eclipse/sensinact/gateway/nthbnd/http/callback/internal/CallbackWebSocketServlet.java
@@ -18,6 +18,7 @@
 import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
 import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
 import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+import org.eclipse.sensinact.gateway.common.bundle.Mediator;
 import org.eclipse.sensinact.gateway.nthbnd.http.callback.CallbackService;
 import org.eclipse.sensinact.gateway.nthbnd.http.callback.WebSocketCallbackContext;
 import org.eclipse.sensinact.gateway.nthbnd.http.callback.WebSocketRequestWrapper;
@@ -37,11 +38,20 @@
     private Logger LOG = LoggerFactory.getLogger(CallbackWebSocketServlet.class.getName());
     
 	private CallbackService callbackService;
-    
+	private Mediator mediator;
     protected Session session;
 
-    protected CallbackWebSocketServlet(CallbackService callbackService) {
+    /**
+     * Constructor
+     * 
+     * @param mediator the {@link Mediator} allowing the CallbackWebSocketServlet to be 
+     * instantiated to interact with the OSGi host environment
+     * @param callbackService the {@link CallbackService} allowing the
+     * CallbackWebSocketServlet to be instantiated to process the callback request
+     */ 
+    protected CallbackWebSocketServlet(Mediator mediator, CallbackService callbackService) {
         this.callbackService = callbackService;
+        this.mediator = mediator;
     }
     
     /**
@@ -73,7 +83,7 @@
      */
     @OnWebSocketMessage
     public void onMessage(String message) {
-        final WebSocketCallbackContext context = new WebSocketCallbackContext(
+        final WebSocketCallbackContext context = new WebSocketCallbackContext(mediator,
         new WebSocketRequestWrapper(message), new WebSocketResponseWrapper(this));
         try {
             if (this.callbackService != null) {