Skip to content

[Bug] There is a bug in jetty in java-agent #13500

Closed
apache/skywalking-java
#775

Description

@xhrg

Search before asking

  • I had searched in the issues and found no similar issues.

Apache SkyWalking Component

OAP server (apache/skywalking)

What happened

When using the Jetty client, the application cannot receive the returned data

What you expected to happen

When using the Jetty client, the application can receive the returned data

How to reproduce

Use the Jetty client to request the HTTP interface and check the response

Anything else

AsyncHttpRequestSendInterceptor.java beforeMethod below, This is my repair method

if (allArguments[0] instanceof BufferingResponseListener) {
            BufferingResponseListener callback = (BufferingResponseListener) allArguments[0];
            allArguments[0] = new BufferingResponseListenerWrapper(callback, ContextManager.capture());
        } else {
            Response.CompleteListener callback = (Response.CompleteListener) allArguments[0];
            allArguments[0] = new CompleteListenerWrapper(callback, ContextManager.capture());
        }

public class BufferingResponseListenerWrapper extends BufferingResponseListener {
    private BufferingResponseListener callback;
    private ContextSnapshot context;

    public BufferingResponseListenerWrapper(BufferingResponseListener callback, ContextSnapshot context) {
        this.callback = callback;
        this.context = context;
    }

    @Override
    public void onComplete(Result result) {
        AbstractSpan span = ContextManager.createLocalSpan(Constants.PLUGIN_NAME + "/CompleteListener/onComplete");
        span.setComponent(ComponentsDefine.JETTY_CLIENT);
        SpanLayer.asHttp(span);
        if (context != null) {
            ContextManager.continued(context);
        }
        if (callback != null) {
            callback.onComplete(result);
        }
        ContextManager.stopSpan();
    }

    @Override
    public void onHeaders(Response response) {
        callback.onHeaders(response);
    }

    @Override
    public void onContent(Response response, ByteBuffer content) {
        callback.onContent(response, content);
    }

    @Override
    public void onBegin(Response response) {
        callback.onBegin(response);
    }

    @Override
    public boolean onHeader(Response response, HttpField field) {
        return callback.onHeader(response, field);
    }

    @Override
    public void onSuccess(Response response) {
        callback.onSuccess(response);
    }

    @Override
    public void onFailure(Response response, Throwable failure) {
        callback.onFailure(response, failure);
    }
}

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct

Activity

  1. added
    bugSomething isn't working and you are sure it's a bug!
    on Sep 18, 2025
  2. wu-sheng commented on Sep 18, 2025

    @wu-sheng
    Member

    Could you be clear about what your fix is? Do you mean you are using BufferingResponseListener and it is not supported before?

  3. added
    agentLanguage agent related.
    javaJava agent related
    on Sep 18, 2025
  4. xhrg commented on Sep 18, 2025

    @xhrg
    Author

    jetty-client-9.4.42.v20210604

    in HttpReceiver.java

    private ContentListeners(List<Response.ResponseListener> responseListeners)
            {
                listeners = new ArrayList<>(responseListeners.size());
                responseListeners.stream()
                    .filter(Response.DemandedContentListener.class::isInstance)
                    .map(Response.DemandedContentListener.class::cast)
                    .forEach(listeners::add);
            }
    

    This anonymous object must be an instance of Response.DemandedContentListener.class,
    "onContent" can only be called


    Below is the test code for my application

    request.send(new BufferingResponseListener() {
                @Override
                public void onComplete(Result result) {
                    System.out.println(result.getResponse().getStatus());
                    System.out.println(getContent().length);
                }
    
                @Override
                public void onFailure(Response response, Throwable failure) {
                    System.out.println(response);
                    System.out.println(failure);
                }
    
                @Override
                public void onSuccess(Response response) {
                    System.out.println(123);
                }
            });
    
  5. wu-sheng commented on Sep 18, 2025

    @wu-sheng
    Member

    I am not completely following. Could you fire the PR and add new versions to the plugin test?

  6. xhrg commented on Sep 23, 2025

    @xhrg
    Author
  7. added this to the Java - 9.6.0 milestone on Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agentLanguage agent related.bugSomething isn't working and you are sure it's a bug!javaJava agent related

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions