Package org.geoserver.wps

Examples of org.geoserver.wps.WPSException


                                refInput = conn.getInputStream();
                            }
                            post.setRequestEntity(new InputStreamRequestEntity(refInput, ppio
                                    .getMimeType()));
                        } else {
                            throw new WPSException("A POST request should contain a non empty body");
                        }
                    } else if (body instanceof String) {
                        post.setRequestEntity(new StringRequestEntity((String) body, ppio
                                .getMimeType(), encoding));
                    } else {
                        throw new WPSException(
                                "The request body should be contained in a CDATA section, "
                                        + "otherwise it will get parsed as XML instead of being preserved as is");

                    }
                    method = post;
                }
                // add eventual extra headers
                if (ref.getHeader() != null) {
                    for (Iterator it = ref.getHeader().iterator(); it.hasNext();) {
                        HeaderType header = (HeaderType) it.next();
                        method.setRequestHeader(header.getKey(), header.getValue());
                    }
                }
                int code = client.executeMethod(method);

                if (code == 200) {
                    input = method.getResponseBodyAsStream();
                } else {
                    throw new WPSException("Error getting remote resources from " + ref.getHref()
                            + ", http error " + code + ": " + method.getStatusText());
                }
            } else {
                // use the normal url connection methods then...
                URLConnection conn = destination.openConnection();
                conn.setConnectTimeout(executor.getConnectionTimeout());
                conn.setReadTimeout(executor.getConnectionTimeout());
                input = conn.getInputStream();
            }

            // actually parse teh data
            if (input != null) {
                return ppio.decode(input);
            } else {
                throw new WPSException("Could not find a mean to read input " + inputId);
            }
        } finally {
            // make sure to close the connection and streams no matter what
            if (input != null) {
                input.close();
View Full Code Here


        Map original = new KvpMap(KvpUtils.parseQueryString(href));
        KvpUtils.normalize(original);
        Map parsed = new KvpMap(original);
        List<Throwable> errors = KvpUtils.parse(parsed);
        if (errors.size() > 0) {
            throw new WPSException("Failed to parse KVP request", errors.get(0));
        }

        // hack to allow wcs filters to work... we should really upgrade the WCS models instead...
        Request r = Dispatcher.REQUEST.get();
        if (r != null) {
View Full Code Here

        Configuration config  = null;

        try {
            config = (Configuration)(this.getXMLConfiguration().getConstructor().newInstance());
        } catch(Exception e) {
            throw new WPSException("NoApplicableCode", "Failed to initialize XMLConfiguration");
        }

        org.geotools.xml.Parser parser = new org.geotools.xml.Parser(config);

        try {
            decoded = (Geometry)parser.parse(stream);
        } catch(Exception e) {
            throw new WPSException("NoApplicableCode", "Parsing error " + e);
        }

        return decoded;
    }
View Full Code Here

     *
     * @param input
     * @return
     */
    public Object encode(Object input) {
        throw new WPSException("NoApplicableCode", "Unimplemented encoder for ComplexTransmuter.");
    }
View Full Code Here

          String targetSRSCode = null;
          if (srs != null) {
            try {
              Integer code = CRS.lookupEpsgCode(srs, true);
              if (code == null) {
                throw new WPSException("Could not find a EPSG code for " + srs);
              }
              targetSRSCode = "EPSG:" + code;
            } catch (Exception e) {
              throw new ProcessException("Could not lookup the EPSG code for the provided srs", e);
            }
          } else {
            // check we can extract a code from the original data
            GeometryDescriptor gd = features.getSchema().getGeometryDescriptor();
            if (gd == null) {
              // data is geometryless, we need a fake SRS
              targetSRSCode = "EPSG:4326";
              srsHandling = ProjectionPolicy.FORCE_DECLARED;
            } else {
              CoordinateReferenceSystem nativeCrs = gd.getCoordinateReferenceSystem();
              if (nativeCrs == null) {
                throw new ProcessException("The original data has no native CRS, "
                    + "you need to specify the srs parameter");
              } else {
                try {
                  Integer code = CRS.lookupEpsgCode(nativeCrs, true);
                  if (code == null) {
                    throw new ProcessException("Could not find an EPSG code for data "
                        + "native spatial reference system: " + nativeCrs);
                  } else {
                    targetSRSCode = "EPSG:" + code;
                  }
                } catch (Exception e) {
                  throw new ProcessException("Failed to loookup an official EPSG code for "
                      + "the source data native " + "spatial reference system", e);
                }
              }
            }
          }

          // import the data into the target store
          SimpleFeatureType targetType;
          try {
            targetType = importDataIntoStore(features, name, (DataStoreInfo) storeInfo);
          } catch (IOException e) {
            throw new ProcessException("Failed to import data into the target store", e);
          }

          // now import the newly created layer into GeoServer
          try {
            cb.setStore(storeInfo);

            // build the typeInfo and set CRS if necessary
            FeatureTypeInfo typeInfo = cb.buildFeatureType(targetType.getName());
            if (targetSRSCode != null) {
              typeInfo.setSRS(targetSRSCode);
            }
            if (srsHandling != null) {
              typeInfo.setProjectionPolicy(srsHandling);
            }
            // compute the bounds
            cb.setupBounds(typeInfo);

            // build the layer and set a style
            LayerInfo layerInfo = cb.buildLayer(typeInfo);
            if (targetStyle != null) {
              layerInfo.setDefaultStyle(targetStyle);
            }

            catalog.add(typeInfo);
            catalog.add(layerInfo);

            return layerInfo.prefixedName();
          } catch (Exception e) {
            throw new ProcessException(
                "Failed to complete the import inside the GeoServer catalog", e);
          }
        }
        else if (coverage != null)
        {
          try {
            final File directory = catalog.getResourceLoader().findOrCreateDirectory("data", workspace, store);
            final File file = File.createTempFile(store, ".tif", directory);
                ((CoverageStoreInfo)storeInfo).setURL( file.toURL().toExternalForm() );
                ((CoverageStoreInfo)storeInfo).setType("GeoTIFF");
               
              // check the target crs
                CoordinateReferenceSystem cvCrs = coverage.getCoordinateReferenceSystem();
                String targetSRSCode = null;
              if (srs != null) {
                try {
                  Integer code = CRS.lookupEpsgCode(srs, true);
                  if (code == null) {
                    throw new WPSException("Could not find a EPSG code for " + srs);
                  }
                  targetSRSCode = "EPSG:" + code;
                } catch (Exception e) {
                  throw new ProcessException("Could not lookup the EPSG code for the provided srs", e);
                }
View Full Code Here

            // try with the typical Oracle mangling
            targetType = ds.getSchema(sourceType.getTypeName().toUpperCase());
        }

        if (targetType == null) {
            throw new WPSException(
                    "The target schema was created, but with a name "
                            + "that we cannot relate to the one we provided the data store. Cannot proceeed further");
        } else {
            // check the layer is not already there
            String newLayerName = storeInfo.getWorkspace().getName() + ":"
View Full Code Here

        Double decoded;

        try {
            decoded = Double.valueOf(encoded);
        } catch(NumberFormatException e) {
            throw new WPSException("InvalidParameterType", "Could not convert paramter to object.");
        }

        return decoded;
    }
View Full Code Here

       
        // grab the process, we need it to parse the data inputs
        Name processName = Ows11Util.name(execute.getIdentifier());
        ProcessFactory pf = GeoServerProcessors.createProcessFactory(processName);
        if (pf == null) {
            throw new WPSException("No such process: " + processName);
        }

        // parse inputs
        List<InputType> inputs = parseDataInputs(pf.getParameterInfo(processName), (String) rawKvp.get("DataInputs"));
        DataInputsType1 input1 = factory.createDataInputsType1();
        input1.getInput().addAll(inputs);
        execute.setDataInputs(input1);
       
        if(rawKvp.containsKey("responseDocument")) {
            execute.setResponseForm(parseResponseDocument(pf.getResultInfo(processName, null), (String) rawKvp.get("responseDocument")));
        } else if(rawKvp.containsKey("rawDataOutput")) {
            execute.setResponseForm(parseRawDataOutput(pf.getResultInfo(processName, null), (String) rawKvp.get("rawDataOutput")));
        } else {
            ResponseFormType responseForm = factory.createResponseFormType();
            responseForm.setResponseDocument(factory.createResponseDocumentType());
            execute.setResponseForm(responseForm);
        }
       
        if("true".equals(kvp.get("storeExecuteResponse"))) {
            if(execute.getResponseForm().getResponseDocument() == null) {
                throw new WPSException("InvalidParameterValue", "Cannot store the response for raw data outputs, " +
                    "please use response document instead");
            }
            execute.getResponseForm().getResponseDocument().setStoreExecuteResponse(true);
        }
       
        if("true".equals(kvp.get("lineage"))) {
            if(execute.getResponseForm().getResponseDocument() == null) {
                throw new WPSException("InvalidParameterValue", "Cannot provide lineage in the response for raw data outputs, " +
                        "please use response document instead");
            }
            execute.getResponseForm().getResponseDocument().setLineage(true);
        }
       
        if("true".equals(kvp.get("status"))) {
            if(execute.getResponseForm().getResponseDocument() == null) {
                throw new WPSException("InvalidParameterValue", "Cannot add status with raw data outputs, " +
                        "please use response document with store option instead");
            }
            if(!execute.getResponseForm().getResponseDocument().isStoreExecuteResponse()) {
                throw new WPSException("InvalidParameterValue", "Cannot add status if the response " +
                    "is not stored, please add storeExecuteResponse=true your request");
            }
            execute.getResponseForm().getResponseDocument().setStatus(true);
        }
       
View Full Code Here

    public LazyInputMap getProcessInputs(WPSExecutionManager manager) {
        // get the input descriptors
        Name processName = Ows11Util.name(request.getIdentifier());
        ProcessFactory pf = GeoServerProcessors.createProcessFactory(processName);
        if(pf == null) {
            throw new WPSException("Unknown process " + processName);
        }
       
        final Map<String, Parameter<?>> parameters = pf.getParameterInfo(processName);
        Map<String, InputProvider> providers = new HashMap<String, InputProvider>();

        // see what output raw data we have that need the user chosen mime type to be
        // sent back to the process as an input
        Map<String, String> outputMimeParameters = AbstractRawData.getOutputMimeParameters(
                processName, pf);
        if (!outputMimeParameters.isEmpty()) {
            Map<String, String> requestedRawDataMimeTypes = getRequestedRawDataMimeTypes(outputMimeParameters.keySet(), processName, pf);
            for (Map.Entry<String, String> param : outputMimeParameters.entrySet()) {
                String outputName = param.getKey();
                String inputParameter = param.getValue();
                String mime = requestedRawDataMimeTypes.get(outputName);
                StringInputProvider provider = new StringInputProvider(mime, inputParameter);
                providers.put(inputParameter, provider);
            }
        }

        // turn them into a map of input providers
        for (Iterator i = request.getDataInputs().getInput().iterator(); i.hasNext();) {
            InputType input = (InputType) i.next();
            String inputId = input.getIdentifier().getValue();

            // locate the parameter for this request
            Parameter p = parameters.get(inputId);
            if (p == null) {
                throw new WPSException("No such parameter: " + inputId);
            }

            // find the ppio
            String mime = null;
            if (input.getData() != null && input.getData().getComplexData() != null) {
                mime = input.getData().getComplexData().getMimeType();
            } else if (input.getReference() != null) {
                mime = input.getReference().getMimeType();
            }
            ProcessParameterIO ppio = ProcessParameterIO.find(p, manager.applicationContext, mime);
            if (ppio == null) {
                throw new WPSException("Unable to decode input: " + inputId);
            }

            // build the provider
            InputProvider provider = new SimpleInputProvider(input, ppio, manager,
                    manager.applicationContext);
View Full Code Here

            it.setIdentifier(Ows11Util.code(ioParam.id));
            it.setData(factory.createDataType());
           
            Parameter<?> gtParam = inputParams.get(ioParam.id);
            if(gtParam == null) {
                throw new WPSException("Unknown data input named '" + ioParam.id + "'");
            }
            ProcessParameterIO ppio = ProcessParameterIO.findAll(gtParam, applicationContext).get(0);
           
            if(ppio instanceof LiteralPPIO) {
                it.getData().setLiteralData(parseLiteral(it, factory, ioParam));
View Full Code Here

TOP

Related Classes of org.geoserver.wps.WPSException

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.