Commit 31b95985 authored by Ole Voldsæter's avatar Ole Voldsæter
Browse files

fixes #1825 Nailed it using Accept-Language http header. New user sessions are...

fixes #1825 Nailed it using Accept-Language http header. New user sessions are created when new languages are requested. These sessions are shared by all requests with the same preferred language
parent 18b00c6a
package com.nesstar.rest;
import com.nesstar.rest.common.ServerHandler;
import com.nesstar.rest.filters.LanguageFilter;
import com.nesstar.rest.healthchecks.NesstarHealthCheck;
import com.nesstar.rest.resources.*;
import com.yammer.dropwizard.Service;
......@@ -49,5 +50,7 @@ public class NesstarDropService extends Service<NesstarDropConfiguration> {
FilterBuilder filterConfig = environment.addFilter(CrossOriginFilter.class, "*");
filterConfig.setInitParam(CrossOriginFilter.PREFLIGHT_MAX_AGE_PARAM, String.valueOf(60 * 60 * 24)); // 1 day
filterConfig.setInitParam(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*");
environment.addFilter(LanguageFilter.class, "*");
}
}
......@@ -23,7 +23,6 @@ public final class ServerHandler {
public Server getServer() throws IOException {
NesstarDB db = NesstarDBFactory.getInstance();
db.setSession(toString());
if (server == null) {
server = db.getServer(serverURI);
if (userId != null && password != null) {
......
package com.nesstar.rest.filters;
import com.nesstar.api.NesstarDB;
import com.nesstar.api.NesstarDBFactory;
import javax.servlet.*;
import java.io.IOException;
import java.util.Locale;
public class LanguageFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {
}
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
NesstarDB db = NesstarDBFactory.getInstance();
Locale locale = servletRequest.getLocale();
String sessionID = locale.toString();
db.setSession(sessionID);
db.setPreferredLanguages(locale);
filterChain.doFilter(servletRequest, servletResponse);
}
@Override
public void destroy() {
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment