We previously tried to migrate, but there were strange problems with the jMeter running on our CI...maybe we'll give it another try. In the following, the error message and the code of the custom sampler that produces it, along with a screenshot (attached) of the sampler's configuration:
<samplerResult><testsuite>TC008 XML: Automatisch Intervenieren Import</testsuite><testcase>clean mailbox</testcase><durationInSeconds>0.062</durationInSeconds><date>24.11.2011 16:27:51</date><result><![CDATA[FAILURE Response Message: Response Data: Response Code: 000 Response Headers: Sampler Data: pop3://[email protected]]]></result></samplerResult> Custom sampler code: package ch.admin.bit.edec.jmeter.mail; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.security.KeyStore; import java.security.Security; import java.security.cert.X509Certificate; import java.util.Enumeration; import java.util.Properties; import java.util.zip.DataFormatException; import javax.mail.Address; import javax.mail.BodyPart; import javax.mail.Flags; import javax.mail.Folder; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Multipart; import javax.mail.NoSuchProviderException; import javax.mail.Session; import javax.mail.Store; import javax.mail.internet.MimeBodyPart; import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMultipart; import org.apache.jmeter.samplers.AbstractSampler; import org.apache.jmeter.samplers.Entry; import org.apache.jmeter.samplers.SampleResult; import org.apache.jmeter.testbeans.TestBean; import org.apache.jorphan.logging.LoggingManager; import org.apache.log.Logger; import org.bouncycastle.cms.RecipientId; import org.bouncycastle.cms.RecipientInformation; import org.bouncycastle.cms.RecipientInformationStore; import org.bouncycastle.mail.smime.SMIMEEnveloped; import org.bouncycastle.mail.smime.SMIMESigned; import org.bouncycastle.mail.smime.SMIMEUtil; import ch.admin.bit.edec.jmeter.zip.UnzipMailAttachment; public class CustomMailReader extends AbstractSampler implements TestBean { private static final Logger log = LoggingManager.getLoggerForClass(); private static final long serialVersionUID = 658721321; private static final String SEP = System.getProperty("line.separator"); public final static String HOST_TYPE_POP3 = "pop3"; public final static String HOST_TYPE_IMAP = "imap"; // Bodyparts with this suffix get stored in the SamplerResult public final static String FILE_NAME_SUFFIX[] = { "xml", "dat" }; // User input private transient String hostType; private transient String host; private transient String user; private transient String pass; private transient String folder; private transient String deleteMessages; private transient String pkcs12file; private transient String pkcs12pw; private transient String passwordAttachment; /** * AbstractSampler implementation */ public SampleResult sample(Entry e) { SampleResult result = new SampleResult(); result.setSuccessful(false); // Assume it will fail result.setResponseCode("000"); // dito result.setSampleLabel(getName()); result.setSamplerData(buildSamplerData()); boolean success = false; Store store = null; Folder folder = null; try { result.sampleStart(); log.debug("Mail Reader Sampler started"); // Connect to Mailstore Properties props = new Properties(); Session session = Session.getDefaultInstance(props, null); store = session.getStore(getHostType()); store.connect(getHost(), getUser(), getPass()); log.debug("Connected to " + getHost()); // Get folder folder = store.getFolder(getFolder()); if (isDeleteMessages()) { folder.open(Folder.READ_WRITE); } else { folder.open(Folder.READ_ONLY); } // / Get Messages Message messages[] = folder.getMessages(); log.debug("Found folder " + getFolder() + " with " + messages.length + " messages"); // Read each Message and store its contents in the SampleResult (data) MimeMessage message; StringBuffer data = new StringBuffer(); data.append(messages.length); data.append(" messages found" + SEP); for (int i = 0; i < messages.length; i++) { message = (MimeMessage) messages[i]; Object contentMessage = message.getContent(); if (contentMessage instanceof MimeMultipart) { // MIME data.append(getMessageAstring(message)); } else { // SMIME data.append(this.unsignSMIME(message)); } if (i == 0) { // Assumes all the messaged have the same type ... result.setContentType(message.getContentType()); } if (isDeleteMessages()) { message.setFlag(Flags.Flag.DELETED, true); } // Set up the sample result details result.setResponseData(data.toString().getBytes()); result.setDataType(SampleResult.TEXT); // HINT vielleicht result.setDataEncoding() result.setSuccessful(true); result.setResponseCodeOK(); result.setResponseMessage("OK"); success = true; } } catch (NoSuchProviderException ex) { String message = ex.getMessage(); log.error(ex.toString()); result.setResponseMessage(message); result.setResponseCode("500"); } catch (MessagingException ex) { String message = ex.getMessage(); log.error(ex.toString()); result.setResponseMessage(message); result.setResponseCode("500"); } catch (IOException ex) { String message = ex.getMessage(); log.error(ex.toString()); result.setResponseMessage(message); result.setResponseCode("500"); } catch (Exception ex) { String message = ex.getMessage(); log.error(ex.toString()); result.setResponseMessage(message); result.setResponseCode("500"); } finally { // Clean up try { folder.close(true); store.close(); } catch (Exception ex) { log.error(ex.toString()); } } result.sampleEnd(); result.setSuccessful(success); log.debug("Mail Reader ended"); return result; } /** * Build nice String representation of the data used by the sampler. * * @return Sampler data */ private String buildSamplerData() { StringBuffer buf = new StringBuffer(); buf.append(getHostType()); buf.append("://"); buf.append(getUser()); buf.append("@"); buf.append(getHost()); return buf.toString(); } /** * Converts the given Message to String * * @param msg * The Message which should be converted * @return String representation of the given Message * @throws MessagingException * @throws IOException * @throws DataFormatException */ private String getMessageAstring(Message msg) throws MessagingException, IOException, DataFormatException { StringBuffer buf = new StringBuffer(); // heading buf.append("Message "); buf.append(msg.getSubject()); buf.append(":"); buf.append(SEP); // date buf.append("Date: "); buf.append(msg.getSentDate()); buf.append(SEP); // to buf.append("To: "); Address[] recips = msg.getAllRecipients(); for (int j = 0; j < recips.length; j++) { buf.append(recips[j].toString()); if (j < recips.length - 1) buf.append("; "); } buf.append(SEP); // from buf.append("From: "); Address[] from = msg.getFrom(); for (int j = 0; j < from.length; j++) { buf.append(from[j].toString()); if (j < from.length - 1) buf.append("; "); } buf.append(SEP); // subject buf.append("Subject: "); buf.append(msg.getSubject()); buf.append(SEP); // content (all bodyparts) buf.append(SEP); Object content = msg.getContent(); if (content instanceof MimeMultipart) { MimeMultipart mmp = (MimeMultipart) content; int count = mmp.getCount(); buf.append("Multipart. Count: "); buf.append(count); buf.append(SEP); for (int j = 0; j < count; j++) { BodyPart bodyPart = mmp.getBodyPart(j); buf.append("Type: "); buf.append(bodyPart.getContentType()); buf.append(SEP); try { String name = bodyPart.getDataHandler().getName(); if (name != null) { String suffix = name.substring(name.length() - 3); boolean readAttachment = false; for (int i = 0; i < FILE_NAME_SUFFIX.length; i++) { if (suffix.equalsIgnoreCase(FILE_NAME_SUFFIX[i])) { readAttachment = true; break; } } boolean readZip = suffix.equalsIgnoreCase("zip") && passwordAttachment != null; String bpcontent; if (readAttachment) { bpcontent = convertInputStreamToString(bodyPart.getInputStream()); buf.append(bpcontent); break; } else if (readZip) { // if there is a password for an attachment, unzip attachment bpcontent = UnzipMailAttachment.unzipMailAttachment(bodyPart.getInputStream(), passwordAttachment); buf.append(bpcontent); } else { buf.append(bodyPart.getContent()); } } else { buf.append(bodyPart.getContent()); } } catch (UnsupportedEncodingException ex) { String message = ex.getMessage(); buf.append(message); log.error(ex.toString()); } buf.append(SEP); } } else { buf.append(content); } buf.append(SEP); return buf.toString(); } /** * Converts the given InputStream to a String * * @param is * The InputStream which gets converted * @return String representation of is */ private String convertInputStreamToString(InputStream is) { BufferedReader din = new BufferedReader(new InputStreamReader(is)); StringBuffer sb = new StringBuffer(); try { String line = null; while ((line = din.readLine()) != null) { sb.append(line); sb.append(SEP); } } catch (Exception ex) { log.error(ex.toString()); } finally { try { is.close(); } catch (Exception ex) { } } return sb.toString(); } public String getHostType() { return hostType; } public void setHostType(String hostType) { this.hostType = hostType; } public String getHost() { return host; } public void setHost(String host) { this.host = host; } public String getUser() { return user; } public void setUser(String user) { this.user = user; } public String getPass() { return pass; } public void setPass(String pass) { this.pass = pass; } public String getFolder() { return folder; } public void setFolder(String folder) { this.folder = folder; } public String getDeleteMessages() { return deleteMessages; } public void setDeleteMessages(String deleteMessages) { this.deleteMessages = deleteMessages; } public String getPkcs12file() { return pkcs12file; } public String getPkcs12pw() { return pkcs12pw; } public void setPkcs12file(String pkcs12file) { this.pkcs12file = pkcs12file; } public void setPkcs12pw(String pkcs12pw) { this.pkcs12pw = pkcs12pw; } /** * Indicates whether all messages in the folder should be deleted or not. * * @return TRUE if messages should be deleted or FALSE otherwise */ private boolean isDeleteMessages() { if (deleteMessages != null && deleteMessages.equalsIgnoreCase("yes")) { return true; } else { return false; } } public MimeBodyPart decryptSMIME(MimeMessage message) throws Exception { // Needed for SMIME Decryption Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); // // Open the key store // KeyStore ks = KeyStore.getInstance("PKCS12", "BC"); if (getPkcs12file().equals("") || getPkcs12pw().equals("")) { throw new Exception("You have to specify a pkcs12 and a password"); } log.debug("pkcs12file: " + getPkcs12file() + " , pkcs12pw: " + getPkcs12pw()); ks.load(new FileInputStream(getPkcs12file()), getPkcs12pw().toCharArray()); // "c:/temp/IntegrationstestSpediteurVQ8F5S-SN30044.p12"), "088TQS1Y7R".toCharArray() Enumeration<String> e1 = ks.aliases(); String keyAlias = null; while (e1.hasMoreElements()) { String alias = (String) e1.nextElement(); if (ks.isKeyEntry(alias)) { keyAlias = alias; } } if (keyAlias == null) { log.error("can't find a private key!"); } // // find the certificate for the private key and generate a // suitable recipient identifier. // X509Certificate cert = (X509Certificate) ks.getCertificate(keyAlias); RecipientId recId = new RecipientId(); recId.setSerialNumber(cert.getSerialNumber()); recId.setIssuer(cert.getIssuerX500Principal().getEncoded()); SMIMEEnveloped m = new SMIMEEnveloped(message); RecipientInformationStore recipients = m.getRecipientInfos(); RecipientInformation recipient = recipients.get(recId); if (recipient == null) { throw new Exception("recipient not found -> could not find key for encryption"); } return SMIMEUtil.toMimeBodyPart(recipient.getContent(ks.getKey(keyAlias, null), "BC")); } public String unsignSMIME(MimeMessage message) throws Exception { // SMIME StringBuffer buf = new StringBuffer(); // heading buf.append("Message "); buf.append(message.getSubject()); buf.append(":"); buf.append(SEP); // date buf.append("Date: "); buf.append(message.getSentDate()); buf.append(SEP); // to buf.append("To: "); Address[] recips = message.getAllRecipients(); for (int j = 0; j < recips.length; j++) { buf.append(recips[j].toString()); if (j < recips.length - 1) buf.append("; "); } buf.append(SEP); // from buf.append("From: "); Address[] from = message.getFrom(); for (int j = 0; j < from.length; j++) { buf.append(from[j].toString()); if (j < from.length - 1) buf.append("; "); } buf.append(SEP); // subject buf.append("Subject: "); buf.append(message.getSubject()); buf.append(SEP); // content (all bodyparts) buf.append(SEP); MimeBodyPart res = decryptSMIME(message); if (res.isMimeType("multipart/signed")) { SMIMESigned s = new SMIMESigned((MimeMultipart) res.getContent()); extractContentAndAppendIt(buf, s); } else if (res.isMimeType("application/pkcs7-mime") || res.isMimeType("application/x-pkcs7-mime")) { // // in this case the content is wrapped in the signature block. // SMIMESigned s = new SMIMESigned(res); extractContentAndAppendIt(buf, s); } else { return "Not a signed message!"; } return buf.toString(); } private void extractContentAndAppendIt(StringBuffer out, SMIMESigned s) throws IOException, MessagingException { MimeBodyPart content = s.getContent(); Object cont = content.getContent(); if (cont instanceof String) { out.append(cont.toString()); } else if (cont instanceof Multipart) { Multipart mp = (Multipart) cont; int count = mp.getCount(); out.append("Multipart. Count: "); out.append(count); for (int i1 = 0; i1 < count; i1++) { BodyPart m1 = mp.getBodyPart(i1); out.append(SEP); out.append("Type: "); out.append(m1.getContentType()); out.append(SEP); InputStream data_is = m1.getInputStream(); byte[] buf = new byte[1024]; int r; while ((r = data_is.read(buf)) > 0) { out.append(new String(buf, 0, r)); } } } } public void setPasswordAttachment(String passwordAttachment) { this.passwordAttachment = passwordAttachment; } public String getPasswordAttachment() { return passwordAttachment; } } Here are the bean infos: package ch.admin.bit.edec.jmeter.mail; import java.beans.PropertyDescriptor; import org.apache.jmeter.testbeans.BeanInfoSupport; import org.apache.jmeter.testbeans.gui.FileEditor; public class CustomMailReaderBeanInfo extends BeanInfoSupport { // These names must agree case-wise with the variable and property names private static final String HOST_TYPE = "hostType"; private static final String HOST = "host"; private static final String USER = "user"; private static final String PASS = "pass"; private static final String FOLDER = "folder"; private static final String PKCS12FILE = "pkcs12file"; private static final String PKCS12PW = "pkcs12pw"; private static final String DELETE_MESSAGES = "deleteMessages"; private static final String PASS_ATT = "passwordAttachment"; public CustomMailReaderBeanInfo() { super(CustomMailReader.class); createPropertyGroup("reader_configuration", new String[] { HOST_TYPE, HOST, USER, PASS, FOLDER, DELETE_MESSAGES }); createPropertyGroup("reader_configuration_secure", new String[] { PKCS12FILE, PKCS12PW }); createPropertyGroup("zipped_mail_attachment", new String[] { PASS_ATT }); PropertyDescriptor p = property(HOST_TYPE); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, CustomMailReader.HOST_TYPE_POP3); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p = property(HOST); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p = property(USER); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p = property(PASS); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p = property(PKCS12FILE); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p.setPropertyEditorClass(FileEditor.class); p = property(PKCS12PW); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.TRUE); p = property(FOLDER); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, "INBOX"); p.setValue(NOT_EXPRESSION, Boolean.FALSE); p = property(DELETE_MESSAGES); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, "YES"); p.setValue(NOT_EXPRESSION, Boolean.FALSE); p = property(PASS_ATT); p.setValue(NOT_UNDEFINED, Boolean.TRUE); p.setValue(DEFAULT, ""); p.setValue(NOT_EXPRESSION, Boolean.FALSE); } } And here are the resources properties: displayName=Custom Mail Reader reader_configuration.displayName=Configuration reader_configuration_secure.displayName=Signed and Encrypted Mails zipped_mail_attachment.displayName=Zipped and encrypted mail attachments hostType.displayName=Host Type (pop3/imap) hostType.shortDescription=Either POP3 or IMAP host.displayName=Host host.shortDescription=Hostname or IP Address user.displayName=User user.shortDescription=Mailstore username pass.displayName=Pass pass.shortDescription=Mailstore password pkcs12file.displayName=PKCS12 Zertifikatsfile pkcs12file.shortDescription=pkcs12file pkcs12pw.displayName=PKCS12 Zertifikatspasswort pkcs12pw.shortDescription=pkcs12pw folder.displayName=Folder folder.shortDescription=Fetch messages from this folder deleteMessages.displayName=Delete Messages on Host (yes/no) deleteMessages.shortDescription=YES or NO whether fetched messages are deleted or not passwordAttachment.displayName=Password for the zipped mail attachment passwordAttachment.shortDescription=Password for the zipped mail attachment ________________________________________ Von: sebb [[email protected]] Gesendet: Donnerstag, 24. November 2011 16:29 Bis: JMeter Users List Betreff: Re: Problems with headless Mode On 24 November 2011 15:19, Schweizer, Adrian <[email protected]> wrote: > Hello > > Is there a known problem with headless mode in jMeter v2.3? We have some > tests that work fine using the GUI, but fail in headless mode. I'm wondering > if there are special circumstances that must be comsidered when using the -n > parameter. JMeter 2.3 is very old; would be worth trying 2.5.1. What error messages are you getting (don't need them all, just a sample selection)? > Kind regards > Adrian > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
