View Javadoc

1   //
2   //  ========================================================================
3   //  Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4   //  ------------------------------------------------------------------------
5   //  All rights reserved. This program and the accompanying materials
6   //  are made available under the terms of the Eclipse Public License v1.0
7   //  and Apache License v2.0 which accompanies this distribution.
8   //
9   //      The Eclipse Public License is available at
10  //      http://www.eclipse.org/legal/epl-v10.html
11  //
12  //      The Apache License v2.0 is available at
13  //      http://www.opensource.org/licenses/apache2.0.php
14  //
15  //  You may elect to redistribute this code under either of these licenses.
16  //  ========================================================================
17  //
18  
19  
20  package org.eclipse.jetty.client;
21  
22  import java.io.IOException;
23  
24  import org.eclipse.jetty.io.Buffer;
25  
26  public class HttpEventListenerWrapper implements HttpEventListener
27  {
28      HttpEventListener _listener;
29      boolean _delegatingRequests;
30      boolean _delegatingResponses;
31      boolean _delegationResult = true;
32      private Buffer _version;
33      private int _status;
34      private Buffer _reason;
35  
36      public HttpEventListenerWrapper()
37      {
38          _listener=null;
39          _delegatingRequests=false;
40          _delegatingResponses=false;
41      }
42      
43      public HttpEventListenerWrapper(HttpEventListener eventListener,boolean delegating)
44      {
45          _listener=eventListener;
46          _delegatingRequests=delegating;
47          _delegatingResponses=delegating;
48      }
49      
50      public HttpEventListener getEventListener()
51      {
52          return _listener;
53      }
54  
55      public void setEventListener(HttpEventListener listener)
56      {
57          _listener = listener;
58      }
59  
60      public boolean isDelegatingRequests()
61      {
62          return _delegatingRequests;
63      }
64      
65      public boolean isDelegatingResponses()
66      {
67          return _delegatingResponses;
68      }
69  
70      public void setDelegatingRequests(boolean delegating)
71      {
72          _delegatingRequests = delegating;
73      }
74      
75      public void setDelegatingResponses(boolean delegating)
76      {
77          _delegatingResponses = delegating;
78      }
79      
80      public void setDelegationResult( boolean result )
81      {
82          _delegationResult = result;
83      }
84      
85      public void onConnectionFailed(Throwable ex)
86      {
87          if (_delegatingRequests)
88              _listener.onConnectionFailed(ex);
89      }
90  
91      public void onException(Throwable ex)
92      {
93          if (_delegatingRequests||_delegatingResponses)
94              _listener.onException(ex);
95      }
96  
97      public void onExpire()
98      {
99          if (_delegatingRequests||_delegatingResponses)
100             _listener.onExpire();
101     }
102 
103     public void onRequestCommitted() throws IOException
104     {
105         if (_delegatingRequests)
106             _listener.onRequestCommitted();
107     }
108 
109     public void onRequestComplete() throws IOException
110     {
111         if (_delegatingRequests)
112             _listener.onRequestComplete();
113     }
114 
115     public void onResponseComplete() throws IOException
116     {
117         if (_delegatingResponses)
118         {
119             if (_delegationResult == false)
120             {
121                 _listener.onResponseStatus(_version,_status,_reason);
122             }
123             _listener.onResponseComplete();
124         }
125     }
126 
127     public void onResponseContent(Buffer content) throws IOException
128     {
129         if (_delegatingResponses)
130             _listener.onResponseContent(content);
131     }
132 
133     public void onResponseHeader(Buffer name, Buffer value) throws IOException
134     {
135         if (_delegatingResponses)
136             _listener.onResponseHeader(name,value);
137     }
138 
139     public void onResponseHeaderComplete() throws IOException
140     {
141         if (_delegatingResponses)
142             _listener.onResponseHeaderComplete();
143     }
144 
145     public void onResponseStatus(Buffer version, int status, Buffer reason) throws IOException
146     {
147         if (_delegatingResponses)
148         {
149             _listener.onResponseStatus(version,status,reason);
150         }
151         else
152         {
153             _version = version;
154             _status = status;
155             _reason = reason;
156         }
157     }
158 
159     public void onRetry()
160     {
161         if (_delegatingRequests)
162             _listener.onRetry();
163     }
164     
165     
166     
167 }