Exemplo n.º 1
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws RequestBodyExceededException, IOException {
    try {
      Document document = ServletHandlingUtils.extractXMLRequestDocument(request);
      Map<String, String[]> parameterMap = createParameterMapFromDocument(document);
      // we're going to treat this as a GetObservation by default if not specified
      parameterMap = applyBusinessRules(parameterMap);
      queryAndSend(request, response, parameterMap);

    } catch (RequestBodyExceededException rbe) {
      // If we get errors in the request parsing, then just send the error
      int errorCode =
          (rbe.errorCode != null) ? rbe.errorCode : 403; // 403 as default value for error code
      rbe.printStackTrace();
      response.sendError(errorCode, rbe.getMessage());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
  private void queryAndSend(
      HttpServletRequest request, HttpServletResponse response, Map<String, String[]> parameterMap)
      throws IOException {
    ServletHandlingUtils.dumpRequestParamsToConsole(parameterMap);
    // TODO parameterMap may or may not be case-insensitive, depending on path of arrival post or
    // get. Correct this later.
    SOS_1_0_Operation opType = SOS_1_0_Operation.parse(parameterMap.get("request"));

    ServletOutputStream outputStream = response.getOutputStream();
    response.setContentType(OGC_WFSConstants.DEFAULT_DESCRIBEFEATURETYPE_OUTPUTFORMAT);
    response.setCharacterEncoding(DEFAULT_ENCODING);
    switch (opType) {
      case GetObservationById:
        parameterMap = cleanObservationId(parameterMap);
        if (parameterMap.get(OGCBusinessRules.FEATURE_ID) == null) {
          // for us, the observationId is really the featureId
          parameterMap.put(OGCBusinessRules.FEATURE_ID, parameterMap.get(OBSERVATION_ID));
        }
        // intentional fall through to GetObservation
      case GetObservation:
        parameterMap = USGS_OGC_BusinessRules.cleanFeatureId(parameterMap);

        try {
          XMLStreamReader streamReader =
              getXMLStreamReaderDAO().getStreamReader("dvMapper.observationsSelect", parameterMap);
          XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(outputStream);
          XMLStreamUtils.copy(streamReader, streamWriter);
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          outputStream.flush();
        }
        break;
      case GetDataAvailability:
        parameterMap = USGS_OGC_BusinessRules.cleanFeatureId(parameterMap);

        try {
          XMLStreamReader streamReader =
              getXMLStreamReaderDAO().getStreamReader("dataMapper.dataSelect_1", parameterMap);
          XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(outputStream);
          XMLStreamUtils.copy(streamReader, streamWriter);
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          outputStream.flush();
        }
        break;
      case GetHistoricalData:
        parameterMap = USGS_OGC_BusinessRules.cleanFeatureId(parameterMap);

        try {
          XMLStreamReader streamReader =
              getXMLStreamReaderDAO()
                  .getStreamReader("HistoricalMapper.dataHistorySelect", parameterMap);
          XMLStreamWriter streamWriter = xmlOutputFactory.createXMLStreamWriter(outputStream);
          XMLStreamUtils.copy(streamReader, streamWriter);
        } catch (Exception e) {
          e.printStackTrace();
        } finally {
          outputStream.flush();
        }
        break;
      case GetCapabilities:
        {
          Map<String, String> replacementMap = new HashMap<String, String>();
          replacementMap.put("base.url", ServletHandlingUtils.parseBaseURL(request));

          // Just sending back static file for now.
          String resource = "/ogc/sos/dv" + opType.name() + ".xml";
          String errorMessage = "<error>Unable to retrieve resource " + resource + "</error";
          FileResponseUtil.writeToStreamWithReplacements(
              resource, outputStream, replacementMap, errorMessage);
        }
        break;
      case GetProfile:
      case DescribeSensor:
        {
          Map<String, String> replacementMap = new HashMap<String, String>();
          replacementMap.put("base.url", ServletHandlingUtils.parseBaseURL(request));

          // Just sending back static file for now.
          String resource = "/ogc/sos/" + opType.name() + ".xml";
          String errorMessage = "<error>Unable to retrieve resource " + resource + "</error";
          FileResponseUtil.writeToStreamWithReplacements(
              resource, outputStream, replacementMap, errorMessage);
        }
        break;
      default:
        BufferedWriter writer = FileResponseUtil.wrapAsBufferedWriter(outputStream);
        try {
          writer.append("unrecognized or unhandled REQUEST type = " + opType);
        } catch (Exception e) {
          // TODO: handle exception
        } finally {
          outputStream.flush();
        }
        break;
    }
  }