/**
   * validates the passed object as a response to a OWS request. The validity of the response may is
   * assigned to specific user rights. If the passed user is <>null this will be evaluated. <br>
   * the reponse may contain three valid kinds of objects:
   *
   * <ul>
   *   <li>a xml encoded exception
   *   <li>a GML document
   *   <li>a XML document
   *   <li>any other kind of document that is valid against the formats defined for GetRecord in the
   *       capabilities
   * </ul>
   *
   * Each of these types can be identified by the mime-type of the response that is also passed to
   * the method. <br>
   * If something basic went wrong it is possible that not further specified kind of object is
   * passed as response. In this case the method will throw an
   * <tt>InvalidParameterValueException</tt> to avoid sending bad responses to the client.
   *
   * @param service service which produced the response (WMS, WFS ...)
   * @param response
   * @param mime mime-type of the response
   * @param user
   * @return the response array
   * @throws InvalidParameterValueException
   */
  @Override
  public byte[] validateResponse(String service, byte[] response, String mime, User user)
      throws InvalidParameterValueException {

    Request req = policy.getRequest(service, "GetRecord");
    // request is valid because no restrictions are made
    if (req.isAny() || req.getPostConditions().isAny()) {
      return response;
    }

    // Condition condition = req.getPostConditions();

    if (MimeTypeMapper.isKnownOGCType(mime)) {
      // if the mime-type isn't an image type but a known
      // OGC mime-type it must be an XML document.
      // probably it is an exception but it also could be
      // a GML document
      response = validateXML(response, mime, user);
    } else if (mime.equals("text/xml")) {
      // if the mime-type isn't an image type but 'text/xml'
      // it could be an exception
      response = validateXML(response, mime, user);
    } else {
      throw new InvalidParameterValueException(UNKNOWNMIMETYPE + mime);
    }

    return response;
  }
Esempio n. 2
0
  /**
   * Sends the result of a someWPVService.doService( request ) bacn to the client
   *
   * @param httpResponse the response object used to pipe the result
   * @param getViewResponse the actua result to be sent
   */
  private void sendGetViewResponse(
      HttpServletResponse httpResponse, GetViewResponse getViewResponse) {
    LOG.entering();

    String mime = MimeTypeMapper.toMimeType(getViewResponse.getOutputFormat());
    httpResponse.setContentType(mime);

    // GetView response is, for the time being, always an image
    writeImage((Image) getViewResponse.getOutput(), httpResponse, mime);

    LOG.exiting();
  }
Esempio n. 3
0
  //  TODO common to WMS
  private void sendExceptionImage(
      HttpServletResponse httpResponse, OGCWebServiceException e, GetView request) {

    Dimension d = request.getImageDimension();

    BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_RGB);
    Graphics g = bi.getGraphics();
    g.setColor(Color.WHITE);
    g.fillRect(0, 0, d.width, d.height);
    g.setColor(Color.BLUE);

    String s = e.getLocator();
    String location = s != null ? s : "Unknown";
    s = e.getMessage();
    String message = s != null ? s : "Unknown reason!";

    g.drawString(location, 5, 20);
    g.drawString(message, 15, 50);
    String mime = MimeTypeMapper.toMimeType(request.getOutputFormat());
    g.dispose();
    writeImage(bi, mime, httpResponse);
  }