public static void addToParser(GeoServer geoServer, Parser parser) { parser.getURIHandlers().add(0, new WFSURIHandler(geoServer)); }
static void init(InitStrategy strategy) { if (!DISABLED) { initAddresses(strategy); initAliases(); initLog(); } }
@Override public boolean canHandle(URI uri) { if (DISABLED) return false; // check if this uri is a reflective one if (uriIsReflective(uri)) { // it is, check the query string to determine if it is a DescribeFeatureType request String q = uri.query(); if (q != null && !"".equals(q.trim())) { KvpMap kv = parseQueryString(q); if ("DescribeFeatureType".equalsIgnoreCase((String) kv.get("REQUEST")) || (uri.path().endsWith("DescribeFeatureType"))) { return true; } } } return false; }
@Test public void testRecognizeReflexiveSimple() { WFSURIHandler.init(strategy); WFSURIHandler handler = new WFSURIHandler(gs); final URI wrongHost = URI.createURI( "http://example.com/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); final URI notDFT = URI.createURI( "http://localhost/geoserver/wfs?service=wfs&version=2.0.0&request=GetCapabilities"); final URI localDFT = URI.createURI( "http://localhost/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); assertThat(handler.canHandle(wrongHost), is(false)); assertThat(handler.canHandle(notDFT), is(false)); assertThat(handler.canHandle(localDFT), is(true)); }
@Test public void testDefaultAliases() { WFSURIHandler.init(strategy); assertThat(WFSURIHandler.ADDRESSES, empty()); assertThat(WFSURIHandler.ADDITIONAL_HOSTNAMES, contains("localhost")); }
public static void initRequestParser(Parser parser, WFSInfo wfs, GeoServer geoServer, Map kvp) { // check the strict flag to determine if we should validate or not Boolean strict = (Boolean) kvp.get("strict"); if (strict == null) { strict = Boolean.FALSE; } // check for cite compliance, we always validate for cite if (wfs.isCiteCompliant()) { strict = Boolean.TRUE; } parser.setValidating(strict.booleanValue()); WFSURIHandler.addToParser(geoServer, parser); Catalog catalog = geoServer.getCatalog(); // "inject" namespace mappings parser.getNamespaces().add(new CatalogNamespaceSupport(catalog)); }
Catalog catalog = geoServer.getCatalog(); try { KvpMap kv = parseQueryString(uri.query());
@Test public void testRecognizeReflexiveProxy() { this.setProxyBase("http://foo/geoserver"); WFSURIHandler.init(strategy); WFSURIHandler handler = new WFSURIHandler(gs); final URI wrongHost = URI.createURI( "http://example.com/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); final URI notDFT = URI.createURI( "http://foo/geoserver/wfs?service=wfs&version=2.0.0&request=GetCapabilities"); final URI fooDFT = URI.createURI( "http://foo/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); final URI uppercaseFooDFT = URI.createURI( "http://FOO/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); assertThat(handler.canHandle(wrongHost), is(false)); assertThat(handler.canHandle(notDFT), is(false)); assertThat(handler.canHandle(fooDFT), is(true)); assertThat(handler.canHandle(uppercaseFooDFT), is(true)); } }
@Test public void testOverrideAliasesComma() { aliases.setValue("foo,bar , baz"); WFSURIHandler.init(strategy); assertThat(WFSURIHandler.ADDRESSES, empty()); assertThat(WFSURIHandler.ADDITIONAL_HOSTNAMES, containsInAnyOrder("foo", "bar", "baz")); }
WFSURIHandler.addToParser(geoServer, parser);
@Test public void testRecognizeReflexiveUserAliases() { aliases.setValue("foo bar baz"); WFSURIHandler.init(strategy); WFSURIHandler handler = new WFSURIHandler(gs); final URI wrongHost = URI.createURI( "http://example.com/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); final URI notDFT = URI.createURI( "http://foo/geoserver/wfs?service=wfs&version=2.0.0&request=GetCapabilities"); final URI fooDFT = URI.createURI( "http://foo/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); final URI barDFT = URI.createURI( "http://bar/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); final URI bazDFT = URI.createURI( "http://baz/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); final URI localhostDFT = URI.createURI( "http://localhost/geoserver/wfs?service=wfs&version=2.0.0&request=DescribeFeatureType"); assertThat(handler.canHandle(wrongHost), is(false)); assertThat(handler.canHandle(notDFT), is(false)); assertThat(handler.canHandle(fooDFT), is(true)); assertThat(handler.canHandle(barDFT), is(true)); assertThat(handler.canHandle(bazDFT), is(true)); assertThat(handler.canHandle(localhostDFT), is(false)); }
@Test public void testOverrideAliasesSpace() { aliases.setValue("foo bar baz "); WFSURIHandler.init(strategy); assertThat(WFSURIHandler.ADDRESSES, empty()); assertThat(WFSURIHandler.ADDITIONAL_HOSTNAMES, containsInAnyOrder("foo", "bar", "baz")); }