Skip to content

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

@xhrg

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

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

Relationships

None yet

Development

No branches or pull requests

Issue actions