Package org.vfny.geoserver.wcs

Examples of org.vfny.geoserver.wcs.WcsException


          }
        }
        GeoServerInfo gsInfo = request.getServiceConfig().getGeoServer().getGlobal();
  long geoUS = gsInfo.getUpdateSequence();
      if (reqUS > geoUS) {
        throw new WcsException("Client supplied an updateSequence that is greater than the current sever updateSequence", WcsExceptionCode.InvalidUpdateSequence, "");
      }
      if (reqUS == geoUS) {
        throw new WcsException("WCS capabilities document is current (updateSequence = " + geoUS + ")", WcsExceptionCode.CurrentUpdateSequence, "");
      }
      //otherwise it's a normal response...

        WCSCapsTransformer transformer = new WCSCapsTransformer(request
        .getBaseUrl(), applicationContext);

        transformer.setIndentation(2);
        transformer.setEncoding(Charset.forName(gsInfo.getCharset()));
       
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try {
            transformer.transform(request, out);
        } catch (TransformerException e) {
            throw new WcsException(e);
        }

        this.rawResponse = out.toByteArray();
    }
View Full Code Here


            // freeing everything
            writer.dispose();
            this.sourceCoverage.dispose(false);
            this.sourceCoverage = null;
        } catch (Exception e) {
            throw new WcsException(new StringBuffer("Problems Rendering Image").append(
                    e.getMessage()).toString(), e);
        }
    }
View Full Code Here

        intersectionEnvelope.setCoordinateReferenceSystem(sourceCRS);
        intersectionEnvelope.intersect((GeneralEnvelope) sourceEnvelope);

        // dow we have something to show?
        if (intersectionEnvelope.isEmpty()) {
            throw new WcsException("The Intersection is null. Check the requested BBOX!");
        }

        if (!intersectionEnvelope.equals((GeneralEnvelope) sourceEnvelope)) {
            // get the cropped grid geometry
            // final GridGeometry2D cropGridGeometry = getCroppedGridGeometry(
View Full Code Here

        GetCoverageType request = (GetCoverageType) operation.getParameters()[0];
        String outputFormat = request.getOutput().getFormat();
        CoverageResponseDelegate delegate = CoverageResponseDelegateFactory
                .encoderFor(outputFormat);
        if (delegate == null)
            throw new WcsException("Could not find encoder for output format " + outputFormat);

        // grab the coverage info for Coverages document encoding
        final GridCoverage2D coverage = (GridCoverage2D) coverages[0];
        CoverageInfo coverageInfo = catalog.getCoverageByName(request.getIdentifier().getValue());

        // use javamail classes to actually encode the document
        try {
            // coverages xml structure (always set the headers after the data
            // handlers, setting
            // the data handlers kills some of them)
            BodyPart coveragesPart = new MimeBodyPart();
            final CoveragesData coveragesData = new CoveragesData(coverageInfo, request);
            coveragesPart.setDataHandler(new DataHandler(coveragesData, "geoserver/coverages"));
            coveragesPart.setHeader("Content-ID", "<urn:ogc:wcs:1.1:coverages>");
            coveragesPart.setHeader("Content-Type", "text/xml");
            multipart.addBodyPart(coveragesPart);

            // the actual coverage
            BodyPart coveragePart = new MimeBodyPart();
            delegate.prepare(outputFormat, coverage);
            coveragePart.setDataHandler(new DataHandler(delegate, "geoserver/coverageDelegate"));
            coveragePart.setHeader("Content-ID", "<theCoverage>");
            coveragePart.setHeader("Content-Type", delegate.getContentType());
            coveragePart.setHeader("Content-Transfer-Encoding", "base64");
            multipart.addBodyPart(coveragePart);

            // write out the multipart (we need to use mime message trying to
            // encode directly with multipart or BodyPart does not set properly
            // the encodings and binary files gets ruined
            MimeMessage message = new GeoServerMimeMessage();
            message.setContent(multipart);
            message.writeTo(output);
            output.flush();
        } catch (MessagingException e) {
            throw new WcsException("Error occurred while encoding the mime multipart response", e);
        }
    }
View Full Code Here

                            if (selectedBands.size() == 0) {
                                throw new Exception("WRONG PARAM VALUES.");
                            }
                        }
                    } catch (Exception e) {
                        throw new WcsException("Band parameters incorrectly specified: "
                            + e.getLocalizedMessage());
                    }
                }
            }
        }
View Full Code Here

        GetCoverageType request = (GetCoverageType) operation.getParameters()[0];
        String outputFormat = request.getOutput().getFormat();
        CoverageResponseDelegate delegate = CoverageResponseDelegateFactory
                .encoderFor(outputFormat);
        if (delegate == null)
            throw new WcsException("Could not find encoder for output format " + outputFormat);

        // grab the coverage info for Coverages document encoding
        final GridCoverage2D coverage = (GridCoverage2D) coverages[0];
        CoverageInfo coverageInfo = catalog.getCoverageByName(request.getIdentifier().getValue());
       
        // write the coverage to temporary storage in the data dir
        File wcsStore = null;
        try {
            File temp = GeoserverDataDirectory.findCreateConfigDir("temp");
            wcsStore = new File(temp, "wcs");
            if(!wcsStore.exists())
                wcsStore.mkdir();
        } catch(Exception e) {
            throw new WcsException("Could not create the temporary storage directory for WCS");
        }
       
        // Make sure we create a file name that's not already there (even if splitting the same nanosecond
        // with two requests should not ever happen...)
        File coverageFile = null;
        while(true) {
            // TODO: find a way to get good extensions
            coverageFile = new File(wcsStore, coverageInfo.getName().replace(':', '_') + "_" + System.nanoTime() + "." + delegate.getFileExtension());
            if(!coverageFile.exists())
                break;
        }
      
        // store the coverage
        OutputStream os = null;
        try {
            os = new BufferedOutputStream(new FileOutputStream(coverageFile));
            delegate.prepare(outputFormat, coverage);
            delegate.encode(os);
            os.flush();
        } finally {
            if(os != null) os.close();
        }
        System.out.println(coverageFile);
       
        // build the path where the clients will be able to retrieve the coverage files
        final String coverageLocation = buildURL(request.getBaseUrl(),
                appendPath("temp/wcs", coverageFile.getName()), null, URLType.RESOURCE);
       
        // build the response
        CoveragesTransformer tx = new CoveragesTransformer(wcs, request, coverageLocation);
        try {
            tx.transform(coverageInfo, output);
        } catch (TransformerException e) {
            throw new WcsException("Failure trying to encode Coverages response", e);
        }
    }
View Full Code Here

            long requestedUpdateSequence = -1;
            if (request.getUpdateSequence() != null) {
                try {
                    requestedUpdateSequence = Long.parseLong(request.getUpdateSequence());
                } catch (NumberFormatException e) {
                    throw new WcsException("Invalid update sequence number format, "
                            + "should be an integer", WcsExceptionCode.InvalidUpdateSequence,
                            "updateSequence");
                }
                if (requestedUpdateSequence > updateSequence) {
                    throw new WcsException("Invalid update sequence value, it's higher "
                            + "than the current value, " + updateSequence,
                            WcsExceptionCode.InvalidUpdateSequence, "updateSequence");
                }
            }

            final AttributesImpl attributes = new AttributesImpl();
            attributes.addAttribute("", "version", "version", "", CUR_VERSION);
            attributes.addAttribute("", "xmlns:wcs", "xmlns:wcs", "", WCS_URI);

            attributes.addAttribute("", "xmlns:xlink", "xmlns:xlink", "",
                    "http://www.w3.org/1999/xlink");
            attributes.addAttribute("", "xmlns:ogc", "xmlns:ogc", "", "http://www.opengis.net/ogc");
            attributes.addAttribute("", "xmlns:ows", "xmlns:ows", "",
                    "http://www.opengis.net/ows/1.1");
            attributes.addAttribute("", "xmlns:gml", "xmlns:gml", "", "http://www.opengis.net/gml");

            final String prefixDef = new StringBuffer("xmlns:").append(XSI_PREFIX).toString();
            attributes.addAttribute("", prefixDef, prefixDef, "", XSI_URI);

            final String locationAtt = new StringBuffer(XSI_PREFIX).append(":schemaLocation")
                    .toString();

            final String locationDef = buildSchemaURL(request.getBaseUrl(), "wcs/1.1.1/wcsGetCapabilities.xsd");
           
            attributes.addAttribute("", locationAtt, locationAtt, "", locationDef);
            attributes.addAttribute("", "updateSequence", "updateSequence", "", String
                    .valueOf(updateSequence));
            start("wcs:Capabilities", attributes);

            // handle the sections directive
            boolean allSections;
            List<String> sections;
            if (request.getSections() == null) {
                allSections = true;
                sections = Collections.emptyList();
            } else {
                sections = request.getSections().getSection();
                allSections = sections.contains("All");
            }
            final Set<String> knownSections = new HashSet<String>(Arrays.asList(
                    "ServiceIdentification", "ServiceProvider", "OperationsMetadata", "Contents",
                    "All"));
            for (String section : sections) {
                if(!knownSections.contains(section))
                    throw new WcsException("Unknown section " + section,
                            WcsExceptionCode.InvalidParameterValue, "Sections");
            }

            // encode the actual capabilities contents taking into consideration
            // the sections
View Full Code Here

        intersectionEnvelope.setCoordinateReferenceSystem(sourceCRS);
        intersectionEnvelope.intersect((GeneralEnvelope) sourceEnvelope);

        // dow we have something to show?
        if (intersectionEnvelope.isEmpty()) {
            throw new WcsException("The Intersection is null. Check the requested BBOX!");
        }

        if (!intersectionEnvelope.equals((GeneralEnvelope) sourceEnvelope)) {
            // get the cropped grid geometry
            // final GridGeometry2D cropGridGeometry = getCroppedGridGeometry(
View Full Code Here

                String coverageId = (String) it.next();

                // check the coverage is known
                LayerInfo layer = catalog.getLayerByName(coverageId);
                if (layer == null || layer.getType() != LayerInfo.Type.RASTER) {
                    throw new WcsException("Could not find the specified coverage: " + coverageId,
                            WcsExceptionCode.InvalidParameterValue, "coverage");
                }

                CoverageInfo ci = catalog.getCoverageByName(coverageId);
                try {
View Full Code Here

        private void handleLonLatEnvelope(CoverageInfo ci, ReferencedEnvelope referencedEnvelope) {

            CoverageStoreInfo csinfo = ci.getStore();
           
            if(csinfo == null)
                throw new WcsException("Unable to acquire coverage store resource for coverage: " + ci.getName());
           
            AbstractGridCoverage2DReader reader = null;
            try {
                reader = (AbstractGridCoverage2DReader) ci.getGridCoverageReader(null, GeoTools.getDefaultHints());
            } catch (IOException e) {
                LOGGER.severe("Unable to acquire a reader for this coverage with format: " + csinfo.getFormat().getName());
            }
           
            if(reader == null)
                throw new WcsException("Unable to acquire a reader for this coverage with format: " + csinfo.getFormat().getName());

            final String[] metadataNames = reader.getMetadataNames();
           

            String timeMetadata = null;
View Full Code Here

TOP

Related Classes of org.vfny.geoserver.wcs.WcsException

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.