コード例 #1
0
 @Test
 public void testDNSWithNameHeader() throws Exception {
   resultEndpoint.expectedMessageCount(1);
   resultEndpoint.expectedMessagesMatches(
       new Predicate() {
         public boolean matches(Exchange exchange) {
           Record[] record = (Record[]) exchange.getIn().getBody();
           return record[0].getName().toString().equals("www.example.com.");
         }
       });
   Map<String, Object> headers = new HashMap<String, Object>();
   headers.put("dns.name", "www.example.com");
   template.sendBodyAndHeaders("hello", headers);
   resultEndpoint.assertIsSatisfied();
 }
コード例 #2
0
ファイル: PdfAppendTest.java プロジェクト: Rabeea/camel
  @Test
  public void testAppend() throws Exception {
    final String originalText = "Test";
    final String textToAppend = "Append";
    PDDocument document = new PDDocument();
    PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.setFont(PDType1Font.HELVETICA, 12);
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(20, 400);
    contentStream.drawString(originalText);
    contentStream.endText();
    contentStream.close();

    template.sendBodyAndHeader(
        "direct:start", textToAppend, PdfHeaderConstants.PDF_DOCUMENT_HEADER_NAME, document);

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(
        new Predicate() {
          @Override
          public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(ByteArrayOutputStream.class));
            try {
              PDDocument doc =
                  PDDocument.load(
                      new ByteArrayInputStream(((ByteArrayOutputStream) body).toByteArray()));
              PDFTextStripper pdfTextStripper = new PDFTextStripper();
              String text = pdfTextStripper.getText(doc);
              assertEquals(2, doc.getNumberOfPages());
              assertThat(text, containsString(originalText));
              assertThat(text, containsString(textToAppend));
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
            return true;
          }
        });
    resultEndpoint.assertIsSatisfied();
  }
コード例 #3
0
ファイル: PdfAppendTest.java プロジェクト: Rabeea/camel
  @Test
  public void testAppendEncrypted() throws Exception {
    final String originalText = "Test";
    final String textToAppend = "Append";
    PDDocument document = new PDDocument();
    PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.setFont(PDType1Font.HELVETICA, 12);
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(20, 400);
    contentStream.drawString(originalText);
    contentStream.endText();
    contentStream.close();

    final String ownerPass = "******";
    final String userPass = "******";
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setCanExtractContent(false);
    StandardProtectionPolicy protectionPolicy =
        new StandardProtectionPolicy(ownerPass, userPass, accessPermission);
    protectionPolicy.setEncryptionKeyLength(128);

    document.protect(protectionPolicy);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    document.save(output);

    // Encryption happens after saving.
    PDDocument encryptedDocument = PDDocument.load(new ByteArrayInputStream(output.toByteArray()));

    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(PdfHeaderConstants.PDF_DOCUMENT_HEADER_NAME, encryptedDocument);
    headers.put(
        PdfHeaderConstants.DECRYPTION_MATERIAL_HEADER_NAME,
        new StandardDecryptionMaterial(userPass));

    template.sendBodyAndHeaders("direct:start", textToAppend, headers);

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(
        new Predicate() {
          @Override
          public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(ByteArrayOutputStream.class));
            try {
              PDDocument doc =
                  PDDocument.load(
                      new ByteArrayInputStream(((ByteArrayOutputStream) body).toByteArray()));
              PDFTextStripper pdfTextStripper = new PDFTextStripper();
              String text = pdfTextStripper.getText(doc);
              assertEquals(2, doc.getNumberOfPages());
              assertThat(text, containsString(originalText));
              assertThat(text, containsString(textToAppend));
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
            return true;
          }
        });
    resultEndpoint.assertIsSatisfied();
  }
  @Test
  public void testQuartzPersistentStoreClusteredApp() throws Exception {
    // boot up the database the two apps are going to share inside a clustered quartz setup
    AbstractXmlApplicationContext db =
        new ClassPathXmlApplicationContext(
            "org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppDatabase.xml");
    db.start();

    // now launch the first clustered app which will acquire the quartz database lock and become the
    // master
    AbstractXmlApplicationContext app =
        new ClassPathXmlApplicationContext(
            "org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppOne.xml");
    app.start();

    // as well as the second one which will run in slave mode as it will not be able to acquire the
    // same lock
    AbstractXmlApplicationContext app2 =
        new ClassPathXmlApplicationContext(
            "org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml");
    app2.start();

    CamelContext camel = app.getBean("camelContext", CamelContext.class);

    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMinimumMessageCount(3);
    mock.expectedMessagesMatches(new ClusteringPredicate(true));

    // let the route run a bit...
    Thread.sleep(5000);

    mock.assertIsSatisfied();

    // now let's simulate a crash of the first app (the quartz instance 'app-one')
    log.warn("The first app is going to crash NOW!");
    IOHelper.close(app);

    log.warn("Crashed...");
    log.warn("Crashed...");
    log.warn("Crashed...");

    // wait long enough until the second app takes it over...
    Thread.sleep(20000);
    // inside the logs one can then clearly see how the route of the second app ('app-two') starts
    // consuming:
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:35,340 [_ClusterManager] INFO  LocalDataSourceJobStore        -
    // ClusterManager: detected 1 failed or restarted instances.
    // 2013-09-30 11:22:35,340 [_ClusterManager] INFO  LocalDataSourceJobStore        -
    // ClusterManager: Scanning for instance "app-one"'s failed in-progress jobs.
    // 2013-09-30 11:22:35,369 [eduler_Worker-1] INFO  triggered                      -
    // Exchange[ExchangePattern: InOnly, BodyType: String, Body: clustering PONGS!]

    CamelContext camel2 = app2.getBean("camelContext2", CamelContext.class);

    MockEndpoint mock2 = camel2.getEndpoint("mock:result", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(3);
    mock2.expectedMessagesMatches(new ClusteringPredicate(false));

    mock2.assertIsSatisfied();

    // and as the last step shutdown the second app as well as the database
    IOHelper.close(app2, db);
  }