@Test public void testSelectProvider() throws HttpErrorPage { Properties p = new Properties(); p.setProperty("provider1." + Parameters.REMOTE_URL_BASE, "http: p.setProperty("provider1." + Parameters.MAPPINGS, "http: p.setProperty("provider2." + Parameters.REMOTE_URL_BASE, "http: p.setProperty("provider2." + Parameters.MAPPINGS, "http: p.setProperty("single." + Parameters.REMOTE_URL_BASE, "http: p.setProperty("single." + Parameters.MAPPINGS, "*"); DriverFactory.configure(p); IncomingRequest request = IncomingRequest.builder("http: .addHeader("Host", "sub2.domain.com").setContextPath("/test").build(); Assert.assertEquals("provider2", DriverFactory.selectProvider(request).getDriver().getConfiguration() .getInstanceName()); request = IncomingRequest.builder("http: .addHeader("Host", "sub.domain.com").setContextPath("/test").build(); Assert.assertEquals("provider1", DriverFactory.selectProvider(request).getDriver().getConfiguration() .getInstanceName()); request = IncomingRequest.builder("http: .addHeader("Host", "foo.com").setContextPath("/test").build(); Assert.assertEquals("single", DriverFactory.selectProvider(request).getDriver().getConfiguration() .getInstanceName()); }
static MatchedRequest selectProvider(IncomingRequest request) throws HttpErrorPage { URI requestURI = UriUtils.createURI(request.getRequestLine().getUri()); String host = UriUtils.extractHost(requestURI).toHostString(); Header hostHeader = request.getFirstHeader(HttpHeaders.HOST); if (hostHeader != null) { host = hostHeader.getValue(); } String scheme = requestURI.getScheme(); String relativeUri = requestURI.getPath(); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath) && relativeUri.startsWith(contextPath)) { relativeUri = relativeUri.substring(contextPath.length()); } Driver driver = null; UriMapping uriMapping = null; for (UriMapping mapping : instances.getUrimappings().keySet()) { if (mapping.matches(scheme, host, relativeUri)) { driver = getInstance(instances.getUrimappings().get(mapping)); uriMapping = mapping; break; } } if (driver == null) { throw new HttpErrorPage(HttpStatus.SC_NOT_FOUND, "Not found", "No mapping defined for this URI."); } if (driver.getConfiguration().isStripMappingPath()) { relativeUri = DriverFactory.stripMappingPath(relativeUri, uriMapping); } MatchedRequest context = new MatchedRequest(driver, relativeUri); LOG.debug("Selected {} for scheme:{} host:{} relUrl:{}", driver, scheme, host, relativeUri); return context; }
DriverFactory { static MatchedRequest selectProvider(IncomingRequest request) throws HttpErrorPage { URI requestURI = UriUtils.createURI(request.getRequestLine().getUri()); String host = UriUtils.extractHost(requestURI).toHostString(); Header hostHeader = request.getFirstHeader(HttpHeaders.HOST); if (hostHeader != null) { host = hostHeader.getValue(); } String scheme = requestURI.getScheme(); String relativeUri = requestURI.getPath(); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath) && relativeUri.startsWith(contextPath)) { relativeUri = relativeUri.substring(contextPath.length()); } Driver driver = null; UriMapping uriMapping = null; for (UriMapping mapping : instances.getUrimappings().keySet()) { if (mapping.matches(scheme, host, relativeUri)) { driver = getInstance(instances.getUrimappings().get(mapping)); uriMapping = mapping; break; } } if (driver == null) { throw new HttpErrorPage(HttpStatus.SC_NOT_FOUND, "Not found", "No mapping defined for this URI."); } if (driver.getConfiguration().isStripMappingPath()) { relativeUri = DriverFactory.stripMappingPath(relativeUri, uriMapping); } MatchedRequest context = new MatchedRequest(driver, relativeUri); LOG.debug("Selected {} for scheme:{} host:{} relUrl:{}", driver, scheme, host, relativeUri); return context; } }
DriverFactory { static MatchedRequest selectProvider(IncomingRequest request) throws HttpErrorPage { URI requestURI = UriUtils.createURI(request.getRequestLine().getUri()); String host = UriUtils.extractHost(requestURI).toHostString(); Header hostHeader = request.getFirstHeader(HttpHeaders.HOST); if (hostHeader != null) { host = hostHeader.getValue(); } String scheme = requestURI.getScheme(); String relativeUri = requestURI.getPath(); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath) && relativeUri.startsWith(contextPath)) { relativeUri = relativeUri.substring(contextPath.length()); } Driver driver = null; UriMapping uriMapping = null; for (UriMapping mapping : instances.getUrimappings().keySet()) { if (mapping.matches(scheme, host, relativeUri)) { driver = getInstance(instances.getUrimappings().get(mapping)); uriMapping = mapping; break; } } if (driver == null) { throw new HttpErrorPage(HttpStatus.SC_NOT_FOUND, "Not found", "No mapping defined for this URI."); } if (driver.getConfiguration().isStripMappingPath()) { relativeUri = DriverFactory.stripMappingPath(relativeUri, uriMapping); } MatchedRequest context = new MatchedRequest(driver, relativeUri); LOG.debug("Selected {} for scheme:{} host:{} relUrl:{}", driver, scheme, host, relativeUri); return context; } private  DriverFactory(); }
DriverFactory { static MatchedRequest selectProvider(IncomingRequest request) throws HttpErrorPage { URI requestURI = UriUtils.createURI(request.getRequestLine().getUri()); String host = UriUtils.extractHost(requestURI).toHostString(); Header hostHeader = request.getFirstHeader(HttpHeaders.HOST); if (hostHeader != null) { host = hostHeader.getValue(); } String scheme = requestURI.getScheme(); String relativeUri = requestURI.getPath(); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath) && relativeUri.startsWith(contextPath)) { relativeUri = relativeUri.substring(contextPath.length()); } Driver driver = null; UriMapping uriMapping = null; for (UriMapping mapping : instances.getUrimappings().keySet()) { if (mapping.matches(scheme, host, relativeUri)) { driver = getInstance(instances.getUrimappings().get(mapping)); uriMapping = mapping; break; } } if (driver == null) { throw new HttpErrorPage(HttpStatus.SC_NOT_FOUND, "Not found", "No mapping defined for this URI."); } if (driver.getConfiguration().isStripMappingPath()) { relativeUri = DriverFactory.stripMappingPath(relativeUri, uriMapping); } MatchedRequest context = new MatchedRequest(driver, relativeUri); LOG.debug("Selected {} for scheme:{} host:{} relUrl:{}", driver, scheme, host, relativeUri); return context; } private  DriverFactory(); static Collection<Driver> getInstances(); static void configure(); static void configure(Properties props); static void configure(String name, Properties props); static Driver getInstance(String instanceName); static Driver getInstance(); static void put(String instanceName, Driver instance); static void ensureConfigured(); static URL getConfigUrl(); static CloseableHttpResponse proxy(IncomingRequest incomingRequest); }
DriverFactory { static MatchedRequest selectProvider(IncomingRequest request) throws HttpErrorPage { URI requestURI = UriUtils.createURI(request.getRequestLine().getUri()); String host = UriUtils.extractHost(requestURI).toHostString(); Header hostHeader = request.getFirstHeader(HttpHeaders.HOST); if (hostHeader != null) { host = hostHeader.getValue(); } String scheme = requestURI.getScheme(); String relativeUri = requestURI.getPath(); String contextPath = request.getContextPath(); if (!StringUtils.isEmpty(contextPath) && relativeUri.startsWith(contextPath)) { relativeUri = relativeUri.substring(contextPath.length()); } Driver driver = null; UriMapping uriMapping = null; for (UriMapping mapping : instances.getUrimappings().keySet()) { if (mapping.matches(scheme, host, relativeUri)) { driver = getInstance(instances.getUrimappings().get(mapping)); uriMapping = mapping; break; } } if (driver == null) { throw new HttpErrorPage(HttpStatus.SC_NOT_FOUND, "Not found", "No mapping defined for this URI."); } if (driver.getConfiguration().isStripMappingPath()) { relativeUri = DriverFactory.stripMappingPath(relativeUri, uriMapping); } MatchedRequest context = new MatchedRequest(driver, relativeUri); LOG.debug("Selected {} for scheme:{} host:{} relUrl:{}", driver, scheme, host, relativeUri); return context; } private  DriverFactory(); static Collection<Driver> getInstances(); static void configure(); static void configure(Properties props); static void configure(String name, Properties props); static Driver getInstance(String instanceName); static Driver getInstance(); static void put(String instanceName, Driver instance); static void ensureConfigured(); static URL getConfigUrl(); static CloseableHttpResponse proxy(IncomingRequest incomingRequest); static final String PROP_CONF_LOCATION; }