Пример #1
0
  @SuppressWarnings("unchecked")
  private boolean define(StoreInfo store, JSONObj obj) {
    boolean reconnect = false;
    for (String prop : obj.keys()) {
      if ("description".equals(prop)) {
        store.setDescription(obj.str(prop));
      } else if ("enabled".equals(prop)) {
        store.setEnabled(obj.bool(prop));
        reconnect = true;
      } else if ("name".equals(prop)) {
        store.setName(obj.str(prop));
      } else if ("workspace".equals(prop)) {
        WorkspaceInfo newWorkspace = findWorkspace(obj.str(prop));
        store.setWorkspace(newWorkspace);
      } else if (store instanceof CoverageStoreInfo) {
        CoverageStoreInfo info = (CoverageStoreInfo) store;
        if ("connection".equals(prop)) {
          JSONObj connection = obj.object(prop);
          if (!connection.has("raster") && connection.str("raster") != null) {
            throw new IllegalArgumentException(
                "Property connection.raster required for coverage store");
          }
          for (String param : connection.keys()) {
            if ("raster".equals(param)) {
              String url = connection.str(param);
              reconnect = reconnect || url == null || !url.equals(info.getURL());
              info.setURL(url);
            }
          }
        }
      } else if (store instanceof WMSStoreInfo) {
        WMSStoreInfo info = (WMSStoreInfo) store;
        if ("connection".equals(prop)) {
          JSONObj connection = obj.object(prop);
          if (!connection.has("url") && connection.str("url") != null) {
            throw new IllegalArgumentException("Property connection.url required for wms store");
          }
          for (String param : connection.keys()) {
            if ("url".equals(param)) {
              String url = connection.str(param);
              reconnect = reconnect || url == null || !url.equals(info.getCapabilitiesURL());
              info.setCapabilitiesURL(url);
            }
          }
        }
      }
      if (store instanceof DataStoreInfo) {
        DataStoreInfo info = (DataStoreInfo) store;
        if ("connection".equals(prop)) {
          JSONObj connection = obj.object(prop);
          info.getConnectionParameters().clear();
          info.getConnectionParameters().putAll(connection.raw());
          reconnect = true;
        }
      }
    }

    return reconnect;
  }
Пример #2
0
  @Override
  protected void onSetUp(SystemTestData testData) throws Exception {
    super.onSetUp(testData);

    // we need to add a wms store
    CatalogBuilder cb = new CatalogBuilder(catalog);
    cb.setWorkspace(catalog.getWorkspaceByName("sf"));
    WMSStoreInfo wms = cb.buildWMSStore("demo");
    wms.setCapabilitiesURL("http://demo.opengeo.org/geoserver/wms?");
    catalog.add(wms);

    // and a wms layer as well (cannot use the builder, would turn this test into an online one
    addStatesWmsLayer();
  }
  @org.junit.Test
  public void testCascadingWMS() throws Exception {
    Catalog catalog = getCatalog();

    CatalogBuilder builder = new CatalogBuilder(catalog);
    WMSStoreInfo wmsStore = builder.buildWMSStore("cascadeWMS");
    wmsStore.setCapabilitiesURL(
        "http://wms.geonorge.no/skwms1/wms.toporaster2?service=WMS&version=1.1.1");
    catalog.add(wmsStore);

    builder.setStore(wmsStore);
    WMSLayerInfo wmsLayer = builder.buildWMSLayer("toporaster");
    catalog.add(wmsLayer);

    requiredParameters.put("LAYER", "toporaster");
    GetLegendGraphicRequest request =
        requestReader.read(new GetLegendGraphicRequest(), requiredParameters, requiredParameters);
    assertNotNull(request);
  }
Пример #4
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  @RequestMapping(value = "/{wsName}/{name}", method = RequestMethod.POST)
  public @ResponseBody JSONObj create(
      @PathVariable String wsName,
      @PathVariable String name,
      @RequestBody JSONObj obj,
      HttpServletRequest req)
      throws IOException {
    Catalog cat = geoServer.getCatalog();
    CatalogFactory factory = cat.getFactory();

    WorkspaceInfo workspace = findWorkspace(wsName);
    StoreInfo store = null;

    JSONObj params = obj.object("connection");
    if (params == null) {
      throw new IllegalArgumentException("connection parameters required");
    }
    if (params.has("raster")) {
      String url = params.str("raster");
      CoverageStoreInfo info = factory.createCoverageStore();
      info.setWorkspace(workspace);
      info.setType(name);

      // connect and defaults
      info.setURL(url);
      info.setType(obj.str("type"));
      try {
        GridCoverageReader reader = info.getGridCoverageReader(null, null);
        Format format = reader.getFormat();
        info.setDescription(format.getDescription());
        info.setEnabled(true);
      } catch (IOException e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    } else if (params.has("url")
        && params.str("url").toLowerCase().contains("Service=WMS")
        && params.str("url").startsWith("http")) {
      WMSStoreInfo info = factory.createWebMapServer();
      info.setWorkspace(workspace);
      info.setType(name);

      // connect and defaults
      info.setCapabilitiesURL(params.str("url"));
      try {
        WebMapServer service = info.getWebMapServer(new NullProgressListener());
        info.setDescription(service.getInfo().getDescription());
        info.setEnabled(true);
      } catch (Throwable e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    } else {
      HashMap map = new HashMap(params.raw());
      Map resolved = ResourcePool.getParams(map, cat.getResourceLoader());
      DataAccess dataStore = DataAccessFinder.getDataStore(resolved);
      if (dataStore == null) {
        throw new IllegalArgumentException(
            "Connection parameters incomplete (does not match an available data store, coverage store or wms store).");
      }
      DataStoreInfo info = factory.createDataStore();
      info.setWorkspace(workspace);
      info.setType(name);
      info.getConnectionParameters().putAll(map);
      try {
        info.setDescription(dataStore.getInfo().getDescription());
        info.setEnabled(true);
      } catch (Throwable e) {
        info.setError(e);
        info.setEnabled(false);
      }
      store = info;
    }
    boolean refresh = define(store, obj);
    if (refresh) {
      LOG.log(
          Level.FINE, "Inconsistent: default connection used for store creation required refresh");
    }
    cat.add(store);

    return storeDetails(new JSONObj(), store, req);
  }