ASF Bugzilla – Attachment 36360 Details for
Bug 63025
Search and replace not working for port number
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Replace port and protocol in HTTP Samplers
01-replace-values.diff (text/plain), 3.62 KB, created by
Felix Schumacher
on 2019-01-02 12:09:54 UTC
(
hide
)
Description:
Replace port and protocol in HTTP Samplers
Filename:
MIME Type:
Creator:
Felix Schumacher
Created:
2019-01-02 12:09:54 UTC
Size:
3.62 KB
patch
obsolete
>diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java b/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java >index c2f7d2056..0d42224db 100644 >--- a/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java >+++ b/src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerBase.java >@@ -39,6 +39,7 @@ import java.util.Set; > import java.util.concurrent.Callable; > import java.util.concurrent.ExecutionException; > import java.util.concurrent.Future; >+import java.util.function.Consumer; > > import org.apache.commons.io.IOUtils; > import org.apache.commons.lang3.StringUtils; >@@ -2092,42 +2093,31 @@ public abstract class HTTPSamplerBase extends AbstractSampler > @Override > public int replace(String regex, String replaceBy, boolean caseSensitive) throws Exception { > int totalReplaced = 0; >+ > for (JMeterProperty jMeterProperty : getArguments()) { > HTTPArgument arg = (HTTPArgument) jMeterProperty.getObjectValue(); >- String value = arg.getValue(); >- if(!StringUtils.isEmpty(value)) { >- Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive); >- // check if there is anything to replace >- int nbReplaced = ((Integer)result[1]).intValue(); >- if (nbReplaced>0) { >- String replacedText = (String) result[0]; >- arg.setValue(replacedText); >- totalReplaced += nbReplaced; >- } >- } >- } >- String value = getPath(); >- if(!StringUtils.isEmpty(value)) { >- Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive); >- // check if there is anything to replace >- int nbReplaced = ((Integer)result[1]).intValue(); >- if (nbReplaced>0) { >- String replacedText = (String) result[0]; >- setPath(replacedText); >- totalReplaced += nbReplaced; >- } >+ totalReplaced += replaceValue(regex, replaceBy, caseSensitive, arg.getValue(), arg::setValue); > } > >- if(!StringUtils.isEmpty(getDomain())) { >- Object[] result = JOrphanUtils.replaceAllWithRegex(getDomain(), regex, replaceBy, caseSensitive); >- // check if there is anything to replace >- int nbReplaced = ((Integer)result[1]).intValue(); >- if (nbReplaced>0) { >- String replacedText = (String) result[0]; >- setDomain(replacedText); >- totalReplaced += nbReplaced; >- } >- } >+ totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getPath(), this::setPath); >+ totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getDomain(), this::setDomain); >+ totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getProtocol(), this::setProtocol); >+ totalReplaced += replaceValue(regex, replaceBy, caseSensitive, getPort() + "", (s) -> setPort(Integer.parseInt(s))); >+ > return totalReplaced; > } >+ >+ private int replaceValue(String regex, String replaceBy, boolean caseSensitive, String value, Consumer<String> setter) { >+ if (StringUtils.isBlank(value)) { >+ return 0; >+ } >+ Object[] result = JOrphanUtils.replaceAllWithRegex(value, regex, replaceBy, caseSensitive); >+ int nbReplaced = ((Integer) result[1]).intValue(); >+ if (nbReplaced <= 0) { >+ return 0; >+ } >+ setter.accept((String) result[0]); >+ return nbReplaced; >+ } >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 63025
:
36358
|
36359
| 36360