Exemplo n.º 1
0
    private void endBuffer(ZipEntry ze) {
      if (ze == null) {
        return;
      }
      if (store != null) {
        store.close(); // 終了処理は別スレッドで実行中
        String digest = store.getDigest();
        logPersister.addDigest(addDigests, digest);
        store = null;
      } else if (charsetDecoder != null) {
        charBuffer.flip();
        charBuffer.array();
        String accessLogJson =
            new String(charBuffer.array(), charBuffer.position(), charBuffer.limit());
        charsetDecoder = null;
        charBuffer = null;
        AccessLog accessLog = AccessLog.fromJson(accessLogJson);
        if (accessLog == null) {
          return;
        }
        logPersister.addDigest(refDigests, accessLog.getRequestHeaderDigest());
        logPersister.addDigest(refDigests, accessLog.getRequestBodyDigest());
        logPersister.addDigest(refDigests, accessLog.getResponseHeaderDigest());
        logPersister.addDigest(refDigests, accessLog.getResponseBodyDigest());
        accessLog.setId(null);
        accessLog.setPersist(true);

        PersistenceManager pm = JdoUtil.getPersistenceManager();
        logPersister.executeInsert(pm, accessLog);
        if (pm.currentTransaction().isActive()) {
          pm.currentTransaction().rollback();
        }
      }
    }
Exemplo n.º 2
0
 private PersistenceManager doJob(PersistenceManager pm, Object req) {
   JSONObject response = null;
   if (req instanceof AccessLog) {
     executeInsert(pm, (AccessLog) req);
     return pm;
   }
   RequestInfo requestInfo = (RequestInfo) req;
   switch (requestInfo.type) {
     case TYPE_QUERY_DELTE:
       requestInfo.ids = queryAccessLog(pm, requestInfo.query);
     case TYPE_LIST_DELTE:
       response = new JSONObject();
       response.element("command", "listDelete");
       response.element("result", "success");
       executeDelete(pm, requestInfo.ids);
       break;
     case TYPE_QUERY_EXPORT:
       requestInfo.ids = queryAccessLog(pm, requestInfo.query);
     case TYPE_LIST_EXPORT:
       try {
         File exportFile = executeExport(pm, requestInfo.ids);
         Blob exportBlob = Blob.create(exportFile, true);
         requestInfo.peer.download(exportBlob);
       } catch (IOException e) {
         response = new JSONObject();
         response.element("command", "listExport");
         response.element("result", "fail");
         logger.warn("failt to export", e);
       } catch (Throwable t) {
         response = new JSONObject();
         response.element("command", "listExport");
         response.element("result", "fail");
         logger.error("failt to export", t);
       }
       break;
     case TYPE_IMPORT:
       try {
         pm = null;
         executeImport(requestInfo.importBlob, requestInfo.peer);
       } catch (IOException e) {
         logger.warn("failt to import", e);
         response = new JSONObject();
         response.element("command", "import");
         response.element("result", "fail");
       }
       break;
   }
   if (requestInfo.peer != null && response != null) {
     requestInfo.peer.message(response);
   }
   return pm;
 }