-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52fed52
commit bf29af7
Showing
20 changed files
with
414 additions
and
5 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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,31 @@ | ||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
|
||
implementation("org.eclipse.jetty.ee9:jetty-ee9-nested:12.0.3") | ||
} | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.jetty-12-ee9-nested' } | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'org.eclipse.jetty.ee9:jetty-ee9-nested:[12.0.0,)' | ||
exclude 'org.eclipse.jetty.ee9:jetty-ee9-nested:[12.0.0-alpha0,12.0.0.beta4]' | ||
} | ||
|
||
site { | ||
title 'Jetty' | ||
type 'Appserver' | ||
} | ||
|
||
// Jetty Server 10+ is only compatible with Java 11+ | ||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(17)) | ||
} | ||
} | ||
|
||
compileJava { | ||
options.fork = true | ||
options.bootstrapClasspath = null | ||
} |
48 changes: 48 additions & 0 deletions
48
...ted/src/main/java/com/nr/agent/instrumentation/jetty/ee9/nested/AsyncListenerFactory.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,48 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.nr.agent.instrumentation.jetty.ee9.nested; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import jakarta.servlet.AsyncEvent; | ||
import jakarta.servlet.AsyncListener; | ||
|
||
import java.io.IOException; | ||
|
||
public final class AsyncListenerFactory { | ||
|
||
private AsyncListenerFactory() { | ||
} | ||
|
||
private static final AsyncListener ASYNC_LISTENER = new AsyncListener() { | ||
|
||
@Override | ||
public void onComplete(AsyncEvent asyncEvent) throws IOException { | ||
AgentBridge.asyncApi.completeAsync(asyncEvent.getAsyncContext()); | ||
} | ||
|
||
@Override | ||
public void onTimeout(AsyncEvent asyncEvent) throws IOException { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void onError(AsyncEvent asyncEvent) throws IOException { | ||
AgentBridge.asyncApi.errorAsync(asyncEvent.getAsyncContext(), asyncEvent.getThrowable()); | ||
} | ||
|
||
@Override | ||
public void onStartAsync(AsyncEvent asyncEvent) throws IOException { | ||
// do nothing | ||
} | ||
|
||
}; | ||
|
||
public static AsyncListener getAsyncListener() { | ||
return ASYNC_LISTENER; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...tty-12-ee9-nested/src/main/java/org/eclipse/jetty/ee9/nested/Request_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,44 @@ | ||
package org.eclipse.jetty.ee9.nested; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import com.newrelic.api.agent.weaver.Weave; | ||
import com.newrelic.api.agent.weaver.Weaver; | ||
import com.nr.agent.instrumentation.jetty.ee9.nested.AsyncListenerFactory; | ||
import jakarta.servlet.AsyncContext; | ||
import jakarta.servlet.ServletRequest; | ||
import jakarta.servlet.ServletResponse; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import org.eclipse.jetty.server.Response; | ||
import org.eclipse.jetty.server.internal.HttpChannelState; | ||
|
||
import java.util.logging.Level; | ||
|
||
@Weave(originalName = "org.eclipse.jetty.ee9.nested.Request") | ||
public abstract class Request_Instrumentation implements HttpServletRequest { | ||
|
||
@Override | ||
public AsyncContext startAsync(ServletRequest request, ServletResponse response) { | ||
AsyncContext asyncContext = Weaver.callOriginal(); | ||
|
||
asyncContext.addListener(AsyncListenerFactory.getAsyncListener()); | ||
AgentBridge.getAgent().getLogger().log(Level.FINER, "Added async listener"); | ||
|
||
return asyncContext; | ||
} | ||
|
||
@Override | ||
public AsyncContext startAsync() { | ||
|
||
AsyncContext asyncContext = Weaver.callOriginal(); | ||
|
||
asyncContext.addListener(AsyncListenerFactory.getAsyncListener()); | ||
AgentBridge.getAgent().getLogger().log(Level.FINER, "Added async listener"); | ||
|
||
return asyncContext; | ||
} | ||
|
||
public abstract HttpChannelState getHttpChannelState(); | ||
|
||
public abstract Response getResponse(); | ||
|
||
} |
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,32 @@ | ||
|
||
dependencies { | ||
implementation(project(":agent-bridge")) | ||
|
||
implementation("org.eclipse.jetty.ee9:jetty-ee9-servlet:12.0.3") | ||
} | ||
|
||
jar { | ||
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.jetty-12-ee9-servlet' } | ||
} | ||
|
||
verifyInstrumentation { | ||
passesOnly 'org.eclipse.jetty.ee9:jetty-ee9-servlet:[12.0.0,)' | ||
exclude 'org.eclipse.jetty.ee9:jetty-ee9-servlet:[12.0.0-alpha0,12.0.0.beta4]' | ||
} | ||
|
||
site { | ||
title 'Jetty' | ||
type 'Appserver' | ||
} | ||
|
||
// Jetty Server 10+ is only compatible with Java 11+ | ||
java { | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(17)) | ||
} | ||
} | ||
|
||
compileJava { | ||
options.fork = true | ||
options.bootstrapClasspath = null | ||
} |
48 changes: 48 additions & 0 deletions
48
...et/src/main/java/com/nr/agent/instrumentation/jetty/ee9/servlet/AsyncListenerFactory.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,48 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.nr.agent.instrumentation.jetty.ee9.servlet; | ||
|
||
import com.newrelic.agent.bridge.AgentBridge; | ||
import jakarta.servlet.AsyncEvent; | ||
import jakarta.servlet.AsyncListener; | ||
|
||
import java.io.IOException; | ||
|
||
public final class AsyncListenerFactory { | ||
|
||
private AsyncListenerFactory() { | ||
} | ||
|
||
private static final AsyncListener ASYNC_LISTENER = new AsyncListener() { | ||
|
||
@Override | ||
public void onComplete(AsyncEvent asyncEvent) throws IOException { | ||
AgentBridge.asyncApi.completeAsync(asyncEvent.getAsyncContext()); | ||
} | ||
|
||
@Override | ||
public void onTimeout(AsyncEvent asyncEvent) throws IOException { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void onError(AsyncEvent asyncEvent) throws IOException { | ||
AgentBridge.asyncApi.errorAsync(asyncEvent.getAsyncContext(), asyncEvent.getThrowable()); | ||
} | ||
|
||
@Override | ||
public void onStartAsync(AsyncEvent asyncEvent) throws IOException { | ||
// do nothing | ||
} | ||
|
||
}; | ||
|
||
public static AsyncListener getAsyncListener() { | ||
return ASYNC_LISTENER; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...e9-servlet/src/main/java/com/nr/agent/instrumentation/jetty/ee9/servlet/JettyRequest.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,88 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.nr.agent.instrumentation.jetty.ee9.servlet; | ||
|
||
import com.newrelic.api.agent.ExtendedRequest; | ||
import com.newrelic.api.agent.HeaderType; | ||
import jakarta.servlet.http.Cookie; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
import java.util.Collections; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
|
||
public class JettyRequest extends ExtendedRequest { | ||
private final HttpServletRequest request; | ||
|
||
public JettyRequest(HttpServletRequest request) { | ||
super(); | ||
this.request = request; | ||
} | ||
|
||
@Override | ||
public String getRequestURI() { | ||
return request.getRequestURI(); | ||
} | ||
|
||
@Override | ||
public String getHeader(String name) { | ||
return request.getHeader(name); | ||
} | ||
|
||
@Override | ||
public String getRemoteUser() { | ||
return request.getRemoteUser(); | ||
} | ||
|
||
@Override | ||
public Enumeration getParameterNames() { | ||
return request.getParameterNames(); | ||
} | ||
|
||
@Override | ||
public String[] getParameterValues(String name) { | ||
return request.getParameterValues(name); | ||
} | ||
|
||
@Override | ||
public Object getAttribute(String name) { | ||
return request.getAttribute(name); | ||
} | ||
|
||
@Override | ||
public String getCookieValue(String name) { | ||
Cookie[] cookies = request.getCookies(); | ||
if (cookies != null) { | ||
for (Cookie cookie : cookies) { | ||
if (name.equals(cookie.getName())) { | ||
return cookie.getValue(); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public HeaderType getHeaderType() { | ||
return HeaderType.HTTP; | ||
} | ||
|
||
@Override | ||
public String getMethod() { | ||
return request.getMethod(); | ||
} | ||
|
||
@Override | ||
public List<String> getHeaders(String name) { | ||
Enumeration headers = request.getHeaders(name); | ||
if (headers == null) { | ||
return Collections.emptyList(); | ||
} | ||
return Collections.list(headers); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...9-servlet/src/main/java/com/nr/agent/instrumentation/jetty/ee9/servlet/JettyResponse.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,46 @@ | ||
/* | ||
* | ||
* * Copyright 2022 New Relic Corporation. All rights reserved. | ||
* * SPDX-License-Identifier: Apache-2.0 | ||
* | ||
*/ | ||
|
||
package com.nr.agent.instrumentation.jetty.ee9.servlet; | ||
|
||
import com.newrelic.api.agent.HeaderType; | ||
import com.newrelic.api.agent.Response; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
|
||
public class JettyResponse implements Response { | ||
|
||
private final HttpServletResponse delegate; | ||
|
||
public JettyResponse(HttpServletResponse response) { | ||
this.delegate = response; | ||
} | ||
|
||
@Override | ||
public int getStatus() throws Exception { | ||
return delegate.getStatus(); | ||
} | ||
|
||
@Override | ||
public String getStatusMessage() throws Exception { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setHeader(String name, String value) { | ||
delegate.setHeader(name, value); | ||
} | ||
|
||
@Override | ||
public String getContentType() { | ||
return delegate.getContentType(); | ||
} | ||
|
||
@Override | ||
public HeaderType getHeaderType() { | ||
return HeaderType.HTTP; | ||
} | ||
} |
Oops, something went wrong.