use of org.eclipse.jetty.server.session.SessionHandler in project camel by apache.
the class HttpProducerSessionTest method initServer.
@BeforeClass
public static void initServer() throws Exception {
port = AvailablePortFinder.getNextAvailable(24000);
localServer = new Server(new InetSocketAddress("127.0.0.1", port));
ContextHandler contextHandler = new ContextHandler();
contextHandler.setContextPath("/session");
SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setHandler(new SessionReflectionHandler());
contextHandler.setHandler(sessionHandler);
localServer.setHandler(contextHandler);
localServer.start();
}
use of org.eclipse.jetty.server.session.SessionHandler in project drill by axbaretto.
the class WebServer method createSessionHandler.
/**
* @return A {@link SessionHandler} which contains a {@link HashSessionManager}
*/
private SessionHandler createSessionHandler(final SecurityHandler securityHandler) {
SessionManager sessionManager = new HashSessionManager();
sessionManager.setMaxInactiveInterval(config.getInt(ExecConstants.HTTP_SESSION_MAX_IDLE_SECS));
sessionManager.addEventListener(new HttpSessionListener() {
@Override
public void sessionCreated(HttpSessionEvent se) {
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
final HttpSession session = se.getSession();
if (session == null) {
return;
}
final Object authCreds = session.getAttribute(SessionAuthentication.__J_AUTHENTICATED);
if (authCreds != null) {
final SessionAuthentication sessionAuth = (SessionAuthentication) authCreds;
securityHandler.logout(sessionAuth);
session.removeAttribute(SessionAuthentication.__J_AUTHENTICATED);
}
// Clear all the resources allocated for this session
@SuppressWarnings("resource") final WebSessionResources webSessionResources = (WebSessionResources) session.getAttribute(WebSessionResources.class.getSimpleName());
if (webSessionResources != null) {
webSessionResources.close();
session.removeAttribute(WebSessionResources.class.getSimpleName());
}
}
});
return new SessionHandler(sessionManager);
}
use of org.eclipse.jetty.server.session.SessionHandler in project api-core by ca-cwds.
the class BaseApiApplication method run.
@Override
public final void run(final T configuration, final Environment environment) throws Exception {
environment.servlets().setSessionHandler(new SessionHandler());
registerExceptionMappers(environment);
LOGGER.info("Application name: {}, Version: {}", configuration.getApplicationName(), configuration.getVersion());
LOGGER.info("Configuring CORS: Cross-Origin Resource Sharing");
configureCors(environment);
LOGGER.info("Configuring ObjectMapper");
ObjectMapperUtils.configureObjectMapper(environment.getObjectMapper());
LOGGER.info("Configuring SWAGGER");
configureSwagger(configuration, environment);
LOGGER.info("Registering Filters");
registerFilters(environment, guiceBundle);
LOGGER.info("Registering SystemCodeCache");
LOGGER.info("Setting up Guice injector");
// Providing access to the guice injector from external classes such as custom validators
InjectorHolder.INSTANCE.setInjector(injector);
runInternal(configuration, environment);
}
use of org.eclipse.jetty.server.session.SessionHandler in project ddf by codice.
the class HttpSessionFactory method getCachedSession.
/**
* DDF-6587 - This check is made so that when simultaneous requests are received for the same
* context, the second request will not attempt to create a new session. The first request will
* create a new session object and the second one will look up the previously created session
* object from the jetty session cache. This is necessary because at this point in the processing
* chain, jetty was not able to associate a session for either of the simultaneous requests.
* Therefore, we need to manually attach the session to the second request. Otherwise, jetty will
* attempt to recreate the same session object and fail, causing the second request to fail.
*/
private HttpSession getCachedSession(HttpServletRequest httpRequest) {
if (httpRequest instanceof Request && hasValidDependencies((Request) httpRequest)) {
try {
Request request = (Request) httpRequest;
SessionHandler sessionHandler = request.getSessionHandler();
SessionCache sessionCache = sessionHandler.getSessionCache();
String sessionId = sessionHandler.getSessionIdManager().newSessionId(request, System.currentTimeMillis());
Session cachedSession = sessionCache.get(sessionId);
if (cachedSession != null && cachedSession instanceof HttpSession && cachedSession.isValid()) {
HttpSession session = (HttpSession) cachedSession;
request.enterSession(session);
request.setSession(session);
return session;
}
} catch (Exception e) {
LOGGER.trace("Unable to get session from cache, letting a new one get created", e);
}
}
return null;
}
use of org.eclipse.jetty.server.session.SessionHandler in project dropbox-sdk-java by dropbox.
the class Main method main.
// -------------------------------------------------------------------------------------------
// main()
// -------------------------------------------------------------------------------------------
// Parse command-line arguments and start server.
public static void main(String[] args) throws IOException {
if (args.length != 3) {
System.out.println("");
System.out.println("Usage: COMMAND <http-listen-port> <app-info-file> <database-file>");
System.out.println("");
System.out.println(" <http-listen-port>: The port to run the HTTP server on. For example,");
System.out.println(" \"8080\").");
System.out.println("");
System.out.println(" <app-info-file>: A JSON file containing your Dropbox API app key, secret");
System.out.println(" and access type. For example, \"my-app.app\" with:");
System.out.println("");
System.out.println(" {");
System.out.println(" \"key\": \"Your Dropbox app key...\",");
System.out.println(" \"secret\": \"Your Dropbox app secret...\"");
System.out.println(" }");
System.out.println("");
System.out.println(" <database-file>: Where you want this program to store its database. For");
System.out.println(" example, \"web-file-browser.db\".");
System.out.println("");
System.exit(1);
return;
}
String argPort = args[0];
String argAppInfo = args[1];
String argDatabase = args[2];
// Figure out what port to listen on.
int port;
try {
port = Integer.parseInt(argPort);
if (port < 1 || port > 65535) {
System.err.println("Expecting <http-listen-port> to be a number from 1 to 65535. Got: " + port + ".");
System.exit(1);
return;
}
} catch (NumberFormatException ex) {
System.err.println("Expecting <http-listen-port> to be a number from 1 to 65535. Got: " + jq(argPort) + ".");
System.exit(1);
return;
}
// Read app info file (contains app key and app secret)
DbxAppInfo dbxAppInfo;
try {
dbxAppInfo = DbxAppInfo.Reader.readFromFile(argAppInfo);
} catch (JsonReader.FileLoadException ex) {
System.err.println("Error loading <app-info-file>: " + ex.getMessage());
System.exit(1);
return;
}
System.out.println("Loaded app info from " + jq(argAppInfo));
File dbFile = new File(argDatabase);
// Run server
try {
Main main = new Main(new PrintWriter(System.out, true), dbxAppInfo, dbFile);
Server server = new Server(port);
SessionHandler sessionHandler = new SessionHandler();
sessionHandler.setServer(server);
sessionHandler.setHandler(main);
server.setHandler(sessionHandler);
server.start();
System.out.println("Server running: http://localhost:" + port + "/");
server.join();
} catch (Exception ex) {
System.err.println("Error running server: " + ex.getMessage());
System.exit(1);
}
}
Aggregations