diff --git a/src/main/java/JMeter/plugins/functional/samplers/websocket/ServiceSocket.java b/src/main/java/JMeter/plugins/functional/samplers/websocket/ServiceSocket.java
index 0204c64..afe2cae 100644
--- a/src/main/java/JMeter/plugins/functional/samplers/websocket/ServiceSocket.java
+++ b/src/main/java/JMeter/plugins/functional/samplers/websocket/ServiceSocket.java
@@ -54,13 +54,11 @@ public class ServiceSocket {
public ServiceSocket(WebSocketSampler parent, WebSocketClient client) {
this.parent = parent;
this.client = client;
-
- //Evaluate response matching patterns in case thay contain JMeter variables (i.e. ${var})
- responsePattern = new CompoundVariable(parent.getResponsePattern()).execute();
- disconnectPattern = new CompoundVariable(parent.getCloseConncectionPattern()).execute();
+
+ setResponsePattern(parent.getResponsePattern());
+ setDisconnectPattern(parent.getCloseConncectionPattern());
logMessage.append("\n\n[Execution Flow]\n");
logMessage.append(" - Opening new connection\n");
- initializePatterns();
}
@OnWebSocketMessage
@@ -234,7 +232,17 @@ public void log(String message) {
logMessage.append(message);
}
- protected void initializePatterns() {
+ /**
+ * Resets the patterns used to end a sample
+ * @param newResponsePattern the new response pattern to use
+ */
+ protected void setResponsePattern(String newResponsePattern) {
+ // Evaluate response matching patterns in case thay contain JMeter variables (i.e. ${var})
+ responsePattern = new CompoundVariable(newResponsePattern).execute();
+ initializeResponsePattern();
+ }
+
+ private void initializeResponsePattern() {
try {
logMessage.append(" - Using response message pattern \"").append(responsePattern).append("\"\n");
responseExpression = (responsePattern != null || !responsePattern.isEmpty()) ? Pattern.compile(responsePattern) : null;
@@ -243,7 +251,19 @@ protected void initializePatterns() {
log.error("Invalid response message regular expression pattern: " + ex.getLocalizedMessage());
responseExpression = null;
}
+ }
+
+ /**
+ * Resets the patterns used to close the connection
+ * @param newDisconnectPattern the new disconnect pattern to use
+ */
+ protected void setDisconnectPattern(String newDisconnectPattern) {
+ // Evaluate response matching patterns in case thay contain JMeter variables (i.e. ${var})
+ disconnectPattern = new CompoundVariable(newDisconnectPattern).execute();
+ initializeDisconnectPattern();
+ }
+ private void initializeDisconnectPattern() {
try {
logMessage.append(" - Using disconnect pattern \"").append(disconnectPattern).append("\"\n");
disconnectExpression = (disconnectPattern != null || !disconnectPattern.isEmpty()) ? Pattern.compile(disconnectPattern) : null;
@@ -252,7 +272,6 @@ protected void initializePatterns() {
log.error("Invalid disconnect regular regular expression pattern: " + ex.getLocalizedMessage());
disconnectExpression = null;
}
-
}
/**
diff --git a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSampler.java b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSampler.java
index 8a2975e..72e2071 100644
--- a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSampler.java
+++ b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSampler.java
@@ -70,9 +70,20 @@ private ServiceSocket getConnectionSocket() throws URISyntaxException, Exception
String connectionId = getThreadName() + getConnectionId();
+ // Get the existing socket for this client
if (isStreamingConnection() && connectionList.containsKey(connectionId)) {
ServiceSocket socket = connectionList.get(connectionId);
socket.initialize();
+
+ // use new response and disconnect patterns if overriden
+ if (this.isOverrideResponsePattern()) {
+ socket.setResponsePattern(this.getResponsePattern());
+ }
+
+ if (this.isOverrideDisconnectPattern()) {
+ socket.setDisconnectPattern(this.getCloseConncectionPattern());
+ }
+
return socket;
}
@@ -391,6 +402,22 @@ public String getCloseConncectionPattern() {
return getPropertyAsString("closeConncectionPattern");
}
+ void setOverrideResponsePattern(Boolean overrideResponsePattern) {
+ setProperty("isOverrideResponsePattern", overrideResponsePattern);
+ }
+
+ Boolean isOverrideResponsePattern() {
+ return getPropertyAsBoolean("isOverrideResponsePattern", false);
+ }
+
+ void setOverrideDisconnectPattern(Boolean overrideDisconnectPattern) {
+ setProperty("isOverrideDisconnectPattern", overrideDisconnectPattern);
+ }
+
+ Boolean isOverrideDisconnectPattern() {
+ return getPropertyAsBoolean("isOverrideDisconnectPattern", false);
+ }
+
public void setProxyAddress(String proxyAddress) {
setProperty("proxyAddress", proxyAddress);
}
@@ -515,6 +542,4 @@ public void testEnded(String host) {
}
}
-
-
}
diff --git a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerGui.java b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerGui.java
index 0b6933b..3838b6f 100644
--- a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerGui.java
+++ b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerGui.java
@@ -67,6 +67,8 @@ public void configure(TestElement element) {
webSocketSamplerPanel.setProxyPort(webSocketSamplerTestElement.getProxyPort());
webSocketSamplerPanel.setProxyUsername(webSocketSamplerTestElement.getProxyUsername());
webSocketSamplerPanel.setMessageBacklog(webSocketSamplerTestElement.getMessageBacklog());
+ webSocketSamplerPanel.setOverrideResponsePattern(webSocketSamplerTestElement.isOverrideResponsePattern());
+ webSocketSamplerPanel.setOverrideDisconnectPattern(webSocketSamplerTestElement.isOverrideDisconnectPattern());
Arguments queryStringParameters = webSocketSamplerTestElement.getQueryStringParameters();
if (queryStringParameters != null) {
@@ -106,6 +108,9 @@ public void modifyTestElement(TestElement te) {
webSocketSamplerTestElement.setProxyPort(webSocketSamplerPanel.getProxyPort());
webSocketSamplerTestElement.setProxyUsername(webSocketSamplerPanel.getProxyUsername());
webSocketSamplerTestElement.setMessageBacklog(webSocketSamplerPanel.getMessageBacklog());
+ webSocketSamplerTestElement.setOverrideResponsePattern(webSocketSamplerPanel.isOverrideResponsePattern());
+ webSocketSamplerTestElement.setOverrideDisconnectPattern(webSocketSamplerPanel.isOverrideDisconnectPattern());
+
ArgumentsPanel queryStringParameters = webSocketSamplerPanel.getAttributePanel();
if (queryStringParameters != null) {
diff --git a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.form b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.form
index 2ed45b8..b547ed0 100644
--- a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.form
+++ b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.form
@@ -353,7 +353,9 @@
-
+
+
+
@@ -362,6 +364,8 @@
+
+
@@ -376,6 +380,7 @@
+
@@ -386,6 +391,7 @@
+
@@ -414,6 +420,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.java b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.java
index 4185aa6..5e26c91 100644
--- a/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.java
+++ b/src/main/java/JMeter/plugins/functional/samplers/websocket/WebSocketSamplerPanel.java
@@ -71,6 +71,8 @@ private void initComponents() {
closeConncectionPatternTextField = new javax.swing.JTextField();
jLabel16 = new javax.swing.JLabel();
messageBacklogTextField = new javax.swing.JTextField();
+ overrideResponsePatternCheckBox = new javax.swing.JCheckBox();
+ overrideDisconnectPatternCheckBox = new javax.swing.JCheckBox();
jPanel6 = new javax.swing.JPanel();
jLabel10 = new javax.swing.JLabel();
proxyAddressTextField = new javax.swing.JTextField();
@@ -250,6 +252,10 @@ private void initComponents() {
jLabel16.setText("Message backlog:");
+ overrideResponsePatternCheckBox.setText("Override previous");
+
+ overrideDisconnectPatternCheckBox.setText("Override previous");
+
javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
jPanel5.setLayout(jPanel5Layout);
jPanel5Layout.setHorizontalGroup(
@@ -261,14 +267,18 @@ private void initComponents() {
.addComponent(jLabel7)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(responsePatternTextField)
- .addGap(18, 18, 18)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
+ .addComponent(overrideResponsePatternCheckBox)
+ .addGap(6, 6, 6)
.addComponent(jLabel16)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(messageBacklogTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
.addComponent(jLabel9)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(closeConncectionPatternTextField)))
+ .addComponent(closeConncectionPatternTextField)
+ .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
+ .addComponent(overrideDisconnectPatternCheckBox)))
.addContainerGap())
);
jPanel5Layout.setVerticalGroup(
@@ -278,14 +288,16 @@ private void initComponents() {
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel16)
- .addComponent(messageBacklogTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(messageBacklogTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(overrideResponsePatternCheckBox))
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel7)
.addComponent(responsePatternTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel9)
- .addComponent(closeConncectionPatternTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
+ .addComponent(closeConncectionPatternTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
+ .addComponent(overrideDisconnectPatternCheckBox))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
@@ -413,6 +425,8 @@ private void initComponents() {
private javax.swing.JPanel jPanel6;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField messageBacklogTextField;
+ private javax.swing.JCheckBox overrideDisconnectPatternCheckBox;
+ private javax.swing.JCheckBox overrideResponsePatternCheckBox;
private javax.swing.JTextField protocolTextField;
private javax.swing.JTextField proxyAddressTextField;
private javax.swing.JTextField proxyPasswordTextField;
@@ -580,7 +594,23 @@ public void setMessageBacklog(String messageBacklog) {
public String getMessageBacklog() {
return messageBacklogTextField.getText();
- }
+ }
+
+ public void setOverrideResponsePattern(Boolean overrideResponsePattern) {
+ overrideResponsePatternCheckBox.setSelected(overrideResponsePattern);
+ }
+
+ public Boolean isOverrideResponsePattern() {
+ return overrideResponsePatternCheckBox.isSelected();
+ }
+
+ public void setOverrideDisconnectPattern(Boolean overrideDisconnectPattern) {
+ overrideDisconnectPatternCheckBox.setSelected(overrideDisconnectPattern);
+ }
+
+ public Boolean isOverrideDisconnectPattern() {
+ return overrideDisconnectPatternCheckBox.isSelected();
+ }
/**
* @return the attributePanel