GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge pull request #23 from uavorg/master · windgoogle/uavstack@25a197d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • com.creditease.uav.base/src/main/java/com/creditease/agent/profile/api
    • StandardProfileModeler.java
  • com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm
    • RewriteIvcOutputStream.java
    • RewriteIvcPrintWriter.java
    • RewriteIvcResponseWrapper.java
  • com.creditease.uav.monitorframework/src/main/java/com/creditease/uav
    • profiling/handlers
      • ComponentProfileHandler.java
    • util
      • TransformWrapperUtil.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎com.creditease.uav.base/src/main/java/com/creditease/agent/profile/api/StandardProfileModeler.java‎

Copy file name to clipboardExpand all lines: com.creditease.uav.base/src/main/java/com/creditease/agent/profile/api/StandardProfileModeler.java
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,12 @@ private void getSpringMVCURLs(String springMVCBaseUrl, Map<String, Set<String>>
900900
if (annoWebService != null) {
901901

902902
resourceClassRelativePaths = (List<String>) annoWebService.get("value");
903+
/**
904+
* NOTE: RequestMapping can setup a path by 'value' or 'path'
905+
*/
906+
if (resourceClassRelativePaths == null) {
907+
resourceClassRelativePaths = (List<String>) annoWebService.get("path");
908+
}
903909
}
904910

905911
/**
@@ -968,6 +974,11 @@ private void getSpringMVCURLs(String springMVCBaseUrl, Map<String, Set<String>>
968974

969975
List<String> methodRelativePaths = (List<String>) pathAnnoInfo.get("value");
970976

977+
// try to get info from filed 'path'
978+
if (methodRelativePaths == null) {
979+
methodRelativePaths = (List<String>) pathAnnoInfo.get("path");
980+
}
981+
971982
// FIX NPE
972983
if (methodRelativePaths == null) {
973984
compServicesURLs.add(serviceURL);
Collapse file

‎com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/RewriteIvcOutputStream.java‎

Copy file name to clipboardExpand all lines: com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/RewriteIvcOutputStream.java
+34-8Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@
2121
package com.creditease.uav.apm;
2222

2323
import java.io.IOException;
24-
import java.util.concurrent.atomic.AtomicBoolean;
2524

2625
import javax.servlet.ServletOutputStream;
2726

27+
import com.creditease.agent.helpers.DataConvertHelper;
2828
import com.creditease.agent.helpers.StringHelper;
2929

3030
public class RewriteIvcOutputStream extends ServletOutputStream {
3131

32+
private static final int bodyLength = DataConvertHelper
33+
.toInt(System.getProperty("com.creditease.uav.ivcdat.rpc.body"), 2000);
34+
3235
private ServletOutputStream outputStream;
3336

3437
private StringBuilder builder = new StringBuilder();
3538

36-
private AtomicBoolean isWrited = new AtomicBoolean();
39+
private Boolean isWrited = false;
3740

3841
private String encoding;
3942

@@ -50,29 +53,34 @@ public RewriteIvcOutputStream(ServletOutputStream outputStream, String encoding)
5053
public void write(byte[] b, int off, int len) throws IOException {
5154

5255
this.outputStream.write(b, off, len);
53-
if (!isWrited.get()) {
54-
builder.append(new String(b, encoding));
56+
if (!isWrited) {
57+
int remainderLength = getRemainderLength(b.length);
58+
if (remainderLength > 0) {
59+
builder.append(new String(b, off, remainderLength, encoding));
60+
}
5561
}
5662
}
5763

5864
@Override
5965
public void flush() throws IOException {
6066

6167
this.outputStream.flush();
62-
isWrited.set(true);
6368
}
6469

6570
@Override
6671
public void close() throws IOException {
6772

6873
this.outputStream.close();
69-
isWrited.set(true);
74+
isWrited = true;
7075
}
7176

7277
@Override
7378
public void write(int b) throws IOException {
7479

7580
this.outputStream.write(b);
81+
if (!isWrited && this.builder.length() < bodyLength) {
82+
builder.append((char) b);
83+
}
7684
}
7785

7886
public StringBuilder getContent() {
@@ -86,12 +94,30 @@ public StringBuilder getContent() {
8694
public void clearBodyContent() {
8795

8896
this.builder.delete(0, this.builder.length());
89-
isWrited.set(true);
97+
isWrited = true;
9098
}
9199

92100
@Override
93101
public void write(byte[] b) throws IOException {
94102

95103
this.outputStream.write(b);
104+
if (!isWrited) {
105+
int remainderLength = getRemainderLength(b.length);
106+
if (remainderLength > 0) {
107+
builder.append(new String(b, 0, remainderLength, encoding));
108+
}
109+
}
110+
}
111+
112+
private int getRemainderLength(int length) {
113+
114+
if (bodyLength <= this.builder.length()) {
115+
return 0;
116+
}
117+
int remainderLength = bodyLength - this.builder.length();
118+
/**
119+
* simply consider 1 character cost 2 bytes, it's not accurate.
120+
*/
121+
return (2 * remainderLength) < length ? (2 * remainderLength) : length;
96122
}
97-
}
123+
}
Collapse file

‎com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/RewriteIvcPrintWriter.java‎

Copy file name to clipboard
+132Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*-
2+
* <<
3+
* UAVStack
4+
* ==
5+
* Copyright (C) 2016 - 2018 UAVStack
6+
* ==
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* >>
19+
*/
20+
package com.creditease.uav.apm;
21+
22+
import java.io.PrintWriter;
23+
24+
import com.creditease.agent.helpers.DataConvertHelper;
25+
26+
public class RewriteIvcPrintWriter extends PrintWriter {
27+
28+
private static final int bodyLength = DataConvertHelper
29+
.toInt(System.getProperty("com.creditease.uav.ivcdat.rpc.body"), 2000);
30+
31+
private PrintWriter out;
32+
33+
private StringBuilder builder = new StringBuilder();
34+
35+
private Boolean isWrited = false;
36+
37+
public RewriteIvcPrintWriter(PrintWriter out) {
38+
39+
super(out);
40+
this.out = out;
41+
}
42+
43+
public StringBuilder getContent() {
44+
45+
return this.builder;
46+
}
47+
48+
public void clearBodyContent() {
49+
50+
this.builder.delete(0, this.builder.length());
51+
isWrited = true;
52+
}
53+
54+
@Override
55+
public void flush() {
56+
57+
super.flush();
58+
}
59+
60+
@Override
61+
public void close() {
62+
63+
super.close();
64+
isWrited = true;
65+
}
66+
67+
@Override
68+
public void write(int c) {
69+
70+
out.write(c);
71+
if (!isWrited && this.builder.length() < bodyLength) {
72+
this.builder.append((char) c);
73+
}
74+
}
75+
76+
@Override
77+
public void write(char[] buf, int off, int len) {
78+
79+
out.write(buf, off, len);
80+
if (!isWrited) {
81+
int remainderLength = getRemainderLength(len);
82+
if (remainderLength > 0) {
83+
this.builder.append(buf, off, remainderLength);
84+
}
85+
}
86+
}
87+
88+
@Override
89+
public void write(char[] buf) {
90+
91+
out.write(buf);
92+
if (!isWrited) {
93+
int remainderLength = getRemainderLength(buf.length);
94+
if (remainderLength > 0) {
95+
this.builder.append(buf, 0, remainderLength);
96+
}
97+
}
98+
}
99+
100+
@Override
101+
public void write(String s, int off, int len) {
102+
103+
out.write(s, off, len);
104+
if (!isWrited) {
105+
int remainderLength = getRemainderLength(len);
106+
if (remainderLength > 0) {
107+
this.builder.append(s, off, remainderLength);
108+
}
109+
}
110+
}
111+
112+
@Override
113+
public void write(String s) {
114+
115+
out.write(s);
116+
if (!isWrited) {
117+
int remainderLength = getRemainderLength(s.length());
118+
if (remainderLength > 0) {
119+
this.builder.append(s, 0, remainderLength);
120+
}
121+
}
122+
}
123+
124+
private int getRemainderLength(int length) {
125+
126+
if (bodyLength <= this.builder.length()) {
127+
return 0;
128+
}
129+
int remainderLength = bodyLength - this.builder.length();
130+
return remainderLength < length ? remainderLength : length;
131+
}
132+
}
Collapse file

‎com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/RewriteIvcResponseWrapper.java‎

Copy file name to clipboardExpand all lines: com.creditease.uav.monitorframework.apm/src/main/java/com/creditease/uav/apm/RewriteIvcResponseWrapper.java
+38-18Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929

3030
public class RewriteIvcResponseWrapper extends HttpServletResponseWrapper {
3131

32-
private ServletOutputStream outputStream;
33-
3432
private RewriteIvcOutputStream rewriteOutStream;
3533

36-
private StringBuilder builder;
34+
private RewriteIvcPrintWriter rewritePrintWriter;
35+
36+
private StringBuilder builder = new StringBuilder();
3737

3838
private String tag;
3939

@@ -43,16 +43,6 @@ public RewriteIvcResponseWrapper(HttpServletResponse response, String tag) {
4343
super(response);
4444
this.tag = tag;
4545
this.response = response;
46-
try {
47-
this.outputStream = response.getOutputStream();
48-
// 由于tomcat等实现类会记录是否调用了getOutputStream方法,故此处进行这种操作
49-
response.reset();
50-
}
51-
catch (IOException e) {
52-
// 出现异常时则将异常信息放入
53-
builder.append(e.toString());
54-
}
55-
this.rewriteOutStream = new RewriteIvcOutputStream(outputStream, response.getCharacterEncoding());
5646
}
5747

5848
public String getTag() {
@@ -63,27 +53,48 @@ public String getTag() {
6353
@Override
6454
public ServletOutputStream getOutputStream() throws IOException {
6555

56+
if (this.rewriteOutStream == null) {
57+
try {
58+
this.rewriteOutStream = new RewriteIvcOutputStream(response.getOutputStream(),
59+
response.getCharacterEncoding());
60+
}
61+
catch (IOException e) {
62+
// 出现异常时则将异常信息放入
63+
builder.append(e.toString());
64+
throw e;
65+
}
66+
}
67+
6668
return this.rewriteOutStream;
6769
}
6870

6971
public StringBuilder getContent() {
7072

71-
if (this.builder == null) {
73+
if (rewriteOutStream != null) {
7274
return this.rewriteOutStream.getContent();
7375
}
74-
else {
76+
else if (rewritePrintWriter != null) {
77+
return this.rewritePrintWriter.getContent();
78+
}
79+
else if (this.builder != null) {
7580
return this.builder;
7681
}
82+
83+
return new StringBuilder();
84+
7785
}
7886

7987
/**
8088
* 清空池,方便回收
8189
*/
8290
public void clearBodyContent() {
8391

84-
if (this.builder == null) {
92+
if (rewriteOutStream != null) {
8593
this.rewriteOutStream.clearBodyContent();
8694
}
95+
else if (rewritePrintWriter != null) {
96+
this.rewritePrintWriter.clearBodyContent();
97+
}
8798
else {
8899
this.builder.delete(0, this.builder.length());
89100
}
@@ -92,7 +103,16 @@ public void clearBodyContent() {
92103
@Override
93104
public PrintWriter getWriter() throws IOException {
94105

95-
return this.response.getWriter();
106+
if (this.rewritePrintWriter == null) {
107+
try {
108+
this.rewritePrintWriter = new RewriteIvcPrintWriter(this.response.getWriter());
109+
}
110+
catch (IOException e) {
111+
builder.append(e.toString());
112+
throw e;
113+
}
114+
}
115+
return rewritePrintWriter;
96116
}
97117

98-
}
118+
}
Collapse file

‎com.creditease.uav.monitorframework/src/main/java/com/creditease/uav/profiling/handlers/ComponentProfileHandler.java‎

Copy file name to clipboardExpand all lines: com.creditease.uav.monitorframework/src/main/java/com/creditease/uav/profiling/handlers/ComponentProfileHandler.java
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,6 +2605,12 @@ private void addAppFrkServiceMapBinding(ProfileServiceMapMgr smgr, String appid,
26052605
if (classAnno != null) {
26062606

26072607
value = classAnno.get(classPathAnnoAttrName);
2608+
/**
2609+
* SpringMVC RequestMapping can setup a path by 'value' or 'path'
2610+
*/
2611+
if (value == null) {
2612+
value = classAnno.get("path");
2613+
}
26082614
}
26092615
else if (classPathAnnoClass.equals("org.springframework.web.bind.annotation.RequestMapping")) {
26102616
/**
@@ -2683,6 +2689,13 @@ else if (classPathAnnoClass.equals("org.springframework.web.bind.annotation.Requ
26832689

26842690
Object pvalue = methodPathAnno.get("value");
26852691

2692+
/**
2693+
* SpringMVC RequestMapping can setup a path by 'value' or 'path'
2694+
*/
2695+
if (pvalue == null) {
2696+
pvalue = methodPathAnno.get("path");
2697+
}
2698+
26862699
if (pvalue == null) {
26872700
continue;
26882701
}

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.