コード例 #1
0
  /**
   * Looks up a {@link LayerInfo} or {@link LayerGroupInfo} named after the {@code <layer>} in the
   * requested resource {@code <layer>.kml} name
   *
   * @see org.restlet.Finder#findTarget(org.restlet.data.Request, org.restlet.data.Response)
   */
  @Override
  public Resource findTarget(final Request request, Response response) {
    if (!Method.GET.equals(request.getMethod())) {
      response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
      return null;
    }
    final String name = RESTUtils.getAttribute(request, "layer");
    if (name == null) {
      throw new RestletException("No layer name specified", Status.CLIENT_ERROR_BAD_REQUEST);
    }
    final Catalog catalog = geoserver.getCatalog();
    CatalogInfo layer = catalog.getLayerByName(name);
    MetadataMap mdmap;
    if (layer == null) {
      layer = catalog.getLayerGroupByName(name);
      if (layer == null) {
        throw new RestletException("Layer " + name + " not found", Status.CLIENT_ERROR_NOT_FOUND);
      }
      mdmap = ((LayerGroupInfo) layer).getMetadata();
    } else {
      mdmap = ((LayerInfo) layer).getMetadata();
    }

    Boolean enabled = mdmap.get(Properties.INDEXING_ENABLED, Boolean.class);
    if (enabled == null || !enabled.booleanValue()) {
      throw new RestletException("Layer " + name + " not found", Status.CLIENT_ERROR_NOT_FOUND);
    }
    final Context context = getContext();
    return new GeoSearchLayer(context, request, response, layer, geoserver);
  }
コード例 #2
0
  public void handle(Request request, Response response) {
    GEOSERVER_ROOT = getBaseURL(request);

    if (request.getMethod().equals(Method.GET)) {
      doGet(request, response);
    } else {
      response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    }
  }
コード例 #3
0
  @Override
  public Resource findTarget(Request request, Response response) {
    String layer = (String) request.getAttributes().get("layer");

    if (layer != null && request.getMethod() == Method.GET) {
      return new ListAttributesResource(getContext(), request, response, catalog);
    }

    throw new RestletException("No such layer: " + layer, Status.CLIENT_ERROR_NOT_FOUND);
  }
コード例 #4
0
ファイル: MailActionResource.java プロジェクト: TATRC/KMR2
  public MailActionResource(Context context, Request request, Response response) {
    super(context, request, response);

    try {
      String query = request.getResourceRef().getQueryAsForm().getQueryString();
      //      System.out.println("query: "+query);
      if (checkApiCaller(query) != true) {
        getResponse().setStatus(Status.CLIENT_ERROR_UNAUTHORIZED);
        return;
      }

    } catch (Exception e) {
      getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
      return;
    }

    setModifiable(true);
    setAvailable(true);
    allowPut();

    final Method httpMethod = request.getMethod();
    Logger.getLogger(MailActionResource.class.getName())
        .log(Level.INFO, "httpMethod: " + httpMethod);

    try {
      userId = request.getResourceRef().getQueryAsForm().getFirstValue("userId");
      action = request.getResourceRef().getQueryAsForm().getFirstValue("action");
      Logger.getLogger(MailActionResource.class.getName()).log(Level.INFO, userId);
      Logger.getLogger(MailActionResource.class.getName()).log(Level.INFO, action);

      //            fromUser=request.getResourceRef().getQueryAsForm().getFirstValue("fromUser");
      //
      // fromUserProvider=request.getResourceRef().getQueryAsForm().getFirstValue("fromUserProvider");
      //            toUser=request.getResourceRef().getQueryAsForm().getFirstValue("toUser");
      //
      // toUserProvider=request.getResourceRef().getQueryAsForm().getFirstValue("toUserProvider");
      //            subject=request.getResourceRef().getQueryAsForm().getFirstValue("subject");
      //            message=request.getResourceRef().getQueryAsForm().getFirstValue("message");
    } catch (Exception e) {
      // don't care
    }

    getVariants().add(new Variant(MediaType.APPLICATION_JSON));
  }
コード例 #5
0
ファイル: SeedRestlet.java プロジェクト: robstek/geowebcache
 public void handle(Request request, Response response) {
   Method met = request.getMethod();
   try {
     if (met.equals(Method.GET)) {
       doGet(request, response);
     } else if (met.equals(Method.POST)) {
       doPost(request, response);
     } else {
       throw new RestletException("Method not allowed", Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
     }
   } catch (RestletException re) {
     response.setEntity(re.getRepresentation());
     response.setStatus(re.getStatus());
   } catch (IOException ioe) {
     StringBuilder strBld = new StringBuilder();
     strBld.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
     strBld.append("\n<GeoWebCacheException>");
     strBld.append("\nEncountered IO error " + ioe.getMessage());
     strBld.append("\n</GeoWebCacheException>");
     response.setEntity(strBld.toString(), MediaType.TEXT_XML);
     response.setStatus(Status.SERVER_ERROR_INTERNAL);
   }
 }
コード例 #6
0
  @Override
  public void performService(Request request, Response response) {
    try {
      String username = request.getChallengeResponse().getIdentifier();

      if (username == null || username.equals("")) {
        response.setStatus(Status.CLIENT_ERROR_FORBIDDEN);
      } else if (request.getMethod().equals(Method.GET)) {
        String id = (String) request.getAttributes().get("id");
        String ret = null;

        try {
          if (id == null) ret = getAssessments(request, username);
          else
            ret =
                AssessmentIO.readAssessmentAsString(
                    vfs, id, (String) request.getAttributes().get("type"), username);

          if (ret != null) {
            response.setEntity(ret, MediaType.TEXT_XML);
            response.setStatus(Status.SUCCESS_OK);
          } else response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
        } catch (IOException e) {
          e.printStackTrace();
          response.setStatus(Status.SERVER_ERROR_INTERNAL);
        }
      } else if (request.getMethod().equals(Method.PUT)) {
        try {
          putAssessment(request, response, username);
        } catch (Throwable e) {
          e.printStackTrace();
        }
      } else if (request.getMethod().equals(Method.POST)) {
        String action = request.getResourceRef().getQueryAsForm().getFirstValue("action");
        if (action == null) {
          postAssessment(request, response, username);
        } else if (action.equalsIgnoreCase("fetch")) {
          try {
            String ret = getAssessments(request, username);

            if (ret != null) {
              response.setEntity(ret, MediaType.TEXT_XML);
              response.setStatus(Status.SUCCESS_OK);
            } else response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
          } catch (IOException e) {
            e.printStackTrace();
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
          }
        } else if (action.equalsIgnoreCase("batch")) {
          String ret = batchCreate(request, username);

          if (ret != null) {
            response.setEntity(ret, MediaType.TEXT_XML);
            response.setStatus(Status.SUCCESS_OK);
          } else {
            response.setStatus(Status.SERVER_ERROR_INTERNAL);
          }
        }
      } else if (request.getMethod().equals(Method.DELETE)) {
        if (request.getResourceRef().getPath().startsWith("assessmentsByTaxon")) {
          String taxonID = (String) request.getAttributes().get("id");
          String type = (String) request.getAttributes().get("type");
          deleteAssessmentsForTaxon(taxonID, type, username, request, response);
        } else {
          String id = (String) request.getAttributes().get("id");
          String type = (String) request.getAttributes().get("type");
          deleteAssessment(request, response, id, type, username);
        }
      } else {
        response.setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
      }
    } catch (Exception e) {
      e.printStackTrace();
      response.setStatus(Status.SERVER_ERROR_INTERNAL);
    }
  }