3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.remote
.controller
.interceptor
;
13 import java
.util
.regex
.Matcher
;
14 import java
.util
.regex
.Pattern
;
16 import javax
.servlet
.http
.HttpServletRequest
;
17 import javax
.servlet
.http
.HttpServletResponse
;
19 import org
.apache
.log4j
.Logger
;
20 import org
.springframework
.web
.servlet
.handler
.HandlerInterceptorAdapter
;
22 import eu
.etaxonomy
.cdm
.database
.NamedContextHolder
;
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.
33 * See http://dev.e-taxonomy.eu/trac/wiki/CdmServerSwitchableDataSources for more information.</em>
36 public class DatasourceContextHandlerInterceptor
extends HandlerInterceptorAdapter
{
37 private static final Logger logger
= Logger
.getLogger(DatasourceContextHandlerInterceptor
.class);
39 private final static Pattern basepathPattern
= Pattern
.compile("^/([^/]+)/.*");
42 public boolean preHandle(HttpServletRequest request
, HttpServletResponse response
, Object handler
) throws Exception
{
43 Matcher matcher
= basepathPattern
.matcher(request
.getServletPath());
44 if (matcher
.matches())
46 String basepath
= matcher
.group(1);
47 NamedContextHolder
.setContextKey(basepath
);
48 logger
.info("datasource context set to: " + basepath
);
56 public void afterCompletion(HttpServletRequest request
, HttpServletResponse response
, Object handler
, Exception ex
) throws Exception
{
57 NamedContextHolder
.clearContextKey();
58 logger
.info("datasource context cleared");