Skip to content

Commit

Permalink
Add jetty 12 ee9 modules
Browse files Browse the repository at this point in the history
  • Loading branch information
obenkenobi committed Nov 20, 2023
1 parent 52fed52 commit bf29af7
Show file tree
Hide file tree
Showing 20 changed files with 414 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dependencies {
}

jar {
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.jetty-ee10-servlet-12' }
manifest { attributes 'Implementation-Title': 'com.newrelic.instrumentation.jetty-12-ee10-servlet' }
}

verifyInstrumentation {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void preHandleDispatchAsync(ServletContextRequest servletContextRe
AgentBridge.getAgent().getLogger().log(Level.FINE, "AsyncContextEvent is null for request: {0}.", request);
return;
}
AgentBridge.asyncApi.resumeAsync(request.getAsyncContext());
AgentBridge.asyncApi.resumeAsync(asyncContextEvent.getAsyncContext());
}

public static void postHandleDispatch(ServletContextRequest servletContextRequest) {
Expand Down
31 changes: 31 additions & 0 deletions instrumentation/jetty-12-ee9-nested/build.gradle
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
}
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;
}
}
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();

}
32 changes: 32 additions & 0 deletions instrumentation/jetty-12-ee9-servlet/build.gradle
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
}
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;
}
}
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);
}
}
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;
}
}
Loading

0 comments on commit bf29af7

Please sign in to comment.