1+ /*
2+ * Licensed to the Apache Software Foundation (ASF) under one or more
3+ * contributor license agreements. See the NOTICE file distributed with
4+ * this work for additional information regarding copyright ownership.
5+ * The ASF licenses this file to You under the Apache License, Version 2.0
6+ * (the "License"); you may not use this file except in compliance with
7+ * the License. You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ *
17+ */
18+
19+ package org .apache .skywalking .apm .plugin .jetty .v9 .client ;
20+
21+ import org .apache .skywalking .apm .agent .core .context .ContextManager ;
22+ import org .apache .skywalking .apm .agent .core .context .ContextSnapshot ;
23+ import org .apache .skywalking .apm .agent .core .context .trace .AbstractSpan ;
24+ import org .apache .skywalking .apm .agent .core .context .trace .SpanLayer ;
25+ import org .apache .skywalking .apm .network .trace .component .ComponentsDefine ;
26+ import org .eclipse .jetty .client .api .Response ;
27+ import org .eclipse .jetty .client .api .Result ;
28+ import org .eclipse .jetty .http .HttpField ;
29+
30+ import java .nio .ByteBuffer ;
31+
32+ public class ResponseListenerWrapper implements Response .Listener {
33+ private final Response .Listener callback ;
34+ private final ContextSnapshot context ;
35+
36+ public ResponseListenerWrapper (Response .Listener callback , ContextSnapshot context ) {
37+ this .callback = callback ;
38+ this .context = context ;
39+ }
40+
41+ @ Override
42+ public void onComplete (Result result ) {
43+ AbstractSpan span = ContextManager .createLocalSpan (Constants .PLUGIN_NAME + "/CompleteListener/onComplete" );
44+ span .setComponent (ComponentsDefine .JETTY_CLIENT );
45+ SpanLayer .asHttp (span );
46+ if (context != null ) {
47+ ContextManager .continued (context );
48+ }
49+ if (callback != null ) {
50+ callback .onComplete (result );
51+ }
52+ ContextManager .stopSpan ();
53+ }
54+
55+ @ Override
56+ public void onHeaders (Response response ) {
57+ callback .onHeaders (response );
58+ }
59+
60+ @ Override
61+ public void onContent (Response response , ByteBuffer content ) {
62+ callback .onContent (response , content );
63+ }
64+
65+ @ Override
66+ public void onBegin (Response response ) {
67+ callback .onBegin (response );
68+ }
69+
70+ @ Override
71+ public boolean onHeader (Response response , HttpField field ) {
72+ return callback .onHeader (response , field );
73+ }
74+
75+ @ Override
76+ public void onSuccess (Response response ) {
77+ callback .onSuccess (response );
78+ }
79+
80+ @ Override
81+ public void onFailure (Response response , Throwable failure ) {
82+ callback .onFailure (response , failure );
83+ }
84+ }
0 commit comments