org.apache.activemq.command.ActiveMQBlobMessage

Here are the examples of the java api class org.apache.activemq.command.ActiveMQBlobMessage taken from open source projects.

1. FTPBlobUploadStrategyTest#testFileUpload()

View license
public void testFileUpload() throws Exception {
    setConnection();
    File file = File.createTempFile("amq-data-file-", ".dat");
    // lets write some data
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.append("hello world");
    writer.close();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ((ActiveMQConnection) connection).setCopyMessageOnSend(false);
    ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession) session).createBlobMessage(file);
    message.setJMSMessageID("testmessage");
    message.onSend();
    assertEquals(ftpUrl + "ID_testmessage", message.getURL().toString());
    File uploaded = new File(ftpHomeDirFile, "ID_testmessage");
    assertTrue("File doesn't exists", uploaded.exists());
}

2. FTPBlobUploadStrategyTest#testWriteDenied()

View license
public void testWriteDenied() throws Exception {
    userNamePass = "guest";
    setConnection();
    File file = File.createTempFile("amq-data-file-", ".dat");
    // lets write some data
    BufferedWriter writer = new BufferedWriter(new FileWriter(file));
    writer.append("hello world");
    writer.close();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ((ActiveMQConnection) connection).setCopyMessageOnSend(false);
    ActiveMQBlobMessage message = (ActiveMQBlobMessage) ((ActiveMQSession) session).createBlobMessage(file);
    message.setJMSMessageID("testmessage");
    try {
        message.onSend();
    } catch (JMSException e) {
        e.printStackTrace();
        return;
    }
    fail("Should have failed with permission denied exception!");
}

3. FTPBlobDownloadStrategyTest#testWrongAuthentification()

View license
public void testWrongAuthentification() throws MalformedURLException {
    ActiveMQBlobMessage message = new ActiveMQBlobMessage();
    BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy());
    try {
        message.setURL(new URL("ftp://" + userNamePass + "_wrong:" + userNamePass + "@localhost:" + ftpPort + "/ftptest/"));
        strategy.getInputStream(message);
    } catch (JMSException e) {
        assertEquals("Wrong Exception", "Cant Authentificate to FTP-Server", e.getMessage());
        return;
    } catch (Exception e) {
        System.out.println(e);
        assertTrue("Wrong Exception " + e, false);
        return;
    }
    assertTrue("Expect Exception", false);
}

4. FTPBlobDownloadStrategyTest#testWrongFTPPort()

View license
public void testWrongFTPPort() throws MalformedURLException {
    ActiveMQBlobMessage message = new ActiveMQBlobMessage();
    BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy());
    try {
        message.setURL(new URL("ftp://" + userNamePass + ":" + userNamePass + "@localhost:" + 422 + "/ftptest/"));
        strategy.getInputStream(message);
    } catch (JMSException e) {
        assertEquals("Wrong Exception", "Problem connecting the FTP-server", e.getMessage());
        return;
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue("Wrong Exception " + e, false);
        return;
    }
    assertTrue("Expect Exception", false);
}

5. FTPBlobDownloadStrategyTest#testDownload()

View license
public void testDownload() throws Exception {
    setConnection();
    // create file
    File uploadFile = new File(ftpHomeDirFile, "test.txt");
    FileWriter wrt = new FileWriter(uploadFile);
    wrt.write("hello world");
    for (int ix = 0; ix < FILE_SIZE; ++ix) {
        wrt.write("a");
    }
    wrt.close();
    ActiveMQBlobMessage message = new ActiveMQBlobMessage();
    BlobDownloadStrategy strategy = new FTPBlobDownloadStrategy(new BlobTransferPolicy());
    InputStream stream;
    try {
        message.setURL(new URL(ftpUrl + "test.txt"));
        stream = strategy.getInputStream(message);
        int i = stream.read();
        StringBuilder sb = new StringBuilder(2048);
        while (i != -1) {
            sb.append((char) i);
            i = stream.read();
        }
        assertEquals("hello world", sb.toString().substring(0, "hello world".length()));
        assertEquals(FILE_SIZE, sb.toString().substring("hello world".length()).length());
        assertTrue(uploadFile.exists());
        strategy.deleteFile(message);
        assertFalse(uploadFile.exists());
    } catch (Exception e) {
        e.printStackTrace();
        assertTrue(false);
    }
}