Ignore:
Timestamp:
01/12/16 21:03:47 (8 years ago)
Author:
Oliver Schonefeld
Message:
  • some steps towards SRU 2.0
File:
1 edited

Legend:

Unmodified
Added
Removed
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUAbstractRequest.java

    r6076 r6903  
    3434 */
    3535abstract class SRUAbstractRequest {
    36     static final String PARAM_OPERATION                = "operation";
    37     static final String PARAM_VERSION                  = "version";
    38     static final String PARAM_RECORD_PACKING           = "recordPacking";
    39     static final String PARAM_STYLESHEET               = "stylesheet";
    40     static final String PARAM_QUERY                    = "query";
    41     static final String PARAM_START_RECORD             = "startRecord";
    42     static final String PARAM_MAXIMUM_RECORDS          = "maximumRecords";
    43     static final String PARAM_RECORD_SCHEMA            = "recordSchema";
    44     static final String PARAM_RECORD_X_PATH            = "recordXPath";
    45     static final String PARAM_RESULT_SET_TTL           = "resultSetTTL";
    46     static final String PARAM_SORT_KEYS                = "sortKeys";
    47     static final String PARAM_SCAN_CLAUSE              = "scanClause";
    48     static final String PARAM_RESPONSE_POSITION        = "responsePosition";
    49     static final String PARAM_MAXIMUM_TERMS            = "maximumTerms";
    50     static final String RECORD_PACKING_XML             = "xml";
    51     static final String RECORD_PACKING_STRING          = "string";
    52     private static final String OP_EXPLAIN             = "explain";
    53     private static final String OP_SCAN                = "scan";
    54     private static final String OP_SEARCH_RETRIEVE     = "searchRetrieve";
    55     private static final String VERSION_1_1            = "1.1";
    56     private static final String VERSION_1_2            = "1.2";
    57     private static final String PARAM_EXTENSION_PREFIX = "x-";
     36    /* general / explain related parameter names */
     37    protected static final String PARAM_OPERATION            = "operation";
     38    protected static final String PARAM_VERSION              = "version";
     39    protected static final String PARAM_STYLESHEET           = "stylesheet";
     40    protected static final String PARAM_RENDER_BY            = "renderedBy";
     41    protected static final String PARAM_HTTP_ACCEPT          = "httpAccept";
     42    protected static final String PARAM_RESPONSE_TYPE        = "responseType";
     43    /* searchRetrieve related parameter names */
     44    protected static final String PARAM_QUERY                = "query";
     45    protected static final String PARAM_QUERY_TYPE           = "queryType";
     46    protected static final String PARAM_START_RECORD         = "startRecord";
     47    protected static final String PARAM_MAXIMUM_RECORDS      = "maximumRecords";
     48    protected static final String PARAM_RECORD_XML_ESCAPING  = "recordXMLEscaping";
     49    protected static final String PARAM_RECORD_PACKING       = "recordPacking";
     50    protected static final String PARAM_RECORD_SCHEMA        = "recordSchema";
     51    protected static final String PARAM_RECORD_X_PATH        = "recordXPath";
     52    protected static final String PARAM_RESULT_SET_TTL       = "resultSetTTL";
     53    protected static final String PARAM_SORT_KEYS            = "sortKeys";
     54    /* scan related parameter names */
     55    protected static final String PARAM_SCAN_CLAUSE          = "scanClause";
     56    protected static final String PARAM_RESPONSE_POSITION    = "responsePosition";
     57    protected static final String PARAM_MAXIMUM_TERMS        = "maximumTerms";
     58    /* operations */
     59    protected static final String OP_EXPLAIN                 = "explain";
     60    protected static final String OP_SCAN                    = "scan";
     61    protected static final String OP_SEARCH_RETRIEVE         = "searchRetrieve";
     62    protected static final String VERSION_1_1                = "1.1";
     63    protected static final String VERSION_1_2                = "1.2";
     64    /* various parameter values */
     65    protected static final String RECORD_XML_ESCAPING_XML    = "xml";
     66    protected static final String RECORD_XML_ESCPAING_STRING = "string";
     67    protected static final String RECORD_PACKING_PACKED      = "packed";
     68    protected static final String RECORD_PACKING_UNPACKED    = "unpacked";
     69    protected static final String RENDER_BY_CLIENT           = "client";
     70    protected static final String RENDER_BY_SERVER           = "server";
     71    protected static final String PARAM_EXTENSION_PREFIX = "x-";
    5872    /** for end-point conformance testing only. never use in production. */
    5973    public static final String X_MALFORMED_OPERATION   =
     
    220234     * Get the version for this request.
    221235     *
    222      * @return version for this request or <code>null</code> of client default
     236     * @return version for this request or <code>null</code> if client default
    223237     *         is used
    224238     */
     
    347361                    new URIHelper(new URIBuilder(baseURI));
    348362
    349             /*
    350              * append operation parameter
    351              *
    352              * NB: Setting "x-malformed-operation" as an extra request parameter
    353              * makes the client send invalid requests. This is intended to
    354              * use for testing SRU servers for protocol conformance (i.e.
    355              * provoke an error) and SHOULD NEVER be used in production!
    356              */
    357             final String malformedOperation =
    358                     getExtraRequestData(X_MALFORMED_OPERATION);
    359             if (malformedOperation == null) {
    360                 switch (getOperation()) {
    361                 case EXPLAIN:
    362                     uriBuilder.append(PARAM_OPERATION, OP_EXPLAIN);
    363                     break;
    364                 case SCAN:
    365                     uriBuilder.append(PARAM_OPERATION, OP_SCAN);
    366                     break;
    367                 case SEARCH_RETRIEVE:
    368                     uriBuilder.append(PARAM_OPERATION, OP_SEARCH_RETRIEVE);
    369                     break;
    370                 default:
    371                     throw new SRUClientException("unsupported operation: " +
    372                             getOperation());
    373                 } // switch
    374             } else {
    375                 if (!malformedOperation.equals(MALFORMED_OMIT)) {
    376                     uriBuilder.append(PARAM_OPERATION, malformedOperation);
     363            /* store the version, we use for this request */
     364            versionRequested = (version != null) ? version : defaultVersion;
     365
     366            switch (versionRequested) {
     367            case VERSION_1_1:
     368                /* $FALL-THROUGH$ */
     369            case VERSION_1_2:
     370                /*
     371                 * append operation parameter
     372                 *
     373                 * NB: Setting "x-malformed-operation" as an extra request parameter
     374                 * makes the client send invalid requests. This is intended to
     375                 * use for testing SRU servers for protocol conformance (i.e.
     376                 * provoke an error) and SHOULD NEVER be used in production!
     377                 */
     378                final String malformedOperation =
     379                        getExtraRequestData(X_MALFORMED_OPERATION);
     380                if (malformedOperation == null) {
     381                    switch (getOperation()) {
     382                    case EXPLAIN:
     383                        uriBuilder.append(PARAM_OPERATION, OP_EXPLAIN);
     384                        break;
     385                    case SCAN:
     386                        uriBuilder.append(PARAM_OPERATION, OP_SCAN);
     387                        break;
     388                    case SEARCH_RETRIEVE:
     389                        uriBuilder.append(PARAM_OPERATION, OP_SEARCH_RETRIEVE);
     390                        break;
     391                    default:
     392                    } // switch
     393                } else {
     394                    if (!malformedOperation.equals(MALFORMED_OMIT)) {
     395                        uriBuilder.append(PARAM_OPERATION, malformedOperation);
     396                    }
    377397                }
    378             }
    379 
    380             /*
    381              * append version parameter
    382              *
    383              * NB: Setting "x-malformed-version" as an extra request parameter
    384              * makes the client send invalid requests. This is intended to
    385              * use for testing SRU servers for protocol conformance (i.e.
    386              * provoke an error) and SHOULD NEVER be used in production!
    387              */
    388             final String malformedVersion =
    389                     getExtraRequestData(X_MALFORMED_VERSION);
    390             if (malformedVersion == null) {
    391                 versionRequested = (version != null) ? version : defaultVersion;
    392                 switch (versionRequested) {
    393                 case VERSION_1_1:
    394                     uriBuilder.append(PARAM_VERSION, VERSION_1_1);
    395                     break;
    396                 case VERSION_1_2:
    397                     uriBuilder.append(PARAM_VERSION, VERSION_1_2);
    398                     break;
    399                 default:
    400                     throw new SRUClientException("unsupported version: " +
    401                             versionRequested);
    402                 } // switch
    403             } else {
    404                 if (!malformedVersion.equalsIgnoreCase(MALFORMED_OMIT)) {
    405                     uriBuilder.append(PARAM_VERSION, malformedVersion);
     398
     399                /*
     400                 * append version parameter
     401                 *
     402                 * NB: Setting "x-malformed-version" as an extra request parameter
     403                 * makes the client send invalid requests. This is intended to
     404                 * use for testing SRU servers for protocol conformance (i.e.
     405                 * provoke an error) and SHOULD NEVER be used in production!
     406                 */
     407                final String malformedVersion =
     408                        getExtraRequestData(X_MALFORMED_VERSION);
     409                if (malformedVersion == null) {
     410                    versionRequested = (version != null) ? version : defaultVersion;
     411                    switch (versionRequested) {
     412                    case VERSION_1_1:
     413                        uriBuilder.append(PARAM_VERSION, VERSION_1_1);
     414                        break;
     415                    case VERSION_1_2:
     416                        uriBuilder.append(PARAM_VERSION, VERSION_1_2);
     417                        break;
     418                    default:
     419                        throw new SRUClientException("unsupported version: " +
     420                                versionRequested);
     421                    } // switch
     422                } else {
     423                    if (!malformedVersion.equalsIgnoreCase(MALFORMED_OMIT)) {
     424                        uriBuilder.append(PARAM_VERSION, malformedVersion);
     425                    }
    406426                }
     427                break;
     428            case VERSION_2_0:
     429                if (getExtraRequestData(X_MALFORMED_OPERATION) != null) {
     430                    throw new SRUClientException("parameter '" +
     431                            X_MALFORMED_OPERATION +
     432                            "' is not supported when using version 2.0");
     433                }
     434                if (getExtraRequestData(X_MALFORMED_VERSION) != null) {
     435                    throw new SRUClientException("parameter '" +
     436                            X_MALFORMED_VERSION +
     437                            "' is not supported when using version 2.0");
     438                }
     439                break;
     440            default:
     441                throw new SRUClientException("unsupported version: " +
     442                        versionRequested);
    407443            }
    408444
    409445            // request specific parameters
    410             addParametersToURI(uriBuilder);
     446            addParametersToURI(uriBuilder, versionRequested);
    411447
    412448            // extraRequestData
     
    418454                    /*
    419455                     * make sure, we skip the client-internal parameters
    420                      * to generate invalid requests ...
     456                     * used to generate invalid requests ...
    421457                     */
    422458                    if (!key.startsWith(MALFORMED_KEY_PREFIX)) {
     
    442478
    443479
    444     abstract void addParametersToURI(URIHelper uriBuilder)
     480    abstract void addParametersToURI(URIHelper uriBuilder, SRUVersion version)
    445481            throws SRUClientException;
    446482
Note: See TracChangeset for help on using the changeset viewer.