Changeset 2622


Ignore:
Timestamp:
02/25/13 19:57:34 (11 years ago)
Author:
oschonef
Message:
  • prefix all (initialization) parameters with "eu.clarin.sru.server(.utils)"
  • add support for legacy (= unprefixed) parameters

HEADS UP: All users of this library should update the parameters to the non-legacy versions!

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  
    4343import javax.xml.xpath.XPathFactory;
    4444
     45import org.slf4j.Logger;
     46import org.slf4j.LoggerFactory;
    4547import org.w3c.dom.Attr;
    4648import org.w3c.dom.Document;
     
    8385 */
    8486public 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     */
    93175    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 =
    94241            "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 =
    96247            "sru.allowOverrideIndentResponse";
    97     public static final int DEFAULT_NUMBER_OF_RECORDS = 100;
    98     public static 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;
    99250    private static final String CONFIG_FILE_NAMESPACE_URI =
    100251            "http://www.clarin.eu/sru-server/1.0/";
     
    424575    } // IndexInfo
    425576
     577    private static final Logger logger =
     578            LoggerFactory.getLogger(SRUServerConfig.class);
    426579    private final String transport;
    427580    private final String host;
     
    699852            List<SchemaInfo> schemaInfo = buildSchemaInfo(xpath, doc);
    700853
     854            /*
     855             * convert legacy parameters
     856             */
     857            convertLegacyParameter(params);
     858
     859            /*
     860             * fetch parameters more parameters
     861             */
    701862            String transport = params.get(SRU_TRANSPORT);
    702863            if ((transport == null) || transport.isEmpty()) {
     
    10441205    }
    10451206
     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
    10461255} // class SRUEndpointConfig
  • SRUServer/trunk/src/main/java/eu/clarin/sru/server/utils/SRUServerServlet.java

    r2302 r2622  
    3333import javax.servlet.http.HttpServletResponse;
    3434
     35import org.slf4j.Logger;
     36import org.slf4j.LoggerFactory;
     37
    3538import eu.clarin.sru.server.SRUConfigException;
    3639import eu.clarin.sru.server.SRUException;
     
    4346 * {@link SRUServer} in a Servlet container. Your search engine <b>must</b> use
    4447 * {@link SRUSearchEngineBase} as base class.
    45  * 
     48 *
    4649 * <p>
    4750 * 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 parameter
    49  * "sruServerSerachEngineClass" must be adapted to match the name of your search
    50  * engine implementation. Furthermore, you can choose different url-pattern, to
    51  * 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.
    5255 * </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 *
    5463 * <pre>
    5564 * &lt;servlet&gt;
     
    5766 *   &lt;servlet-class&gt;eu.clarin.sru.server.utils.SRUServerServlet&lt;/servlet-class&gt;
    5867 *   &lt;init-param&gt;
    59  *     &lt;param-name&gt;sruServerSerachEngineClass&lt;/param-name&gt;
     68 *     &lt;param-name&gt;eu.clarin.sru.server.utils.sruServerSerachEngineClass&lt;/param-name&gt;
    6069 *     &lt;param-value&gt;com.acme.MySearchEngine&lt;/param-value&gt;
    6170 *   &lt;/init-param&gt;
     
    7382     */
    7483    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 =
    7590            "sruServerConfigLocation";
     91
    7692    /**
    7793     * Servlet initialization parameter name for the class that implements the
     
    7995     */
    8096    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 =
    81103            "sruServerSerachEngineClass";
     104
    82105    /**
    83106     * Default value for the location of the SRU server configuration.
     
    86109            "/WEB-INF/sru-server-config.xml";
    87110    private static final long serialVersionUID = 1L;
     111    private static final Logger logger =
     112            LoggerFactory.getLogger(SRUServerServlet.class);
    88113    private SRUServer sruServer;
    89114    private SRUSearchEngineBase searchEngine;
     
    92117    /**
    93118     * Initialize the SRU server Servlet.
    94      * 
     119     *
    95120     * @see javax.servlet.GenericServlet#init()
    96121     */
     
    103128                cfg.getInitParameter(SRU_SERVER_CONFIG_LOCATION_PARAM);
    104129        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            }
    106139        }
    107140
     
    124157                cfg.getInitParameter(SRU_SERVER_SERACH_ENGINE_CLASS_PARAM);
    125158        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            }
    129170        }
    130171
     
    154195            }
    155196        }
     197
     198        /* convert legacy parameters */
     199        SRUServerConfig.convertLegacyParameter(params);
    156200
    157201        /*
     
    245289    /**
    246290     * Destroy the SRU server Servlet.
    247      * 
     291     *
    248292     * @see javax.servlet.GenericServlet#destroy()
    249293     */
     
    259303    /**
    260304     * Handle a HTTP get request.
    261      * 
     305     *
    262306     * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest,
    263307     *      javax.servlet.http.HttpServletResponse)
     
    275319    /**
    276320     * Handle a HTTP post request.
    277      * 
     321     *
    278322     * @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest,
    279323     *      javax.servlet.http.HttpServletResponse)
Note: See TracChangeset for help on using the changeset viewer.