示例#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();
        }
      }
    }
示例#2
0
 // TODO非同期
 public File executeExport(PersistenceManager pm, Collection<Long> accessLogsIds)
     throws IOException {
   File exportFile = File.createTempFile("export", ".zip", config.getTmpDir());
   ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(exportFile));
   Set<String> traceDigests = new HashSet<String>();
   for (Long id : accessLogsIds) {
     AccessLog accessLog = null;
     try {
       accessLog = (AccessLog) pm.detachCopy(pm.getObjectById(AccessLog.class, id));
     } catch (JDOObjectNotFoundException e) {
       continue;
     }
     ZipEntry ze = new ZipEntry("/accessLog/" + accessLog.getId());
     addDigest(traceDigests, accessLog.getRequestHeaderDigest());
     addDigest(traceDigests, accessLog.getRequestBodyDigest());
     addDigest(traceDigests, accessLog.getResponseHeaderDigest());
     addDigest(traceDigests, accessLog.getResponseBodyDigest());
     String json = accessLog.toJson().toString();
     byte[] jsonBytes = json.getBytes("utf-8");
     int length = jsonBytes.length;
     ze.setSize(length);
     zos.putNextEntry(ze);
     zos.write(jsonBytes);
     zos.closeEntry();
   }
   for (String digest : traceDigests) {
     long length = StoreManager.getStoreLength(digest);
     long storeId = StoreManager.getStoreId(digest);
     if (length < 0 || storeId == Store.FREE_ID) {
       logger.warn("illegal digest:" + digest);
       continue;
     }
     ZipEntry ze = new ZipEntry("/store/" + Long.toString(storeId));
     ze.setSize(length);
     zos.putNextEntry(ze);
     StoreStream.storeToStream(storeId, zos);
     zos.closeEntry();
   }
   zos.close(); // 必要
   return exportFile;
 }