Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Jakarta support #372

Merged
merged 10 commits into from
Feb 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws-xray-recorder-sdk-core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {

compileOnly("com.google.code.findbugs:jsr305:3.0.2")
compileOnly("javax.servlet:javax.servlet-api:3.1.0")
compileOnly("jakarta.servlet:jakarta.servlet-api:5.0.0")

testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310")
testImplementation("com.github.stefanbirkner:system-rules:1.16.0")
Expand All @@ -16,6 +17,7 @@ dependencies {
testImplementation("org.powermock:powermock-module-junit4:2.0.7")
testImplementation("org.powermock:powermock-api-mockito2:2.0.7")
testImplementation("org.skyscreamer:jsonassert:1.3.0")
testImplementation("jakarta.servlet:jakarta.servlet-api:5.0.0")
}

tasks.jar {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package com.amazonaws.xray.jakarta.servlet;

import com.amazonaws.xray.AWSXRayRecorder;
import com.amazonaws.xray.entities.Entity;
import jakarta.servlet.AsyncEvent;
import jakarta.servlet.AsyncListener;
import java.io.IOException;
import org.checkerframework.checker.initialization.qual.UnderInitialization;
import org.checkerframework.checker.nullness.qual.Nullable;

class AWSXRayServletAsyncListener implements AsyncListener {

public static final String ENTITY_ATTRIBUTE_KEY = "com.amazonaws.xray.entities.Entity";

@Nullable
private AWSXRayRecorder recorder;
private final AWSXRayServletFilter filter;

// TODO(anuraaga): Better define lifecycle relationship between this listener and the filter.
@SuppressWarnings("nullness")
AWSXRayServletAsyncListener(@UnderInitialization AWSXRayServletFilter filter, @Nullable AWSXRayRecorder recorder) {
this.filter = filter;
this.recorder = recorder;
}

private void processEvent(AsyncEvent event) throws IOException {
Entity entity = (Entity) event.getSuppliedRequest().getAttribute(ENTITY_ATTRIBUTE_KEY);
entity.run(() -> {
if (event.getThrowable() != null) {
entity.addException(event.getThrowable());
}
filter.postFilter(event.getSuppliedRequest(), event.getSuppliedResponse());
});
}

@Override
public void onComplete(AsyncEvent event) throws IOException {
processEvent(event);
}

@Override
public void onTimeout(AsyncEvent event) throws IOException {
processEvent(event);
}

@Override
public void onError(AsyncEvent event) throws IOException {
processEvent(event);
}

@Override
public void onStartAsync(AsyncEvent event) throws IOException {
}
}
Loading