コード例 #1
0
  public void processNextBulletin() {
    if (isSleeping()) return;

    BulletinMirroringInformation item = getNextItemToRetrieve();
    if (item == null) {
      scheduleSleep();
      return;
    }

    // TODO handle delete requests when we are propagating deletes.

    try {
      UniversalId uid = item.getUid();
      String publicCode = MartusCrypto.getFormattedPublicCode(uid.getAccountId());
      logNotice("Getting bulletin: " + publicCode + "->" + uid.getLocalId());
      String bur = retrieveBurFromMirror(uid);
      File zip = File.createTempFile("$$$MirroringRetriever", null);
      try {
        zip.deleteOnExit();
        retrieveOneBulletin(zip, uid);
        long zipSize = zip.length();
        long mTime = item.getmTime();
        BulletinHeaderPacket bhp = store.saveZipFileToDatabase(zip, uid.getAccountId(), mTime);
        store.writeBur(bhp, bur);
        store.deleteDel(bhp.getUniversalId());
        logNotice(
            "Stored bulletin:  " + publicCode + "->" + uid.getLocalId() + " Size: " + zipSize);
      } finally {
        zip.delete();
      }
    } catch (ServerErrorException e) {
      logError("Supplier server:", e);
    } catch (ServerNotAvailableException e) {
      // TODO: Notify once per hour that something is wrong
    } catch (Exception e) {
      logError(e);
    }
  }
コード例 #2
0
ファイル: Bulletin.java プロジェクト: RHoKBelgium/MartusRepo
  public Bulletin(
      MartusCrypto securityToUse,
      UniversalId headerUid,
      UniversalId publicDataUid,
      UniversalId privateDataUid,
      FieldSpecCollection publicFieldSpecs,
      FieldSpecCollection privateFieldSpecs)
      throws Exception {
    security = securityToUse;
    isNonAttachmentDataValidFlag = true;

    header = createHeaderPacket(headerUid);

    fieldData = createPublicFieldDataPacket(publicDataUid, publicFieldSpecs);
    fieldData.setEncrypted(true);
    header.setFieldDataPacketId(publicDataUid.getLocalId());

    privateFieldData = createPrivateFieldDataPacket(privateDataUid, privateFieldSpecs);
    privateFieldData.setEncrypted(true);
    header.setPrivateFieldDataPacketId(privateDataUid.getLocalId());

    clearAllUserData();
  }
コード例 #3
0
  public static void writeAttachmentsToZip(
      ReadableDatabase db,
      Bulletin b,
      ZipOutputStream zipOut,
      AttachmentProxy[] attachments,
      MartusCrypto sigVerifier)
      throws IOException, CryptoException {
    for (int i = 0; i < attachments.length; ++i) {
      UniversalId uid = attachments[i].getUniversalId();
      ZipEntry attachmentEntry = new ZipEntry(uid.getLocalId());
      zipOut.putNextEntry(attachmentEntry);
      DatabaseKey key = b.getDatabaseKeyForLocalId(uid.getLocalId());
      InputStream in = new BufferedInputStream(db.openInputStream(key, sigVerifier));

      byte[] bytes = new byte[MartusConstants.streamBufferCopySize];
      int got;
      while ((got = in.read(bytes)) != -1) {
        zipOut.write(bytes, 0, got);
      }
      in.close();
      zipOut.flush();
    }
  }
コード例 #4
0
  public void testGetBulletinUploadRecordSealedOld() throws Exception {
    supplier.authorizedCaller = callerAccountId;

    UniversalId uid = UniversalIdForTesting.createDummyUniversalId();
    String bur = "This pretends to be a BUR";
    supplier.addBur(uid, bur, BulletinConstants.STATUSSEALED);
    Vector parameters = new Vector();
    parameters.add(MirroringInterface.CMD_MIRRORING_GET_BULLETIN_UPLOAD_RECORD);
    parameters.add(uid.getAccountId());
    parameters.add(uid.getLocalId());
    String sig = callerSecurity.createSignatureOfVectorOfStrings(parameters);
    Vector result = handler.request(callerAccountId, parameters, sig);
    assertEquals(NetworkInterfaceConstants.OK, result.get(0));
    assertEquals(2, result.size());
    assertEquals(bur, ((Object[]) result.get(1))[0]);
  }