Package org.geowebcache

Examples of org.geowebcache.GeoWebCacheException


        try {
            gsDispatcher.handleRequest(req, resp);
        } catch (Exception e) {
            log.fine(e.getMessage());
           
            throw new GeoWebCacheException("Problem communicating with GeoServer" + e.getMessage());
        }
       
        if(super.mimeStringCheck(expectedMimeType, resp.getContentType())) {
            int responseCode = resp.getResponseCode();
            tileRespRecv.setStatus(responseCode);
            if(responseCode == 200) {
                byte[] bytes = resp.getBytes();
               
                log.finer("Received " + bytes.length);
               
                return bytes;
            } else if(responseCode == 204) {
                return new byte[0];
            } else {
                throw new GeoWebCacheException("Unexpected response from GeoServer for request "
                        + wmsParams + ", got response code " + responseCode);
            }
        } else {
            log.severe("Unexpected response from GeoServer for request: " + wmsParams);
           
            throw new GeoWebCacheException("Unexpected response from GeoServer for request " + wmsParams);
        }
    }
View Full Code Here


       
        long[] gridRect = gridSubset.getCoverageBestFit();
       
        // Check whether we need two tiles for world bounds or not
        if(gridRect[4] > 0 && (gridRect[2] != gridRect[0] || gridRect[3] != gridRect[1])) {
            throw new GeoWebCacheException(
                    layer.getName() + " is too big for the sub grid set for "
                    + gridSubset.getName() + ", allow for smaller zoom levels.");
        } else if(gridRect[0] != gridRect[2]) {
            long[] gridLocWest = {0,0,0};
            long[] gridLocEast = {1,0,0};
View Full Code Here

        URL wmsBackendUrl = null;

        final Integer backendTimeout = layer.getBackendTimeout();
        int backendTries = 0; // keep track of how many backends we have tried
        GeoWebCacheException fetchException = null;
        while (target.getSize() == 0 && backendTries < layer.getWMSurl().length) {
            String requestUrl = layer.nextWmsURL();

            try {
                wmsBackendUrl = new URL(requestUrl);
            } catch (MalformedURLException maue) {
                throw new GeoWebCacheException("Malformed URL: " + requestUrl + " "
                        + maue.getMessage());
            }
            try {
                connectAndCheckHeaders(tileRespRecv, wmsBackendUrl, wmsParams, expectedMimeType,
                        backendTimeout, target);
            } catch (GeoWebCacheException e) {
                fetchException = e;
            }

            backendTries++;
        }

        if (target.getSize() == 0) {
            String msg = "All backends (" + backendTries + ") failed.";
            if (fetchException != null) {
                msg += " Reason: " + fetchException.getMessage() + ". ";
            }
            msg += " Last request: '"
                    + wmsBackendUrl.toString()
                    + "'. "
                    + (tileRespRecv.getErrorMessage() == null ? "" : tileRespRecv.getErrorMessage());

            tileRespRecv.setError();
            tileRespRecv.setErrorMessage(msg);
            throw new GeoWebCacheException(msg);
        }
    }
View Full Code Here

            } catch (IOException ce) {
                if (log.isDebugEnabled()) {
                    String message = "Error forwarding request " + wmsBackendUrl.toString();
                    log.debug(message, ce);
                }
                throw new GeoWebCacheException(ce);
            }
            // Check that the response code is okay
            tileRespRecv.setStatus(responseCode);
            if (responseCode != 200 && responseCode != 204) {
                tileRespRecv.setError();
                throw new ServiceException("Unexpected response code from backend: " + responseCode
                        + " for " + wmsBackendUrl.toString());
            }

            // Check that we're not getting an error MIME back.
            String responseMime = getMethod.getResponseHeader("Content-Type").getValue();
            if (responseCode != 204 && responseMime != null
                    && !mimeStringCheck(requestMime, responseMime)) {
                String message = null;
                if (responseMime.equalsIgnoreCase(ErrorMime.vnd_ogc_se_inimage.getFormat())) {
                    // TODO: revisit: I don't understand why it's trying to create a String message
                    // out of an ogc_se_inimage response?
                    InputStream stream = null;
                    try {
                        stream = getMethod.getResponseBodyAsStream();
                        byte[] error = IOUtils.toByteArray(stream);
                        message = new String(error);
                    } catch (IOException ioe) {
                        // Do nothing
                    } finally {
                        IOUtils.closeQuietly(stream);
                    }
                } else if (responseMime != null
                        && responseMime.toLowerCase().startsWith("application/vnd.ogc.se_xml")) {
                    InputStream stream = null;
                    try {
                        stream = getMethod.getResponseBodyAsStream();
                        message = IOUtils.toString(stream);
                    } catch (IOException e) {
                        //
                    } finally {
                        IOUtils.closeQuietly(stream);
                    }
                }
                String msg = "MimeType mismatch, expected " + requestMime + " but got "
                        + responseMime + " from " + wmsBackendUrl.toString()
                        + (message == null ? "" : (":\n" + message));
                tileRespRecv.setError();
                tileRespRecv.setErrorMessage(msg);
                log.warn(msg);
            }

            // Everything looks okay, try to save expiration
            if (tileRespRecv.getExpiresHeader() == GWCVars.CACHE_USE_WMS_BACKEND_VALUE) {
                String expireValue = getMethod.getResponseHeader("Expires").getValue();
                long expire = ServletUtils.parseExpiresHeader(expireValue);
                if (expire != -1) {
                    tileRespRecv.setExpiresHeader(expire / 1000);
                }
            }

            // Read the actual data
            if (responseCode != 204) {
                try {
                    InputStream inStream = getMethod.getResponseBodyAsStream();
                    ReadableByteChannel channel = Channels.newChannel(inStream);
                    try {
                        target.transferFrom(channel);
                    } finally {
                        channel.close();
                    }
                    if (responseLength > 0) {
                        int readAccu = (int) target.getSize();
                        if (readAccu != responseLength) {
                            tileRespRecv.setError();
                            throw new GeoWebCacheException("Responseheader advertised "
                                    + responseLength + " bytes, but only received " + readAccu
                                    + " from " + wmsBackendUrl.toString());
                        }
                    }
                } catch (IOException ioe) {
View Full Code Here

                handleGetFeatureInfo(tile);
            } else {
                WMSRequests.handleProxy(tld, tile);
            }
        } else {
            throw new GeoWebCacheException("The WMS Service would love to help, "
                    + "but has no idea what you're trying to do?"
                    + "Please include request URL if you file a bug report.");
        }
    }
View Full Code Here

     */
    private void handleGetFeatureInfo(ConveyorTile tile) throws GeoWebCacheException {
        TileLayer tl = tld.getTileLayer(tile.getLayerId());

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

        String[] keys = { "x", "y", "srs", "info_format", "bbox", "height", "width" };
        Map<String, String> values = ServletUtils.selectedStringsFromMap(
                tile.servletReq.getParameterMap(), tile.servletReq.getCharacterEncoding(), keys);

        // TODO Arent we missing some format stuff here?
        GridSubset gridSubset = tl.getGridSubsetForSRS(SRS.getSRS(values.get("srs")));

        BoundingBox bbox = null;
        try {
            bbox = new BoundingBox(values.get("bbox"));
        } catch (NumberFormatException nfe) {
            log.debug(nfe.getMessage());
        }

        if (bbox == null || !bbox.isSane()) {
            throw new ServiceException("The bounding box parameter (" + values.get("srs")
                    + ") is missing or not sane");
        }

        // long[] tileIndex = gridSubset.closestIndex(bbox);

        MimeType mimeType;
        try {
            mimeType = MimeType.createFromFormat(values.get("info_format"));
        } catch (MimeException me) {
            throw new GeoWebCacheException("The info_format parameter ("
                    + values.get("info_format") + ")is missing or not recognized.");
        }

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

        int x, y;
        try {
            x = Integer.parseInt(values.get("x"));
            y = Integer.parseInt(values.get("y"));
        } catch (NumberFormatException nfe) {
            throw new GeoWebCacheException(
                    "The parameters for x and y must both be positive integers.");
        }

        int height, width;
        try {
            height = Integer.parseInt(values.get("height"));
            width = Integer.parseInt(values.get("width"));
        } catch (NumberFormatException nfe) {
            throw new GeoWebCacheException(
                    "The parameters for height and width must both be positive integers.");
        }

        Resource data = tl.getFeatureInfo(gfiConv, bbox, height, width, x, y);

View Full Code Here

        if (mime == null) {
            mime = this.formats.get(0);
        }

        if (!formats.contains(mime)) {
            throw new GeoWebCacheException(mime.getFormat() + " is not a supported format for "
                    + name);
        }

        String tileGridSetId = tile.getGridSetId();
View Full Code Here

            }

            sourceHelper.makeRequest(metaTile, buffer);

            if (metaTile.getError()) {
                throw new GeoWebCacheException("Empty metatile, error message: "
                        + metaTile.getErrorMessage());
            }

            if (saveExpirationHeaders) {
                // Converting to seconds
View Full Code Here

        ByteArrayResource buffer = getImageBuffer(WMS_BUFFER);
        sourceHelper.makeRequest(tile, buffer);

        if (tile.getError() || buffer.getSize() == 0) {
            throw new GeoWebCacheException("Empty tile, error message: " + tile.getErrorMessage());
        }

        tile.setBlob(buffer);
        return tile;
    }
View Full Code Here

            if(layer.getName().equals(layerName)) {
                return layer;
            }
        }
       
        throw new GeoWebCacheException("Layer " + layerName +
                " not found, set has " + layers.size() + " layers.");
    }
View Full Code Here

TOP

Related Classes of org.geowebcache.GeoWebCacheException

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.