Skip to content

Commit

Permalink
Add option to set content type property
Browse files Browse the repository at this point in the history
  • Loading branch information
tinexw committed Apr 14, 2015
1 parent 7d62133 commit 1e2fc7f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/main/com/zeroclue/jmeter/protocol/amqp/AMQPPublisher.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.zeroclue.jmeter.protocol.amqp;

import com.rabbitmq.client.AMQP;

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

import com.rabbitmq.client.MessageProperties;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.Interruptible;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class AMQPPublisher extends AMQPSampler implements Interruptible {
private final static String MESSAGE_ROUTING_KEY = "AMQPPublisher.MessageRoutingKey";
private final static String MESSAGE_TYPE = "AMQPPublisher.MessageType";
private final static String REPLY_TO_QUEUE = "AMQPPublisher.ReplyToQueue";
private final static String CONTENT_TYPE = "AMQPPublisher.ContentType";
private final static String CORRELATION_ID = "AMQPPublisher.CorrelationId";
private final static String HEADERS = "AMQPPublisher.Headers";

Expand Down Expand Up @@ -170,6 +172,14 @@ public void setReplyToQueue(String content) {
setProperty(REPLY_TO_QUEUE, content);
}

public String getContentType() {
return getPropertyAsString(CONTENT_TYPE);
}

public void setContentType(String contentType) {
setProperty(CONTENT_TYPE, contentType);
}

/**
* @return the correlation identifier for the sample
*/
Expand Down Expand Up @@ -226,9 +236,11 @@ protected AMQP.BasicProperties getProperties() {
AMQP.BasicProperties parentProps = super.getProperties();

int deliveryMode = getPersistent() ? 2 : 1;

final String contentType = StringUtils.defaultString(getContentType(), parentProps.getContentType());

AMQP.BasicProperties publishProperties =
new AMQP.BasicProperties(parentProps.getContentType(), parentProps.getContentEncoding(),
new AMQP.BasicProperties(contentType, parentProps.getContentEncoding(),
parentProps.getHeaders(), deliveryMode, parentProps.getPriority(),
getCorrelationId(), getReplyToQueue(), parentProps.getExpiration(),
parentProps.getMessageId(), parentProps.getTimestamp(), getMessageType(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class AMQPPublisherGui extends AMQPSamplerGui {
private JLabeledTextField messageType = new JLabeledTextField("Message Type");
private JLabeledTextField replyToQueue = new JLabeledTextField("Reply-To Queue");
private JLabeledTextField correlationId = new JLabeledTextField("Correlation Id");
private JLabeledTextField contentType = new JLabeledTextField("ContentType");

private JCheckBox persistent = new JCheckBox("Persistent?", AMQPPublisher.DEFAULT_PERSISTENT);
private JCheckBox useTx = new JCheckBox("Use Transactions?", AMQPPublisher.DEFAULT_USE_TX);
Expand Down Expand Up @@ -76,6 +77,7 @@ public void configure(TestElement element) {
messageRoutingKey.setText(sampler.getMessageRoutingKey());
messageType.setText(sampler.getMessageType());
replyToQueue.setText(sampler.getReplyToQueue());
contentType.setText(sampler.getContentType());
correlationId.setText(sampler.getCorrelationId());
message.setText(sampler.getMessage());
configureHeaders(sampler);
Expand Down Expand Up @@ -110,6 +112,7 @@ public void modifyTestElement(TestElement te) {
sampler.setMessageType(messageType.getText());
sampler.setReplyToQueue(replyToQueue.getText());
sampler.setCorrelationId(correlationId.getText());
sampler.setContentType(contentType.getText());
sampler.setHeaders((Arguments) headers.createTestElement());
}

Expand All @@ -130,6 +133,7 @@ protected final void init() {
messageType.setPreferredSize(new Dimension(100, 25));
replyToQueue.setPreferredSize(new Dimension(100, 25));
correlationId.setPreferredSize(new Dimension(100, 25));
contentType.setPreferredSize(new Dimension(100, 25));
message.setPreferredSize(new Dimension(400, 150));

mainPanel.add(persistent);
Expand All @@ -138,6 +142,7 @@ protected final void init() {
mainPanel.add(messageType);
mainPanel.add(replyToQueue);
mainPanel.add(correlationId);
mainPanel.add(contentType);
mainPanel.add(headers);
mainPanel.add(message);
}
Expand All @@ -154,6 +159,7 @@ public void clearGui() {
messageType.setText("");
replyToQueue.setText("");
correlationId.setText("");
contentType.setText("");
headers.clearGui();
message.setText("");
}
Expand Down

0 comments on commit 1e2fc7f

Please sign in to comment.