Ignore:
Timestamp:
06/25/14 14:51:13 (10 years ago)
Author:
Oliver Schonefeld
Message:
  • update HttpClient?
  • use pooled connection manager
  • add concurrent request support to schema loader
  • rework persistent identifier checking
  • rework handle resolver
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CMDIValidator/trunk/cmdi-validator-core/src/main/java/eu/clarin/cmdi/validator/extensions/CheckHandlesExtension.java

    r5384 r5387  
    1717package eu.clarin.cmdi.validator.extensions;
    1818
     19import java.io.IOException;
    1920import java.net.URI;
    2021import java.net.URISyntaxException;
     
    4647    private static final Logger logger =
    4748            LoggerFactory.getLogger(CheckHandlesExtension.class);
    48     private final int threads;
    4949    private final boolean resolveHandles;
    5050    private HandleResolver resolver = null;
     
    5252
    5353
    54     public CheckHandlesExtension(int threads, boolean resolveHandles) {
    55         if (threads < 1) {
    56             throw new IllegalArgumentException("threads < 1");
    57         }
    58         this.threads        = threads;
     54    public CheckHandlesExtension(boolean resolveHandles) {
    5955        this.resolveHandles = resolveHandles;
    6056    }
    6157
    6258
    63     public CheckHandlesExtension(boolean resolveHandles) {
    64         this(Runtime.getRuntime().availableProcessors(), resolveHandles);
     59    public boolean isResolvingHandles() {
     60        return resolveHandles;
     61    }
     62
     63
     64    public HandleResolver.Statistics getStatistics() {
     65        return (resolver != null) ? resolver.getStatistics() : null;
    6566    }
    6667
     
    6970    protected void doInitialize() throws CMDIValidatorInitException {
    7071        if (resolveHandles) {
    71             this.resolver = new HandleResolver(threads);
     72            this.resolver = new HandleResolver();
    7273        }
    7374
     
    8990            selector.setContextItem(document);
    9091            for (XdmItem item : selector) {
    91                 String handle = item.getStringValue();
    92                 if (handle != null) {
    93                     handle = handle.trim();
     92                String handle = null;
     93                final String h = item.getStringValue();
     94                if (h != null) {
     95                    handle = h.trim();
    9496                    if (handle.isEmpty()) {
    9597                        handle = null;
     98                    } else {
     99                        if (!handle.equals(h)) {
     100                            result.reportWarning(-1, -1, "handle '" + h +
     101                                    "' contains leading or tailing spaces " +
     102                                    "within <ResourceRef> element");
     103                        }
    96104                    }
    97105                }
     
    124132                    checkHandleResolves(actionableURI, result);
    125133                } catch (URISyntaxException e) {
     134                    /* should not happen */
    126135                    throw new CMDIValidatorException(
    127136                            "created an invalid URI", e);
     
    137146            } else if (HDL_PROXY_HTTP.equalsIgnoreCase(uri.getScheme()) ||
    138147                    HDL_PROXY_HTTPS.equalsIgnoreCase(uri.getScheme())) {
    139                 if (HDL_PROXY_HOST.equalsIgnoreCase(uri.getHost())) {
     148                if (uri.getHost() != null) {
     149                    if (!HDL_PROXY_HOST.equalsIgnoreCase(uri.getHost())) {
     150                        result.reportError(-1, -1,
     151                                "The URI of PID '" + handle +
     152                                "' contains an unexpected host part of '" +
     153                                uri.getHost() + "'");
     154                    }
    140155                    checkHandleResolves(uri, result);
    141156                } else {
     157                    result.reportError(-1, -1, "The URI of PID '" + handle +
     158                            "' is missing the host part");
     159                }
     160            } else {
     161                if (uri.getScheme() != null) {
    142162                    result.reportError(-1, -1,
    143                             "PID '" + handle +
    144                             "' contains an unexpected host part in the URI: " +
    145                             uri.getHost());
    146                 }
    147             } else {
    148                 result.reportError(-1, -1,
    149                         "PID '" + handle +
    150                         "' contains an unexpected schema part in the URI: " +
    151                         uri.getScheme());
     163                            "The URI of PID '" + handle +
     164                            "' contains an unexpected schema part of '" +
     165                            uri.getScheme() + "'");
     166                } else {
     167                    result.reportError(-1, -1, "The URI of PID '" + handle +
     168                            "' is missing a proper schema part");
     169                }
    152170            }
    153171        } catch (URISyntaxException e) {
     
    161179            CMDIValidatorWriteableResult result) throws CMDIValidatorException {
    162180        if (resolver != null) {
    163             int code = resolver.resolve(uri);
    164             switch (code) {
    165             case HttpStatus.SC_OK:
    166                 /* no special message in this case */
    167                 break;
    168             case HttpStatus.SC_UNAUTHORIZED:
    169                 /* FALL-THROUGH */
    170             case HttpStatus.SC_FORBIDDEN:
    171                 result.reportInfo(-1, -1, "PID '" + uri +
    172                         "' resolved to an access protected resource (" + code +
    173                         ")");
    174                 break;
    175             case HttpStatus.SC_NOT_FOUND:
    176                 result.reportError(-1, -1, "PID '" + uri +
    177                         "' resolved to an non-existing resource (" + code + ")");
    178                 break;
    179             default:
    180                 result.reportError(-1, -1, "PID '" + uri +
    181                         "' resolved with an unexpected result (" + code + ")");
    182                 break;
     181            try {
     182                int code = resolver.resolve(uri);
     183                switch (code) {
     184                case HttpStatus.SC_OK:
     185                    /* no special message in this case */
     186                    break;
     187                case HttpStatus.SC_UNAUTHORIZED:
     188                    /* FALL-THROUGH */
     189                case HttpStatus.SC_FORBIDDEN:
     190                    result.reportInfo(-1, -1, "PID '" + uri +
     191                            "' resolved to an access protected resource (" +
     192                            code + ")");
     193                    break;
     194                case HttpStatus.SC_NOT_FOUND:
     195                    result.reportError(-1, -1, "PID '" + uri +
     196                            "' resolved to an non-existing resource (" + code +
     197                            ")");
     198                    break;
     199                case HandleResolver.TIMEOUT:
     200                    result.reportWarning(-1, -1, "Timeout while resolving PID '" +
     201                            uri + "'");
     202                    break;
     203                case HandleResolver.UNKNOWN_HOST:
     204                    result.reportWarning(-1, -1, "Unable to resolve host '" +
     205                            uri.getHost() + "' while resolving PID '" +
     206                            uri + "'");
     207                    break;
     208                case HandleResolver.ERROR:
     209                    result.reportWarning(-1, -1,
     210                            "An error occurred while resolving PID '" +
     211                            uri + "'");
     212                    break;
     213                default:
     214                    result.reportWarning(-1, -1, "PID '" + uri +
     215                            "' resolved with an unexpected result (" + code +
     216                            ")");
     217                    break;
     218                } // switch
     219            } catch (IOException e) {
     220                throw new CMDIValidatorException(
     221                        "error while resolving handle '" + uri + "'", e);
    183222            }
    184223        }
Note: See TracChangeset for help on using the changeset viewer.