Changeset 2121


Ignore:
Timestamp:
08/20/12 20:15:37 (12 years ago)
Author:
oschonef
Message:
  • add more quirks for SRU/CQL conformance testing
Location:
SRUClient/trunk/src/main/java/eu/clarin/sru/client
Files:
3 edited

Legend:

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

    r2088 r2121  
    4646    private static final String PARAM_EXTENSION_PREFIX = "x-";
    4747    /** for end-point conformance testing only. never use in production. */
     48    public static final String X_MALFORMED_OPERATION   =
     49            "x-malformed-operation";
     50    /** for end-point conformance testing only. never use in production. */
    4851    public static final String X_MALFORMED_VERSION     =
    4952            "x-malformed-version";
    5053    /** for end-point conformance testing only. never use in production. */
    51     public static final String X_MALFORMED_OPERATION   =
    52             "x-maformed-operation";
    53     /** for end-point conformance testing only. never use in production. */
    5454    public static final String MALFORMED_OMIT          = "omit";
     55    private static final String MALFORMED_KEY_PREFIX   = "x-malformed";
    5556
    5657
     
    5960    } // enum SRUOperation
    6061
    61    
     62
    6263    class URIBuilder {
    6364        private final StringBuilder sb;
     
    6869        }
    6970
    70        
     71
    7172        public URIBuilder append(String name, String value) {
    7273            if (name == null) {
     
    9394        }
    9495
    95        
     96
    9697        public URIBuilder append(String name, int value) {
    9798            return append(name, Integer.toString(value));
     
    122123    /**
    123124     * Get the endpoint URI.
    124      * 
     125     *
    125126     * @return the endpoiunt URI
    126127     */
     
    132133    /**
    133134     * Set the version for this request.
    134      * 
     135     *
    135136     * @param version a version of <code>null</code> for client default
    136137     */
     
    142143    /**
    143144     * Get the version for this request.
    144      * 
     145     *
    145146     * @return version for this request or <code>null</code> of client default
    146147     *         is used
     
    153154    /**
    154155     * Set an extra request parameter for this request.
    155      * 
     156     *
    156157     * @param name
    157158     *            the name for the extra request data parameter
     
    191192    /**
    192193     * Set the value of extra request parameter for this request.
    193      * 
     194     *
    194195     * @param name
    195196     *            the name for the extra request data parameter
     
    225226    }
    226227
    227    
     228
    228229    final URI makeURI(SRUVersion defaultVersion)
    229230            throws SRUClientException {
     
    236237         * append operation parameter
    237238         *
    238          * NB: Setting "x-operation-version" as an extra request parameter makes
    239          * the client to send invalid requests. This is intended to use for
    240          * testing endpoints for protocol conformance (i.e. provoke an error)
    241          * and SHOULD NEVER be used in production!
     239         * NB: Setting "x-malformed-operation" as an extra request parameter
     240         * makes the client to send invalid requests. This is intended to use
     241         * for testing endpoints for protocol conformance (i.e. provoke an
     242         * error) and SHOULD NEVER be used in production!
    242243         */
    243244        final String malformedOperation =
     
    301302                extraRequestData.entrySet()) {
    302303                String key = entry.getKey();
    303                 if (key.equals(X_MALFORMED_OPERATION) ||
    304                         key.equals(X_MALFORMED_VERSION)) {
     304                if (key.startsWith(MALFORMED_KEY_PREFIX)) {
    305305                    continue;
    306306                }
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUScanRequest.java

    r2088 r2121  
    2929 */
    3030public final class SRUScanRequest extends SRUAbstractRequest {
     31    /** for end-point conformance testing only. never use in production. */
     32    public static final String X_MALFORMED_SCAN_CLAUSE =
     33            "x-malformed-scanClause";
     34    /** for end-point conformance testing only. never use in production. */
     35    public static final String X_MALFORMED_RESPONSE_POSITION =
     36            "x-malformed-responsePosition";
     37    /** for end-point conformance testing only. never use in production. */
     38    public static final String X_MALFORMED_MAXIMUM_TERMS =
     39            "x-malformed-maximumTerms";
    3140    private String scanClause;
    3241    private int responsePosition = -1;
     
    138147    void addParametersToURI(URIBuilder uriBuilder) throws SRUClientException {
    139148        // scanClause
    140         if ((scanClause == null) || scanClause.isEmpty()) {
    141             throw new SRUClientException(
    142                     "mandatory argument 'scanClause' not set or empty");
     149        final String malformedScan =
     150                getExtraRequestData(X_MALFORMED_SCAN_CLAUSE);
     151        if (malformedScan == null) {
     152            if ((scanClause == null) || scanClause.isEmpty()) {
     153                throw new SRUClientException(
     154                        "mandatory argument 'scanClause' not set or empty");
     155            }
     156            uriBuilder.append(PARAM_SCAN_CLAUSE, scanClause);
     157        } else {
     158            if (!malformedScan.equalsIgnoreCase(MALFORMED_OMIT)) {
     159                uriBuilder.append(PARAM_VERSION, malformedScan);
     160            }
    143161        }
    144         uriBuilder.append(PARAM_SCAN_CLAUSE, scanClause);
    145162
    146163        // responsePosition
    147         if (responsePosition > -1) {
    148             uriBuilder.append(PARAM_RESPONSE_POSITION, responsePosition);
     164        final String malformedResponsePosition =
     165                getExtraRequestData(X_MALFORMED_RESPONSE_POSITION);
     166        if (malformedResponsePosition == null) {
     167            if (responsePosition > -1) {
     168                uriBuilder.append(PARAM_RESPONSE_POSITION, responsePosition);
     169            }
     170        } else {
     171            if (!malformedResponsePosition.equalsIgnoreCase(MALFORMED_OMIT)) {
     172                uriBuilder.append(PARAM_RESPONSE_POSITION,
     173                        malformedResponsePosition);
     174            }
    149175        }
    150176
    151177        // maximumTerms
    152         if (maximumTerms > -1) {
    153             uriBuilder.append(PARAM_MAXIMUM_TERMS, maximumTerms);
     178        final String malformedMaximumTerms =
     179                getExtraRequestData(X_MALFORMED_MAXIMUM_TERMS);
     180        if (malformedMaximumTerms == null) {
     181            if (maximumTerms > -1) {
     182                uriBuilder.append(PARAM_MAXIMUM_TERMS, maximumTerms);
     183            }
     184        } else {
     185            if (!malformedMaximumTerms.equalsIgnoreCase(MALFORMED_OMIT)) {
     186                uriBuilder.append(PARAM_MAXIMUM_TERMS, malformedMaximumTerms);
     187            }
    154188        }
    155189    }
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSearchRetrieveRequest.java

    r2088 r2121  
    2525 * <li><em>query</em></li>
    2626 * </ul>
    27  * 
     27 *
    2828 * @see SRUSearchRetrieveHandler
    2929 * @see <a href="http://www.loc.gov/standards/sru/specs/search-retrieve.html">
     
    3131 */
    3232public final class SRUSearchRetrieveRequest extends SRUAbstractRequest {
     33    /** for end-point conformance testing only. never use in production. */
     34    public static final String X_MALFORMED_QUERY =
     35            "x-malformed-query";
     36    /** for end-point conformance testing only. never use in production. */
     37    public static final String X_MALFORMED_START_RECORD =
     38            "x-malformed-startRecord";
     39    /** for end-point conformance testing only. never use in production. */
     40    public static final String X_MALFORMED_MAXIMUM_RECORDS =
     41            "x-malformed-maximumRecords";
     42    /** for end-point conformance testing only. never use in production. */
     43    public static final String X_MALFORMED_RECORD_PACKING =
     44            "x-malformed-recordPacking";
    3345    private String query;
    3446    private int startRecord = -1;
     
    4153    /**
    4254     * Constructor.
    43      * 
     55     *
    4456     * @param baseURI
    4557     *            the baseURI of the endpoint
     
    5264    /**
    5365     * Get the value of the <em>query</em> argument for this request.
    54      * 
     66     *
    5567     * @return the value for the <em>query</em> argument or <code>null</code> of
    5668     *         none was set
     
    6375    /**
    6476     * Set the value of the <em>query</em> argument for this request.
    65      * 
     77     *
    6678     * @param query
    6779     *            the value for the <em>query</em> argument
     
    8496    /**
    8597     * Get the value of the <em>startRecord</em> argument for this request.
    86      * 
     98     *
    8799     * @return the value for the <em>startRecord</em> argument or
    88100     *         <code>-1</code> of none was set
     
    95107    /**
    96108     * Set the value of the <em>startRecord</em> argument for this request.
    97      * 
     109     *
    98110     * @param startRecord
    99111     *            the value for the <em>startRecord</em> argument
     
    111123    /**
    112124     * Get the value of the <em>maximumRecords</em> argument for this request.
    113      * 
     125     *
    114126     * @return the value for the <em>maximumRecords</em> argument or
    115127     *         <code>-1</code> of none was set
     
    122134    /**
    123135     * Set the value of the <em>maximumRecords</em> argument for this request.
    124      * 
     136     *
    125137     * @param maximumRecords
    126138     *            the value for the <em>maximumRecords</em> argument
     
    138150    /**
    139151     * Get the value of the <em>recordSchema</em> argument for this request.
    140      * 
     152     *
    141153     * @return the value for the <em>recordSchema</em> argument or
    142154     *         <code>null</code> of none was set
     
    149161    /**
    150162     * Set the value of the <em>recordSchema</em> argument for this request.
    151      * 
     163     *
    152164     * @param recordSchema
    153165     *            the value for the <em>recordSchema</em> argument
     
    164176    /**
    165177     * Get the value of the <em>recordSchema</em> argument for this request.
    166      * 
     178     *
    167179     * @return the value for the <em>recordSchema</em> argument or
    168180     *         <code>null</code> of none was set
     
    175187    /**
    176188     * Set the value of the <em>recordPacking</em> argument for this request.
    177      * 
     189     *
    178190     * @param recordPacking
    179191     *            the value for the <em>recordPacking</em> argument
     
    191203    /**
    192204     * Get the value of the <em>resultSetTTL</em> argument for this request.
    193      * 
     205     *
    194206     * @return the value for the <em>resultSetTTL</em> argument or
    195207     *         <code>-1</code> of none was set
     
    202214    /**
    203215     * Set the value of the <em>resultSetTTL</em> argument for this request.
    204      * 
     216     *
    205217     * @param resultSetTTL
    206218     *            the value for the <em>resultSetTTL</em> argument
     
    221233    @Override
    222234    void addParametersToURI(URIBuilder uriBuilder) throws SRUClientException {
    223         // query
    224         if ((query == null) || query.isEmpty()) {
    225             throw new SRUClientException(
    226                     "mandatory argument 'query' not set or empty");
    227         }
    228         uriBuilder.append(PARAM_QUERY, query);
    229 
    230         // startRecord
    231         if (startRecord > 0) {
    232             uriBuilder.append(PARAM_START_RECORD, startRecord);
    233         }
    234 
    235         // maximumRecords
    236         if (maximumRecords > -1) {
    237             uriBuilder.append(PARAM_MAXIMUM_RECORDS, maximumRecords);
    238         }
    239 
    240         // recordPacking
    241         if (recordPacking != null) {
    242             switch (recordPacking) {
    243             case XML:
    244                 uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML);
    245                 break;
    246             case STRING:
    247                 uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_STRING);
    248                 break;
    249             default:
    250                 throw new SRUClientException("unsupported record packing: " +
    251                         recordPacking);
    252             } // switch
    253         }
    254 
    255         // recordSchema
     235        /*
     236         * append query argument (mandatory)
     237         *
     238         * NB: Setting "x-malformed-query" as an extra request parameter makes
     239         * the client to send invalid requests. This is intended to use for
     240         * testing endpoints for protocol conformance (i.e. provoke an error)
     241         * and SHOULD NEVER be used in production!
     242         */
     243        final String malformedQuery = getExtraRequestData(X_MALFORMED_QUERY);
     244        if (malformedQuery == null) {
     245            if ((query == null) || query.isEmpty()) {
     246                throw new SRUClientException(
     247                        "mandatory argument 'query' not set or empty");
     248            }
     249            uriBuilder.append(PARAM_QUERY, query);
     250        } else {
     251            if (!malformedQuery.equalsIgnoreCase(MALFORMED_OMIT)) {
     252                uriBuilder.append(PARAM_QUERY, malformedQuery);
     253            }
     254        }
     255
     256        /*
     257         * append startRecord argument (optional)
     258         *
     259         * NB: Setting "x-malformed-startRecord" as an extra request parameter
     260         * makes the client to send invalid requests. This is intended to use
     261         * for testing endpoints for protocol conformance (i.e. provoke an
     262         * error) and SHOULD NEVER be used in production!
     263         */
     264        final String malformedStartRecord =
     265                getExtraRequestData(X_MALFORMED_START_RECORD);
     266        if (malformedStartRecord == null) {
     267            if (startRecord > 0) {
     268                uriBuilder.append(PARAM_START_RECORD, startRecord);
     269            }
     270        } else {
     271            if (!malformedStartRecord.equalsIgnoreCase(MALFORMED_OMIT)) {
     272                uriBuilder.append(PARAM_START_RECORD, malformedStartRecord);
     273            }
     274        }
     275
     276        /*
     277         * append maximumRecords argument (optional)
     278         *
     279         * NB: Setting "x-malformed-maximumRecords" as an extra request
     280         * parameter makes the client to send invalid requests. This is
     281         * intended to use for testing endpoints for protocol conformance
     282         * (i.e. provoke an error) and SHOULD NEVER be used in production!
     283         */
     284        final String malformedMaxiumRecords =
     285                getExtraRequestData(X_MALFORMED_MAXIMUM_RECORDS);
     286        if (malformedMaxiumRecords == null) {
     287            if (maximumRecords > -1) {
     288                uriBuilder.append(PARAM_MAXIMUM_RECORDS, maximumRecords);
     289            }
     290        } else {
     291            if (!malformedMaxiumRecords.equalsIgnoreCase(MALFORMED_OMIT)) {
     292                uriBuilder.append(PARAM_MAXIMUM_RECORDS,
     293                        malformedMaxiumRecords);
     294            }
     295        }
     296
     297        /*
     298         * append recordPacking argument (optional)
     299         *
     300         * NB: Setting "x-malformed-recordPacking" as an extra request
     301         * parameter makes the client to send invalid requests. This is
     302         * intended to use for testing endpoints for protocol conformance
     303         * (i.e. provoke an error) and SHOULD NEVER be used in production!
     304         */
     305        final String malformedRecordPacking =
     306                getExtraRequestData(X_MALFORMED_RECORD_PACKING);
     307        if (malformedRecordPacking == null) {
     308            if (recordPacking != null) {
     309                switch (recordPacking) {
     310                case XML:
     311                    uriBuilder.append(PARAM_RECORD_PACKING, RECORD_PACKING_XML);
     312                    break;
     313                case STRING:
     314                    uriBuilder.append(PARAM_RECORD_PACKING,
     315                            RECORD_PACKING_STRING);
     316                    break;
     317                default:
     318                    throw new SRUClientException(
     319                            "unsupported record packing: " + recordPacking);
     320                } // switch
     321            }
     322        } else {
     323            if (!malformedRecordPacking.equalsIgnoreCase(MALFORMED_OMIT)) {
     324                uriBuilder.append(PARAM_RECORD_PACKING, malformedRecordPacking);
     325            }
     326        }
     327
     328        /*
     329         * append recordSchema argument (optional)
     330         */
    256331        if (recordSchema != null) {
    257332            uriBuilder.append(PARAM_RECORD_SCHEMA, recordSchema);
    258333        }
    259334
    260         // resultSetTTL
     335        /*
     336         * append resultSetTTL argument (optional)
     337         */
    261338        if (resultSetTTL > -1) {
    262339            uriBuilder.append(PARAM_RESULT_SET_TTL, resultSetTTL);
Note: See TracChangeset for help on using the changeset viewer.