Repository: pinpoint-apm/pinpoint
Issue: Server map fails to link nodes on HTTP calls made to non-80 ports
Labels: bug

Related to Google Groups [issue](https://groups.google.com/forum/#!topic/pinpoint_user/5zxtnFo1y3Q).

The server map currently fails to recognize the target node when a node makes a http call with the port number specified.
![image](https://cloud.githubusercontent.com/assets/10057488/9922689/82890674-5d26-11e5-943e-39050c3a9a9b.png)

The above image should correctly render like the image below.
![image](https://cloud.githubusercontent.com/assets/10057488/9922703/a250f9ee-5d26-11e5-879f-6df676f6f332.png)

Needs a fix.


Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/interceptor/HttpMethodBaseExecuteMethodInterceptor.java b/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/interceptor/HttpMethodBaseExecuteMethodInterceptor.java
index f6ce373a3269..5e784a71a6d8 100644
--- a/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/interceptor/HttpMethodBaseExecuteMethodInterceptor.java
+++ b/plugins/httpclient3/src/main/java/com/navercorp/pinpoint/plugin/httpclient3/interceptor/HttpMethodBaseExecuteMethodInterceptor.java
@@ -164,7 +164,8 @@ public Object createAttachment() {
 
     private String getHost(HttpMethod httpMethod) {
         try {
-            return httpMethod.getURI().getHost();
+            URI url = httpMethod.getURI();
+            return getEndpoint(url.getHost(), url.getPort());
         } catch (URIException e) {
             logger.error("Fail get URI", e);
         }
diff --git a/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/DefaultClientExchangeHandlerImplStartMethodInterceptor.java b/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/DefaultClientExchangeHandlerImplStartMethodInterceptor.java
index 5857e692d930..6ad0e980c81f 100644
--- a/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/DefaultClientExchangeHandlerImplStartMethodInterceptor.java
+++ b/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/DefaultClientExchangeHandlerImplStartMethodInterceptor.java
@@ -125,7 +125,13 @@ public void before(Object target, Object[] args) {
             httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
             final NameIntValuePair<String> host = getHost(target);
             if (host != null) {
-                httpRequest.setHeader(Header.HTTP_HOST.toString(), host.getName());
+                final StringBuilder hostStringBuilder = new StringBuilder(host.getName());
+                if (host.getValue() > 0) {
+                    hostStringBuilder.append(":").append(host.getValue()); 
+                }
+                final String hostString = hostStringBuilder.toString();
+                logger.debug("Get host {}", hostString);
+                httpRequest.setHeader(Header.HTTP_HOST.toString(), hostString);
             }
         }
 
diff --git a/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/HttpRequestExecutorExecuteMethodInterceptor.java b/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/HttpRequestExecutorExecuteMethodInterceptor.java
index 2ee9c6704b30..036aeca16f8b 100644
--- a/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/HttpRequestExecutorExecuteMethodInterceptor.java
+++ b/plugins/httpclient4/src/main/java/com/navercorp/pinpoint/plugin/httpclient4/interceptor/HttpRequestExecutorExecuteMethodInterceptor.java
@@ -148,8 +148,13 @@ public void before(Object target, Object[] args) {
             httpRequest.setHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
             final NameIntValuePair<String> host = getHost();
             if (host != null) {
-                logger.debug("Get host {}", host.getName());
-                httpRequest.setHeader(Header.HTTP_HOST.toString(), host.getName());
+                final StringBuilder hostStringBuilder = new StringBuilder(host.getName());
+                if (host.getValue() > 0) {
+                    hostStringBuilder.append(":").append(host.getValue()); 
+                }
+                final String hostString = hostStringBuilder.toString();
+                logger.debug("Get host {}", hostString);
+                httpRequest.setHeader(Header.HTTP_HOST.toString(), hostString);
             }
         }
 
diff --git a/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/HttpURLConnectionInterceptor.java b/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/HttpURLConnectionInterceptor.java
index 74ddac604a87..4ac8870852b4 100644
--- a/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/HttpURLConnectionInterceptor.java
+++ b/plugins/jdk-http/src/main/java/com/navercorp/pinpoint/plugin/jdk/http/interceptor/HttpURLConnectionInterceptor.java
@@ -97,6 +97,8 @@ public void before(Object target, Object[] args) {
         final URL url = request.getURL();
         final String host = url.getHost();
         final int port = url.getPort();
+        // TODO How to represent protocol?
+        String endpoint = getEndpoint(host, port);
 
         request.setRequestProperty(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
         request.setRequestProperty(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
@@ -106,13 +108,10 @@ public void before(Object target, Object[] args) {
         request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
         request.setRequestProperty(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
         if(host != null) {
-            request.setRequestProperty(Header.HTTP_HOST.toString(), host);
+            request.setRequestProperty(Header.HTTP_HOST.toString(), endpoint);
         }
 
         recorder.recordServiceType(SERVICE_TYPE);
-
-        // TODO How to represent protocol?
-        String endpoint = getEndpoint(host, port);
         
         // Don't record end point because it's same with destination id.
         recorder.recordDestinationId(endpoint);
diff --git a/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java
index f222ad9406bb..0b8911bf348b 100644
--- a/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java
+++ b/plugins/ning-asynchttpclient/src/main/java/com/navercorp/pinpoint/plugin/ning/asynchttpclient/interceptor/ExecuteRequestInterceptor.java
@@ -122,9 +122,9 @@ public void before(Object target, Object[] args) {
             putHeader(httpRequestHeaders, Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
             putHeader(httpRequestHeaders, Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
             putHeader(httpRequestHeaders, Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
-            final String host = httpRequest.getURI().getHost();
-            if(host != null) {
-                putHeader(httpRequestHeaders, Header.HTTP_HOST.toString(), host);
+            final String hostString = getEndpoint(httpRequest.getURI().getHost(), httpRequest.getURI().getPort());
+            if(hostString != null) {
+                putHeader(httpRequestHeaders, Header.HTTP_HOST.toString(), hostString);
             }
         }
     }


Test patch: