Skip to content

Commit

Permalink
Add support for SSLed connections
Browse files Browse the repository at this point in the history
  • Loading branch information
simmel committed Jun 24, 2013
1 parent ac666a9 commit b13fc74
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/main/com/zeroclue/jmeter/protocol/amqp/AMQPSampler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.IOException;
import java.util.*;
import java.security.*;

import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.testelement.ThreadListener;
Expand Down Expand Up @@ -44,6 +45,7 @@ public abstract class AMQPSampler extends AbstractSampler implements ThreadListe
protected static final String VIRUTAL_HOST = "AMQPSampler.VirtualHost";
protected static final String HOST = "AMQPSampler.Host";
protected static final String PORT = "AMQPSampler.Port";
protected static final String SSL = "AMQPSampler.SSL";
protected static final String USERNAME = "AMQPSampler.Username";
protected static final String PASSWORD = "AMQPSampler.Password";
private static final String TIMEOUT = "AMQPSampler.Timeout";
Expand All @@ -63,7 +65,7 @@ protected AMQPSampler(){
factory.setRequestedHeartbeat(DEFAULT_HEARTBEAT);
}

protected boolean initChannel() throws IOException {
protected boolean initChannel() throws IOException, NoSuchAlgorithmException, KeyManagementException {
Channel channel = getChannel();

if(channel != null && !channel.isOpen()){
Expand Down Expand Up @@ -261,6 +263,17 @@ protected int getPortAsInt() {
return getPropertyAsInt(PORT);
}

public void setConnectionSSL(String content) {
setProperty(SSL, content);
}

public void setConnectionSSL(Boolean value) {
setProperty(SSL, value.toString());
}

public boolean connectionSSL() {
return getPropertyAsBoolean(SSL);
}


public String getUsername() {
Expand Down Expand Up @@ -367,7 +380,7 @@ public void threadStarted() {

}

protected Channel createChannel() throws IOException {
protected Channel createChannel() throws IOException, NoSuchAlgorithmException, KeyManagementException {
log.info("Creating channel " + getVirtualHost()+":"+getPortAsInt());

if (connection == null || !connection.isOpen()) {
Expand All @@ -377,6 +390,9 @@ protected Channel createChannel() throws IOException {
factory.setPort(getPortAsInt());
factory.setUsername(getUsername());
factory.setPassword(getPassword());
if (connectionSSL()) {
factory.useSslProtocol("TLS");
}

log.info("RabbitMQ ConnectionFactory using:"
+"\n\t virtual host: " + getVirtualHost()
Expand All @@ -399,7 +415,7 @@ protected Channel createChannel() throws IOException {
return channel;
}

protected void deleteQueue() throws IOException {
protected void deleteQueue() throws IOException, NoSuchAlgorithmException, KeyManagementException {
// use a different channel since channel closes on exception.
Channel channel = createChannel();
try {
Expand All @@ -417,7 +433,7 @@ protected void deleteQueue() throws IOException {
}
}

protected void deleteExchange() throws IOException {
protected void deleteExchange() throws IOException, NoSuchAlgorithmException, KeyManagementException {
// use a different channel since channel closes on exception.
Channel channel = createChannel();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public abstract class AMQPSamplerGui extends AbstractSamplerGui {
protected JLabeledTextField timeout = new JLabeledTextField("Timeout");
protected JLabeledTextField username = new JLabeledTextField("Username");
protected JLabeledTextField password = new JLabeledTextField("Password");
private final JCheckBox SSL = new JCheckBox("SSL?", false);

private final JLabeledTextField iterations = new JLabeledTextField("Number of samples to Aggregate");

Expand Down Expand Up @@ -77,6 +78,7 @@ public void configure(TestElement element) {
port.setText(sampler.getPort());
username.setText(sampler.getUsername());
password.setText(sampler.getPassword());
SSL.setSelected(sampler.connectionSSL());
log.info("AMQPSamplerGui.configure() called");
}

Expand Down Expand Up @@ -106,6 +108,7 @@ public void clearGui() {
port.setText(AMQPSampler.DEFAULT_PORT_STRING);
username.setText("guest");
password.setText("guest");
SSL.setSelected(false);
}

/**
Expand Down Expand Up @@ -137,6 +140,7 @@ public void modifyTestElement(TestElement element) {
sampler.setPort(port.getText());
sampler.setUsername(username.getText());
sampler.setPassword(password.getText());
sampler.setConnectionSSL(SSL.isSelected());
log.info("AMQPSamplerGui.modifyTestElement() called, set user/pass to " + username.getText() + "/" + password.getText() + " on sampler " + sampler);
}

Expand Down Expand Up @@ -248,6 +252,10 @@ private Component makeCommonPanel() {
gridBagConstraints.gridy = 2;
serverSettings.add(port, gridBagConstraints);

gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 2;
serverSettings.add(SSL, gridBagConstraints);

gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
serverSettings.add(username, gridBagConstraints);
Expand Down

0 comments on commit b13fc74

Please sign in to comment.