Maintaining session timeout globally in java spring configuration
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
Below is my code to maintain a session timeout globally in Java spring configuration and to load the session timeout value from a properties file. Do you have any suggestions to improve my code?
public class MySessionListener implements HttpSessionListener
@Override
public void sessionCreated(HttpSessionEvent event)
try
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream stream = classLoader.getResourceAsStream("bimspring.properties");
Properties properties = new Properties();
properties.load(stream);
String sessionTimeout = properties.getProperty("cookieName", "No Value Found");
event.getSession().setMaxInactiveInterval(Integer.parseInt(sessionTimeout));
catch (IOException e)
e.printStackTrace();
@Override
public void sessionDestroyed(HttpSessionEvent event)
java spring-mvc
add a comment |Â
up vote
2
down vote
favorite
Below is my code to maintain a session timeout globally in Java spring configuration and to load the session timeout value from a properties file. Do you have any suggestions to improve my code?
public class MySessionListener implements HttpSessionListener
@Override
public void sessionCreated(HttpSessionEvent event)
try
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream stream = classLoader.getResourceAsStream("bimspring.properties");
Properties properties = new Properties();
properties.load(stream);
String sessionTimeout = properties.getProperty("cookieName", "No Value Found");
event.getSession().setMaxInactiveInterval(Integer.parseInt(sessionTimeout));
catch (IOException e)
e.printStackTrace();
@Override
public void sessionDestroyed(HttpSessionEvent event)
java spring-mvc
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
Below is my code to maintain a session timeout globally in Java spring configuration and to load the session timeout value from a properties file. Do you have any suggestions to improve my code?
public class MySessionListener implements HttpSessionListener
@Override
public void sessionCreated(HttpSessionEvent event)
try
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream stream = classLoader.getResourceAsStream("bimspring.properties");
Properties properties = new Properties();
properties.load(stream);
String sessionTimeout = properties.getProperty("cookieName", "No Value Found");
event.getSession().setMaxInactiveInterval(Integer.parseInt(sessionTimeout));
catch (IOException e)
e.printStackTrace();
@Override
public void sessionDestroyed(HttpSessionEvent event)
java spring-mvc
Below is my code to maintain a session timeout globally in Java spring configuration and to load the session timeout value from a properties file. Do you have any suggestions to improve my code?
public class MySessionListener implements HttpSessionListener
@Override
public void sessionCreated(HttpSessionEvent event)
try
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
InputStream stream = classLoader.getResourceAsStream("bimspring.properties");
Properties properties = new Properties();
properties.load(stream);
String sessionTimeout = properties.getProperty("cookieName", "No Value Found");
event.getSession().setMaxInactiveInterval(Integer.parseInt(sessionTimeout));
catch (IOException e)
e.printStackTrace();
@Override
public void sessionDestroyed(HttpSessionEvent event)
java spring-mvc
edited Jun 3 at 8:43
Daniel
4,1132836
4,1132836
asked Jun 3 at 8:09
user171106
111
111
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
Quite a number of points for this short piece of code:
- As the properties file will probably not change at runtime, loading it every single time a session gets created is a total waste. See whether you can cache the session timeout in a static variable.
- If the value is not set, the default "no value found" will lead to a number format exception. Better use a sensible parseable default.
- Similar context: by setting the value to a non-parseable string, you can kill the server with a misconfiguration.
- "sessionTimeout" should not be named "cookieName"
- Separation of concerns: a method should do one thing. This is a mixup of reading the program configuration and using the determined value to set the timeout.
- Error handling: printStackTrace does not accomplish anything. Do something real (e.g. log an error for the server admin, shutdown, whatever.) If you decide to continue the process in case of an I/O exception, set a sensible default on the session.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Quite a number of points for this short piece of code:
- As the properties file will probably not change at runtime, loading it every single time a session gets created is a total waste. See whether you can cache the session timeout in a static variable.
- If the value is not set, the default "no value found" will lead to a number format exception. Better use a sensible parseable default.
- Similar context: by setting the value to a non-parseable string, you can kill the server with a misconfiguration.
- "sessionTimeout" should not be named "cookieName"
- Separation of concerns: a method should do one thing. This is a mixup of reading the program configuration and using the determined value to set the timeout.
- Error handling: printStackTrace does not accomplish anything. Do something real (e.g. log an error for the server admin, shutdown, whatever.) If you decide to continue the process in case of an I/O exception, set a sensible default on the session.
add a comment |Â
up vote
1
down vote
Quite a number of points for this short piece of code:
- As the properties file will probably not change at runtime, loading it every single time a session gets created is a total waste. See whether you can cache the session timeout in a static variable.
- If the value is not set, the default "no value found" will lead to a number format exception. Better use a sensible parseable default.
- Similar context: by setting the value to a non-parseable string, you can kill the server with a misconfiguration.
- "sessionTimeout" should not be named "cookieName"
- Separation of concerns: a method should do one thing. This is a mixup of reading the program configuration and using the determined value to set the timeout.
- Error handling: printStackTrace does not accomplish anything. Do something real (e.g. log an error for the server admin, shutdown, whatever.) If you decide to continue the process in case of an I/O exception, set a sensible default on the session.
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Quite a number of points for this short piece of code:
- As the properties file will probably not change at runtime, loading it every single time a session gets created is a total waste. See whether you can cache the session timeout in a static variable.
- If the value is not set, the default "no value found" will lead to a number format exception. Better use a sensible parseable default.
- Similar context: by setting the value to a non-parseable string, you can kill the server with a misconfiguration.
- "sessionTimeout" should not be named "cookieName"
- Separation of concerns: a method should do one thing. This is a mixup of reading the program configuration and using the determined value to set the timeout.
- Error handling: printStackTrace does not accomplish anything. Do something real (e.g. log an error for the server admin, shutdown, whatever.) If you decide to continue the process in case of an I/O exception, set a sensible default on the session.
Quite a number of points for this short piece of code:
- As the properties file will probably not change at runtime, loading it every single time a session gets created is a total waste. See whether you can cache the session timeout in a static variable.
- If the value is not set, the default "no value found" will lead to a number format exception. Better use a sensible parseable default.
- Similar context: by setting the value to a non-parseable string, you can kill the server with a misconfiguration.
- "sessionTimeout" should not be named "cookieName"
- Separation of concerns: a method should do one thing. This is a mixup of reading the program configuration and using the determined value to set the timeout.
- Error handling: printStackTrace does not accomplish anything. Do something real (e.g. log an error for the server admin, shutdown, whatever.) If you decide to continue the process in case of an I/O exception, set a sensible default on the session.
answered Jun 4 at 7:57
mtj
2,675212
2,675212
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f195733%2fmaintaining-session-timeout-globally-in-java-spring-configuration%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password