Beispiel #1
0
  private Map<String, String> readRequest(Request request) {
    Map<String, String> attributes = new HashMap<>();

    for (Field field : request.getClass().getDeclaredFields()) {
      field.setAccessible(true);

      try {
        attributes.put(field.getName(), field.get(request).toString());
      } catch (DOMException | IllegalArgumentException | IllegalAccessException e) {
      }

      field.setAccessible(false);
    }

    return attributes;
  }
 @Get("/injection/:param1/:param2")
 public String route(
     String param1,
     String param2,
     Context context,
     Request request,
     Response response,
     Cookies cookies) {
   return String.join(
       "/",
       param1,
       param2,
       context.getClass().getSimpleName(),
       request.getClass().getSimpleName(),
       response.getClass().getSimpleName(),
       cookies.getClass().getSimpleName());
 }
 private static void insertRequest(
     DatabaseLayer databaseLayer,
     int type,
     boolean isPersistent,
     int accountDbId,
     String tag,
     String appSession,
     Request request) {
   // Writing to requests database.
   ContentValues contentValues = new ContentValues();
   contentValues.put(GlobalProvider.REQUEST_TYPE, type);
   contentValues.put(GlobalProvider.REQUEST_CLASS, request.getClass().getName());
   contentValues.put(GlobalProvider.REQUEST_PERSISTENT, isPersistent ? 1 : 0);
   contentValues.put(GlobalProvider.REQUEST_ACCOUNT_DB_ID, accountDbId);
   contentValues.put(GlobalProvider.REQUEST_STATE, Request.REQUEST_PENDING);
   if (!TextUtils.isEmpty(appSession)) {
     contentValues.put(GlobalProvider.REQUEST_SESSION, appSession);
   }
   if (!TextUtils.isEmpty(tag)) {
     Cursor cursor = null;
     try {
       // Obtain existing request.
       QueryBuilder queryBuilder =
           new QueryBuilder().columnEquals(GlobalProvider.REQUEST_TAG, tag);
       cursor = databaseLayer.query(Settings.REQUEST_RESOLVER_URI, queryBuilder);
       // Checking for at least one such download request exist.
       if (cursor == null || cursor.moveToFirst()) {
         return;
       }
     } finally {
       if (cursor != null) {
         cursor.close();
       }
     }
     contentValues.put(GlobalProvider.REQUEST_TAG, tag);
   }
   contentValues.put(GlobalProvider.REQUEST_BUNDLE, GsonSingleton.getInstance().toJson(request));
   databaseLayer.insert(Settings.REQUEST_RESOLVER_URI, contentValues);
 }
Beispiel #4
0
  /**
   * Process all the requests. The connection must have been opened and set first.
   *
   * @param requests the requets to process
   */
  public void processRequests(List requests)
      throws IOException, UnconfiguredRequestException, ResponseException, CommandAbortedException {

    if (requests == null || requests.size() == 0) {
      throw new IllegalArgumentException(
          "[processRequests] requests "
              + // NOI18N
              "was either null or empty."); // NOI18N
    }

    if (abort) {
      throw new CommandAbortedException(
          "Aborted during request processing", // NOI18N
          CommandException.getLocalMessage("Client.commandAborted", null)); // NOI18N
    }

    loggedDataInputStream = null;
    loggedDataOutputStream = null;

    // send the initialisation requests if we are handling the first
    // command
    boolean filterRootRequest = true;
    if (isFirstCommand()) {
      setIsFirstCommand(false);
      int pos = 0;
      if (!initialRequestsSent) {
        pos = fillInitialRequests(requests);
        initialRequestsSent = true;
        filterRootRequest = false;
      }
      if (globalOptions != null) {
        // sends the global options that are to be sent to server (-q, -Q, -t, -n, l)
        for (Iterator it = globalOptions.createRequestList().iterator(); it.hasNext(); ) {
          Request request = (Request) it.next();
          requests.add(pos++, request);
        }

        if (globalOptions.isUseGzip() && globalOptions.getCompressionLevel() != 0) {
          requests.add(pos++, new GzipFileContentsRequest(globalOptions.getCompressionLevel()));
        }
      }
    } else if (printConnectionReuseWarning) {
      if (System.getProperty("javacvs.multiple_commands_warning") == null) { // NOI18N
        System.err.println("WARNING TO DEVELOPERS:"); // NOI18N
        System.err.println(
            "Please be warned that attempting to reuse one open connection for more commands is not supported by cvs servers very well."); // NOI18N
        System.err.println("You are advised to open a new Connection each time."); // NOI18N
        System.err.println(
            "If you still want to proceed, please do: System.setProperty(\"javacvs.multiple_commands_warning\", \"false\")"); // NOI18N
        System.err.println("That will disable this message."); // NOI18N
      }
    }

    if (!ALLOWED_CONNECTION_REUSE_REQUESTS.contains(requests.get(requests.size() - 1).getClass())) {
      printConnectionReuseWarning = true;
    }

    final boolean fireEnhancedEvents = getEventManager().isFireEnhancedEventSet();
    int fileDetailRequestCount = 0;

    if (fireEnhancedEvents) {
      for (Iterator it = requests.iterator(); it.hasNext(); ) {
        Request request = (Request) it.next();

        FileDetails fileDetails = request.getFileForTransmission();
        if (fileDetails != null && fileDetails.getFile().exists()) {
          fileDetailRequestCount++;
        }
      }
      CVSEvent event =
          new EnhancedMessageEvent(
              this, EnhancedMessageEvent.REQUESTS_COUNT, new Integer(fileDetailRequestCount));
      getEventManager().fireCVSEvent(event);
    }

    LoggedDataOutputStream dos = connection.getOutputStream();
    loggedDataOutputStream = dos;

    // this list stores stream modification requests, each to be called
    // to modify the input stream the next time we need to process a
    // response
    List streamModifierRequests = new LinkedList();

    // sending files does not seem to allow compression
    transmitFileHandler = getUncompressedFileHandler();

    for (Iterator it = requests.iterator(); it.hasNext(); ) {
      if (abort) {
        throw new CommandAbortedException(
            "Aborted during request processing", // NOI18N
            CommandException.getLocalMessage("Client.commandAborted", null)); // NOI18N
      }

      final Request request = (Request) it.next();

      if (request instanceof GzipFileContentsRequest) {
        if (dontUseGzipFileHandler) {
          stderr.println(
              "Warning: The server is not supporting gzip-file-contents request, no compression is used.");
          continue;
        }
      }

      // skip the root request if already sent
      if (request instanceof RootRequest) {
        if (filterRootRequest) {
          continue;
        } else { // Even if we should not filter the RootRequest now, we must filter all successive
                 // RootRequests
          filterRootRequest = true;
        }
      }
      // send request to server
      String requestString = request.getRequestString();
      dos.writeBytes(requestString);

      // we must modify the outputstream now, but defer modification
      // of the inputstream until we are about to read a response.
      // This is because some modifiers (e.g. gzip) read the header
      // on construction, and obviously no header is present when
      // no response has been sent
      request.modifyOutputStream(connection);
      if (request.modifiesInputStream()) {
        streamModifierRequests.add(request);
      }
      dos = connection.getOutputStream();

      FileDetails fileDetails = request.getFileForTransmission();
      if (fileDetails != null) {
        final File file = fileDetails.getFile();
        // only transmit the file if it exists! When committing
        // a remove request you cannot transmit the file
        if (file.exists()) {
          Logger.logOutput(
              new String(
                      "<Sending file: "
                          + // NOI18N
                          file.getAbsolutePath()
                          + ">\n")
                  .getBytes("utf8")); // NOI18N

          if (fireEnhancedEvents) {
            CVSEvent event =
                new EnhancedMessageEvent(this, EnhancedMessageEvent.FILE_SENDING, file);
            getEventManager().fireCVSEvent(event);

            fileDetailRequestCount--;
          }

          if (fileDetails.isBinary()) {
            transmitFileHandler.transmitBinaryFile(file, dos);
          } else {
            transmitFileHandler.transmitTextFile(file, dos);
          }

          if (fireEnhancedEvents && fileDetailRequestCount == 0) {
            CVSEvent event =
                new EnhancedMessageEvent(this, EnhancedMessageEvent.REQUESTS_SENT, "Ok"); // NOI18N
            getEventManager().fireCVSEvent(event);
          }
        }
      }
      if (request.isResponseExpected()) {
        dos.flush();

        // now perform the deferred modification of the input stream
        Iterator modifiers = streamModifierRequests.iterator();
        while (modifiers.hasNext()) {
          System.err.println("Modifying the inputstream..."); // NOI18N
          final Request smRequest = (Request) modifiers.next();
          System.err.println(
              "Request is a: "
                  + // NOI18N
                  smRequest.getClass().getName());
          smRequest.modifyInputStream(connection);
        }
        streamModifierRequests.clear();

        handleResponse();
      }
    }
    dos.flush();

    transmitFileHandler = null;
  }