Example #1
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());
  }
  @Test
  public void testGetFeatureInfoQueryLayers() throws MimeException {

    // a layer with no query layers
    WMSLayer l = createFeatureInfoLayer("a,b", null);
    assertNotNull(l.getWmsLayers());
    assertNull(l.getWmsQueryLayers());
    Map<String, String> rt =
        l.getWMSRequestTemplate(MimeType.createFromFormat("text/plain"), RequestType.FEATUREINFO);
    assertEquals(l.getWmsLayers(), rt.get("QUERY_LAYERS"));

    // a layer with query layers
    l = createFeatureInfoLayer("a,b", "b");
    assertNotNull(l.getWmsLayers());
    assertNotNull(l.getWmsQueryLayers());
    rt = l.getWMSRequestTemplate(MimeType.createFromFormat("text/plain"), RequestType.FEATUREINFO);
    assertEquals(l.getWmsQueryLayers(), rt.get("QUERY_LAYERS"));
  }
Example #3
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 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");
  }
  public ConveyorTile getConveyor(HttpServletRequest request, HttpServletResponse response)
      throws ServiceException {
    String layerId = super.getLayersParameter(request);

    String encoding = request.getCharacterEncoding();

    Map<String, String[]> params = request.getParameterMap();
    String strFormat = ServletUtils.stringFromMap(params, encoding, "format");
    String strZoom = ServletUtils.stringFromMap(params, encoding, "zoom");
    String strX = ServletUtils.stringFromMap(params, encoding, "x");
    String strY = ServletUtils.stringFromMap(params, encoding, "y");
    String strCached = ServletUtils.stringFromMap(params, encoding, "cached");
    String strMetaTiled = ServletUtils.stringFromMap(params, encoding, "metatiled");

    long[] gridLoc =
        GMapsConverter.convert(
            Integer.parseInt(strZoom), Integer.parseInt(strX), Integer.parseInt(strY));

    MimeType mimeType = null;
    try {
      if (strFormat == null) {
        strFormat = "image/png";
      }
      mimeType = MimeType.createFromFormat(strFormat);
    } catch (MimeException me) {
      throw new ServiceException("Unable to determine requested format, " + strFormat);
    }

    ConveyorTile ret =
        new ConveyorTile(
            sb,
            layerId,
            gsb.WORLD_EPSG3857.getName(),
            gridLoc,
            mimeType,
            null,
            null,
            request,
            response);

    if (strCached != null && !Boolean.parseBoolean(strCached)) {
      ret.setRequestHandler(ConveyorTile.RequestHandler.SERVICE);

      if (strMetaTiled != null && !Boolean.parseBoolean(strMetaTiled)) {
        ret.setHint("not_cached,not_metatiled");
      } else {
        ret.setHint("not_cached");
      }
    }

    return ret;
  }
  /**
   * @see
   *     org.geoserver.wms.ExtendedCapabilitiesProvider#encode(org.geoserver.wms.ExtendedCapabilitiesProvider.Translator,
   *     org.geoserver.wms.WMSInfo, org.geotools.util.Version)
   */
  public void encode(final Translator tx, final WMSInfo wms, final GetCapabilitiesRequest request)
      throws IOException {
    Version version = WMS.version(request.getVersion(), true);
    if (!WMS.VERSION_1_1_1.equals(version) || !isTiled(request)) {
      return;
    }

    String namespacePrefixFilter = request.getNamespace();
    Iterable<TileLayer> tileLayers = gwc.getTileLayersByNamespacePrefix(namespacePrefixFilter);

    for (TileLayer layer : tileLayers) {

      Set<String> layerGrids = layer.getGridSubsets();

      for (String gridId : layerGrids) {
        GridSubset grid = layer.getGridSubset(gridId);
        for (MimeType mime : layer.getMimeTypes()) {
          vendorSpecificTileset(tx, layer, grid, mime.getFormat());
        }
      }
    }
  }
  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");
  }
  /**
   * Initializes the layer, creating internal structures for calculating grid location and so forth.
   *
   * <p>Subclasses shall implement {@link #initializeInternal(GridSetBroker)} for anything else
   */
  @Override
  public final boolean initialize(GridSetBroker gridSetBroker) {

    if (this.expireCacheList == null) {
      this.expireCacheList = new ArrayList<ExpirationRule>(1);

      if (this.expireCache == null) {
        expireCacheList.add(new ExpirationRule(0, GWCVars.CACHE_NEVER_EXPIRE));
      } else {
        int expireCacheInt = Integer.parseInt(expireCache);
        if (expireCacheInt == GWCVars.CACHE_USE_WMS_BACKEND_VALUE) {
          saveExpirationHeaders = true;
        }
        expireCacheList.add(new ExpirationRule(0, expireCacheInt));
      }
    }

    if (this.expireClientsList == null) {
      this.expireClientsList = new ArrayList<ExpirationRule>(1);

      if (this.expireClients == null) {
        expireClientsList.add(new ExpirationRule(0, 7200));
      } else {
        int expireClientsInt = Integer.parseInt(expireClients);

        if (expireClientsInt == GWCVars.CACHE_USE_WMS_BACKEND_VALUE) {
          saveExpirationHeaders = true;
        } else if (expireClientsInt == GWCVars.CACHE_NEVER_EXPIRE) {
          // One year should do
          expireClientsInt = 3600 * 24 * 365;
        }
        expireClientsList.add(new ExpirationRule(0, expireClientsInt));
      }
    }

    try {
      // mimetypes
      this.formats = new ArrayList<MimeType>();
      if (mimeFormats != null) {
        for (String fmt : mimeFormats) {
          formats.add(MimeType.createFromFormat(fmt));
        }
      }
      if (formats.size() == 0) {
        formats.add(0, MimeType.createFromFormat("image/png"));
        formats.add(1, MimeType.createFromFormat("image/jpeg"));
      }
    } catch (GeoWebCacheException gwce) {
      log.error(gwce.getMessage());
      gwce.printStackTrace();
    }

    if (subSets == null) {
      subSets = new HashMap<String, GridSubset>();
    }

    if (this.gridSubsets != null) {
      Iterator<XMLGridSubset> iter = gridSubsets.iterator();
      while (iter.hasNext()) {
        XMLGridSubset xmlGridSubset = iter.next();
        GridSubset gridSubset = xmlGridSubset.getGridSubSet(gridSetBroker);

        if (gridSubset == null) {
          log.error(
              xmlGridSubset.getGridSetName()
                  + " is not known by the GridSetBroker, skipping for layer "
                  + name);
        } else {
          subSets.put(gridSubset.getName(), gridSubset);
        }
      }

      this.gridSubsets = null;
    }

    // Convert version 1.1.x and 1.0.x grid objects
    if (grids != null && !grids.isEmpty()) {
      Iterator<XMLOldGrid> iter = grids.values().iterator();
      while (iter.hasNext()) {
        GridSubset converted = iter.next().convertToGridSubset(gridSetBroker);
        subSets.put(converted.getSRS().toString(), converted);
      }

      // Null it for the garbage collector
      grids = null;
    }

    if (this.subSets.size() == 0) {
      subSets.put(
          gridSetBroker.WORLD_EPSG4326.getName(),
          GridSubsetFactory.createGridSubSet(gridSetBroker.WORLD_EPSG4326));
      subSets.put(
          gridSetBroker.WORLD_EPSG3857.getName(),
          GridSubsetFactory.createGridSubSet(gridSetBroker.WORLD_EPSG3857));
    }

    return initializeInternal(gridSetBroker);
  }
Example #9
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();
  }