Skip to content

Commit 7db052f

Browse files
committed
pinpoint-apm#2312 Deprecated StringUtils.drop() api
- drop() -> abbreviate() - Similar to apache-common-lang StringUtils.abbreviate()
1 parent e9d0935 commit 7db052f

File tree

18 files changed

+94
-71
lines changed

18 files changed

+94
-71
lines changed

bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/jdbc/bindvalue/BindValueUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public static String bindValueToString(String[] bindValueArray, int limit) {
7777
break;
7878
}
7979
final String bindValue = StringUtils.defaultString(bindValueArray[i], "");
80-
StringUtils.appendDrop(sb, bindValue, limit);
80+
StringUtils.appendAbbreviate(sb, bindValue, limit);
8181
if (i < end) {
8282
sb.append(", ");
8383
}

bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/jdbc/bindvalue/ClassNameConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public String convert(Object[] args) {
2828
return "null";
2929
}
3030
if (args.length == 2) {
31-
return StringUtils.drop(getClassName(args[1]));
31+
return StringUtils.abbreviate(getClassName(args[1]));
3232
} else if(args.length == 3) {
3333
// need to handle 3rd arg?
34-
return StringUtils.drop(getClassName(args[1]));
34+
return StringUtils.abbreviate(getClassName(args[1]));
3535
}
3636
return "error";
3737
}

bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/jdbc/bindvalue/ObjectConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private String getParameter(Object param) {
9090
}
9191

9292
private String dropToString(Object param) {
93-
return StringUtils.drop(param.toString());
93+
return StringUtils.abbreviate(param.toString());
9494
}
9595

9696
private String getClassName(Object param) {

bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/plugin/jdbc/bindvalue/SimpleTypeConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ public String convert(Object[] args) {
2828
return "null";
2929
}
3030
if (args.length == 2) {
31-
return StringUtils.drop(StringUtils.toString(args[1]));
31+
return StringUtils.abbreviate(StringUtils.toString(args[1]));
3232
} else if (args.length == 3) {
3333
// need to handle 3rd arg?
34-
return StringUtils.drop(StringUtils.toString(args[1]));
34+
return StringUtils.abbreviate(StringUtils.toString(args[1]));
3535
}
3636
return "error";
3737
}

bootstrap-core/src/main/java/com/navercorp/pinpoint/bootstrap/util/StringUtils.java

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
public final class StringUtils {
2525

26+
private static final int DEFAULT_ABBREVIATE_MAX_WIDTH = 64;
27+
2628
private StringUtils() {
2729
}
2830

@@ -64,47 +66,70 @@ public static List<String> splitAndTrim(String value, String separator) {
6466
return result;
6567
}
6668

69+
/**
70+
* @deprecated Since 1.6.1. Use {@link StringUtils#abbreviate(String)}
71+
*/
72+
@Deprecated
73+
public static String drop(final String str) {
74+
return abbreviate(str);
75+
}
6776

6877

69-
public static String drop(final String str) {
70-
return drop(str, 64);
78+
public static String abbreviate(final String str) {
79+
return abbreviate(str, DEFAULT_ABBREVIATE_MAX_WIDTH);
7180
}
7281

73-
public static String drop(final String str, final int length) {
82+
/**
83+
* @deprecated Since 1.6.1. Use {@link StringUtils#abbreviate(String, int)}
84+
*/
85+
@Deprecated
86+
public static String drop(final String str, final int maxWidth) {
87+
return abbreviate(str, maxWidth);
88+
}
89+
90+
public static String abbreviate(final String str, final int maxWidth) {
7491
if (str == null) {
7592
return "null";
7693
}
77-
if (length < 0) {
78-
throw new IllegalArgumentException("negative length:" + length);
94+
if (maxWidth < 0) {
95+
throw new IllegalArgumentException("negative maxWidth:" + maxWidth);
7996
}
80-
if (str.length() > length) {
81-
StringBuilder buffer = new StringBuilder(length + 10);
82-
buffer.append(str, 0, length);
83-
appendDropMessage(buffer, str.length());
97+
if (str.length() > maxWidth) {
98+
StringBuilder buffer = new StringBuilder(maxWidth + 10);
99+
buffer.append(str, 0, maxWidth);
100+
appendAbbreviateMessage(buffer, str.length());
84101
return buffer.toString();
85102
} else {
86103
return str;
87104
}
88105
}
89106

90-
public static void appendDrop(StringBuilder builder, final String str, final int length) {
107+
/**
108+
* @deprecated Since 1.6.1. Use {@link StringUtils#appendAbbreviate(StringBuilder, String, int)}
109+
*/
110+
@Deprecated
111+
public static void appendDrop(StringBuilder builder, final String str, final int maxWidth) {
112+
appendAbbreviate(builder, str, maxWidth);
113+
}
114+
115+
public static void appendAbbreviate(StringBuilder builder, final String str, final int maxWidth) {
91116
if (str == null) {
92117
return;
93118
}
94-
if (length < 0) {
119+
if (maxWidth < 0) {
95120
return;
96121
}
97-
if (str.length() > length) {
98-
builder.append(str, 0, length);
99-
appendDropMessage(builder, str.length());
122+
if (str.length() > maxWidth) {
123+
builder.append(str, 0, maxWidth);
124+
appendAbbreviateMessage(builder, str.length());
100125
} else {
101126
builder.append(str);
102127
}
103128
}
104129

105-
private static void appendDropMessage(StringBuilder buffer, int length) {
130+
private static void appendAbbreviateMessage(StringBuilder buffer, int strLength) {
106131
buffer.append("...(");
107-
buffer.append(length);
132+
buffer.append(strLength);
108133
buffer.append(')');
109134
}
110135
}

bootstrap-core/src/test/java/com/navercorp/pinpoint/bootstrap/util/StringUtilsTest.java

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,29 +49,29 @@ public void toStringTest() {
4949
}
5050

5151
@Test
52-
public void drop() {
52+
public void abbreviate() {
5353

54-
Assert.assertEquals(StringUtils.drop(null), "null");
55-
Assert.assertEquals(StringUtils.drop(null, 4), "null");
56-
Assert.assertEquals(StringUtils.drop(null, 0), "null");
57-
Assert.assertEquals(StringUtils.drop(null, -4), "null");
54+
Assert.assertEquals(StringUtils.abbreviate(null), "null");
55+
Assert.assertEquals(StringUtils.abbreviate(null, 4), "null");
56+
Assert.assertEquals(StringUtils.abbreviate(null, 0), "null");
57+
Assert.assertEquals(StringUtils.abbreviate(null, -4), "null");
5858

59-
Assert.assertEquals(StringUtils.drop(longString), "This is a very long string for testing drop function. Length of ...(100)");
60-
Assert.assertEquals(StringUtils.drop(longString, 4), "This...(100)");
61-
Assert.assertEquals(StringUtils.drop(longString, 0), "...(100)");
59+
Assert.assertEquals(StringUtils.abbreviate(longString), "This is a very long string for testing drop function. Length of ...(100)");
60+
Assert.assertEquals(StringUtils.abbreviate(longString, 4), "This...(100)");
61+
Assert.assertEquals(StringUtils.abbreviate(longString, 0), "...(100)");
6262
try {
63-
StringUtils.drop(longString, -4);
63+
StringUtils.abbreviate(longString, -4);
6464
Assert.fail();
6565
} catch (IllegalArgumentException ignored) {
6666
} catch (Exception e) {
6767
Assert.fail();
6868
}
6969

70-
Assert.assertEquals(StringUtils.drop(shortString), shortString);
71-
Assert.assertEquals(StringUtils.drop(shortString, 4), "This...(22)");
72-
Assert.assertEquals(StringUtils.drop(shortString, 0), "...(22)");
70+
Assert.assertEquals(StringUtils.abbreviate(shortString), shortString);
71+
Assert.assertEquals(StringUtils.abbreviate(shortString, 4), "This...(22)");
72+
Assert.assertEquals(StringUtils.abbreviate(shortString, 0), "...(22)");
7373
try {
74-
StringUtils.drop(shortString, -4);
74+
StringUtils.abbreviate(shortString, -4);
7575
Assert.fail();
7676
} catch (IllegalArgumentException ignored) {
7777
} catch (Exception e) {
@@ -80,60 +80,60 @@ public void drop() {
8080
}
8181

8282
@Test
83-
public void appendDrop() {
83+
public void appendAbbreviate() {
8484
StringBuilder buffer = new StringBuilder();
8585

86-
StringUtils.appendDrop(buffer, null, 4);
86+
StringUtils.appendAbbreviate(buffer, null, 4);
8787
Assert.assertEquals(buffer.toString(), "");
8888

89-
StringUtils.appendDrop(buffer, null, 0);
89+
StringUtils.appendAbbreviate(buffer, null, 0);
9090
Assert.assertEquals(buffer.toString(), "");
9191

92-
StringUtils.appendDrop(buffer, null, -4);
92+
StringUtils.appendAbbreviate(buffer, null, -4);
9393
Assert.assertEquals(buffer.toString(), "");
9494

95-
StringUtils.appendDrop(buffer, shortString, 4);
95+
StringUtils.appendAbbreviate(buffer, shortString, 4);
9696
Assert.assertEquals(buffer.toString(), "This...(22)");
9797

98-
StringUtils.appendDrop(buffer, longString, 16);
98+
StringUtils.appendAbbreviate(buffer, longString, 16);
9999
Assert.assertEquals(buffer.toString(), "This...(22)This is a very l...(100)");
100100
}
101101

102102

103103
@Test
104-
public void testDrop1() throws Exception {
104+
public void testAbbreviate1() throws Exception {
105105
String string = "abc";
106-
String drop = StringUtils.drop(string, 1);
106+
String drop = StringUtils.abbreviate(string, 1);
107107
Assert.assertEquals("a...(3)", drop);
108108
}
109109

110110
@Test
111-
public void testDrop2() throws Exception {
111+
public void testAbbreviate2() throws Exception {
112112
String string = "abc";
113-
String drop = StringUtils.drop(string, 5);
113+
String drop = StringUtils.abbreviate(string, 5);
114114
Assert.assertEquals("abc", drop);
115115
}
116116

117117
@Test
118-
public void testDrop3() throws Exception {
118+
public void testAbbreviate3() throws Exception {
119119
String string = "abc";
120-
String drop = StringUtils.drop(string, 3);
120+
String drop = StringUtils.abbreviate(string, 3);
121121
Assert.assertEquals("abc", drop);
122122
}
123123

124124
@Test
125-
public void testDrop4() throws Exception {
125+
public void testAbbreviate4() throws Exception {
126126
String string = "abc";
127-
String drop = StringUtils.drop(string, 0);
127+
String drop = StringUtils.abbreviate(string, 0);
128128
Assert.assertEquals("...(3)", drop);
129129

130130
}
131131

132132
@Test
133-
public void testDropNegative() throws Exception {
133+
public void testAbbreviateNegative() throws Exception {
134134
String string = "abc";
135135
try {
136-
StringUtils.drop(string, -1);
136+
StringUtils.abbreviate(string, -1);
137137
Assert.fail();
138138
} catch (Exception ignore) {
139139
// skip

plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/interceptor/HttpMethodBaseExecuteMethodInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ private void recordCookie(HttpMethod httpMethod, Trace trace) {
385385
if (value != null && !value.isEmpty()) {
386386
if (cookieSampler.isSampling()) {
387387
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
388-
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(value, MAX_READ_SIZE));
388+
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(value, MAX_READ_SIZE));
389389
}
390390
}
391391
}

plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/DefaultClientExchangeHandlerImplStartMethodInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ protected void recordCookie(HttpMessage httpMessage, SpanEventRecorder recorder)
281281
final String value = header.getValue();
282282
if (value != null && !value.isEmpty()) {
283283
if (cookieSampler.isSampling()) {
284-
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(value, 1024));
284+
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(value, 1024));
285285
}
286286

287287
// Can a cookie have 2 or more values?

plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/HttpRequestExecutorExecuteMethodInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ protected void recordCookie(HttpMessage httpMessage, Trace trace) {
300300
if (value != null && !value.isEmpty()) {
301301
if (cookieSampler.isSampling()) {
302302
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
303-
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(value, 1024));
303+
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(value, 1024));
304304
}
305305

306306
// Can a cookie have 2 or more values?

plugins/jboss/src/main/java/com/navercorp/pinpoint/plugin/jboss/interceptor/StandardHostValveInvokeInterceptor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import javax.servlet.http.HttpServletRequest;
2222

2323
import com.navercorp.pinpoint.bootstrap.config.Filter;
24-
import com.navercorp.pinpoint.bootstrap.config.ProfilerConfig;
2524
import com.navercorp.pinpoint.bootstrap.context.Header;
2625
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
2726
import com.navercorp.pinpoint.bootstrap.context.RemoteAddressResolver;
@@ -46,7 +45,6 @@
4645
import com.navercorp.pinpoint.plugin.jboss.ServletAsyncMethodDescriptor;
4746
import com.navercorp.pinpoint.plugin.jboss.ServletSyncMethodDescriptor;
4847
import com.navercorp.pinpoint.plugin.jboss.TraceAccessor;
49-
import com.navercorp.pinpoint.plugin.jboss.util.JbossUtility;
5048

5149
/**
5250
* The Class StandardHostValveInvokeInterceptor.
@@ -530,11 +528,11 @@ private String getRequestParameter(final HttpServletRequest request, final int e
530528
return params.toString();
531529
}
532530
final String key = attrs.nextElement().toString();
533-
params.append(StringUtils.drop(key, eachLimit));
531+
params.append(StringUtils.abbreviate(key, eachLimit));
534532
params.append("=");
535533
final Object value = request.getParameter(key);
536534
if (value != null) {
537-
params.append(StringUtils.drop(StringUtils.toString(value), eachLimit));
535+
params.append(StringUtils.abbreviate(StringUtils.toString(value), eachLimit));
538536
}
539537
}
540538
return params.toString();

plugins/jetty/src/main/java/com/navercorp/pinpoint/plugin/jetty/interceptor/AbstractServerHandleInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,11 @@ private String getRequestParameter(Request request, int eachLimit, int totalLimi
192192
return params.toString();
193193
}
194194
String key = attrs.nextElement().toString();
195-
params.append(StringUtils.drop(key, eachLimit));
195+
params.append(StringUtils.abbreviate(key, eachLimit));
196196
params.append("=");
197197
Object value = request.getParameter(key);
198198
if (value != null) {
199-
params.append(StringUtils.drop(StringUtils.toString(value), eachLimit));
199+
params.append(StringUtils.abbreviate(StringUtils.toString(value), eachLimit));
200200
}
201201
}
202202
return params.toString();

plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ protected void recordCookie(com.ning.http.client.Request httpRequest, SpanEventR
241241
sb.append(",");
242242
}
243243
}
244-
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(sb.toString(), config.getCookieDumpSize()));
244+
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(sb.toString(), config.getCookieDumpSize()));
245245
}
246246
}
247247

@@ -264,7 +264,7 @@ protected void recordEntity(final com.ning.http.client.Request httpRequest, fina
264264
protected void recordNonMultipartData(final com.ning.http.client.Request httpRequest, final SpanEventRecorder recorder) {
265265
final String stringData = httpRequest.getStringData();
266266
if (stringData != null) {
267-
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.drop(stringData, config.getEntityDumpSize()));
267+
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.abbreviate(stringData, config.getEntityDumpSize()));
268268
return;
269269
}
270270

@@ -335,7 +335,7 @@ protected void recordMultipartData(final com.ning.http.client.Request httpReques
335335
sb.append(",");
336336
}
337337
}
338-
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.drop(sb.toString(), config.getEntityDumpSize()));
338+
recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, StringUtils.abbreviate(sb.toString(), config.getEntityDumpSize()));
339339
}
340340
}
341341

@@ -350,7 +350,7 @@ protected void recordParam(final com.ning.http.client.Request httpRequest, final
350350
FluentStringsMap requestParams = httpRequest.getParams();
351351
if (requestParams != null) {
352352
String params = paramsToString(requestParams, config.getParamDumpSize());
353-
recorder.recordAttribute(AnnotationKey.HTTP_PARAM, StringUtils.drop(params, config.getParamDumpSize()));
353+
recorder.recordAttribute(AnnotationKey.HTTP_PARAM, StringUtils.abbreviate(params, config.getParamDumpSize()));
354354
}
355355
}
356356
}

plugins/okhttp/src/main/java/com/navercorp/pinpoint/plugin/okhttp/interceptor/HttpEngineSendRequestMethodInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private void recordCookie(Request request, Trace trace) {
195195
for(String cookie : request.headers("Cookie")) {
196196
if(cookieSampler.isSampling()) {
197197
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
198-
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.drop(cookie, 1024));
198+
recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(cookie, 1024));
199199
}
200200

201201
return;

plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/client/TServiceClientReceiveBaseInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,6 @@ protected void doInAfterTrace(SpanEventRecorder recorder, Object target, Object[
6060
}
6161

6262
private String getResult(TBase<?, ?> args) {
63-
return StringUtils.drop(args.toString(), 256);
63+
return StringUtils.abbreviate(args.toString(), 256);
6464
}
6565
}

plugins/thrift/src/main/java/com/navercorp/pinpoint/plugin/thrift/interceptor/client/TServiceClientSendBaseInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
174174
}
175175

176176
private String getMethodArgs(TBase<?, ?> args) {
177-
return StringUtils.drop(args.toString(), 256);
177+
return StringUtils.abbreviate(args.toString(), 256);
178178
}
179179

180180
}

0 commit comments

Comments
 (0)