@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 #2
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;
  }
  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;
  }
  /**
   * 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);
  }