Author: sebb Date: Tue Feb 23 15:23:27 2010 New Revision: 915382 URL: http://svn.apache.org/viewvc?rev=915382&view=rev Log: Implement reading mail from a single file
Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java?rev=915382&r1=915381&r2=915382&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java (original) +++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileFolder.java Tue Feb 23 15:23:27 2010 @@ -37,7 +37,8 @@ private static final String FILENAME_FORMAT = "%d.msg"; private static final String FILENAME_REGEX = "\\d+\\.msg"; private boolean isOpen; - private final File folderPath; + private final File folderPath;// Parent folder (or single message file) + private final boolean isFile; private static final FilenameFilter FILENAME_FILTER = new FilenameFilter(){ public boolean accept(File dir, String name) { return name.matches(FILENAME_REGEX); @@ -48,7 +49,13 @@ public MailFileFolder(Store store, String path) { super(store); String base = store.getURLName().getHost(); // == ServerName from mail sampler - folderPath = new File(base,path); + File parentFolder = new File(base); + isFile = parentFolder.isFile(); + if (isFile){ + folderPath = new File(base); + } else { + folderPath = new File(base,path); + } } public MailFileFolder(Store store, URLName path) { @@ -98,7 +105,12 @@ @Override public Message getMessage(int index) throws MessagingException { - File f = new File(folderPath,String.format(FILENAME_FORMAT, Integer.valueOf(index))); + File f; + if (isFile) { + f = folderPath; + } else { + f = new File(folderPath,String.format(FILENAME_FORMAT, Integer.valueOf(index))); + } try { FileInputStream fis = new FileInputStream(f); try { @@ -115,6 +127,7 @@ @Override public int getMessageCount() throws MessagingException { if (!isOpen) return -1; + if (isFile) return 1; File[] listFiles = folderPath.listFiles(FILENAME_FILTER); return listFiles != null ? listFiles.length : 0; } Modified: jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java?rev=915382&r1=915381&r2=915382&view=diff ============================================================================== --- jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java (original) +++ jakarta/jmeter/trunk/src/protocol/mail/org/apache/jmeter/protocol/mail/sampler/MailFileStore.java Tue Feb 23 15:23:27 2010 @@ -18,6 +18,8 @@ package org.apache.jmeter.protocol.mail.sampler; +import java.io.File; + import javax.mail.Folder; import javax.mail.MessagingException; import javax.mail.Session; @@ -31,8 +33,13 @@ } @Override - protected boolean protocolConnect(String host, int port, String user, String password){ - return true; + protected boolean protocolConnect(String host, int port, String user, String password) + throws MessagingException { + File base = new File(host); + if (base.isDirectory() || base.isFile()) { + return true; + } + throw new MessagingException("Host must be a valid directory or file"); } @Override Modified: jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=915382&r1=915381&r2=915382&view=diff ============================================================================== --- jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml (original) +++ jakarta/jmeter/trunk/xdocs/usermanual/component_reference.xml Tue Feb 23 15:23:27 2010 @@ -1331,11 +1331,11 @@ For example <code>file</code> for use with the read-only mail file provider. The actual provider names for POP3 and IMAP are <code>pop3</code> and <code>imap</code> </property> -<property name="Server" required="Yes">Hostname or IP address of the server</property> +<property name="Server" required="Yes">Hostname or IP address of the server. See below for use with <code>file</code> protocol.</property> <property name="Port" required="No">Port to be used to connect to the server (optional)</property> <property name="Username" required="">User login name</property> <property name="Password" required="">User login password (N.B. this is stored unencrypted in the test plan)</property> -<property name="Folder" required="Yes, if using IMAP(S)">The IMAP(S) folder to use</property> +<property name="Folder" required="Yes, if using IMAP(S)">The IMAP(S) folder to use. See below for use with <code>file</code> protocol.</property> <property name="Number of messages to retrieve" required="Yes">Set this to retrieve all or some messages</property> <property name="Delete messages from the server" required="Yes">If set, messages will be deleted after retrieval</property> <property name="Store the message using MIME" required="Yes">Whether to store the message as MIME. @@ -1349,10 +1349,12 @@ In versions of JMeter after 2.3.4, multipart message parts are stored as subsamples of the message. </p> <p> +<b>Special handling for "file" protocol:</b><br></br> The <code>file</code> JavaMail provider can be used to read raw messages from files. The <code>server</code> field is used to specify the path to the parent of the <code>folder</code>. Individual message files should be stored with the name <code>n.msg</code>, where <code>n</code> is the message number. +Alternatively, the <code>server</code> field can be the name of a file which contains a single message. The current implementation is quite basic, and is mainly intended for debugging purposes. </p> </component> --------------------------------------------------------------------- To unsubscribe, e-mail: jmeter-dev-unsubscr...@jakarta.apache.org For additional commands, e-mail: jmeter-dev-h...@jakarta.apache.org