Changeset 1992


Ignore:
Timestamp:
Sep 3, 2011, 9:06:39 PM (12 years ago)
Author:
business@…
Message:

added exception handling for host resolving

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/RestController.groovy

    r1990 r1992  
    426426                // Create data for all assays
    427427                moduleURL = new URL(params.moduleURL)
    428                 moduleInet = InetAddress.getByName(moduleURL.getHost())
     428                try {
     429                        moduleInet = InetAddress.getByName(moduleURL.getHost())
     430                }
     431                catch(Exception e) {
     432                        moduleInet = moduleURL.host
     433                }
     434
    429435                assays.each{ assay ->
    430436                        /**
     
    472478
    473479        def doesModuleMatch = { assay, moduleURL, moduleInet ->
    474                 // only resolve hosts if the urls do not match identically
    475                 def assayModuleURL = new URL(assay.module.url)
    476                 def assayModuleInet = InetAddress.getByName(assayModuleURL.getHost())
    477 
    478                 return (
    479                         moduleInet.hostAddress == assayModuleInet.hostAddress &&
    480                         (moduleURL.path.replaceAll(/[^a-zA-Z0-9]/, "") == assayModuleURL.path.replaceAll(/[^a-zA-Z0-9]/, ""))
    481                 )
     480
     481                try {
     482
     483                        // only resolve hosts if the urls do not match identically
     484                        def assayModuleURL = new URL(assay.module.url)
     485                        def assayModuleInet = InetAddress.getByName(assayModuleURL.getHost())
     486
     487                        return (
     488                                moduleInet.hostAddress == assayModuleInet.hostAddress &&
     489                                (moduleURL.path.replaceAll(/[^a-zA-Z0-9]/, "") == assayModuleURL.path.replaceAll(/[^a-zA-Z0-9]/, ""))
     490                        )
     491                }
     492                catch (Exception e) {
     493                        // If for some reason an error occurs (e.g. because the hostname is invalid and throws an UnknownHostException)
     494                        // assume the calling module does not equal the assay module considered
     495                        return false
     496                }
    482497        }
    483498
Note: See TracChangeset for help on using the changeset viewer.