Skip to content
Permalink
Browse files
Binary parts now use full random bytes for binary parts (not only let…
…ters)

Fix to the MailMatchingUtils size calculator (uses getContent and not part.getSize)
Added a debug helper: exception nesting.

git-svn-id: https://svn.apache.org/repos/asf/james/postage/trunk@451809 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Stefano Bagnara committed Oct 1, 2006
1 parent c27f680 commit 3f2f2ffe3d67f170c6dd8d310230eb8b806bc217
Showing 4 changed files with 38 additions and 21 deletions.
@@ -231,7 +231,7 @@
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server</artifactId>
<version>3.0-SNAPSHOT</version>
<version>2.3.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.bouncycastle</groupId>
@@ -353,7 +353,7 @@
<distributionManagement>
<site>
<id>postage-website</id>
<url>scp://minotaur.apache.org/www/james.apache.org/postage/</url>
<url>scp://people.apache.org/www/james.apache.org/postage/</url>
</site>
</distributionManagement>

@@ -20,26 +20,26 @@

package org.apache.james.postage;

import org.apache.james.postage.configuration.PostageConfiguration;
import org.apache.james.postage.configuration.SendProfile;
import org.apache.james.postage.configuration.MailSender;
import org.apache.james.postage.result.PostageRunnerResultImpl;
import org.apache.james.postage.result.PostageRunnerResult;
import org.apache.james.postage.client.RemoteManagerClient;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.james.postage.client.POP3Client;
import org.apache.james.postage.client.RemoteManagerClient;
import org.apache.james.postage.client.SMTPClient;
import org.apache.james.postage.configuration.MailSender;
import org.apache.james.postage.configuration.PostageConfiguration;
import org.apache.james.postage.configuration.SendProfile;
import org.apache.james.postage.execution.SampleController;
import org.apache.james.postage.smtpserver.SMTPMailSink;
import org.apache.james.postage.jmx.JVMResourceSampler;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.james.postage.result.PostageRunnerResult;
import org.apache.james.postage.result.PostageRunnerResultImpl;
import org.apache.james.postage.smtpserver.SMTPMailSink;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.io.File;

/**
* central controlling class for the testing process. starts all workers, collects data and stops when time is out.<br/>
@@ -384,21 +384,21 @@ private void setupInternalUserAccounts() throws StartupException {
Set existingUsers = getExistingUsers(host, remoteManagerPort, remoteManagerUsername, remoteManagerPassword);

RemoteManagerClient remoteManagerClient = new RemoteManagerClient(host, remoteManagerPort, remoteManagerUsername, remoteManagerPassword);
boolean loginSuccess = remoteManagerClient.login();
remoteManagerClient.login();
ArrayList internalUsers = new ArrayList();
for (int i = 1; i <= internalUserCount; i++) {
String username = internalUsernamePrefix + i;
if (existingUsers.contains(username)) {
log.info("user already exists: " + username);
if (!m_postageConfiguration.isInternalReuseExisting()) {
remoteManagerClient.executeCommand("deluser " + username);
List answers = remoteManagerClient.readAnswer();
remoteManagerClient.readAnswer();
addUser(remoteManagerClient, username, internalPassword);
answers = remoteManagerClient.readAnswer();
remoteManagerClient.readAnswer();
log.info("user deleted and re-created: " + username);
}
remoteManagerClient.executeCommand("setpassword " + username + " " + internalPassword);
List answers = remoteManagerClient.readAnswer();
remoteManagerClient.readAnswer();
} else {
addUser(remoteManagerClient, username, internalPassword);
}
@@ -418,7 +418,7 @@ private void setupForwardedMailInterceptor() throws StartupException {
try {
smtpMailSink.initialize();
} catch (Exception e) {
throw new StartupException("failed to setup");
throw new StartupException("failed to setup",e);
}
m_smtpMailSink = smtpMailSink;
log.info("forwarded mail interceptor is set up.");
@@ -443,7 +443,7 @@ private void setupJMXRemoting() throws StartupException {

private void addUser(RemoteManagerClient remoteManagerClient, String username, String internalPassword) {
remoteManagerClient.executeCommand("adduser " + username + " " + internalPassword);
List answers = remoteManagerClient.readAnswer();
remoteManagerClient.readAnswer();
log.info("user created: " + username);
}

@@ -54,7 +54,7 @@ private static int getRandomInt() {
}

public static byte getRandomByte() {
return (byte)CHARSET[getRandomInt()];
return (byte)(Math.random() * 255);
}

public AbstractMailFactory() {
@@ -22,6 +22,7 @@
import org.apache.james.postage.PostageRuntimeException;
import org.apache.james.postage.classloading.CachedInstanceFactory;
import org.apache.james.postage.result.MailProcessingRecord;
import org.apache.james.util.io.IOUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

@@ -30,6 +31,9 @@
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.regex.Pattern;

/**
@@ -138,7 +142,20 @@ public static int getMimePartSize(MimeMultipart parts, String mimeType) {
for (int i = 0; i < parts.getCount(); i++) {
BodyPart bodyPart = parts.getBodyPart(i);
if (bodyPart.getContentType().startsWith(mimeType)) {
return bodyPart.getSize();
try {
Object content = bodyPart.getContent();
if (content instanceof InputStream) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
IOUtil.copy(((InputStream) content), os);
return os.size();
} else if (content instanceof String) {
return ((String) content).length();
} else {
throw new IllegalStateException("Unsupported content: "+content.getClass().toString());
}
} catch (IOException e) {
throw new IllegalStateException("Unexpected IOException in getContent()");
}
}
}
} catch (MessagingException e) {

0 comments on commit 3f2f2ff

Please sign in to comment.