Пример #1
0
          @Override
          public void handle(Request request, Response response) {
            if (request.getMethod() == Method.GET) {
              List<String> listDBs = null;
              String r = null;
              try {
                listDBs = storageInstance.retrieveDBs(); //
                Logger.stderr(listDBs.toString());
              } catch (StorageException e) {
                e.printStackTrace();
              }

              ObjectMapper om = new ObjectMapper();

              try {
                r = om.writeValueAsString(listDBs);
                response.setEntity(r, MediaType.APPLICATION_JSON);
              } catch (Exception e) {
                Logger.stderr(OBJECT_MAPPING_ERROR_MESSAGE + e);
                return;
              }

              response.setEntity(r, MediaType.APPLICATION_JSON);
            }
          }
Пример #2
0
          @Override
          public void handle(Request request, Response response) {
            if (request.getMethod() == Method.GET) {
              String dbName = (String) request.getAttributes().get("dbname");
              try {
                storageInstance.dropDB(dbName); //
                Logger.stderr(dbName + " db dropped.");
              } catch (StorageException e) {
                e.printStackTrace();
              }

              String r = "{\"dropped dbName\" : \"" + dbName + "\"}";

              response.setEntity(r, MediaType.APPLICATION_JSON);
            }
          }
Пример #3
0
          @Override
          public void handle(Request request, Response response) {

            String dbName = (String) request.getAttributes().get("dbname");
            String collection = (String) request.getAttributes().get("collection");

            if (request.getMethod() == Method.POST) {
              try {
                String text = request.getEntityAsText();
                System.out.println(text);
                TypeReference<List<Map<String, Object>>> typeRef =
                    new TypeReference<List<Map<String, Object>>>() {};
                List<Map<String, Object>> list = null;
                Map<String, Object> key = null;
                Map<String, Object> query = null;

                try {
                  list = om.readValue(text, typeRef);
                  if (list.size() != 2) {
                    Logger.stderr(TYPE_ERROR_MESSAGE);
                    return;
                  }
                  key = list.get(0);
                  query = list.get(1);
                } catch (Exception e) {
                  Logger.stderr(OBJECT_MAPPING_ERROR_MESSAGE + e);
                  return;
                }

                storageInstance.update(dbName, collection, key, query);
                response.setEntity(text, MediaType.APPLICATION_JSON);
              } catch (StorageException e) {
                e.printStackTrace();
              }
            }
          }