String newJson() {
   if (DELETE.equals(triggerEvent)) {
     return "'{}'";
   } else {
     return generateConcatStatement("NEW", tableColumns);
   }
 }
Esempio n. 2
0
  @Override
  public Response serve(final Request req) {

    if (log.isDebugEnabled()) {
      log.debug("uri=" + req.uri);
      log.debug("method=" + req.method);
      log.debug("headers=" + req.headers);
      log.debug("params=" + req.params);
    } else if (log.isInfoEnabled()) log.info(req.method + " '" + req.uri + "' ");

    try {

      if (GET.equalsIgnoreCase(req.method)) {

        return doGet(req);

      } else if (POST.equalsIgnoreCase(req.method)) {

        return doPost(req);

      } else if (PUT.equalsIgnoreCase(req.method)) {

        return doPut(req);

      } else if (DELETE.equalsIgnoreCase(req.method)) {

        return doDelete(req);

      } else {

        return new Response(HTTP_METHOD_NOT_ALLOWED, MIME_TEXT_PLAIN, "" + req.method);
      }

    } catch (Throwable e) {

      log.error(e.getMessage(), e);

      final StringWriter w = new StringWriter();

      e.printStackTrace(new PrintWriter(w));

      /*
       * Note: if you send an HTTP_INTERNALERROR (500) the browser won't
       * display the response body so you have to send an Ok with the text
       * of the error message....
       */

      return new Response(HTTP_OK, MIME_TEXT_PLAIN, w.toString());
    }
  }
 public TextCommandServiceImpl(Node node) {
   this.node = node;
   this.hazelcast = node.factory;
   this.logger = node.getLogger(this.getClass().getName());
   this.parallelExecutor = this.node.executorManager.newParallelExecutor(40);
   textCommandProcessors[GET.getValue()] = new GetCommandProcessor(this, true);
   textCommandProcessors[PARTIAL_GET.getValue()] = new GetCommandProcessor(this, false);
   textCommandProcessors[SET.getValue()] = new SetCommandProcessor(this);
   textCommandProcessors[ADD.getValue()] = new SetCommandProcessor(this);
   textCommandProcessors[REPLACE.getValue()] = new SetCommandProcessor(this);
   textCommandProcessors[GET_END.getValue()] = new NoOpCommandProcessor(this);
   textCommandProcessors[DELETE.getValue()] = new DeleteCommandProcessor(this);
   textCommandProcessors[QUIT.getValue()] = new SimpleCommandProcessor(this);
   textCommandProcessors[STATS.getValue()] = new StatsCommandProcessor(this);
   textCommandProcessors[UNKNOWN.getValue()] = new ErrorCommandProcessor(this);
   textCommandProcessors[ERROR_CLIENT.getValue()] = new ErrorCommandProcessor(this);
   textCommandProcessors[ERROR_SERVER.getValue()] = new ErrorCommandProcessor(this);
   textCommandProcessors[HTTP_GET.getValue()] = new HttpGetCommandProcessor(this);
   textCommandProcessors[HTTP_POST.getValue()] = new HttpPostCommandProcessor(this);
   textCommandProcessors[HTTP_PUT.getValue()] = new HttpPostCommandProcessor(this);
   textCommandProcessors[HTTP_DELETE.getValue()] = new HttpDeleteCommandProcessor(this);
   textCommandProcessors[NO_OP.getValue()] = new NoOpCommandProcessor(this);
 }
Esempio n. 4
0
  private AuthorizationContext getAuthCtx() {

    String resource = getPath();

    SolrParams params = getQueryParams();
    final ArrayList<CollectionRequest> collectionRequests = new ArrayList<>();
    if (getCollectionsList() != null) {
      for (String collection : getCollectionsList()) {
        collectionRequests.add(new CollectionRequest(collection));
      }
    }

    // Extract collection name from the params in case of a Collection Admin request
    if (getPath().equals("/admin/collections")) {
      if (CREATE.isEqual(params.get("action"))
          || RELOAD.isEqual(params.get("action"))
          || DELETE.isEqual(params.get("action")))
        collectionRequests.add(new CollectionRequest(params.get("name")));
      else if (params.get(COLLECTION_PROP) != null)
        collectionRequests.add(new CollectionRequest(params.get(COLLECTION_PROP)));
    }

    // Handle the case when it's a /select request and collections are specified as a param
    if (resource.equals("/select") && params.get("collection") != null) {
      collectionRequests.clear();
      for (String collection : params.get("collection").split(",")) {
        collectionRequests.add(new CollectionRequest(collection));
      }
    }

    // Populate the request type if the request is select or update
    if (requestType == RequestType.UNKNOWN) {
      if (resource.startsWith("/select") || resource.startsWith("/get"))
        requestType = RequestType.READ;
      if (resource.startsWith("/update")) requestType = RequestType.WRITE;
    }

    // There's no collection explicitly mentioned, let's try and extract it from the core if one
    // exists for
    // the purpose of processing this request.
    if (getCore() != null && (getCollectionsList() == null || getCollectionsList().size() == 0)) {
      collectionRequests.add(
          new CollectionRequest(getCore().getCoreDescriptor().getCollectionName()));
    }

    if (getQueryParams().get(COLLECTION_PROP) != null)
      collectionRequests.add(new CollectionRequest(getQueryParams().get(COLLECTION_PROP)));

    return new AuthorizationContext() {
      @Override
      public SolrParams getParams() {
        return solrReq.getParams();
      }

      @Override
      public Principal getUserPrincipal() {
        return getReq().getUserPrincipal();
      }

      @Override
      public String getHttpHeader(String s) {
        return getReq().getHeader(s);
      }

      @Override
      public Enumeration getHeaderNames() {
        return getReq().getHeaderNames();
      }

      @Override
      public List<CollectionRequest> getCollectionRequests() {
        return collectionRequests;
      }

      @Override
      public RequestType getRequestType() {
        return requestType;
      }

      public String getResource() {
        return path;
      }

      @Override
      public String getHttpMethod() {
        return getReq().getMethod();
      }

      @Override
      public Object getHandler() {
        return handler;
      }

      @Override
      public String toString() {
        StringBuilder response =
            new StringBuilder("userPrincipal: [")
                .append(getUserPrincipal())
                .append("]")
                .append(" type: [")
                .append(requestType.toString())
                .append("], collections: [");
        for (CollectionRequest collectionRequest : collectionRequests) {
          response.append(collectionRequest.collectionName).append(", ");
        }
        if (collectionRequests.size() > 0)
          response.delete(response.length() - 1, response.length());

        response.append("], Path: [").append(resource).append("]");
        response.append(" path : ").append(path).append(" params :").append(solrReq.getParams());
        return response.toString();
      }

      @Override
      public String getRemoteAddr() {
        return getReq().getRemoteAddr();
      }

      @Override
      public String getRemoteHost() {
        return getReq().getRemoteHost();
      }
    };
  }