ef4c6f35c58a2360755fe09c4a5408d1df3d4196
[cdmlib.git] / cdmlib-remote / src / main / java / eu / etaxonomy / cdm / remote / controller / interceptor / DatasourceContextHandlerInterceptor.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10
11 package eu.etaxonomy.cdm.remote.controller.interceptor;
12
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
15
16 import javax.servlet.http.HttpServletRequest;
17 import javax.servlet.http.HttpServletResponse;
18
19 import org.apache.log4j.Logger;
20 import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
21
22 import eu.etaxonomy.cdm.database.NamedContextHolder;
23
24 /**
25 * @author a.kohlbecker
26 * @deprecated<b>NOTICE:</b>
27 * <em>This class is related to the switchable database infrastructure which allows to serve
28 * multiple databases with only a single instance of the cdm-remote-webapp.
29 * This concept however is deprecated due to several problems of which the most severe is the term loading issue.
30 * This class should however not deleted since we once might wish to switch back to this concept when we are
31 * able to deal with the implicated issues.</em>
32 */
33 @Deprecated
34 public class DatasourceContextHandlerInterceptor extends HandlerInterceptorAdapter {
35 private static final Logger logger = Logger.getLogger(DatasourceContextHandlerInterceptor.class);
36
37 private final static Pattern basepathPattern = Pattern.compile("^/([^/]+)/.*");
38
39 @Override
40 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
41 Matcher matcher = basepathPattern.matcher(request.getServletPath());
42 if (matcher.matches())
43 {
44 String basepath = matcher.group(1);
45 NamedContextHolder.setContextKey(basepath);
46 logger.info("datasource context set to: " + basepath);
47 }
48 return true;
49 }
50
51
52
53 @Override
54 public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
55 NamedContextHolder.clearContextKey();
56 logger.info("datasource context cleared");
57
58 }
59 }