From 0e30152d5cded26b56a897828afa490630d4d4e9 Mon Sep 17 00:00:00 2001 From: Woonduk Kang Date: Tue, 15 Oct 2013 06:50:19 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EC=9A=B4=EB=8D=95]=20[LUCYSUS-1744]?= =?UTF-8?q?=20span=EC=9D=98=20span=EC=97=AC=EB=B6=80=EB=A5=BC=20=EC=9E=98?= =?UTF-8?q?=EB=AA=BB=20=ED=99=95=EC=9D=B8=ED=95=98=EB=8A=94=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=EC=9D=B4=20=EC=9E=88=EC=96=B4=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=A8.=20=20testweb=EC=97=90=20httpclient4=EC=9D=98=20cooki?= =?UTF-8?q?e=EB=B0=8F=20post=20=EB=8D=A4=ED=94=84=EB=A5=BC=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=ED=95=98=EA=B8=B0=20=EC=9C=84=ED=95=9C=20test?= =?UTF-8?q?=EC=B6=94=EA=B0=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-testweb/trunk@2521 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../controller/AllInOneController.java | 22 +++---- .../controller/HelloWorldController.java | 40 ++++++------- .../controller/HttpClient4Controller.java | 46 ++++++++++++++ .../testweb/service/DummyService.java | 2 +- .../pinpoint/testweb/util/HttpInvoker.java | 60 +++++++++++-------- .../testweb/util/HttpInvokerSupport.java | 2 +- src/main/webapp/index.html | 8 +++ .../pinpoint/testweb/util/HTClientTest.java | 2 +- 8 files changed, 122 insertions(+), 60 deletions(-) create mode 100644 src/main/java/com/nhn/pinpoint/testweb/controller/HttpClient4Controller.java diff --git a/src/main/java/com/nhn/pinpoint/testweb/controller/AllInOneController.java b/src/main/java/com/nhn/pinpoint/testweb/controller/AllInOneController.java index 8ab8e116d..baf42c068 100644 --- a/src/main/java/com/nhn/pinpoint/testweb/controller/AllInOneController.java +++ b/src/main/java/com/nhn/pinpoint/testweb/controller/AllInOneController.java @@ -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()); + client2.execute("http://localhost:8080/donothing.pinpoint", new HashMap()); } private void unknown() { try { HttpInvoker client = new HttpInvoker(new HttpConnectorOptions()); - client.executeToBloc("http://www.naver.com/", new HashMap()); - client.executeToBloc("http://www.naver.com/", new HashMap()); - client.executeToBloc("http://very.very.very.long.long.url/", new HashMap()); - client.executeToBloc("http://url1/", new HashMap()); - client.executeToBloc("http://url2/", new HashMap()); - client.executeToBloc("http://url2/", new HashMap()); - client.executeToBloc("http://url3/", new HashMap()); - client.executeToBloc("http://url3/", new HashMap()); - client.executeToBloc("http://url3/", new HashMap()); + client.execute("http://www.naver.com/", new HashMap()); + client.execute("http://www.naver.com/", new HashMap()); + client.execute("http://very.very.very.long.long.url/", new HashMap()); + client.execute("http://url1/", new HashMap()); + client.execute("http://url2/", new HashMap()); + client.execute("http://url2/", new HashMap()); + client.execute("http://url3/", new HashMap()); + client.execute("http://url3/", new HashMap()); + client.execute("http://url3/", new HashMap()); } 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()); + client.execute("http://localhost:" + port + "/allInOne2.pinpoint", new HashMap()); return "remotecombination"; } diff --git a/src/main/java/com/nhn/pinpoint/testweb/controller/HelloWorldController.java b/src/main/java/com/nhn/pinpoint/testweb/controller/HelloWorldController.java index 72c78e568..d9c85b5b8 100644 --- a/src/main/java/com/nhn/pinpoint/testweb/controller/HelloWorldController.java +++ b/src/main/java/com/nhn/pinpoint/testweb/controller/HelloWorldController.java @@ -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()); + client2.execute("http://localhost:8080/donothing.pinpoint", new HashMap()); HttpInvoker client = new HttpInvoker(new HttpConnectorOptions()); - client.executeToBloc("http://www.naver.com/", new HashMap()); + client.execute("http://www.naver.com/", new HashMap()); 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()); + client.execute("http://localhost:" + port + "/combination.pinpoint", new HashMap()); HttpInvoker client2 = new HttpInvoker(new HttpConnectorOptions()); - client2.executeToBloc("http://localhost:8080/arcus.pinpoint", new HashMap()); + client2.execute("http://localhost:8080/arcus.pinpoint", new HashMap()); - client.executeToBloc("http://www.naver.com/", new HashMap()); - client.executeToBloc("http://www.naver.com/", new HashMap()); + client.execute("http://www.naver.com/", new HashMap()); + client.execute("http://www.naver.com/", new HashMap()); try { - client.executeToBloc("http://very.very.very.long.long.url/", new HashMap()); - client.executeToBloc("http://url1/", new HashMap()); - client.executeToBloc("http://url2/", new HashMap()); - client.executeToBloc("http://url2/", new HashMap()); - client.executeToBloc("http://url3/", new HashMap()); - client.executeToBloc("http://url3/", new HashMap()); - client.executeToBloc("http://url3/", new HashMap()); + client.execute("http://very.very.very.long.long.url/", new HashMap()); + client.execute("http://url1/", new HashMap()); + client.execute("http://url2/", new HashMap()); + client.execute("http://url2/", new HashMap()); + client.execute("http://url3/", new HashMap()); + client.execute("http://url3/", new HashMap()); + client.execute("http://url3/", new HashMap()); } 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()); + client.execute("http://localhost:" + port + "/arcus.pinpoint", new HashMap()); 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()); - client.executeToBloc("http://www.naver.com/", new HashMap()); + client.execute("http://www.naver.com/", new HashMap()); + client.execute("http://www.naver.com/", new HashMap()); - client.executeToBloc("http://section.cafe.naver.com/", new HashMap()); - client.executeToBloc("http://section.cafe.naver.com/", new HashMap()); + client.execute("http://section.cafe.naver.com/", new HashMap()); + client.execute("http://section.cafe.naver.com/", new HashMap()); 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()); + client.execute("http://127.0.0.1/", new HashMap()); 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()); + client.execute("http://localhost:" + port + "/arcus.pinpoint", new HashMap()); return "remotecombination"; } diff --git a/src/main/java/com/nhn/pinpoint/testweb/controller/HttpClient4Controller.java b/src/main/java/com/nhn/pinpoint/testweb/controller/HttpClient4Controller.java new file mode 100644 index 000000000..c3b84dd83 --- /dev/null +++ b/src/main/java/com/nhn/pinpoint/testweb/controller/HttpClient4Controller.java @@ -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(), 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 post = new HashMap(); + post.put("test", "1"); + post.put("test2", "2"); + client.execute("http://localhost:" + 9999 + "/combination.pinpoint", post); + + return "npc"; + } +} diff --git a/src/main/java/com/nhn/pinpoint/testweb/service/DummyService.java b/src/main/java/com/nhn/pinpoint/testweb/service/DummyService.java index 04406a64a..5f1abe311 100644 --- a/src/main/java/com/nhn/pinpoint/testweb/service/DummyService.java +++ b/src/main/java/com/nhn/pinpoint/testweb/service/DummyService.java @@ -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()); + client.execute("http://localhost:8080/mysqlsimple.pinpoint", new HashMap()); } } diff --git a/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvoker.java b/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvoker.java index 7ae028a4c..acbaf2ea3 100644 --- a/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvoker.java +++ b/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvoker.java @@ -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 paramMap) { - if (null == uri) { - return null; - } + public String execute(String uri, Map 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 responseHandler = new BasicResponseHandler(); + ResponseHandler 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 paramMap) { + return execute(uri, paramMap, null); } public int executeToBlocWithReturnInt(String uri, Map paramMap) { diff --git a/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvokerSupport.java b/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvokerSupport.java index b36db9557..e860930ec 100644 --- a/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvokerSupport.java +++ b/src/main/java/com/nhn/pinpoint/testweb/util/HttpInvokerSupport.java @@ -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 params) { diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index e878474e5..b6ec29e2e 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -43,6 +43,14 @@ arcus nestedcall test
/nested.pinpoint
+

+ +/httpclient4 +
+/httpclient4/cookie.pinpoint 에러시 cookie덤프
+
+/httpclient4/post.pinpoint 에러시 post덤프
+

diff --git a/src/test/java/com/nhn/pinpoint/testweb/util/HTClientTest.java b/src/test/java/com/nhn/pinpoint/testweb/util/HTClientTest.java index fc6a9047e..cf95010f4 100644 --- a/src/test/java/com/nhn/pinpoint/testweb/util/HTClientTest.java +++ b/src/test/java/com/nhn/pinpoint/testweb/util/HTClientTest.java @@ -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 executeToBloc = client.execute("http://localhost:9080/", new HashMap()); System.out.println(executeToBloc); }