Changeset 2622
- Timestamp:
- 02/25/13 19:57:34 (11 years ago)
- Location:
- SRUServer/trunk/src/main/java/eu/clarin/sru/server
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
SRUServer/trunk/src/main/java/eu/clarin/sru/server/SRUServerConfig.java
r2246 r2622 43 43 import javax.xml.xpath.XPathFactory; 44 44 45 import org.slf4j.Logger; 46 import org.slf4j.LoggerFactory; 45 47 import org.w3c.dom.Attr; 46 48 import org.w3c.dom.Document; … … 83 85 */ 84 86 public final class SRUServerConfig { 85 public static final String SRU_TRANSPORT = "sru.transport"; 86 public static final String SRU_HOST = "sru.host"; 87 public static final String SRU_PORT = "sru.port"; 88 public static final String SRU_DATABASE = "sru.database"; 89 public static final String SRU_NUMBER_OF_RECORDS = "sru.numberOfRecords"; 90 public static final String SRU_MAXIMUM_RECORDS = "sru.maximumRecords"; 91 public static final String SRU_ECHO_REQUESTS = "sru.echoRequests"; 92 public static final String SRU_INDENT_RESPONSE = "sru.indentResponse"; 87 /** 88 * Parameter constant for configuring the transports for this SRU server. 89 * <p> 90 * Valid values: "<code>http</code>", "<code>https</code>" or " 91 * <code>http https</code>" (without quotation marks) <br /> 92 * <p> 93 * Used as part of the <em>Explain</em> response. 94 * </p> 95 */ 96 public static final String SRU_TRANSPORT = 97 "eu.clarin.sru.server.transport"; 98 /** 99 * Parameter constant for configuring the host of this SRU server. 100 * <p> 101 * Valid values: any fully qualified hostname, e.g. 102 * <code>sru.example.org</code> <br /> 103 * Used as part of the <em>Explain</em> response. 104 * </p> 105 */ 106 public static final String SRU_HOST = 107 "eu.clarin.sru.server.host"; 108 /** 109 * Parameter constant for configuring the port number of this SRU server. 110 * <p> 111 * Valid values: number between 1 and 65535 (typically 80 or 8080) <br /> 112 * Used as part of the <em>Explain</em> response. 113 * </p> 114 */ 115 public static final String SRU_PORT = 116 "eu.clarin.sru.server.port"; 117 /** 118 * Parameter constant for configuring the database of this SRU server. This 119 * is usually the path component of the SRU servers URI. 120 * <p> 121 * Valid values: typically the path component if the SRU server URI. <br /> 122 * Used as part of the <em>Explain</em> response. 123 * </p> 124 */ 125 public static final String SRU_DATABASE = 126 "eu.clarin.sru.server.database"; 127 /** 128 * Parameter constant for configuring the <em>default</em> number of records 129 * the SRU server will provide in the response to a request if the client 130 * does not specify a limit. 131 * <p> 132 * Valid values: a integer greater than 0 (default value is 100) 133 * </p> 134 */ 135 public static final String SRU_NUMBER_OF_RECORDS = 136 "eu.clarin.sru.server.numberOfRecords"; 137 /** 138 * Parameter constant for configuring the <em>maximum</em> number of records 139 * the SRU server will support in one request. If a client requests more 140 * records, the number will be limited to this value. 141 * <p> 142 * Valid values: a integer greater than 0 (default value is 250) 143 * </p> 144 */ 145 public static final String SRU_MAXIMUM_RECORDS = 146 "eu.clarin.sru.server.maximumRecords"; 147 /** 148 * Parameter constant for configuring, if the SRU server will echo the 149 * request. 150 * <p> 151 * Valid values: <code>true</code> or <code>false</code> 152 * </p> 153 */ 154 public static final String SRU_ECHO_REQUESTS = 155 "eu.clarin.sru.server.echoRequests"; 156 /** 157 * Parameter constant for configuring, if the SRU server pretty-print the 158 * XML response. Setting this parameter can be useful for manual debugging, 159 * however it is not recommended for production setups. 160 * <p> 161 * Valid values: <code>true</code> or <code>false</code> 162 * </p> 163 */ 164 public static final String SRU_INDENT_RESPONSE = 165 "eu.clarin.sru.server.indentResponse"; 166 /** 167 * Parameter constant for configuring, if the SRU server will allow the 168 * client to override the maximum number of records the server supports. 169 * This parameter is solely intended for debugging and enabling it is 170 * <em>strongly</em> discouraged for production setups. 171 * <p> 172 * Valid values: <code>true</code> or <code>false</code> 173 * </p> 174 */ 93 175 public static final String SRU_ALLOW_OVERRIDE_MAXIMUM_RECORDS = 176 "eu.clarin.sru.server.allowOverrideMaximumRecords"; 177 /** 178 * Parameter constant for configuring, if the SRU server will allow the 179 * client to override the pretty-printing setting of the server. This 180 * parameter is solely intended for debugging and enabling it is 181 * <em>strongly</em> discouraged for production setups. 182 * <p> 183 * Valid values: <code>true</code> or <code>false</code> 184 * </p> 185 */ 186 public static final String SRU_ALLOW_OVERRIDE_INDENT_RESPONSE = 187 "eu.clarin.sru.server.allowOverrideIndentResponse"; 188 /** 189 * @deprecated use {@link #SRU_TRANSPORT} 190 */ 191 @Deprecated 192 private static final String LEGACY_SRU_TRANSPORT = 193 "sru.transport"; 194 /** 195 * @deprecated use {@link #SRU_HOST} 196 */ 197 @Deprecated 198 private static final String LEGACY_SRU_HOST = 199 "sru.host"; 200 /** 201 * @deprecated use {@link #SRU_PORT} 202 */ 203 @Deprecated 204 private static final String LEGACY_SRU_PORT = 205 "sru.port"; 206 /** 207 * @deprecated use {@link #SRU_DATABASE} 208 */ 209 @Deprecated 210 private static final String LEGACY_SRU_DATABASE = 211 "sru.database"; 212 /** 213 * @deprecated use {@link #SRU_NUMBER_OF_RECORDS} 214 */ 215 @Deprecated 216 private static final String LEGACY_SRU_NUMBER_OF_RECORDS = 217 "sru.numberOfRecords"; 218 /** 219 * @deprecated use {@link #SRU_MAXIMUM_RECORDS} 220 */ 221 @Deprecated 222 private static final String LEGACY_SRU_MAXIMUM_RECORDS = 223 "sru.maximumRecords"; 224 /** 225 * @deprecated use {@link #SRU_ECHO_REQUESTS} 226 */ 227 @Deprecated 228 private static final String LEGACY_SRU_ECHO_REQUESTS = 229 "sru.echoRequests"; 230 /** 231 * @deprecated use {@link #SRU_INDENT_RESPONSE} 232 */ 233 @Deprecated 234 private static final String LEGACY_SRU_INDENT_RESPONSE = 235 "sru.indentResponse"; 236 /** 237 * @deprecated use {@link #SRU_ALLOW_OVERRIDE_MAXIMUM_RECORDS} 238 */ 239 @Deprecated 240 private static final String LEGACY_SRU_ALLOW_OVERRIDE_MAXIMUM_RECORDS = 94 241 "sru.allowOverrideMaximumRecords"; 95 public static final String SRU_ALLOW_OVERRIDE_INDENT_RESPONSE = 242 /** 243 * @deprecated use {@link #SRU_ALLOW_OVERRIDE_INDENT_RESPONSE} 244 */ 245 @Deprecated 246 private static final String LEGACY_SRU_ALLOW_OVERRIDE_INDENT_RESPONSE = 96 247 "sru.allowOverrideIndentResponse"; 97 p ublicstatic final int DEFAULT_NUMBER_OF_RECORDS = 100;98 p ublicstatic final int DEFAULT_MAXIMUM_RECORDS = 250;248 private static final int DEFAULT_NUMBER_OF_RECORDS = 100; 249 private static final int DEFAULT_MAXIMUM_RECORDS = 250; 99 250 private static final String CONFIG_FILE_NAMESPACE_URI = 100 251 "http://www.clarin.eu/sru-server/1.0/"; … … 424 575 } // IndexInfo 425 576 577 private static final Logger logger = 578 LoggerFactory.getLogger(SRUServerConfig.class); 426 579 private final String transport; 427 580 private final String host; … … 699 852 List<SchemaInfo> schemaInfo = buildSchemaInfo(xpath, doc); 700 853 854 /* 855 * convert legacy parameters 856 */ 857 convertLegacyParameter(params); 858 859 /* 860 * fetch parameters more parameters 861 */ 701 862 String transport = params.get(SRU_TRANSPORT); 702 863 if ((transport == null) || transport.isEmpty()) { … … 1044 1205 } 1045 1206 1207 1208 public static void convertLegacyParameter(Map<String, String> params) { 1209 if ((params != null) && !params.isEmpty()) { 1210 convertLegacyParameter1(params, 1211 LEGACY_SRU_TRANSPORT, 1212 SRU_TRANSPORT); 1213 convertLegacyParameter1(params, 1214 LEGACY_SRU_HOST, 1215 SRU_HOST); 1216 convertLegacyParameter1(params, 1217 LEGACY_SRU_PORT, 1218 SRU_PORT); 1219 convertLegacyParameter1(params, 1220 LEGACY_SRU_DATABASE, 1221 SRU_DATABASE); 1222 convertLegacyParameter1(params, 1223 LEGACY_SRU_NUMBER_OF_RECORDS, 1224 SRU_NUMBER_OF_RECORDS); 1225 convertLegacyParameter1(params, 1226 LEGACY_SRU_MAXIMUM_RECORDS, 1227 SRU_MAXIMUM_RECORDS); 1228 convertLegacyParameter1(params, 1229 LEGACY_SRU_ECHO_REQUESTS, 1230 SRU_ECHO_REQUESTS); 1231 convertLegacyParameter1(params, 1232 LEGACY_SRU_INDENT_RESPONSE, 1233 SRU_INDENT_RESPONSE); 1234 convertLegacyParameter1(params, 1235 LEGACY_SRU_ALLOW_OVERRIDE_MAXIMUM_RECORDS, 1236 SRU_ALLOW_OVERRIDE_MAXIMUM_RECORDS); 1237 convertLegacyParameter1(params, 1238 LEGACY_SRU_ALLOW_OVERRIDE_INDENT_RESPONSE, 1239 SRU_ALLOW_OVERRIDE_INDENT_RESPONSE); 1240 } 1241 } 1242 1243 1244 private static void convertLegacyParameter1(Map<String, String> params, 1245 String legacyName, String name) { 1246 final String value = params.get(legacyName); 1247 if (value != null) { 1248 params.put(name, value); 1249 params.remove(legacyName); 1250 logger.warn("parameter '{}' is deprecated, please use " 1251 + "paramter '{}' instead!", legacyName, name); 1252 } 1253 } 1254 1046 1255 } // class SRUEndpointConfig -
SRUServer/trunk/src/main/java/eu/clarin/sru/server/utils/SRUServerServlet.java
r2302 r2622 33 33 import javax.servlet.http.HttpServletResponse; 34 34 35 import org.slf4j.Logger; 36 import org.slf4j.LoggerFactory; 37 35 38 import eu.clarin.sru.server.SRUConfigException; 36 39 import eu.clarin.sru.server.SRUException; … … 43 46 * {@link SRUServer} in a Servlet container. Your search engine <b>must</b> use 44 47 * {@link SRUSearchEngineBase} as base class. 45 * 48 * 46 49 * <p> 47 50 * Add the following to the web.xml of your web applications web.xml to define a 48 * SRU server. Of course, the value of the Servlet parameter49 * " sruServerSerachEngineClass" must be adapted to match the name of your search50 * engine implementation. Furthermore, you can choose different url-pattern, to51 * match your needs.51 * SRU server. Of course, the value of the Servlet initialization parameter 52 * "eu.clarin.sru.server.utils.sruServerSerachEngineClass" must be adapted to 53 * match the name of your search engine implementation. Furthermore, you can 54 * choose different url-pattern, to match your needs. 52 55 * </p> 53 * 56 * 57 * <p> 58 * For example, if your implementation of {@link SRUSearchEngineBase} is 59 * "com.acme.MySearchEngine" and you want to map the Servlet to the URI "/sru" 60 * the following snippet in your "web.xml" should accomplish the task: 61 * </p> 62 * 54 63 * <pre> 55 64 * <servlet> … … 57 66 * <servlet-class>eu.clarin.sru.server.utils.SRUServerServlet</servlet-class> 58 67 * <init-param> 59 * <param-name> sruServerSerachEngineClass</param-name>68 * <param-name>eu.clarin.sru.server.utils.sruServerSerachEngineClass</param-name> 60 69 * <param-value>com.acme.MySearchEngine</param-value> 61 70 * </init-param> … … 73 82 */ 74 83 public static final String SRU_SERVER_CONFIG_LOCATION_PARAM = 84 "eu.clarin.sru.server.utils.sruServerConfigLocation"; 85 /** 86 * @deprecated use {@link #SRU_SERVER_CONFIG_LOCATION_PARAM} 87 */ 88 @Deprecated 89 private static final String LEGACY_SRU_SERVER_CONFIG_LOCATION_PARAM = 75 90 "sruServerConfigLocation"; 91 76 92 /** 77 93 * Servlet initialization parameter name for the class that implements the … … 79 95 */ 80 96 public static final String SRU_SERVER_SERACH_ENGINE_CLASS_PARAM = 97 "eu.clarin.sru.server.utils.sruServerSerachEngineClass"; 98 /** 99 * @deprecated use {@link #SRU_SERVER_SERACH_ENGINE_CLASS_PARAM} 100 */ 101 @Deprecated 102 private static final String LEGACY_SRU_SERVER_SERACH_ENGINE_CLASS_PARAM = 81 103 "sruServerSerachEngineClass"; 104 82 105 /** 83 106 * Default value for the location of the SRU server configuration. … … 86 109 "/WEB-INF/sru-server-config.xml"; 87 110 private static final long serialVersionUID = 1L; 111 private static final Logger logger = 112 LoggerFactory.getLogger(SRUServerServlet.class); 88 113 private SRUServer sruServer; 89 114 private SRUSearchEngineBase searchEngine; … … 92 117 /** 93 118 * Initialize the SRU server Servlet. 94 * 119 * 95 120 * @see javax.servlet.GenericServlet#init() 96 121 */ … … 103 128 cfg.getInitParameter(SRU_SERVER_CONFIG_LOCATION_PARAM); 104 129 if (sruServerConfigLocation == null) { 105 sruServerConfigLocation = SRU_SERVER_CONFIG_LOCATION_DEFAULT; 130 sruServerConfigLocation = cfg.getInitParameter(LEGACY_SRU_SERVER_CONFIG_LOCATION_PARAM); 131 if (sruServerConfigLocation != null) { 132 logger.warn("init parameter '" + 133 LEGACY_SRU_SERVER_CONFIG_LOCATION_PARAM + 134 "' is deprecated, please use init parameter '" + 135 SRU_SERVER_CONFIG_LOCATION_PARAM + "' instead!"); 136 } else { 137 sruServerConfigLocation = SRU_SERVER_CONFIG_LOCATION_DEFAULT; 138 } 106 139 } 107 140 … … 124 157 cfg.getInitParameter(SRU_SERVER_SERACH_ENGINE_CLASS_PARAM); 125 158 if (sruServerSearchEngineClass == null) { 126 throw new ServletException("init parameter '" + 127 SRU_SERVER_SERACH_ENGINE_CLASS_PARAM + 128 "' not defined in servlet configuration"); 159 sruServerSearchEngineClass = cfg.getInitParameter(LEGACY_SRU_SERVER_SERACH_ENGINE_CLASS_PARAM); 160 if (sruServerSearchEngineClass != null) { 161 logger.warn("init parameter '" + 162 LEGACY_SRU_SERVER_SERACH_ENGINE_CLASS_PARAM + 163 "' is deprecated, please use init parameter '" + 164 SRU_SERVER_SERACH_ENGINE_CLASS_PARAM + "' instead!"); 165 } else { 166 throw new ServletException("init parameter '" + 167 SRU_SERVER_SERACH_ENGINE_CLASS_PARAM + 168 "' not defined in servlet configuration"); 169 } 129 170 } 130 171 … … 154 195 } 155 196 } 197 198 /* convert legacy parameters */ 199 SRUServerConfig.convertLegacyParameter(params); 156 200 157 201 /* … … 245 289 /** 246 290 * Destroy the SRU server Servlet. 247 * 291 * 248 292 * @see javax.servlet.GenericServlet#destroy() 249 293 */ … … 259 303 /** 260 304 * Handle a HTTP get request. 261 * 305 * 262 306 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, 263 307 * javax.servlet.http.HttpServletResponse) … … 275 319 /** 276 320 * Handle a HTTP post request. 277 * 321 * 278 322 * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, 279 323 * javax.servlet.http.HttpServletResponse)
Note: See TracChangeset
for help on using the changeset viewer.