From eec26ef47f07218e05ffbbe50c29133e2f69f073 Mon Sep 17 00:00:00 2001 From: Malachi McIntosh Date: Mon, 6 Jun 2022 09:43:35 +1200 Subject: [PATCH 1/2] Added content type to az service bus messages --- .../protocol/amqp/sampler/AzAmqpMessage.java | 21 +++++++++++++++++++ .../amqp/sampler/gui/AzAmqpMessagesPanel.java | 1 + .../sampler/AzServiceBusSampler.java | 6 ++++++ .../gui/AzServiceBusMessagesPanel.java | 12 +++++------ 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessage.java b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessage.java index 4b253fc..064afd1 100644 --- a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessage.java +++ b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/AzAmqpMessage.java @@ -34,6 +34,7 @@ public class AzAmqpMessage extends AbstractTestElement { private static final String GROUP_ID = "Message.groupId"; //$NON-NLS$ private static final String PARTITION_KEY = "Message.partitionKey"; //$NON-NLS$ private static final String CUSTOM_PROPERTIES = "Message.customProperties"; //$NON-NLS$ + private static final String CONTENT_TYPE = "Message.contentType"; //$NON-NLS$ public AzAmqpMessage() { } @@ -52,6 +53,7 @@ public AzAmqpMessage(String messageType) { setProperty(new StringProperty(MESSAGE_ID, "")); setProperty(new StringProperty(GROUP_ID, "")); setProperty(new StringProperty(CUSTOM_PROPERTIES, "")); + setProperty(new StringProperty(CONTENT_TYPE, "")); } /** @@ -168,4 +170,23 @@ public String getCustomProperties() { return getPropertyAsString(CUSTOM_PROPERTIES); } + /** + * Set the content type of the Message. + * + * @param contentType + * the new content type + */ + public void setContentType(String contentType) { + setProperty(new StringProperty(CONTENT_TYPE, contentType)); + } + + /** + * Get the content type. + * + * @return the content type + */ + public String getContentType() { + return getPropertyAsString(CONTENT_TYPE); + } + } diff --git a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java index cb7f47c..fed1afd 100644 --- a/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java +++ b/plugins/protocol/amqp/src/main/java/jp/co/pnop/jmeter/protocol/amqp/sampler/gui/AzAmqpMessagesPanel.java @@ -87,6 +87,7 @@ public class AzAmqpMessagesPanel extends AbstractSamplerGui implements ActionLis COLUMN_NAMES.put("MESSAGE_ID", "message Id"); //$NON-NLS-1$ COLUMN_NAMES.put("GROUP_ID", "group Id"); //$NON-NLS-1$ COLUMN_NAMES.put("CUSTOM_PROPERTIES", "custom properties"); //$NON-NLS-1$ + COLUMN_NAMES.put("CONTENT_TYPE", "content type"); //$NON-NLS-1$ } public AzAmqpMessagesPanel() { diff --git a/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/AzServiceBusSampler.java b/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/AzServiceBusSampler.java index 29692aa..7b8e8bf 100644 --- a/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/AzServiceBusSampler.java +++ b/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/AzServiceBusSampler.java @@ -283,6 +283,12 @@ public SampleResult sample(Entry e) { Map properties = mapper.readValue(customProperties, new TypeReference>(){}); serviceBusMessage.getApplicationProperties().putAll(properties); } + + String contentType = msg.getContentType(); + if (!contentType.isEmpty()) { + serviceBusMessage.setContentType(contentType); + requestBody = requestBody.concat("\n").concat("Content Type: ").concat(contentType); + } batch.tryAddMessage(serviceBusMessage); bodyBytes += serviceBusMessage.getBody().toBytes().length; diff --git a/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java b/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java index dc1c4ff..ae22bd8 100644 --- a/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java +++ b/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java @@ -18,12 +18,12 @@ public AzServiceBusMessagesPanel() { @Override protected void initializeTableModel() { tableModel = new ObjectTableModel( - new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key", COLUMN_NAMES.get("CUSTOM_PROPERTIES") }, - AzAmqpMessage.class, - new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey"), new Functor("getCustomProperties") }, - new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey"), new Functor("setCustomProperties") }, - new Class[] { String.class, String.class, String.class, String.class, String.class, String.class } - ); + new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key", COLUMN_NAMES.get("CUSTOM_PROPERTIES"), COLUMN_NAMES.get("CONTENT_TYPE") }, + AzAmqpMessage.class, + new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey"), new Functor("getCustomProperties"), new Functor("getContentType") }, + new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey"), new Functor("setCustomProperties"), new Functor("setContentType") }, + new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class } + ); } From c1133e0c7c12fb7d5ed255a7b8dd69e2dd0f3d60 Mon Sep 17 00:00:00 2001 From: Malachi Date: Mon, 6 Jun 2022 15:40:02 +1200 Subject: [PATCH 2/2] Content type to az service bus. Formatting. --- .../sampler/gui/AzServiceBusMessagesPanel.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java b/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java index ae22bd8..98a52e7 100644 --- a/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java +++ b/plugins/protocol/servicebus/src/main/java/jp/co/pnop/jmeter/protocol/azureservicebus/sampler/gui/AzServiceBusMessagesPanel.java @@ -18,13 +18,12 @@ public AzServiceBusMessagesPanel() { @Override protected void initializeTableModel() { tableModel = new ObjectTableModel( - new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key", COLUMN_NAMES.get("CUSTOM_PROPERTIES"), COLUMN_NAMES.get("CONTENT_TYPE") }, - AzAmqpMessage.class, - new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey"), new Functor("getCustomProperties"), new Functor("getContentType") }, - new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey"), new Functor("setCustomProperties"), new Functor("setContentType") }, - new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class } - ); + new String[] { COLUMN_NAMES.get("MESSAGE_TYPE"), COLUMN_NAMES.get("MESSAGE"), COLUMN_NAMES.get("MESSAGE_ID"), "session Id", "partition key", COLUMN_NAMES.get("CUSTOM_PROPERTIES"), COLUMN_NAMES.get("CONTENT_TYPE") }, + AzAmqpMessage.class, + new Functor[] { new Functor("getMessageType"), new Functor("getMessage"), new Functor("getMessageId"), new Functor("getGroupId"), new Functor("getPartitionKey"), new Functor("getCustomProperties"), new Functor("getContentType") }, + new Functor[] { new Functor("setMessageType"), new Functor("setMessage"), new Functor("setMessageId"), new Functor("setGroupId"), new Functor("setPartitionKey"), new Functor("setCustomProperties"), new Functor("setContentType") }, + new Class[] { String.class, String.class, String.class, String.class, String.class, String.class, String.class } + ); } - -} +} \ No newline at end of file