mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 08:16:15 +10:00
[강운덕] [LUCYSUS-1744] span의 span여부를 잘못 확인하는 부분이 있어 수정함.
testweb에 httpclient4의 cookie및 post 덤프를 확인하기 위한 test추가. git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-testweb/trunk@2521 84d0f5b1-2673-498c-a247-62c4ff18d310
This commit is contained in:
@@ -94,21 +94,21 @@ public class AllInOneController implements DisposableBean {
|
||||
|
||||
private void nested() {
|
||||
HttpInvoker client2 = new HttpInvoker(new HttpConnectorOptions());
|
||||
client2.executeToBloc("http://localhost:8080/donothing.pinpoint", new HashMap<String, Object>());
|
||||
client2.execute("http://localhost:8080/donothing.pinpoint", new HashMap<String, Object>());
|
||||
}
|
||||
|
||||
private void unknown() {
|
||||
try {
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://very.very.very.long.long.url/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url1/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url2/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url2/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url3/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url3/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://very.very.very.long.long.url/", new HashMap<String, Object>());
|
||||
client.execute("http://url1/", new HashMap<String, Object>());
|
||||
client.execute("http://url2/", new HashMap<String, Object>());
|
||||
client.execute("http://url2/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ public class AllInOneController implements DisposableBean {
|
||||
port = ports[0];
|
||||
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://localhost:" + port + "/allInOne2.pinpoint", new HashMap<String, Object>());
|
||||
client.execute("http://localhost:" + port + "/allInOne2.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
return "remotecombination";
|
||||
}
|
||||
|
||||
@@ -199,10 +199,10 @@ public class HelloWorldController implements DisposableBean {
|
||||
@RequestMapping(value = "/nested")
|
||||
public String nested(Model model) {
|
||||
HttpInvoker client2 = new HttpInvoker(new HttpConnectorOptions());
|
||||
client2.executeToBloc("http://localhost:8080/donothing.pinpoint", new HashMap<String, Object>());
|
||||
client2.execute("http://localhost:8080/donothing.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
mysql(model);
|
||||
return "remotecombination";
|
||||
}
|
||||
@@ -214,21 +214,21 @@ public class HelloWorldController implements DisposableBean {
|
||||
String port = ports[random.nextInt(3)];
|
||||
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://localhost:" + port + "/combination.pinpoint", new HashMap<String, Object>());
|
||||
client.execute("http://localhost:" + port + "/combination.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
HttpInvoker client2 = new HttpInvoker(new HttpConnectorOptions());
|
||||
client2.executeToBloc("http://localhost:8080/arcus.pinpoint", new HashMap<String, Object>());
|
||||
client2.execute("http://localhost:8080/arcus.pinpoint", new HashMap<String, Object>());
|
||||
|
||||
client.executeToBloc("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
try {
|
||||
client.executeToBloc("http://very.very.very.long.long.url/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url1/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url2/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url2/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url3/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url3/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://very.very.very.long.long.url/", new HashMap<String, Object>());
|
||||
client.execute("http://url1/", new HashMap<String, Object>());
|
||||
client.execute("http://url2/", new HashMap<String, Object>());
|
||||
client.execute("http://url2/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
client.execute("http://url3/", new HashMap<String, Object>());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return "remotecombination";
|
||||
@@ -242,7 +242,7 @@ public class HelloWorldController implements DisposableBean {
|
||||
Random random = new Random();
|
||||
String port = ports[random.nextInt(3)];
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://localhost:" + port + "/arcus.pinpoint", new HashMap<String, Object>());
|
||||
client.execute("http://localhost:" + port + "/arcus.pinpoint", new HashMap<String, Object>());
|
||||
return "remotecombination";
|
||||
}
|
||||
|
||||
@@ -269,11 +269,11 @@ public class HelloWorldController implements DisposableBean {
|
||||
randomSlowMethod();
|
||||
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://www.naver.com/", new HashMap<String, Object>());
|
||||
|
||||
client.executeToBloc("http://section.cafe.naver.com/", new HashMap<String, Object>());
|
||||
client.executeToBloc("http://section.cafe.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://section.cafe.naver.com/", new HashMap<String, Object>());
|
||||
client.execute("http://section.cafe.naver.com/", new HashMap<String, Object>());
|
||||
|
||||
npc(model);
|
||||
|
||||
@@ -283,7 +283,7 @@ public class HelloWorldController implements DisposableBean {
|
||||
@RequestMapping(value = "/httperror")
|
||||
public String httperror(Model model) {
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://127.0.0.1/", new HashMap<String, Object>());
|
||||
client.execute("http://127.0.0.1/", new HashMap<String, Object>());
|
||||
return "error";
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ public class HelloWorldController implements DisposableBean {
|
||||
arcus(model);
|
||||
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://localhost:" + port + "/arcus.pinpoint", new HashMap<String, Object>());
|
||||
client.execute("http://localhost:" + port + "/arcus.pinpoint", new HashMap<String, Object>());
|
||||
return "remotecombination";
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.nhn.pinpoint.testweb.controller;
|
||||
|
||||
import com.nhn.pinpoint.testweb.util.HttpConnectorOptions;
|
||||
import com.nhn.pinpoint.testweb.util.HttpInvoker;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Controller
|
||||
public class HttpClient4Controller {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
|
||||
@RequestMapping(value = "/httpclient4/cookie")
|
||||
public String cookie(@RequestHeader(value = "Cookie", required = false) String cookie) {
|
||||
logger.info("Cookie:{}", cookie);
|
||||
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.execute("http://localhost:" + 9999 + "/combination.pinpoint", new HashMap<String, Object>(), cookie);
|
||||
|
||||
return "npc";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/httpclient4/post")
|
||||
public String post() {
|
||||
logger.info("Post");
|
||||
// String[] ports = new String[] { "9080", "10080", "11080" };
|
||||
// Random random = new Random();
|
||||
// String port = ports[random.nextInt(3)];
|
||||
//
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
HashMap<String, Object> post = new HashMap<String, Object>();
|
||||
post.put("test", "1");
|
||||
post.put("test2", "2");
|
||||
client.execute("http://localhost:" + 9999 + "/combination.pinpoint", post);
|
||||
|
||||
return "npc";
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,6 @@ public class DummyService {
|
||||
private void ca() {
|
||||
System.out.println("ca");
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
client.executeToBloc("http://localhost:8080/mysqlsimple.pinpoint", new HashMap<String, Object>());
|
||||
client.execute("http://localhost:8080/mysqlsimple.pinpoint", new HashMap<String, Object>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,18 +18,22 @@ import org.apache.http.params.BasicHttpParams;
|
||||
import org.apache.http.params.CoreProtocolPNames;
|
||||
import org.apache.http.params.HttpConnectionParams;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HttpInvoker {
|
||||
|
||||
public final static int SLOW_REQUEST_TIME = 1000;
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
public final static int SLOW_REQUEST_TIME = 1000;
|
||||
|
||||
private HttpConnectorOptions connectorOptions;
|
||||
|
||||
public HttpInvoker() {
|
||||
}
|
||||
|
||||
public HttpInvoker(HttpConnectorOptions cnnectorOptions) {
|
||||
this.connectorOptions = cnnectorOptions;
|
||||
public HttpInvoker(HttpConnectorOptions connectorOptions) {
|
||||
this.connectorOptions = connectorOptions;
|
||||
}
|
||||
|
||||
private HttpClient getHttpClient(HttpParams params) {
|
||||
@@ -46,34 +50,38 @@ public class HttpInvoker {
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
public String executeToBloc(String uri, Map<String, Object> paramMap) {
|
||||
if (null == uri) {
|
||||
return null;
|
||||
}
|
||||
public String execute(String uri, Map<String, Object> paramMap, String cookie) {
|
||||
if (null == uri) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String responseBody = null;
|
||||
HttpClient httpClient = null;
|
||||
try {
|
||||
HttpPost post = new HttpPost(uri);
|
||||
post.setEntity(getEntity(paramMap));
|
||||
post.setParams(getHttpParams());
|
||||
post.addHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
HttpClient httpClient = null;
|
||||
try {
|
||||
HttpPost post = new HttpPost(uri);
|
||||
if (cookie != null) {
|
||||
post.setHeader("Cookie", cookie);
|
||||
}
|
||||
post.setEntity(getEntity(paramMap));
|
||||
post.setParams(getHttpParams());
|
||||
post.addHeader("Content-Type", "application/json;charset=UTF-8");
|
||||
|
||||
ResponseHandler<String> responseHandler = new BasicResponseHandler();
|
||||
ResponseHandler<String> responseHandler = new BasicResponseHandler();
|
||||
|
||||
httpClient = getHttpClient(getHttpParams());
|
||||
httpClient = getHttpClient(getHttpParams());
|
||||
|
||||
responseBody = httpClient.execute(post, responseHandler);
|
||||
return httpClient.execute(post, responseHandler);
|
||||
} catch (Exception e) {
|
||||
logger.warn("HttpClient.execute() error. Caused:{}", e.getMessage(), e);
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (null != httpClient && null != httpClient.getConnectionManager()) {
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return responseBody;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return e.getMessage();
|
||||
} finally {
|
||||
if (null != httpClient && null != httpClient.getConnectionManager()) {
|
||||
httpClient.getConnectionManager().shutdown();
|
||||
}
|
||||
}
|
||||
public String execute(String uri, Map<String, Object> paramMap) {
|
||||
return execute(uri, paramMap, null);
|
||||
}
|
||||
|
||||
public int executeToBlocWithReturnInt(String uri, Map<String, Object> paramMap) {
|
||||
|
||||
@@ -50,7 +50,7 @@ public class HttpInvokerSupport {
|
||||
// if (log.isDebugEnabled()) {
|
||||
// log.debug("http invoke : " + targetUri);
|
||||
// }
|
||||
// return new HttpInvoker(connectionOptions).executeToBloc(targetUri, params);
|
||||
// return new HttpInvoker(connectionOptions).execute(targetUri, params);
|
||||
// }
|
||||
//
|
||||
// public int invokeWithReturnInt(String uri, Map<String, Object> params) {
|
||||
|
||||
@@ -43,6 +43,14 @@ arcus
|
||||
nestedcall test
|
||||
<br/>
|
||||
<a href="/nested.pinpoint">/nested.pinpoint</a> <br/>
|
||||
<br/><br/>
|
||||
|
||||
/httpclient4
|
||||
<br/>
|
||||
<a href="/httpclient4/cookie.pinpoint">/httpclient4/cookie.pinpoint 에러시 cookie덤프</a> <br/>
|
||||
<br/>
|
||||
<a href="/httpclient4/post.pinpoint">/httpclient4/post.pinpoint 에러시 post덤프</a> <br/>
|
||||
<br/><br/>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -9,7 +9,7 @@ public class HTClientTest {
|
||||
@Test
|
||||
public void test() {
|
||||
HttpInvoker client = new HttpInvoker(new HttpConnectorOptions());
|
||||
String executeToBloc = client.executeToBloc("http://localhost:9080/", new HashMap<String, Object>());
|
||||
String executeToBloc = client.execute("http://localhost:9080/", new HashMap<String, Object>());
|
||||
System.out.println(executeToBloc);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user