-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #297 from newrelic/support/httpserver-response-NR-…
…277771 [NR-277771] Response interception & Route Detection in sun-net-httpserver
- Loading branch information
Showing
8 changed files
with
145 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 25 additions & 3 deletions
28
...y/sun-net-httpserver/src/main/java/com/sun/net/httpserver/HttpServer_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
package com.sun.net.httpserver; | ||
|
||
import com.newrelic.api.agent.security.NewRelicSecurity; | ||
import com.newrelic.api.agent.security.instrumentation.helpers.GenericHelper; | ||
import com.newrelic.api.agent.security.instrumentation.helpers.URLMappingsHelper; | ||
import com.newrelic.api.agent.security.schema.ApplicationURLMapping; | ||
import com.newrelic.api.agent.security.utils.logging.LogLevel; | ||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
|
||
|
||
@Weave(originalName = "com.sun.net.httpserver.HttpServer", type = MatchType.BaseClass) | ||
public class HttpServer_Instrumentation { | ||
|
||
public HttpContext createContext (String path, HttpHandler handler){ | ||
HttpContext context; | ||
HttpContext context = Weaver.callOriginal(); | ||
try { | ||
context = Weaver.callOriginal(); | ||
} finally { | ||
URLMappingsHelper.addApplicationURLMapping(new ApplicationURLMapping(HttpServerHelper.HTTP_METHOD, path, handler.getClass().getName())); | ||
} catch (Exception e){ | ||
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_GETTING_APP_ENDPOINTS, HttpServerHelper.SUN_NET_HTTPSERVER, e.getMessage()), e, this.getClass().getName()); | ||
} | ||
return context; | ||
} | ||
|
||
public void removeContext (String path) throws IllegalArgumentException { | ||
Weaver.callOriginal(); | ||
try { | ||
URLMappingsHelper.removeApplicationURLMapping(HttpServerHelper.HTTP_METHOD, path); | ||
} catch (Exception e){ | ||
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_REMOVING_APP_ENDPOINTS, HttpServerHelper.SUN_NET_HTTPSERVER, e.getMessage()), e, this.getClass().getName()); | ||
} | ||
} | ||
|
||
public void removeContext (HttpContext context) { | ||
Weaver.callOriginal(); | ||
try { | ||
URLMappingsHelper.removeApplicationURLMapping(HttpServerHelper.HTTP_METHOD, context.getPath()); | ||
} catch (Exception e){ | ||
NewRelicSecurity.getAgent().log(LogLevel.WARNING, String.format(GenericHelper.ERROR_WHILE_REMOVING_APP_ENDPOINTS, HttpServerHelper.SUN_NET_HTTPSERVER, e.getMessage()), e, this.getClass().getName()); | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rity/sun-net-httpserver/src/main/java/sun/net/httpserver/ContextList_Instrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package sun.net.httpserver; | ||
|
||
import com.newrelic.api.agent.weaver.MatchType; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.sun.net.httpserver.HttpServerHelper; | ||
|
||
@Weave(originalName = "sun.net.httpserver.ContextList", type = MatchType.ExactClass) | ||
class ContextList_Instrumentation { | ||
|
||
synchronized HttpContextImpl findContext (String protocol, String path, boolean exact) { | ||
HttpContextImpl result = Weaver.callOriginal(); | ||
if (result != null) { | ||
HttpServerHelper.setRoute(result.getPath()); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters