Exemple #1
0
  @Test
  public void testModifyGridsetTruncates() throws Exception {
    final String oldName = "EPSG:4326";
    final String newName = "MyEPSG:4326";

    final GridSet oldGridset = gridSetBroker.get(oldName);
    final GridSet newGridset;
    {
      XMLGridSet xmlGridSet = new XMLGridSet(oldGridset);
      xmlGridSet.setName(newName);

      // make it so the gridset forces truncation
      xmlGridSet.setAlignTopLeft(!xmlGridSet.getAlignTopLeft());
      newGridset = xmlGridSet.makeGridSet();
    }

    XMLConfiguration xmlConfig = mock(XMLConfiguration.class);
    mediator = spy(mediator);
    when(mediator.getXmlConfiguration()).thenReturn(xmlConfig);
    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);

    mediator.modifyGridSet(oldName, newGridset);

    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq(oldName));
    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayerGroup.getName()), eq(oldName));
  }
Exemple #2
0
  @Test
  public void testModifyTileLayer() throws Exception {
    try {
      mediator.save(null);
      fail();
    } catch (NullPointerException e) {
      assertTrue(true);
    }

    when(tld.modify(same(tileLayer))).thenThrow(new IllegalArgumentException());
    try {
      mediator.save(tileLayer);
      fail();
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    when(tld.modify(same(tileLayerGroup))).thenReturn(config);
    mediator.save(tileLayerGroup);
    verify(config, times(1)).save();

    when(tld.modify(same(tileLayer))).thenReturn(config);
    doThrow(new IOException()).when(config).save();
    try {
      mediator.save(tileLayer);
    } catch (RuntimeException e) {
      assertTrue(true);
    }
  }
Exemple #3
0
  public void testAddTileLayer() throws Exception {

    when(tld.addLayer(same(tileLayer))).thenThrow(new IllegalArgumentException("fake"));
    when(tld.addLayer(same(tileLayerGroup))).thenReturn(config);

    try {
      mediator.add(tileLayer);
      fail("Expected IAE");
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    mediator.add(tileLayerGroup);
    verify(config, times(1)).save();
  }
Exemple #4
0
  @Test
  public void testReloadAndLayerRemovedExternally() throws Exception {

    final String removedLayer = tileLayer.getName();
    final String remainingLayer = tileLayerGroup.getName();

    final Set<String> layerNames = Sets.newHashSet(removedLayer, remainingLayer);

    when(tld.getLayerNames()).thenReturn(layerNames);
    doAnswer(
            new Answer<Void>() {

              @Override
              public Void answer(InvocationOnMock invocation) throws Throwable {
                layerNames.remove(removedLayer);
                return null;
              }
            })
        .when(tld)
        .reInit();

    ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class);

    mediator = spy(mediator);
    doReturn(true).when(mediator).layerRemoved(argCaptor.capture());

    mediator.reload();

    verify(tld, times(1)).reInit();
    assertEquals(1, argCaptor.getAllValues().size());
    assertEquals(removedLayer, argCaptor.getValue());
  }
  /** NB The following code is shared across Google Maps, Mobile Google Maps and Virtual Earth */
  public void handleRequest(ConveyorTile tile) throws GeoWebCacheException {
    if (tile.getHint() != null) {
      // boolean requestTiled = true;

      if (tile.getHint().equals("not_cached,not_metatiled")) {
        // requestTiled = false;
      } else if (!tile.getHint().equals("not_cached")) {
        throw new GeoWebCacheException("Hint " + tile.getHint() + " is not known.");
      }

      TileLayer tl = tld.getTileLayer(tile.getLayerId());

      if (tl == null) {
        throw new GeoWebCacheException("Unknown layer " + tile.getLayerId());
      }

      if (!tl.isCacheBypassAllowed().booleanValue()) {
        throw new GeoWebCacheException(
            "Layer " + tile.getLayerId() + " is not configured to allow bypassing the cache.");
      }

      tile.setTileLayer(tl);
      tl.getNoncachedTile(tile);

      Service.writeTileResponse(tile, false);
    }
  }
  private void serviceIdentification(StringBuilder str) {
    ServiceInformation servInfo = tld.getServiceInformation();

    str.append("<ows:ServiceIdentification>\n");

    if (servInfo != null) {
      appendTag(str, "  ", "ows:Title", servInfo.getTitle(), "Web Map Tile Service - GeoWebCache");
      appendTag(str, "  ", "ows:Abstract", servInfo.getDescription(), null);

      if (servInfo != null && servInfo.getKeywords() != null) {
        str.append("  <ows:Keywords>\n");
        Iterator<String> keywordIter = servInfo.getKeywords().iterator();
        while (keywordIter.hasNext()) {
          appendTag(str, "    ", "ows:Keyword", keywordIter.next(), null);
        }
        str.append("  </ows:Keywords>\n");
      }
    } else {
      str.append("  <ows:Title>Web Map Tile Service - GeoWebCache</ows:Title>\n");
    }

    str.append("  <ows:ServiceType>OGC WMTS</ows:ServiceType>\n");
    str.append("  <ows:ServiceTypeVersion>1.0.0</ows:ServiceTypeVersion>\n");

    if (servInfo != null) {
      appendTag(str, "  ", "ows:Fees", servInfo.getFees(), null);
      appendTag(str, "  ", "ows:AccessConstraints", servInfo.getAccessConstraints(), null);
    }

    str.append("</ows:ServiceIdentification>\n");
  }
Exemple #7
0
  @Test
  public void testRemoveTileLayers() throws Exception {
    try {
      mediator.removeTileLayers(null);
    } catch (NullPointerException e) {
      assertTrue(true);
    }

    when(tld.removeLayer(eq(tileLayer.getName()))).thenReturn(config);
    when(tld.removeLayer(eq(tileLayerGroup.getName()))).thenReturn(config);

    List<String> layerNames = Arrays.asList(tileLayer.getName(), tileLayerGroup.getName());
    mediator.removeTileLayers(layerNames);
    verify(tld, times(1)).removeLayer(eq(tileLayer.getName()));
    verify(tld, times(1)).removeLayer(eq(tileLayerGroup.getName()));
    verify(config, times(1)).save();
  }
Exemple #8
0
  private void mockTileLayerDispatcher() throws Exception {
    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    when(tld.getConfiguration(eq(tileLayer.getName()))).thenReturn(config);
    when(tld.getConfiguration(eq(tileLayerGroup.getName()))).thenReturn(config);

    when(tld.getTileLayer(eq(tileLayer.getName()))).thenReturn(tileLayer);
    when(tld.getTileLayer(eq(tileLayerGroup.getName()))).thenReturn(tileLayerGroup);

    when(tld.getLayerNames())
        .thenReturn(ImmutableSet.of(tileLayer.getName(), tileLayerGroup.getName()));
    Iterable<TileLayer> tileLayers =
        ImmutableList.of((TileLayer) tileLayer, (TileLayer) tileLayerGroup);
    when(tld.getLayerList()).thenReturn(tileLayers);

    when(tld.layerExists(eq(tileLayer.getName()))).thenReturn(true);
    when(tld.layerExists(eq(tileLayerGroup.getName()))).thenReturn(true);
  }
Exemple #9
0
  private GeoServerTileLayer mockTileLayer(String layerName, List<String> gridSetNames)
      throws Exception {

    GeoServerTileLayer tileLayer = mock(GeoServerTileLayer.class);
    when(tld.layerExists(eq(layerName))).thenReturn(true);
    when(tld.getTileLayer(eq(layerName))).thenReturn(tileLayer);
    when(tileLayer.getName()).thenReturn(layerName);
    when(tileLayer.isEnabled()).thenReturn(true);

    final MimeType mimeType1 = MimeType.createFromFormat("image/png");
    final MimeType mimeType2 = MimeType.createFromFormat("image/jpeg");
    when(tileLayer.getMimeTypes()).thenReturn(ImmutableList.of(mimeType1, mimeType2));

    Map<String, GridSubset> subsets = Maps.newHashMap();
    Multimap<SRS, GridSubset> bySrs = LinkedHashMultimap.create();

    GridSetBroker broker = gridSetBroker;

    for (String gsetName : gridSetNames) {
      GridSet gridSet = broker.get(gsetName);
      XMLGridSubset xmlGridSubset = new XMLGridSubset();
      String gridSetName = gridSet.getName();
      xmlGridSubset.setGridSetName(gridSetName);
      GridSubset gridSubSet = xmlGridSubset.getGridSubSet(broker);
      subsets.put(gsetName, gridSubSet);
      bySrs.put(gridSet.getSrs(), gridSubSet);

      when(tileLayer.getGridSubset(eq(gsetName))).thenReturn(gridSubSet);
    }
    for (SRS srs : bySrs.keySet()) {
      List<GridSubset> list = ImmutableList.copyOf(bySrs.get(srs));
      when(tileLayer.getGridSubsetsForSRS(eq(srs))).thenReturn(list);
    }
    when(tileLayer.getGridSubsets()).thenReturn(subsets.keySet());

    // sanity check
    for (String gsetName : gridSetNames) {
      assertTrue(tileLayer.getGridSubsets().contains(gsetName));
      assertNotNull(tileLayer.getGridSubset(gsetName));
    }

    return tileLayer;
  }
  private void serviceContact(StringBuilder str) {
    ServiceInformation servInfo = tld.getServiceInformation();
    if (servInfo == null) {
      return;
    }

    ServiceProvider servProv = servInfo.getServiceProvider();
    if (servProv == null) {
      return;
    }

    ServiceContact servCont = servProv.getServiceContact();

    str.append("  <ContactInformation>\n");

    if (servProv.getProviderName() != null || servCont != null) {
      str.append("    <ContactPersonPrimary>\n");
      if (servCont != null) {
        str.append("      <ContactPerson>" + servCont.getIndividualName() + "</ContactPerson>\n");
      }
      str.append(
          "      <ContactOrganization>" + servProv.getProviderName() + "</ContactOrganization>\n");
      str.append("    </ContactPersonPrimary>\n");

      if (servCont != null) {
        str.append("    <ContactPosition>" + servCont.getPositionName() + "</ContactPosition>\n");

        str.append("    <ContactAddress>\n");
        str.append("      <AddressType>" + servCont.getAddressType() + "</AddressType>\n");
        str.append("      <Address>" + servCont.getAddressStreet() + "</Address>\n");
        str.append("      <City>" + servCont.getAddressCity() + "</City>\n");
        str.append(
            "      <StateOrProvince>"
                + servCont.getAddressAdministrativeArea()
                + "</StateOrProvince>\n");
        str.append("      <PostCode>" + servCont.getAddressPostalCode() + "</PostCode>\n");
        str.append("      <Country>" + servCont.getAddressCountry() + "</Country>\n");
        str.append("    </ContactAddress>\n");
        str.append(
            "    <ContactVoiceTelephone>"
                + servCont.getPhoneNumber()
                + "</ContactVoiceTelephone>\n");
        str.append("    <ContactFacsimileTelephone>")
            .append(servCont.getFaxNumber())
            .append("</ContactFacsimileTelephone>\n");
        str.append(
            "    <ContactElectronicMailAddress>"
                + servCont.getAddressEmail()
                + "</ContactElectronicMailAddress>\n");
      }
    }

    str.append("  </ContactInformation>\n");
  }
Exemple #11
0
  @Test
  public void testRemoveAllLayerGridsetsDisablesLayer() throws Exception {

    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    when(tld.modify(same(tileLayer))).thenReturn(config);
    when(tld.modify(same(tileLayerGroup))).thenReturn(config);
    when(tld.removeGridset(eq("EPSG:4326"))).thenReturn(config);
    when(tld.removeGridset(eq("EPSG:900913"))).thenReturn(config);

    // sanity check before modification
    assertTrue(tileLayer.getInfo().isEnabled());
    assertTrue(tileLayer.getInfo().isEnabled());

    mediator.removeGridSets(ImmutableSet.of("EPSG:900913", "EPSG:4326"));

    verify(config, times(1)).save(); // all other checks are in testRemoveGridsets
    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326"));
    verify(storageBroker, times(1))
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913"));
    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326"));
    verify(storageBroker, times(1))
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913"));

    assertTrue(tileLayer.getGridSubsets().isEmpty());
    assertTrue(tileLayerGroup.getGridSubsets().isEmpty());

    // layers ended up with no gridsubsets, shall have been disabled
    assertFalse(tileLayer.getInfo().isEnabled());
    assertFalse(tileLayerGroup.getInfo().isEnabled());
  }
  private void serviceProvider(StringBuilder str) {
    ServiceInformation servInfo = tld.getServiceInformation();
    ServiceProvider servProv = null;
    if (servInfo != null) {
      servProv = servInfo.getServiceProvider();
    }
    str.append("<ows:ServiceProvider>\n");

    if (servProv != null) {
      appendTag(str, "  ", "ows:ProviderName", servProv.getProviderName(), null);

      if (servProv.getProviderSite() != null) {
        appendXlink(str, "  ", "ows:ProviderSite", servProv.getProviderSite());
      }

      ServiceContact servCont = servProv.getServiceContact();
      if (servCont != null) {
        str.append("  <ows:ServiceContact>\n");
        appendTag(str, "    ", "ows:IndividualName", servCont.getIndividualName(), null);
        appendTag(str, "    ", "ows:PositionName", servCont.getPositionName(), null);
        str.append("    <ows:ContactInfo>\n");

        if (servCont.getPhoneNumber() != null || servCont.getFaxNumber() != null) {
          str.append("      <ows:Phone>\n");
          appendTag(str, "      ", "ows:Voice", servCont.getPhoneNumber(), null);
          appendTag(str, "      ", "ows:Facsimile", servCont.getFaxNumber(), null);
          str.append("      </ows:Phone>\n");
        }

        str.append("      <ows:Address>\n");
        appendTag(str, "      ", "ows:DeliveryPoint", servCont.getAddressStreet(), null);
        appendTag(str, "      ", "ows:City", servCont.getAddressCity(), null);
        appendTag(
            str, "      ", "ows:AdministrativeArea", servCont.getAddressAdministrativeArea(), null);
        appendTag(str, "      ", "ows:PostalCode", servCont.getAddressPostalCode(), null);
        appendTag(str, "      ", "ows:Country", servCont.getAddressCountry(), null);
        appendTag(str, "      ", "ows:ElectronicMailAddress", servCont.getAddressEmail(), null);
        str.append("      </ows:Address>\n");

        str.append("    </ows:ContactInfo>\n");
        str.append("  </ows:ServiceContact>\n");
      }
    } else {
      appendTag(str, "  ", "ows:ProviderName", baseUrl, null);
      appendXlink(str, "  ", "ows:ProviderSite", baseUrl);
      str.append("  <ows:ServiceContact>\n");
      appendTag(str, "    ", "ows:IndividualName", "GeoWebCache User", null);
      str.append("  </ows:ServiceContact>\n");
    }

    str.append("</ows:ServiceProvider>\n");
  }
Exemple #13
0
  @Test
  public void testTruncateLayerFully() throws Exception {

    when(tld.getTileLayer(eq(tileLayerGroup.getName())))
        .thenThrow(new GeoWebCacheException("fake"));

    mediator.truncate(tileLayerGroup.getName());
    verify(storageBroker, never()).deleteByGridSetId(anyString(), anyString());

    mediator.truncate(tileLayer.getName());
    verify(storageBroker, times(tileLayer.getGridSubsets().size()))
        .deleteByGridSetId(anyString(), anyString());
  }
Exemple #14
0
  @Test
  public void testModifyGridsetNoNeedToTruncate() throws Exception {
    final String oldName = "EPSG:4326";
    final String newName = "MyEPSG:4326";

    final GridSet oldGridset = gridSetBroker.get(oldName);
    final GridSet newGridset;
    {
      XMLGridSet xmlGridSet = new XMLGridSet(oldGridset);
      xmlGridSet.setName(newName);
      newGridset = xmlGridSet.makeGridSet();
    }

    XMLConfiguration xmlConfig = mock(XMLConfiguration.class);
    mediator = spy(mediator);
    when(mediator.getXmlConfiguration()).thenReturn(xmlConfig);

    assertNotNull(tileLayer.getGridSubset(oldName));
    assertNotNull(tileLayerGroup.getGridSubset(oldName));

    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    mediator.modifyGridSet(oldName, newGridset);

    assertNull(tileLayer.getGridSubset(oldName));
    assertNull(tileLayerGroup.getGridSubset(oldName));
    assertNotNull(tileLayer.getGridSubset(newName));
    assertNotNull(tileLayerGroup.getGridSubset(newName));

    verify(xmlConfig, times(1)).removeGridset(eq(oldName));
    verify(xmlConfig, times(1)).addOrReplaceGridSet(eq(new XMLGridSet(newGridset)));
    verify(xmlConfig, times(1)).save();

    assertNull(gridSetBroker.get(oldName));
    assertEquals(newGridset, gridSetBroker.get(newName));

    verify(config, times(1)).save();
  }
Exemple #15
0
  @Test
  public void testDispatchGetMapDoesntMatchTileCache() throws Exception {
    GetMapRequest request = new GetMapRequest();

    @SuppressWarnings("unchecked")
    Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>());
    request.setRawKvp(rawKvp);

    rawKvp.put("layers", "more,than,one,layer");
    assertDispatchMismatch(request, "more than one layer requested");

    rawKvp.put("layers", "SomeNonCachedLayer");
    when(tld.getTileLayer(eq("SomeNonCachedLayer")))
        .thenThrow(new GeoWebCacheException("layer not found"));
    assertDispatchMismatch(request, "not a tile layer");

    rawKvp.put("layers", tileLayer.getName());

    request.setFormat("badFormat");
    assertDispatchMismatch(request, "not a GWC supported format");

    request.setFormat("image/gif");
    assertDispatchMismatch(request, "no tile cache for requested format");
    request.setFormat(tileLayer.getMimeTypes().get(0).getMimeType());

    request.setSRS("EPSG:4326");
    request.setBbox(new Envelope(10, 10, 20, 20));
    assertDispatchMismatch(request, "request does not align to grid");

    request.setSRS("EPSG:23036");
    assertDispatchMismatch(request, "no cache exists for requested CRS");

    request.setSRS("badCRS");
    assertDispatchMismatch(request, "exception occurred");
    request.setSRS("EPSG:4326");

    request.setWidth(128);
    request.setHeight(256);
    assertDispatchMismatch(request, "request does not align to grid");

    request.setWidth(256);
    request.setHeight(128);
    assertDispatchMismatch(request, "request does not align to grid");

    request.setSRS("EPSG:4326");
    request.setWidth(256);
    request.setHeight(256);
    assertDispatchMismatch(request, "request does not align to grid");
  }
Exemple #16
0
  @Test
  public void testAutoConfigureLayers() throws Exception {
    {
      GWCConfig insaneDefaults = new GWCConfig();
      insaneDefaults.setMetaTilingX(-1);
      assertFalse(insaneDefaults.isSane());
      try {
        mediator.autoConfigureLayers(Arrays.asList(tileLayer.getName()), insaneDefaults);
      } catch (IllegalArgumentException e) {
        assertTrue(true);
      }
    }

    try {
      mediator.autoConfigureLayers(Arrays.asList(tileLayer.getName()), defaults);
      fail("expected IAE, layer exists");
    } catch (IllegalArgumentException e) {
      assertTrue(true);
    }

    LayerInfo layer2 = mockLayer("layer2", new String[] {}, PublishedType.RASTER);
    LayerGroupInfo group2 = mockGroup("group2", layer, layer2);

    when(catalog.getLayerByName(eq(tileLayerName(layer2)))).thenReturn(layer2);
    when(catalog.getLayerGroupByName(eq(tileLayerName(group2)))).thenReturn(group2);

    List<String> layerNames = Arrays.asList(tileLayerName(layer2), tileLayerName(group2));

    when(tld.addLayer(any(GeoServerTileLayer.class))).thenReturn(config);
    mediator.autoConfigureLayers(layerNames, defaults);

    GeoServerTileLayerInfo expected1 =
        new GeoServerTileLayer(layer2, defaults, gridSetBroker).getInfo();
    GeoServerTileLayerInfo expected2 =
        new GeoServerTileLayer(group2, defaults, gridSetBroker).getInfo();

    ArgumentCaptor<GeoServerTileLayer> addCaptor =
        ArgumentCaptor.forClass(GeoServerTileLayer.class);

    verify(tld, times(2)).addLayer(addCaptor.capture());
    verify(config, times(2)).save();

    GeoServerTileLayerInfo actual1 = addCaptor.getAllValues().get(0).getInfo();
    GeoServerTileLayerInfo actual2 = addCaptor.getAllValues().get(1).getInfo();

    assertEquals(expected1, actual1);
    assertEquals(expected2, actual2);
  }
  private void contents(StringBuilder str) {
    str.append("<Contents>\n");
    Iterable<TileLayer> iter = tld.getLayerList();
    for (TileLayer layer : iter) {
      if (!layer.isEnabled()) {
        continue;
      }
      layer(str, layer, baseUrl);
    }

    for (GridSet gset : gsb.getGridSets()) {
      tileMatrixSet(str, gset);
    }

    str.append("</Contents>\n");
  }
Exemple #18
0
  protected WMSTileFuser(TileLayerDispatcher tld, StorageBroker sb, HttpServletRequest servReq)
      throws GeoWebCacheException {
    this.sb = sb;

    String[] keys = {
      "layers", "format", "srs", "bbox", "width", "height", "transparent", "bgcolor"
    };

    Map<String, String> values =
        ServletUtils.selectedStringsFromMap(
            servReq.getParameterMap(), servReq.getCharacterEncoding(), keys);

    // TODO Parameter filters?

    String layerName = values.get("layers");
    layer = tld.getTileLayer(layerName);

    List<MimeType> ml = layer.getMimeTypes();
    Iterator<MimeType> iter = ml.iterator();
    while (iter.hasNext()) {
      MimeType mt = iter.next();
      if (mt.getInternalName().equalsIgnoreCase("png")) {
        this.srcFormat = (ImageMime) mt;
      }
    }

    gridSubset = layer.getGridSubsetForSRS(SRS.getSRS(values.get("srs")));

    outputFormat = (ImageMime) ImageMime.createFromFormat(values.get("format"));

    reqBounds = new BoundingBox(values.get("bbox"));

    reqWidth = Integer.valueOf(values.get("width"));

    reqHeight = Integer.valueOf(values.get("height"));

    // if(values[6] != null) {
    // this.reqTransparent = Boolean.valueOf(values[6]);
    // }

    // if(values[7] != null) {
    // this.reqBgColor = values[7];
    // }

    fullParameters =
        layer.getModifiableParameters(servReq.getParameterMap(), servReq.getCharacterEncoding());
  }
Exemple #19
0
  @Test
  public void testRemoveGridsets() throws Exception {
    try {
      mediator.removeGridSets(null);
      fail();
    } catch (NullPointerException e) {
      assertTrue(true);
    }

    {
      final GridSet oldGridset = gridSetBroker.get("EPSG:4326");
      final GridSet newGridset;
      XMLGridSet xmlGridSet = new XMLGridSet(oldGridset);
      xmlGridSet.setName("My4326");
      // make it a bit different
      xmlGridSet.setAlignTopLeft(!xmlGridSet.getAlignTopLeft());
      newGridset = xmlGridSet.makeGridSet();
      gridSetBroker.put(newGridset);
    }

    when(tld.getConfiguration(same(tileLayer))).thenReturn(config);
    when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config);
    when(tld.modify(same(tileLayer))).thenReturn(config);
    when(tld.modify(same(tileLayerGroup))).thenReturn(config);
    when(tld.removeGridset(eq("EPSG:4326"))).thenReturn(config);
    when(tld.removeGridset(eq("My4326"))).thenReturn(config);

    mediator.removeGridSets(ImmutableSet.of("My4326", "EPSG:4326"));

    assertEquals(ImmutableSet.of("EPSG:900913"), tileLayer.getGridSubsets());
    assertEquals(ImmutableSet.of("EPSG:900913"), tileLayerGroup.getGridSubsets());

    verify(storageBroker, times(1)).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:4326"));
    verify(storageBroker, times(1))
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:4326"));

    verify(storageBroker, never()).deleteByGridSetId(eq(tileLayer.getName()), eq("EPSG:900913"));
    verify(storageBroker, never()).deleteByGridSetId(eq(tileLayer.getName()), eq("My4326"));
    verify(storageBroker, never())
        .deleteByGridSetId(eq(tileLayerGroup.getName()), eq("EPSG:900913"));
    verify(storageBroker, never()).deleteByGridSetId(eq(tileLayerGroup.getName()), eq("My4326"));

    verify(tld, times(1)).modify(same(tileLayer));
    verify(tld, times(1)).modify(same(tileLayerGroup));
    verify(tld, times(1)).removeGridset(eq("EPSG:4326"));
    verify(tld, times(1)).removeGridset(eq("My4326"));
    // all these modifications, and a single save()
    verify(config, times(1)).save();
  }
  private void capabilityRequestGetFeatureInfo(StringBuilder str) {

    // Find all the info formats we support
    Iterable<TileLayer> layerIter = tld.getLayerList();

    HashSet<String> formats = new HashSet<String>();

    for (TileLayer layer : layerIter) {
      if (!layer.isEnabled()) {
        continue;
      }
      if (layer.getMimeTypes() != null) {
        Iterator<MimeType> mimeIter = layer.getInfoMimeTypes().iterator();
        while (mimeIter.hasNext()) {
          MimeType mime = mimeIter.next();
          formats.add(mime.getFormat());
        }
      } else {
        formats.add("text/plain");
        formats.add("text/html");
        formats.add("application/vnd.ogc.gml");
      }
    }

    str.append("    <GetFeatureInfo>\n");
    Iterator<String> formatIter = formats.iterator();
    while (formatIter.hasNext()) {
      str.append("      <Format>" + formatIter.next() + "</Format>\n");
    }
    str.append("      <DCPType>\n");
    str.append("        <HTTP>\n");
    str.append("        <Get>\n");
    str.append(
        "          <OnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\""
            + urlStr
            + "\"/>\n");
    str.append("        </Get>\n");
    str.append("        </HTTP>\n");
    str.append("      </DCPType>\n");
    str.append("    </GetFeatureInfo>\n");
  }
  private void validateLayerQuota(DiskQuotaConfig quotaConfig, LayerQuota lq)
      throws ConfigurationException {
    String layer = lq.getLayer();
    try {
      tileLayerDispatcher.getTileLayer(layer);
    } catch (GeoWebCacheException e) {
      log.error(
          "LayerQuota configuration error: layer "
              + layer
              + " does not exist. Removing quota from runtime configuration.",
          e);
      quotaConfig.remove(lq);
    }

    final ExpirationPolicy expirationPolicyName = lq.getExpirationPolicyName();
    if (expirationPolicyName == null) {
      // if expiration policy is not defined, then there should be no quota defined either,
      // as it means the layer is managed by the global expiration policy, if any
      if (lq.getQuota() != null) {
        throw new ConfigurationException(
            "Layer "
                + lq.getLayer()
                + " has no expiration policy, but does have a quota defined. "
                + "Either both or neither should be present");
      }
      return;
    }

    Quota quota = lq.getQuota();
    try {
      validateQuota(quota);
    } catch (ConfigurationException e) {
      log.error(
          "LayerQuota configuration error for layer "
              + layer
              + ". Error message is: "
              + e.getMessage()
              + ". Quota removed from runtime configuration.");
      quotaConfig.remove(lq);
    }
  }
  private void capabilityLayerOuter(StringBuilder str) {
    str.append("  <Layer>\n");
    str.append("    <Title>GeoWebCache WMS</Title>\n");
    str.append(
        "    <Abstract>Note that not all GeoWebCache instances provide a full WMS service.</Abstract>\n");
    str.append(
        "    <LatLonBoundingBox minx=\"-180.0\" miny=\"-90.0\" maxx=\"180.0\" maxy=\"90.0\"/>\n");

    Iterable<TileLayer> layerIter = tld.getLayerList();
    for (TileLayer layer : layerIter) {
      if (!layer.isEnabled()) {
        continue;
      }
      try {
        capabilityLayerInner(str, layer);
      } catch (GeoWebCacheException e) {
        log.error(e.getMessage());
      }
    }

    str.append("  </Layer>\n");
  }
  private void capabilityVendorSpecific(StringBuilder str) {
    str.append("  <VendorSpecificCapabilities>\n");
    Iterable<TileLayer> layerIter = tld.getLayerList();
    for (TileLayer layer : layerIter) {
      if (!layer.isEnabled()) {
        continue;
      }

      for (String gridSetId : layer.getGridSubsets()) {
        GridSubset grid = layer.getGridSubset(gridSetId);

        List<String> formats = new ArrayList<String>(2);

        if (layer.getMimeTypes() != null) {
          for (MimeType mime : layer.getMimeTypes()) {
            formats.add(mime.getFormat());
          }
        } else {
          formats.add(ImageMime.png.getFormat());
          formats.add(ImageMime.jpeg.getFormat());
        }

        List<String> styles = getStyles(layer.getParameterFilters());
        for (String format : formats) {
          for (String style : styles) {
            try {
              capabilityVendorSpecificTileset(str, layer, grid, format, style);
            } catch (GeoWebCacheException e) {
              log.error(e.getMessage());
            }
          }
        }
      }
    }
    str.append("  </VendorSpecificCapabilities>\n");
  }
  private void service(StringBuilder str) {
    ServiceInformation servInfo = tld.getServiceInformation();
    str.append("<Service>\n");
    str.append("  <Name>OGC:WMS</Name>\n");

    if (servInfo == null) {
      str.append("  <Title>Web Map Service - GeoWebCache</Title>\n");
    } else {
      str.append("  <Title>" + servInfo.getTitle() + "</Title>\n");
      str.append("  <Abstract>" + servInfo.getDescription() + "</Abstract>\n");

      if (servInfo.getKeywords() != null) {
        str.append("  <KeywordList>\n");
        Iterator<String> keywordIter = servInfo.getKeywords().iterator();
        while (keywordIter.hasNext()) {
          str.append("    <Keyword>" + keywordIter.next() + "</Keyword>\n");
        }
        str.append("  </KeywordList>\n");
      }
    }

    str.append(
        "  <OnlineResource xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:type=\"simple\" xlink:href=\""
            + urlStr
            + "\"/>\n");

    serviceContact(str);

    if (servInfo != null) {
      str.append("  <Fees>" + servInfo.getFees() + "</Fees>\n");
      str.append(
          "  <AccessConstraints>" + servInfo.getAccessConstraints() + "</AccessConstraints>\n");
    }

    str.append("</Service>\n");
  }
Exemple #25
0
  private static String tableRows(
      TileLayerDispatcher tileLayerDispatcher, GridSetBroker gridSetBroker)
      throws GeoWebCacheException {
    StringBuffer buf = new StringBuffer();

    Set<String> layerList = new TreeSet<String>(tileLayerDispatcher.getLayerNames());
    for (String layerName : layerList) {
      TileLayer layer = tileLayerDispatcher.getTileLayer(layerName);
      buf.append(
          "<tr><td style=\"min-width: 100px;\"><strong>" + layer.getName() + "</strong><br />\n");
      buf.append("<a href=\"rest/seed/" + layer.getName() + "\">Seed this layer</a>\n");
      buf.append("</td><td>" + layer.isEnabled() + "</td>");
      buf.append("<td><table width=\"100%\">");

      int count = 0;
      for (String gridSetId : layer.getGridSubsets()) {
        GridSubset gridSubset = layer.getGridSubset(gridSetId);
        String gridSetName = gridSubset.getName();
        if (gridSetName.length() > 20) {
          gridSetName = gridSetName.substring(0, 20) + "...";
        }
        buf.append("<tr><td style=\"width: 170px;\">").append(gridSetName);

        buf.append("</td><td>OpenLayers: [");
        Iterator<MimeType> mimeIter = layer.getMimeTypes().iterator();
        boolean prependComma = false;
        while (mimeIter.hasNext()) {
          MimeType mime = mimeIter.next();
          if (mime instanceof ImageMime) {
            if (prependComma) {
              buf.append(", ");
            } else {
              prependComma = true;
            }
            buf.append(generateDemoUrl(layer.getName(), gridSubset.getName(), (ImageMime) mime));
          }
        }
        buf.append("]</td><td>\n");

        if (gridSubset.getName().equals(gridSetBroker.WORLD_EPSG4326.getName())) {
          buf.append(" &nbsp; KML: [");
          String prefix = "";
          prependComma = false;
          Iterator<MimeType> kmlIter = layer.getMimeTypes().iterator();
          while (kmlIter.hasNext()) {
            MimeType mime = kmlIter.next();
            if (mime instanceof ImageMime || mime == XMLMime.kml) {
              if (prependComma) {
                buf.append(", ");
              } else {
                prependComma = true;
              }
              buf.append(
                  "<a href=\""
                      + prefix
                      + "service/kml/"
                      + layer.getName()
                      + "."
                      + mime.getFileExtension()
                      + ".kml\">"
                      + mime.getFileExtension()
                      + "</a>");
            } else if (mime == XMLMime.kmz) {
              if (prependComma) {
                buf.append(", ");
              } else {
                prependComma = true;
              }
              buf.append(
                  "<a href=\"" + prefix + "service/kml/" + layer.getName() + ".kml.kmz\">kmz</a>");
            }
          }
          buf.append("]");
        } else {
          // No Google Earth support
        }
        buf.append("</td></tr>");
        count++;
      }

      // if(count == 0) {
      // buf.append("<tr><td colspan=\"2\"><i>None</i></td></tr>\n");
      // }

      buf.append("</table></td>\n");
      buf.append("</tr>\n");
    }

    return buf.toString();
  }
Exemple #26
0
  public static void makeMap(
      TileLayerDispatcher tileLayerDispatcher,
      GridSetBroker gridSetBroker,
      String action,
      HttpServletRequest request,
      HttpServletResponse response)
      throws GeoWebCacheException {

    String page = null;

    // Do we have a layer, or should we make a list?
    if (action != null) {
      String layerName = ServletUtils.URLDecode(action, request.getCharacterEncoding());

      TileLayer layer = tileLayerDispatcher.getTileLayer(layerName);

      String rawGridSet = request.getParameter("gridSet");
      String gridSetStr = null;
      if (rawGridSet != null)
        gridSetStr = ServletUtils.URLDecode(rawGridSet, request.getCharacterEncoding());

      if (gridSetStr == null) {
        gridSetStr = request.getParameter("srs");

        if (gridSetStr == null) {
          gridSetStr = layer.getGridSubsets().iterator().next();
        }
      }

      String formatStr = request.getParameter("format");

      if (formatStr != null) {
        if (!layer.supportsFormat(formatStr)) {
          throw new GeoWebCacheException("Unknow or unsupported format " + formatStr);
        }
      } else {
        formatStr = layer.getDefaultMimeType().getFormat();
      }

      if (request.getPathInfo().startsWith("/demo")) {
        // Running in GeoServer
        page = generateHTML(layer, gridSetStr, formatStr, true);
      } else {
        page = generateHTML(layer, gridSetStr, formatStr, false);
      }

    } else {
      if (request.getRequestURI().endsWith("/")) {
        try {
          String reqUri = request.getRequestURI();
          response.sendRedirect(
              response.encodeRedirectURL(reqUri.substring(0, reqUri.length() - 1)));
        } catch (IOException e) {
          e.printStackTrace();
        }
        return;
      } else {
        page = generateHTML(tileLayerDispatcher, gridSetBroker);
      }
    }
    response.setContentType("text/html");
    response.setCharacterEncoding("UTF-8");

    try {
      response.getOutputStream().write(page.getBytes());
    } catch (IOException ioe) {
      throw new GeoWebCacheException("failed to render HTML");
    }
  }