Changeset 6076 for SRUClient


Ignore:
Timestamp:
03/05/15 09:43:40 (9 years ago)
Author:
Oliver Schonefeld
Message:
  • make available URI and version that were used for performing the request
Location:
SRUClient/trunk/src/main/java/eu/clarin/sru/client
Files:
2 edited

Legend:

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

    r6075 r6076  
    120120    /** A map of extra request data parameters. */
    121121    protected Map<String, String> extraRequestData;
    122     private SRUVersion versionPerformed;
     122    /*
     123     * The version that was used to perform the request.
     124     * It is set as a side-effect of makeURI().
     125     */
     126    private SRUVersion versionRequested;
     127    /*
     128     * The URI that was used to perform the request.
     129     * It is set a a side-effect of makeURI().
     130     */
     131    private URI uriRequested;
    123132
    124133
     
    289298
    290299
    291     final SRUVersion getVersionPerformed() {
    292         return versionPerformed;
    293     }
    294 
    295 
    296     final URI makeURI(SRUVersion defaultVersion)
     300    /**
     301     * Get the URI that was used to perform the request. This method may only be
     302     * called <em>after</em> the request was carried out, otherwise it will
     303     * throw an {@link IllegalStateException}.
     304     *
     305     * @return the URI that was used to carry out this request
     306     * @throws IllegalStateException
     307     *             if the request was not yet carried out
     308     */
     309    public final URI getRequestedURI() {
     310        if (uriRequested == null) {
     311            throw new IllegalStateException(
     312                    "The request was not yet carried out");
     313        }
     314        return uriRequested;
     315    }
     316
     317
     318    /**
     319     * Get the version that was used to carry out this request. This method may
     320     * only be called <em>after</em> the request was carried out, otherwise it
     321     * will throw an {@link IllegalStateException}.
     322     *
     323     * @return the version that was used to carry out this request
     324     * @throws IllegalStateException
     325     *             if the request was not yet carried out
     326     */
     327    public final SRUVersion getRequestedVersion() {
     328        if (versionRequested == null) {
     329            throw new IllegalStateException(
     330                    "The request was not yet carried out");
     331        }
     332        return versionRequested;
     333    }
     334
     335
     336    /*
     337     * This is not public API.
     338     */
     339    protected final URI makeURI(SRUVersion defaultVersion)
    297340            throws SRUClientException {
    298341        if (defaultVersion == null) {
     
    346389                    getExtraRequestData(X_MALFORMED_VERSION);
    347390            if (malformedVersion == null) {
    348                 versionPerformed = (version != null) ? version : defaultVersion;
    349                 switch (versionPerformed) {
     391                versionRequested = (version != null) ? version : defaultVersion;
     392                switch (versionRequested) {
    350393                case VERSION_1_1:
    351394                    uriBuilder.append(PARAM_VERSION, VERSION_1_1);
     
    356399                default:
    357400                    throw new SRUClientException("unsupported version: " +
    358                             versionPerformed);
     401                            versionRequested);
    359402                } // switch
    360403            } else {
     
    383426            }
    384427
    385             return uriBuilder.makeURI();
     428            final URI uri = uriBuilder.makeURI();
     429            uriRequested = uri;
     430            return uri;
    386431        } catch (URISyntaxException e) {
    387432            throw new SRUClientException("error while building request URI", e);
  • SRUClient/trunk/src/main/java/eu/clarin/sru/client/SRUSimpleClient.java

    r5785 r6076  
    477477            // explainResponse/version
    478478            SRUVersion version = parseVersion(reader);
    479             logger.debug("version = {}, requested = {}",
    480                     version, request.getVersionPerformed());
     479            logger.debug("version = {}, requested = {}", version,
     480                    request.getRequestedVersion());
    481481
    482482            // explainResponse/record
     
    699699                SRUVersion version = parseVersion(reader);
    700700                logger.debug("version = {}, requested = {}", version,
    701                         request.getVersionPerformed());
     701                        request.getRequestedVersion());
    702702
    703703                // scanResponse/terms
     
    879879                SRUVersion version = parseVersion(reader);
    880880                logger.debug("version = {}, requested = {}", version,
    881                         request.getVersionPerformed());
     881                        request.getRequestedVersion());
    882882
    883883                // searchRetrieveResponse/numberOfRecords
Note: See TracChangeset for help on using the changeset viewer.