Skip to content

Commit 87f417c

Browse files
fix: the issue that the httpclient type fails to be built to match the key is fixed (#598)
* fix: uri append (#594) * fix: uri append * fix: uri append * fix: the issue that the httpclient type fails to be built to match the key is fixed --------- Co-authored-by: Nathan Mo <[email protected]>
1 parent d21182e commit 87f417c

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

arex-instrumentation/httpclient/arex-httpclient-resttemplate/src/main/java/io/arex/inst/httpclient/resttemplate/RestTemplateExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.net.URI;
1616
import java.util.HashMap;
1717
import java.util.Map;
18+
import java.util.Objects;
1819
import org.springframework.http.HttpMethod;
1920
import org.springframework.http.ResponseEntity;
2021
import org.springframework.web.client.RequestCallback;
@@ -108,7 +109,7 @@ private Mocker makeMocker() {
108109
Map<String, Object> attributes = new HashMap<>(2);
109110

110111
mocker.getTargetRequest().setAttributes(attributes);
111-
attributes.put(ArexConstants.HTTP_METHOD, httpMethod);
112+
attributes.put(ArexConstants.HTTP_METHOD, Objects.isNull(httpMethod) ? null : httpMethod.name());
112113
attributes.put(ArexConstants.HTTP_QUERY_STRING, uri.getQuery());
113114

114115
mocker.getTargetRequest().setBody(request);

arex-instrumentation/servlet/arex-httpservlet/src/main/java/io/arex/inst/httpservlet/ServletUtil.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.arex.agent.bootstrap.util.CollectionUtil;
55
import io.arex.agent.bootstrap.util.StringUtil;
66
import java.net.URI;
7-
import java.net.URISyntaxException;
87
import java.util.ArrayList;
98
import java.util.Collections;
109
import java.util.HashMap;
@@ -20,22 +19,7 @@ private ServletUtil() {
2019
}
2120

2221
public static String appendUri(String uri, String name, String value) {
23-
try {
24-
URI oldUri = URI.create(uri);
25-
StringBuilder builder = new StringBuilder();
26-
String newQuery = oldUri.getQuery();
27-
if (oldUri.getQuery() == null) {
28-
builder.append(name).append("=").append(value);
29-
} else {
30-
builder.append(newQuery).append("&").append(name).append("=").append(value);
31-
}
32-
33-
URI newUri = new URI(oldUri.getScheme(), oldUri.getAuthority(),
34-
oldUri.getPath(), builder.toString(), oldUri.getFragment());
35-
return newUri.toString();
36-
} catch (URISyntaxException e) {
37-
return uri;
38-
}
22+
return UriComponentsBuilder.fromUriString(uri).queryParam(name, value).build().toString();
3923
}
4024

4125
public static String getRequestPath(String uri) {

arex-instrumentation/servlet/arex-httpservlet/src/test/java/io/arex/inst/httpservlet/ServletUtilTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ void appendUri() {
2222

2323
assertEquals("http://[email protected]&name=mark#fragment",
2424
ServletUtil.appendUri("http://[email protected]#fragment", "name", "mark"));
25+
26+
assertEquals("http://arextest.com?Signature=HJeNHsZ7%2BDMj0JsTK3zd3nzBDQE%3D&name=mark",
27+
ServletUtil.appendUri("http://arextest.com?Signature=HJeNHsZ7%2BDMj0JsTK3zd3nzBDQE%3D", "name", "mark"));
2528
}
2629

2730
@Test

0 commit comments

Comments
 (0)