Package org.geowebcache.conveyor

Examples of org.geowebcache.conveyor.ConveyorTile


        HttpServletRequest req = mock(HttpServletRequest.class);
        MockHttpServletResponse resp = new MockHttpServletResponse();
        when(req.getCharacterEncoding()).thenReturn("UTF-8");
        when(req.getParameterMap()).thenReturn(kvp);

        ConveyorTile conv = service.getConveyor(req, resp);
        assertNotNull(conv);
        assertEquals(Conveyor.RequestHandler.SERVICE, conv.reqHandler);
        assertNotNull(conv.getLayerId());
        assertEquals(layerName, conv.getLayerId());
        assertTrue(!conv.getFullParameters().isEmpty());
        assertEquals(timeValue, conv.getFullParameters().get("TIME"));
    }
View Full Code Here


    throws GeoWebCacheException {
       
        for(int i=0;i<linkGridLocs.length; i++) {
            if(linkGridLocs[i][2] > 0) {
               
                ConveyorTile tile = new ConveyorTile(sb,
                        tileLayer.getName(), gridSetId,
                        linkGridLocs[i], mime, null, null, null);
               
                tile.setTileLayer(tileLayer);
               
                // Apply request filters
                try {
                    tileLayer.applyRequestFilters(tile);
                } catch(GreenTileException e) {
                    // We will link to this one
                } catch(RequestFilterException e) {
                    linkGridLocs[i][2] = -1;
                    continue;
                }
               
                // Special treatment for regionated KML
                if (mime.equals(XMLMime.kml)) {
                    try {
                        tileLayer.getTile(tile);
                    } catch (IOException ioe) {
                        log.error(ioe.getMessage());
                        linkGridLocs[i][2] = -1;
                    } catch (GeoWebCacheException gwce) {
                        linkGridLocs[i][2] = -1;
                    }

                    // If it's a 204 it means no content -> don't link to it
                    if (tile.getStatus() == 204) {
                        linkGridLocs[i][2] = -1;
                    } else if (tile.getStatus() != 200) {
                        throw new GeoWebCacheException(
                                "Unexpected response code from server "
                                + tile.getStatus());
                    }
                }
            }
        }
       
View Full Code Here

       
        int paramsLength = params.length;
       
        if(params.length < 4) {
            // Not a tile request, lets pass it back out
            ConveyorTile tile = new ConveyorTile(sb, null, request, response);
            tile.setRequestHandler(ConveyorTile.RequestHandler.SERVICE);
            return tile;
        }
       
        long[] gridLoc = new long[3];
       
        String[] yExt = params[paramsLength - 1].split("\\.");
       
        try {
            gridLoc[0] = Integer.parseInt(params[paramsLength - 2]);
            gridLoc[1] = Integer.parseInt(yExt[0]);
            gridLoc[2] = Integer.parseInt(params[paramsLength - 3]);
        } catch (NumberFormatException nfe) {
            throw new ServiceException("Unable to parse number " + nfe.getMessage() + " from " + pathInfo);
        }

        String layerId;
        String gridSetId;
       
        // For backwards compatibility, we'll look for @s and use defaults if not found
        String layerNameAndSRS = params[2];
        String[] lsf = ServletUtils.URLDecode(layerNameAndSRS, request.getCharacterEncoding()).split("@");
        if(lsf.length < 3) {
            layerId = lsf[0];
            TileLayer layer = tld.getTileLayer(layerId);
            gridSetId = layer.getGridSubsets().iterator().next();
        } else {
           layerId = lsf[0];
           gridSetId = lsf[1];
           // We don't actually care about the format, we'll pick it from the extension
        }

        MimeType mimeType = null;
        try {
            mimeType = MimeType.createFromExtension(yExt[1]);
        } catch (MimeException me) {
            throw new ServiceException("Unable to determine requested format based on extension " + yExt[1]);
        }

        ConveyorTile ret = new ConveyorTile(sb, layerId, gridSetId, gridLoc, mimeType, null, request, response);
       
        return ret;
    }
View Full Code Here

        if (conv.reqHandler == Conveyor.RequestHandler.SERVICE) {
            // A3 The service object takes it from here
            service.handleRequest(conv);

        } else {
            ConveyorTile convTile = (ConveyorTile) conv;

            // B3) Get the configuration that has to respond to this request
            TileLayer layer = tileLayerDispatcher.getTileLayer(layerName);

            // Save it for later
            convTile.setTileLayer(layer);

            // Apply the filters
            layer.applyRequestFilters(convTile);

            // Keep the URI
View Full Code Here

        GridSubset gridSubset = getGridSubset(tileGridSetId);
        // Final preflight check, throws exception if necessary
        gridSubset.checkCoverage(gridLoc);

        ConveyorTile returnTile;

        tile.setMetaTileCacheOnly(!gridSubset.shouldCacheAtZoom(gridLoc[2]));
        try {
            if (tryCacheFetch(tile)) {
                returnTile = finalizeTile(tile);
View Full Code Here

        while (gridLoc != null && this.terminate == false) {

            checkInterrupted();
            Map<String, String> fullParameters = tr.getParameters();

            ConveyorTile tile = new ConveyorTile(storageBroker, layerName, tr.getGridSetId(), gridLoc,
                    tr.getMimeType(), fullParameters, null, null);

            for (int fetchAttempt = 0; fetchAttempt <= tileFailureRetryCount; fetchAttempt++) {
                try {
                    checkInterrupted();
                    tl.seedTile(tile, tryCache);
                    break;// success, let it go
                } catch (Exception e) {
                    // if GWC_SEED_RETRY_COUNT was not set then none of the settings have effect, in
                    // order to keep backwards compatibility with the old behaviour
                    if (tileFailureRetryCount == 0) {
                        if (e instanceof GeoWebCacheException) {
                            throw (GeoWebCacheException) e;
                        }
                        throw new GeoWebCacheException(e);
                    }

                    long sharedFailureCount = sharedFailureCounter.incrementAndGet();
                    if (sharedFailureCount >= totalFailuresBeforeAborting) {
                        log.info("Aborting seed thread " + Thread.currentThread().getName()
                                + ". Error count reached configured maximum of "
                                + totalFailuresBeforeAborting);
                        super.state = GWCTask.STATE.DEAD;
                        return;
                    }
                    String logMsg = "Seed failed at " + tile.toString() + " after "
                            + (fetchAttempt + 1) + " of " + (tileFailureRetryCount + 1)
                            + " attempts.";
                    if (fetchAttempt < tileFailureRetryCount) {
                        log.debug(logMsg);
                        if (tileFailureRetryWaitTime > 0) {
View Full Code Here

            long startx = srcRectangle[0];
            for (long gridx = startx; gridx <= srcRectangle[2]; gridx++) {

                long[] gridLoc = { gridx, gridy, srcIdx };

                ConveyorTile tile = new ConveyorTile(sb, layer.getName(), gridSubset.getName(),
                        gridLoc, srcFormat, fullParameters, null, null);

                // Check whether this tile is to be rendered at all
                try {
                    layer.applyRequestFilters(tile);
                } catch (RequestFilterException e) {
                    log.debug(e.getMessage(),e);
                    continue;
                }

                layer.getTile(tile);
                // Selection of the resource input stream
                Resource blob = tile.getBlob();
                // Extraction of the image associated with the defined MimeType
                String formatName = srcFormat.getMimeType();
                BufferedImage tileImg = decoderMap.decode(formatName, blob,
                        decoderMap.isAggressiveInputStreamSupported(formatName), null);
View Full Code Here

                filteringParameters = tileLayer.getModifiableParameters(requestParameterMap,
                        encoding);
            }

            // Creation of a Conveyor Tile with a fake Image/png format and the associated parameters.
            ConveyorTile tile = new ConveyorTile(sb, layers, null, null,
                    ImageMime.png, filteringParameters, request, response);
            tile.setHint(req.toLowerCase());
            tile.setRequestHandler(ConveyorTile.RequestHandler.SERVICE);
            return tile;
        }
        if (layers == null) {
            throw new ServiceException("Unable to parse layers parameter from request.");
        }

        // Check whether this request is missing tiled=true
        final boolean tiled = Boolean.valueOf(values.get("tiled"));
        if (proxyNonTiledRequests && tiled) {
            ConveyorTile tile = new ConveyorTile(sb, layers, request, response);
            tile.setHint(req);
            tile.setRequestHandler(Conveyor.RequestHandler.SERVICE);
            return tile;
        }

        String[] paramKeys = { "format", "srs", "bbox" };
        final Map<String, String> paramValues = ServletUtils.selectedStringsFromMap(
                requestParameterMap, encoding, paramKeys);

        final Map<String, String> fullParameters = tileLayer.getModifiableParameters(
                requestParameterMap, encoding);

        final MimeType mimeType;
        String format = paramValues.get("format");
        try {
            mimeType = MimeType.createFromFormat(format);
        } catch (MimeException me) {
            throw new ServiceException("Unable to determine requested format, " + format);
        }

        final SRS srs;
        {
            String requestSrs = paramValues.get("srs");
            if (requestSrs == null) {
                throw new ServiceException("No SRS specified");
            }
            srs = SRS.getSRS(requestSrs);
        }

        final BoundingBox bbox;
        {
            String requestBbox = paramValues.get("bbox");
            try {
                bbox = new BoundingBox(requestBbox);
                if (bbox == null || !bbox.isSane()) {
                    throw new ServiceException("The bounding box parameter (" + requestBbox
                            + ") is missing or not sane");
                }
            } catch (NumberFormatException nfe) {
                throw new ServiceException("The bounding box parameter (" + requestBbox
                        + ") is invalid");
            }
        }

        final int tileWidth = Integer.parseInt(values.get("width"));
        final int tileHeight = Integer.parseInt(values.get("height"));

        final List<GridSubset> crsMatchingSubsets = tileLayer.getGridSubsetsForSRS(srs);
        if (crsMatchingSubsets.isEmpty()) {
            throw new ServiceException("Unable to match requested SRS " + srs
                    + " to those supported by layer");
        }

        long[] tileIndexTarget = new long[3];
        GridSubset gridSubset;
        {
            GridSubset bestMatch = findBestMatchingGrid(bbox, crsMatchingSubsets, tileWidth,
                    tileHeight, tileIndexTarget);
            if (bestMatch == null) {
                // proceed as it used to be
                gridSubset = crsMatchingSubsets.get(0);
                tileIndexTarget = null;
            } else {
                gridSubset = bestMatch;
            }
        }
       
        if (fullWMS) {
            // If we support full WMS we need to do a few tests to determine whether
            // this is a request that requires us to recombine tiles to respond.
            long[] tileIndex = null;
            if (tileIndexTarget == null) {
                try {
                    tileIndex = gridSubset.closestIndex(bbox);
                } catch (GridMismatchException gme) {
                    // Do nothing, the null is info enough
                }
            } else {
                tileIndex = tileIndexTarget;
            }

            if (tileIndex == null || gridSubset.getTileWidth() != tileWidth
                    || gridSubset.getTileHeight() != tileHeight
                    || !bbox.equals(gridSubset.boundsFromIndex(tileIndex), 0.02)) {
                log.debug("Recombinining tiles to respond to WMS request");
                ConveyorTile tile = new ConveyorTile(sb, layers, request, response);
                tile.setHint("getmap");
                tile.setRequestHandler(ConveyorTile.RequestHandler.SERVICE);
                return tile;
            }
        }

        long[] tileIndex = tileIndexTarget == null ? gridSubset.closestIndex(bbox)
                : tileIndexTarget;

        gridSubset.checkTileDimensions(tileWidth, tileHeight);

        return new ConveyorTile(sb, layers, gridSubset.getName(), tileIndex, mimeType,
                fullParameters, request, response);
    }
View Full Code Here

                fullParameters, request, response);
    }

    public void handleRequest(Conveyor conv) throws GeoWebCacheException {

        ConveyorTile tile = (ConveyorTile) conv;
       
        String servletPrefix=null;
        if (controller!=null) servletPrefix=controller.getServletPrefix();
       
        String servletBase = ServletUtils.getServletBaseURL(conv.servletReq, servletPrefix);
        String context = ServletUtils.getServletContextPath(conv.servletReq, SERVICE_PATH, servletPrefix);

        if (tile.getHint() != null) {
            if (tile.getHint().equalsIgnoreCase("getcapabilities")) {
                WMSGetCapabilities wmsCap = new WMSGetCapabilities(tld, tile.servletReq, servletBase, context, urlMangler);
                wmsCap.writeResponse(tile.servletResp);
            } else if (tile.getHint().equalsIgnoreCase("getmap")) {
                WMSTileFuser wmsFuser = new WMSTileFuser(tld, sb, tile.servletReq);
                // Setting of the applicationContext
                wmsFuser.setApplicationContext(utility.getApplicationContext());
                // Setting of the hintConfiguration if present
                wmsFuser.setHintsConfiguration(hintsConfig);
                try {
                    wmsFuser.writeResponse(tile.servletResp, stats);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } else if (tile.getHint().equalsIgnoreCase("getfeatureinfo")) {
                handleGetFeatureInfo(tile);
            } else {
                // see if we can proxy the request
                TileLayer tl = tld.getTileLayer(tile.getLayerId());

                if(tl == null) {
                    throw new GeoWebCacheException(tile.getLayerId() + " is unknown.");
                }
               
                if(tl instanceof ProxyLayer) {
                    ((ProxyLayer) tl).proxyRequest(tile);
                } else {
                    throw new GeoWebCacheException(tile.getLayerId() + " cannot cascade WMS requests.");
                }
            }
        } else {
            throw new GeoWebCacheException("The WMS Service would love to help, "
                    + "but has no idea what you're trying to do?"
View Full Code Here

        if (mimeType != null && !tl.getInfoMimeTypes().contains(mimeType)) {
            throw new GeoWebCacheException("The info_format parameter ("
                    + values.get("info_format") + ") is not supported.");
        }

        ConveyorTile gfiConv = new ConveyorTile(sb, tl.getName(), gridSubset.getName(), null,
                mimeType, tile.getFullParameters(), tile.servletReq, tile.servletResp);
        gfiConv.setTileLayer(tl);

        int x, y;
        try {
            x = Integer.parseInt(values.get("x"));
            y = Integer.parseInt(values.get("y"));
View Full Code Here

TOP

Related Classes of org.geowebcache.conveyor.ConveyorTile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.