Exemple #1
0
  @Test
  public void testPostAsJSON() throws Exception {
    if (!RemoteOWSTestSupport.isRemoteWMSStatesAvailable(LOGGER)) {
      LOGGER.warning("Skipping layer posting test as remote server is not available");
      return;
    }

    assertNull(catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class));

    String json =
        "{"
            + "'wmsLayer':{"
            + "'name':'bugsites',"
            + "'nativeName':'og:bugsites',"
            + "'srs':'EPSG:4326',"
            + "'nativeCRS':'EPSG:4326',"
            + "'store':'demo'"
            + "}"
            + "}";
    MockHttpServletResponse response =
        postAsServletResponse("/rest/workspaces/sf/wmsstores/demo/wmslayers/", json, "text/json");

    assertEquals(201, response.getStatusCode());
    assertNotNull(response.getHeader("Location"));
    assertTrue(
        response
            .getHeader("Location")
            .endsWith("/workspaces/sf/wmsstores/demo/wmslayers/bugsites"));

    WMSLayerInfo layer = catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class);
    assertNotNull(layer.getNativeBoundingBox());
  }
Exemple #2
0
  @Test
  public void testPostAsXML() throws Exception {
    if (!RemoteOWSTestSupport.isRemoteWMSStatesAvailable(LOGGER)) {
      LOGGER.warning("Skipping layer posting test as remote server is not available");
      return;
    }

    assertNull(catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class));

    String xml =
        "<wmsLayer>"
            + "<name>bugsites</name>"
            + "<nativeName>og:bugsites</nativeName>"
            + "<srs>EPSG:4326</srs>"
            + "<nativeCRS>EPSG:4326</nativeCRS>"
            + "<store>demo</store>"
            + "</wmsLayer>";
    MockHttpServletResponse response =
        postAsServletResponse("/rest/workspaces/sf/wmsstores/demo/wmslayers/", xml, "text/xml");

    assertEquals(201, response.getStatusCode());
    assertNotNull(response.getHeader("Location"));
    assertTrue(
        response
            .getHeader("Location")
            .endsWith("/workspaces/sf/wmsstores/demo/wmslayers/bugsites"));

    WMSLayerInfo layer = catalog.getResourceByName("sf", "bugsites", WMSLayerInfo.class);
    assertNotNull(layer.getNativeBoundingBox());
  }
Exemple #3
0
  @Test
  public void testPut() throws Exception {
    String xml = "<wmsLayer>" + "<title>Lots of states here</title>" + "</wmsLayer>";
    MockHttpServletResponse response =
        putAsServletResponse(
            "/rest/workspaces/sf/wmsstores/demo/wmslayers/states", xml, "text/xml");
    assertEquals(200, response.getStatusCode());

    Document dom = getAsDOM("/rest/workspaces/sf/wmsstores/demo/wmslayers/states.xml");
    assertXpathEvaluatesTo("Lots of states here", "/wmsLayer/title", dom);

    WMSLayerInfo wli = catalog.getResourceByName("sf", "states", WMSLayerInfo.class);
    assertEquals("Lots of states here", wli.getTitle());
  }
Exemple #4
0
 public Integer getCascadedHopCount(LayerInfo layer) {
   if (!(layer.getResource() instanceof WMSLayerInfo)) {
     return null;
   }
   WMSLayerInfo wmsLayerInfo = (WMSLayerInfo) layer.getResource();
   Layer wmsLayer;
   int cascaded = 1;
   try {
     wmsLayer = wmsLayerInfo.getWMSLayer(null);
     cascaded = 1 + wmsLayer.getCascaded();
   } catch (IOException e) {
     LOGGER.log(Level.INFO, "Unable to determina WMSLayer cascaded hop count", e);
   }
   return cascaded;
 }
Exemple #5
0
  @Test
  public void testGetAsXML() throws Exception {
    Document dom = getAsDOM("/rest/workspaces/sf/wmslayers/states.xml");

    assertEquals("wmsLayer", dom.getDocumentElement().getNodeName());
    assertXpathEvaluatesTo("states", "/wmsLayer/name", dom);
    assertXpathEvaluatesTo("EPSG:4326", "/wmsLayer/srs", dom);
    assertEquals(CRS.decode("EPSG:4326").toWKT(), xp.evaluate("/wmsLayer/nativeCRS", dom));

    WMSLayerInfo wml = catalog.getResourceByName("sf", "states", WMSLayerInfo.class);

    ReferencedEnvelope re = wml.getLatLonBoundingBox();
    assertXpathEvaluatesTo(re.getMinX() + "", "/wmsLayer/latLonBoundingBox/minx", dom);
    assertXpathEvaluatesTo(re.getMaxX() + "", "/wmsLayer/latLonBoundingBox/maxx", dom);
    assertXpathEvaluatesTo(re.getMinY() + "", "/wmsLayer/latLonBoundingBox/miny", dom);
    assertXpathEvaluatesTo(re.getMaxY() + "", "/wmsLayer/latLonBoundingBox/maxy", dom);
  }
Exemple #6
0
  @Before
  public void addStatesWmsLayer() throws Exception {
    WMSLayerInfo wml = catalog.getResourceByName("sf", "states", WMSLayerInfo.class);
    if (wml == null) {
      wml = catalog.getFactory().createWMSLayer();
      wml.setName("states");
      wml.setNativeName("topp:states");
      wml.setStore(catalog.getStoreByName("demo", WMSStoreInfo.class));
      wml.setCatalog(catalog);
      wml.setNamespace(catalog.getNamespaceByPrefix("sf"));
      wml.setSRS("EPSG:4326");
      CoordinateReferenceSystem wgs84 = CRS.decode("EPSG:4326");
      wml.setNativeCRS(wgs84);
      wml.setLatLonBoundingBox(new ReferencedEnvelope(-110, 0, -60, 50, wgs84));
      wml.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED);

      catalog.add(wml);
    }
  }
Exemple #7
0
  /** Returns true if the layer can be queried */
  public boolean isQueryable(LayerInfo layer) {
    try {
      if (layer.getResource() instanceof WMSLayerInfo) {
        WMSLayerInfo info = (WMSLayerInfo) layer.getResource();
        Layer wl = info.getWMSLayer(null);
        if (!wl.isQueryable()) {
          return false;
        }
        WMSCapabilities caps = info.getStore().getWebMapServer(null).getCapabilities();
        OperationType featureInfo = caps.getRequest().getGetFeatureInfo();
        if (featureInfo == null || !featureInfo.getFormats().contains("application/vnd.ogc.gml")) {
          return false;
        }
      }

      return layer.isQueryable();

    } catch (IOException e) {
      LOGGER.log(Level.INFO, "Failed to determin if the layer is queryable, assuming it's not", e);
      return false;
    }
  }
  /** Reads the catalog from disk. */
  Catalog readCatalog(XStreamPersister xp) throws Exception {
    CatalogImpl catalog = new CatalogImpl();
    catalog.setResourceLoader(resourceLoader);
    xp.setCatalog(catalog);
    xp.setUnwrapNulls(false);

    CatalogFactory factory = catalog.getFactory();

    // global styles
    loadStyles(resourceLoader.find("styles"), catalog, xp);

    // workspaces, stores, and resources
    File workspaces = resourceLoader.find("workspaces");
    if (workspaces != null) {
      // do a first quick scan over all workspaces, setting the default
      File dws = new File(workspaces, "default.xml");
      WorkspaceInfo defaultWorkspace = null;
      if (dws.exists()) {
        try {
          defaultWorkspace = depersist(xp, dws, WorkspaceInfo.class);
          LOGGER.info("Loaded default workspace " + defaultWorkspace.getName());
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Failed to load default workspace", e);
        }
      } else {
        LOGGER.warning("No default workspace was found.");
      }

      for (File wsd : list(workspaces, DirectoryFileFilter.INSTANCE)) {
        File f = new File(wsd, "workspace.xml");
        if (!f.exists()) {
          continue;
        }

        WorkspaceInfo ws = null;
        try {
          ws = depersist(xp, f, WorkspaceInfo.class);
          catalog.add(ws);
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Failed to load workspace '" + wsd.getName() + "'", e);
          continue;
        }

        LOGGER.info("Loaded workspace '" + ws.getName() + "'");

        // load the namespace
        File nsf = new File(wsd, "namespace.xml");
        NamespaceInfo ns = null;
        if (nsf.exists()) {
          try {
            ns = depersist(xp, nsf, NamespaceInfo.class);
            catalog.add(ns);
          } catch (Exception e) {
            LOGGER.log(Level.WARNING, "Failed to load namespace for '" + wsd.getName() + "'", e);
          }
        }

        // set the default workspace, this value might be null in the case of coming from a
        // 2.0.0 data directory. See http://jira.codehaus.org/browse/GEOS-3440
        if (defaultWorkspace != null) {
          if (ws.getName().equals(defaultWorkspace.getName())) {
            catalog.setDefaultWorkspace(ws);
            if (ns != null) {
              catalog.setDefaultNamespace(ns);
            }
          }
        } else {
          // create the default.xml file
          defaultWorkspace = catalog.getDefaultWorkspace();
          if (defaultWorkspace != null) {
            try {
              persist(xp, defaultWorkspace, dws);
            } catch (Exception e) {
              LOGGER.log(
                  Level.WARNING, "Failed to persist default workspace '" + wsd.getName() + "'", e);
            }
          }
        }

        // load the styles for the workspace
        File styles = resourceLoader.find(wsd, "styles");
        if (styles != null) {
          loadStyles(styles, catalog, xp);
        }
      }

      for (File wsd : list(workspaces, DirectoryFileFilter.INSTANCE)) {

        // load the stores for this workspace
        for (File sd : list(wsd, DirectoryFileFilter.INSTANCE)) {
          File f = new File(sd, "datastore.xml");
          if (f.exists()) {
            // load as a datastore
            DataStoreInfo ds = null;
            try {
              ds = depersist(xp, f, DataStoreInfo.class);
              catalog.add(ds);

              LOGGER.info("Loaded data store '" + ds.getName() + "'");

              if (ds.isEnabled()) {
                // connect to the datastore to determine if we should disable it
                try {
                  ds.getDataStore(null);
                } catch (Throwable t) {
                  LOGGER.warning("Error connecting to '" + ds.getName() + "'. Disabling.");
                  LOGGER.log(Level.INFO, "", t);

                  ds.setError(t);
                  ds.setEnabled(false);
                }
              }
            } catch (Exception e) {
              LOGGER.log(Level.WARNING, "Failed to load data store '" + sd.getName() + "'", e);
              continue;
            }

            // load feature types
            for (File ftd : list(sd, DirectoryFileFilter.INSTANCE)) {
              f = new File(ftd, "featuretype.xml");
              if (f.exists()) {
                FeatureTypeInfo ft = null;
                try {
                  ft = depersist(xp, f, FeatureTypeInfo.class);
                } catch (Exception e) {
                  LOGGER.log(
                      Level.WARNING, "Failed to load feature type '" + ftd.getName() + "'", e);
                  continue;
                }

                catalog.add(ft);

                LOGGER.info("Loaded feature type '" + ds.getName() + "'");

                f = new File(ftd, "layer.xml");
                if (f.exists()) {
                  try {
                    LayerInfo l = depersist(xp, f, LayerInfo.class);
                    catalog.add(l);

                    LOGGER.info("Loaded layer '" + l.getName() + "'");
                  } catch (Exception e) {
                    LOGGER.log(
                        Level.WARNING,
                        "Failed to load layer for feature type '" + ft.getName() + "'",
                        e);
                  }
                }
              } else {
                LOGGER.warning("Ignoring feature type directory " + ftd.getAbsolutePath());
              }
            }
          } else {
            // look for a coverage store
            f = new File(sd, "coveragestore.xml");
            if (f.exists()) {
              CoverageStoreInfo cs = null;
              try {
                cs = depersist(xp, f, CoverageStoreInfo.class);
                catalog.add(cs);

                LOGGER.info("Loaded coverage store '" + cs.getName() + "'");
              } catch (Exception e) {
                LOGGER.log(
                    Level.WARNING, "Failed to load coverage store '" + sd.getName() + "'", e);
                continue;
              }

              // load coverages
              for (File cd : list(sd, DirectoryFileFilter.INSTANCE)) {
                f = new File(cd, "coverage.xml");
                if (f.exists()) {
                  CoverageInfo c = null;
                  try {
                    c = depersist(xp, f, CoverageInfo.class);
                    catalog.add(c);

                    LOGGER.info("Loaded coverage '" + cs.getName() + "'");
                  } catch (Exception e) {
                    LOGGER.log(Level.WARNING, "Failed to load coverage '" + cd.getName() + "'", e);
                    continue;
                  }

                  f = new File(cd, "layer.xml");
                  if (f.exists()) {
                    try {
                      LayerInfo l = depersist(xp, f, LayerInfo.class);
                      catalog.add(l);

                      LOGGER.info("Loaded layer '" + l.getName() + "'");
                    } catch (Exception e) {
                      LOGGER.log(
                          Level.WARNING, "Failed to load layer coverage '" + c.getName() + "'", e);
                    }
                  }
                } else {
                  LOGGER.warning("Ignoring coverage directory " + cd.getAbsolutePath());
                }
              }
            } else {
              f = new File(sd, "wmsstore.xml");
              if (f.exists()) {
                WMSStoreInfo wms = null;
                try {
                  wms = depersist(xp, f, WMSStoreInfo.class);
                  catalog.add(wms);

                  LOGGER.info("Loaded wmsstore '" + wms.getName() + "'");
                } catch (Exception e) {
                  LOGGER.log(Level.WARNING, "Failed to load wms store '" + sd.getName() + "'", e);
                  continue;
                }

                // load wms layers
                for (File cd : list(sd, DirectoryFileFilter.INSTANCE)) {
                  f = new File(cd, "wmslayer.xml");
                  if (f.exists()) {
                    WMSLayerInfo wl = null;
                    try {
                      wl = depersist(xp, f, WMSLayerInfo.class);
                      catalog.add(wl);

                      LOGGER.info("Loaded wms layer'" + wl.getName() + "'");
                    } catch (Exception e) {
                      LOGGER.log(
                          Level.WARNING, "Failed to load wms layer '" + cd.getName() + "'", e);
                      continue;
                    }

                    f = new File(cd, "layer.xml");
                    if (f.exists()) {
                      try {
                        LayerInfo l = depersist(xp, f, LayerInfo.class);
                        catalog.add(l);

                        LOGGER.info("Loaded layer '" + l.getName() + "'");
                      } catch (Exception e) {
                        LOGGER.log(
                            Level.WARNING,
                            "Failed to load cascaded wms layer '" + wl.getName() + "'",
                            e);
                      }
                    }
                  } else {
                    LOGGER.warning("Ignoring coverage directory " + cd.getAbsolutePath());
                  }
                }
              } else if (!isConfigDirectory(sd)) {
                LOGGER.warning("Ignoring store directory '" + sd.getName() + "'");
                continue;
              }
            }
          }
        }

        // load hte layer groups for this workspace
        File layergroups = resourceLoader.find(wsd, "layergroups");
        if (layergroups != null) {
          loadLayerGroups(layergroups, catalog, xp);
        }
      }
    } else {
      LOGGER.warning("No 'workspaces' directory found, unable to load any stores.");
    }

    // namespaces

    // layergroups
    File layergroups = resourceLoader.find("layergroups");
    if (layergroups != null) {
      loadLayerGroups(layergroups, catalog, xp);
    }
    xp.setUnwrapNulls(true);
    catalog.resolve();
    return catalog;
  }