/* USE THIS FILE ACCORDING TO THE COPYRIGHT RULES IN LICENSE.TXT WHICH IS PART OF THE SOURCE CODE PACKAGE */ 
package com.wilutions.jsfs;

import java.io.File;

import javax.servlet.http.HttpSession;

import byps.BApiDescriptor;
import byps.BServer;
import byps.BServerRegistry;
import byps.BTransportFactory;
import byps.http.HSession;

/**
 * BYPS session class.
 *
 */
public class MySession extends HSession {

  /**
   * Server class that gives BYPS access to the interface implementations.
   */
  private final BServer_JSFS server;
  
  /**
   * Associated JSFS Dispatcher object.
   * @see JsfsDispatcher
   */
  private final JsfsDispatcher jsfsDispatcher;

	public MySession(HttpSession hsess, String remoteUser, File tempDir,
			BServerRegistry stubRegistry) {
		super(hsess, remoteUser, tempDir, stubRegistry);
    
		// Add JSON serialization
		BApiDescriptor apiDesc = BApiDescriptor_JSFS.instance();
		apiDesc.addRegistry(new JRegistry_JSFS());
		
		// Initialize objects required by BYPS 
    BTransportFactory transportFactory = getTransportFactory(apiDesc);
    server = BServer_JSFS.createServer(transportFactory);
    
    // Assign a JSFS Dispatcher to this session and 
    // add it to the interfaces managed by the server object.
    jsfsDispatcher = new JsfsDispatcher(this);
    server.addRemote(jsfsDispatcher);

    // This session does not need authentication.
    // Authentication is managed by "Your Web Application" which creates the access tokens.
    setSessionAuthenticated();
	}
	
	@Override
	public BServer getServer() {
		return server;
	}
	
	@Override
	public void done() {
	  jsfsDispatcher.removeMyTokenBecauseSessionWasInvalidated();
	  super.done();
	}

}

@@ -1389,18 +1389,17 @@
    // Th
-is
+e
  session
@@ -1403,162 +1403,315 @@
 ion 
-doe
+i
 s no
-t need authentication.%0D%0A    // Authentication is managed by %22Your Web Application%22 which creates the access tokens.%0D%0A    setSessionAuthenticated();
+w valid for 10s. %0D%0A    // If the session is created for JSFS Agent, the lifetime will be extended%0D%0A    // in the subsequent JsfsDispatcher.registerService call.%0D%0A    // If the session is created for the browser, the lifetime will be extended%0D%0A    // if JsfsDispatcher.getService returns not null.%0D%0A    
 %0D%0A%09%7D

Extend browser session lifetime only if JSFS Agent has registered its service.