Пример #1
0
  /**
   * Adds a settings configuration to the test setup. If the settings object already exists it is
   * simply reverted to its original state.
   *
   * @param workspace The optional workspace for the settings, may be <code>null</code>
   * @param geoServer The GeoServer configuration object.
   */
  public void addSettings(String workspace, GeoServer geoServer) {
    WorkspaceInfo ws =
        workspace != null ? geoServer.getCatalog().getWorkspaceByName(workspace) : null;

    GeoServerInfo global = geoServer.getGlobal();
    SettingsInfo settings = ws != null ? geoServer.getSettings(ws) : global.getSettings();
    if (settings == null) {
      settings = geoServer.getFactory().createSettings();
    }
    settings.setWorkspace(ws);
    settings.getContact().setContactPerson("Andrea Aime");
    settings.setNumDecimals(8);
    settings.setOnlineResource("http://geoserver.org");
    settings.setVerbose(false);
    settings.setVerboseExceptions(false);
    settings.setLocalWorkspaceIncludesPrefix(false);

    if (ws != null) {
      if (settings.getId() != null) {
        geoServer.save(settings);
      } else {
        geoServer.add(settings);
      }
    } else {
      // global
      geoServer.save(global);
    }
  }
Пример #2
0
  /** See https://osgeo-org.atlassian.net/browse/GEOS-3965 */
  @Test
  public void testProxyBaseURL() throws Exception {
    GeoServer gs = getGeoServer();
    try {
      GeoServerInfo info = gs.getGlobal();
      info.getSettings().setProxyBaseUrl("http://myhost:9999/gs");
      gs.save(info);

      final String requestUrl =
          "wms/kml?layers=" + getLayerId(MockData.BRIDGES) + "&styles=Bridge&mode=download";
      Document dom = getAsDOM(requestUrl);

      // make sure we are using the proxy base URL
      XMLAssert.assertXpathEvaluatesTo(
          "http://myhost:9999/gs/styles/bridge.png",
          "//kml:Style/kml:IconStyle/kml:Icon/kml:href",
          dom);
    } finally {
      GeoServerInfo info = gs.getGlobal();
      info.getSettings().setProxyBaseUrl(null);
      gs.save(info);
    }
  }
Пример #3
0
  @Test
  public void testConfigureFeatureTypeCacheSize() {
    GeoServer gs = getGeoServer();
    GeoServerInfo global = gs.getGlobal();
    global.setFeatureTypeCacheSize(200);
    gs.save(global);

    Catalog catalog = getCatalog();
    // we actually keep two versions of the feature type in the cache, so we need it
    // twice as big
    assertEquals(
        400,
        ((SoftValueHashMap) catalog.getResourcePool().getFeatureTypeCache())
            .getHardReferencesCount());
  }
  public void mangleURL(
      StringBuilder baseURL, StringBuilder path, Map<String, String> kvp, URLType type) {

    // first check the system property
    String proxyBase = GeoServerExtensions.getProperty("PROXY_BASE_URL");
    if (proxyBase == null) {
      // if no system property fall back to configuration
      proxyBase = geoServer.getGlobal().getProxyBaseUrl();
    }

    // perform the replacement if the proxy base is set
    if (proxyBase != null && proxyBase.trim().length() > 0) {
      baseURL.setLength(0);
      baseURL.append(proxyBase);
    }
  }
Пример #5
0
  @SuppressWarnings("deprecation")
  @Before
  public void setUp() {
    WFSURIHandler.ADDITIONAL_HOSTNAMES.clear();
    WFSURIHandler.ADDRESSES.clear();

    // Suppress the network interface interrogation so it doesn't interfere with other tests
    strategy =
        new InitStrategy() {
          public Collection<NetworkInterface> getNetworkInterfaces() {
            return Collections.emptyList();
          }
        };

    gs = EasyMock.createMock(GeoServer.class);
    config = EasyMock.createMock(GeoServerInfo.class);
    expect(gs.getGlobal()).andStubReturn(config);
    expect(config.getProxyBaseUrl()).andStubReturn(null);
    replay(gs, config);
  }
    /** Encodes the service metadata section of a WMS capabilities document. */
    private void handleService() {
      start("Service");

      final WMSInfo serviceInfo = wmsConfig.getServiceInfo();
      element("Name", "OGC:WMS");
      element("Title", serviceInfo.getTitle());
      element("Abstract", serviceInfo.getAbstract());

      handleKeywordList(serviceInfo.getKeywords());

      AttributesImpl orAtts = new AttributesImpl();
      orAtts.addAttribute("", "xmlns:xlink", "xmlns:xlink", "", XLINK_NS);
      orAtts.addAttribute(XLINK_NS, "xlink:type", "xlink:type", "", "simple");

      String onlineResource = serviceInfo.getOnlineResource();
      if (onlineResource == null || onlineResource.trim().length() == 0) {
        String requestBaseUrl = request.getBaseUrl();
        onlineResource = buildURL(requestBaseUrl, null, null, URLType.SERVICE);
      } else {
        try {
          new URL(onlineResource);
        } catch (MalformedURLException e) {
          LOGGER.log(
              Level.WARNING,
              "WMS online resource seems to be an invalid URL: '" + onlineResource + "'");
        }
      }
      orAtts.addAttribute("", "xlink:href", "xlink:href", "", onlineResource);
      element("OnlineResource", null, orAtts);

      GeoServer geoServer = wmsConfig.getGeoServer();
      ContactInfo contact = geoServer.getGlobal().getContact();
      handleContactInfo(contact);

      element("Fees", serviceInfo.getFees());
      element("AccessConstraints", serviceInfo.getAccessConstraints());
      end("Service");
    }
Пример #7
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public GeoServerHomePage() {
    GeoServer gs = getGeoServer();
    ContactInfo contact = gs.getGlobal().getSettings().getContact();

    // add some contact info
    add(
        new ExternalLink("contactURL", contact.getOnlineResource())
            .add(new Label("contactName", contact.getContactOrganization())));
    {
      String version = String.valueOf(new ResourceModel("version").getObject());
      String contactEmail = contact.getContactEmail();
      HashMap<String, String> params = new HashMap<String, String>();
      params.put("version", version);
      params.put("contactEmail", (contactEmail == null ? "*****@*****.**" : contactEmail));
      Label label =
          new Label(
              "footerMessage",
              new StringResourceModel("GeoServerHomePage.footer", this, new Model(params)));
      label.setEscapeModelStrings(false);
      add(label);
    }

    Authentication auth = getSession().getAuthentication();
    if (isAdmin(auth)) {
      Stopwatch sw = Stopwatch.createStarted();
      Fragment f = new Fragment("catalogLinks", "catalogLinksFragment", this);
      Catalog catalog = getCatalog();

      NumberFormat numberFormat = NumberFormat.getIntegerInstance(getLocale());
      numberFormat.setGroupingUsed(true);

      final Filter allLayers = acceptAll();
      final Filter allStores = acceptAll();
      final Filter allWorkspaces = acceptAll();

      final int layerCount = catalog.count(LayerInfo.class, allLayers);
      final int storesCount = catalog.count(StoreInfo.class, allStores);
      final int wsCount = catalog.count(WorkspaceInfo.class, allWorkspaces);

      f.add(
          new BookmarkablePageLink("layersLink", LayerPage.class)
              .add(new Label("nlayers", numberFormat.format(layerCount))));
      f.add(new BookmarkablePageLink("addLayerLink", NewLayerPage.class));

      f.add(
          new BookmarkablePageLink("storesLink", StorePage.class)
              .add(new Label("nstores", numberFormat.format(storesCount))));
      f.add(new BookmarkablePageLink("addStoreLink", NewDataPage.class));

      f.add(
          new BookmarkablePageLink("workspacesLink", WorkspacePage.class)
              .add(new Label("nworkspaces", numberFormat.format(wsCount))));
      f.add(new BookmarkablePageLink("addWorkspaceLink", WorkspaceNewPage.class));
      add(f);

      sw.stop();
    } else {
      Label placeHolder = new Label("catalogLinks");
      placeHolder.setVisible(false);
      add(placeHolder);
    }

    final IModel<List<GeoServerHomePageContentProvider>> contentProviders;
    contentProviders = getContentProviders(GeoServerHomePageContentProvider.class);
    ListView<GeoServerHomePageContentProvider> contentView =
        new ListView<GeoServerHomePageContentProvider>("contributedContent", contentProviders) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<GeoServerHomePageContentProvider> item) {
            GeoServerHomePageContentProvider provider = item.getModelObject();
            Component extraContent = provider.getPageBodyComponent("contentList");
            if (null == extraContent) {
              Label placeHolder = new Label("contentList");
              placeHolder.setVisible(false);
              extraContent = placeHolder;
            }
            item.add(extraContent);
          }
        };
    add(contentView);

    final IModel<List<CapabilitiesHomePageLinkProvider>> capsProviders;
    capsProviders = getContentProviders(CapabilitiesHomePageLinkProvider.class);

    ListView<CapabilitiesHomePageLinkProvider> capsView =
        new ListView<CapabilitiesHomePageLinkProvider>("providedCaps", capsProviders) {
          private static final long serialVersionUID = 1L;

          @Override
          protected void populateItem(ListItem<CapabilitiesHomePageLinkProvider> item) {
            CapabilitiesHomePageLinkProvider provider = item.getModelObject();
            Component capsList = provider.getCapabilitiesComponent("capsList");
            item.add(capsList);
          }
        };
    add(capsView);
  }
Пример #8
0
 private JAIInfo getJaiInfo() {
   GeoServer geoServer = getGeoServer();
   GeoServerInfo global = geoServer.getGlobal();
   return global.getJAI();
 }