| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hiveboard.util; |
| 16 | |
| 17 | import javax.servlet.http.HttpServletRequest; |
| 18 | import javax.servlet.http.HttpServletResponse; |
| 19 | |
| 20 | import org.apache.commons.logging.Log; |
| 21 | |
| 22 | // Singleton model |
| 23 | public class VersionControlManagerImpl implements VersionControlManager |
| 24 | { |
| 25 | public VersionControlManagerImpl( Log logger, |
| 26 | String serverVersion, |
| 27 | String supportedClientVersions) |
| 28 | { |
| 29 | _logger = logger; |
| 30 | _serverVersion = serverVersion; |
| 31 | _supportedClientVersions = supportedClientVersions; |
| 32 | } |
| 33 | |
| 34 | public Exception checkClientVersion( HttpServletRequest request, |
| 35 | HttpServletResponse response) |
| 36 | { |
| 37 | String clientVersion = request.getHeader(VersionContext.CLIENT_VERSION_KEY); |
| 38 | response.setHeader(VersionContext.SERVER_VERSION_KEY, _serverVersion); |
| 39 | |
| 40 | if ( clientVersion != null |
| 41 | && _supportedClientVersions.indexOf(clientVersion) >= 0) |
| 42 | { |
| 43 | return null; |
| 44 | } |
| 45 | _logger.info("Unsupported client version: " + clientVersion); |
| 46 | return new VersionMismatchException("Unsupported client version", |
| 47 | clientVersion, |
| 48 | _serverVersion, |
| 49 | _supportedClientVersions); |
| 50 | } |
| 51 | |
| 52 | private final Log _logger; |
| 53 | private final String _serverVersion; |
| 54 | private final String _supportedClientVersions; |
| 55 | } |