View Javadoc

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