KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > il > http > HTTPServerIL


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq.il.http;
23
24 import java.io.Serializable JavaDoc;
25 import java.net.URL JavaDoc;
26
27 import javax.jms.Destination JavaDoc;
28 import javax.jms.Queue JavaDoc;
29 import javax.jms.TemporaryQueue JavaDoc;
30 import javax.jms.TemporaryTopic JavaDoc;
31 import javax.jms.Topic JavaDoc;
32 import javax.transaction.xa.Xid JavaDoc;
33
34 import org.jboss.logging.Logger;
35 import org.jboss.mq.AcknowledgementRequest;
36 import org.jboss.mq.ConnectionToken;
37 import org.jboss.mq.DurableSubscriptionID;
38 import org.jboss.mq.Recoverable;
39 import org.jboss.mq.SpyDestination;
40 import org.jboss.mq.SpyMessage;
41 import org.jboss.mq.Subscription;
42 import org.jboss.mq.TransactionRequest;
43 import org.jboss.mq.il.ServerIL;
44
45 /**
46  * Client proxy to the server. For each request, an HTTP or HTTPS
47  * request is created, and posted to the given URL. The URL is supplied
48  * in the HTTPServerILService MBean configuration, or automatically generated
49  * by as localhost here, but can be overridden on the client side by specifying
50  * a property name for the URL value, which will be resolved to a system property
51  * on the client side.
52  *
53  * @author Nathan Phelps (nathan@jboss.org)
54  * @version $Revision: 45317 $
55  * @created January 15, 2003
56  */

57 public class HTTPServerIL implements Serializable JavaDoc, ServerIL, Recoverable
58 {
59     static final long serialVersionUID = -864073076154976490L;
60
61     private static Logger log = Logger.getLogger(HTTPClient.class);
62     
63     private String JavaDoc serverUrlValue = null;
64     private URL JavaDoc serverUrl = null;
65     
66     public HTTPServerIL(String JavaDoc url) throws Exception JavaDoc
67     {
68         if (log.isTraceEnabled())
69         {
70             log.trace("created(String " + url + ")");
71         }
72         this.serverUrlValue = url;
73     }
74     
75     public void acknowledge(ConnectionToken dc, AcknowledgementRequest item) throws Exception JavaDoc
76     {
77         if (log.isTraceEnabled())
78         {
79             log.trace("acknowledge(ConnectionToken " + dc.toString() + ", AcknowledgementRequest " + item.toString() + ")");
80         }
81         HTTPILRequest request = new HTTPILRequest();
82         request.setMethodName("acknowledge");
83         request.setArguments(new Object JavaDoc[]
84         {dc, item}, new Class JavaDoc[]
85         {ConnectionToken.class, AcknowledgementRequest.class});
86         this.postRequest(request);
87     }
88     
89     public void addMessage(ConnectionToken dc, SpyMessage message) throws Exception JavaDoc
90     {
91         if (log.isTraceEnabled())
92         {
93             log.trace("addMessage(ConnectionToken " + dc.toString() + ", SpyMessage " + message.toString() + ")");
94         }
95         HTTPILRequest request = new HTTPILRequest();
96         request.setMethodName("addMessage");
97         request.setArguments(new Object JavaDoc[]
98         {dc, message}, new Class JavaDoc[]
99         {ConnectionToken.class, SpyMessage.class});
100         this.postRequest(request);
101     }
102     
103     public String JavaDoc authenticate(String JavaDoc userName, String JavaDoc password) throws Exception JavaDoc
104     {
105         if (log.isTraceEnabled())
106         {
107             log.trace("authenticate(String " + userName + ", String " + password + ")");
108         }
109         HTTPILRequest request = new HTTPILRequest();
110         request.setMethodName("authenticate");
111         request.setArguments(new Object JavaDoc[]
112         {userName, password}, new Class JavaDoc[]
113         {String JavaDoc.class, String JavaDoc.class});
114         return (String JavaDoc)this.postRequest(request);
115     }
116     
117     public SpyMessage[] browse(ConnectionToken dc, Destination JavaDoc dest, String JavaDoc selector) throws Exception JavaDoc
118     {
119         if (log.isTraceEnabled())
120         {
121             log.trace("browse(ConnectionToken " + dc.toString() + ", Destination " + dest.toString() + ", String " + selector + ")");
122         }
123         HTTPILRequest request = new HTTPILRequest();
124         request.setMethodName("browse");
125         request.setArguments(new Object JavaDoc[]
126         {dc, dest, selector}, new Class JavaDoc[]
127         {ConnectionToken.class, Destination JavaDoc.class, String JavaDoc.class});
128         return (SpyMessage[])this.postRequest(request);
129     }
130     
131     public void checkID(String JavaDoc ID) throws Exception JavaDoc
132     {
133         if (log.isTraceEnabled())
134         {
135             log.trace("checkID(String " + ID + ")");
136         }
137         HTTPILRequest request = new HTTPILRequest();
138         request.setMethodName("checkID");
139         request.setArguments(new Object JavaDoc[]
140         {ID}, new Class JavaDoc[]
141         {String JavaDoc.class});
142         this.postRequest(request);
143     }
144     
145     public String JavaDoc checkUser(String JavaDoc userName, String JavaDoc password) throws Exception JavaDoc
146     {
147         if (log.isTraceEnabled())
148         {
149             log.trace("checkUser(String " + userName + ", String " + password + ")");
150         }
151         HTTPILRequest request = new HTTPILRequest();
152         request.setMethodName("checkUser");
153         request.setArguments(new Object JavaDoc[]
154         {userName, password}, new Class JavaDoc[]
155         {String JavaDoc.class, String JavaDoc.class});
156         return (String JavaDoc)this.postRequest(request);
157     }
158     
159     public ServerIL cloneServerIL() throws Exception JavaDoc
160     {
161         if (log.isTraceEnabled())
162         {
163             log.trace("cloneServerIL()");
164         }
165         return this; // We can return this becuase we're stateless
166
}
167     
168     public void connectionClosing(ConnectionToken dc) throws Exception JavaDoc
169     {
170         if (log.isTraceEnabled())
171         {
172             log.trace("connectionClosing(ConnectionToken " + dc.toString() + ")");
173         }
174         HTTPILRequest request = new HTTPILRequest();
175         request.setMethodName("connectionClosing");
176         request.setArguments(new Object JavaDoc[]
177         {dc}, new Class JavaDoc[]
178         {ConnectionToken.class});
179         this.postRequest(request);
180     }
181     
182     public Queue JavaDoc createQueue(ConnectionToken dc, String JavaDoc dest) throws Exception JavaDoc
183     {
184         if (log.isTraceEnabled())
185         {
186             log.trace("createQueue(ConnectionToken " + dc.toString() + ", String " + dest.toString() + ")");
187         }
188         HTTPILRequest request = new HTTPILRequest();
189         request.setMethodName("createQueue");
190         request.setArguments(new Object JavaDoc[]
191         {dc, dest}, new Class JavaDoc[]
192         {ConnectionToken.class, String JavaDoc.class});
193         return (Queue JavaDoc)this.postRequest(request);
194     }
195     
196     public Topic JavaDoc createTopic(ConnectionToken dc, String JavaDoc dest) throws Exception JavaDoc
197     {
198         if (log.isTraceEnabled())
199         {
200             log.trace("createTopic(ConnectionToken " + dc.toString() + ", String " + dest.toString() + ")");
201         }
202         HTTPILRequest request = new HTTPILRequest();
203         request.setMethodName("createTopic");
204         request.setArguments(new Object JavaDoc[]
205         {dc, dest}, new Class JavaDoc[]
206         {ConnectionToken.class, String JavaDoc.class});
207         return (Topic JavaDoc)this.postRequest(request);
208     }
209     
210     public void deleteTemporaryDestination(ConnectionToken dc, SpyDestination dest) throws Exception JavaDoc
211     {
212         if (log.isTraceEnabled())
213         {
214             log.trace("deleteTemporaryDestination(ConnectionToken " + dc.toString() + ", SpyDestination " + dest.toString() + ")");
215         }
216         HTTPILRequest request = new HTTPILRequest();
217         request.setMethodName("deleteTemporaryDestination");
218         request.setArguments(new Object JavaDoc[]
219         {dc, dest}, new Class JavaDoc[]
220         {ConnectionToken.class, SpyDestination.class});
221         this.postRequest(request);
222     }
223     
224     public void destroySubscription(ConnectionToken dc, DurableSubscriptionID id) throws Exception JavaDoc
225     {
226         if (log.isTraceEnabled())
227         {
228             log.trace("destroySubscription(ConnectionToken " + dc.toString() + ", DurableSubscriptionID " + id.toString() + ")");
229         }
230         HTTPILRequest request = new HTTPILRequest();
231         request.setMethodName("destroySubscription");
232         request.setArguments(new Object JavaDoc[]
233         {dc, id}, new Class JavaDoc[]
234         {ConnectionToken.class, DurableSubscriptionID.class});
235         this.postRequest(request);
236     }
237     
238     public String JavaDoc getID() throws Exception JavaDoc
239     {
240         if (log.isTraceEnabled())
241         {
242             log.trace("getID()");
243         }
244         HTTPILRequest request = new HTTPILRequest();
245         request.setMethodName("getID");
246         return (String JavaDoc)this.postRequest(request);
247     }
248     
249     public TemporaryQueue JavaDoc getTemporaryQueue(ConnectionToken dc) throws Exception JavaDoc
250     {
251         if (log.isTraceEnabled())
252         {
253             log.trace("getTemporaryQueue(ConnectionToken " + dc.toString() + ")");
254         }
255         HTTPILRequest request = new HTTPILRequest();
256         request.setMethodName("getTemporaryQueue");
257         request.setArguments(new Object JavaDoc[]
258         {dc}, new Class JavaDoc[]
259         {ConnectionToken.class});
260         return (TemporaryQueue JavaDoc)this.postRequest(request);
261     }
262     
263     public TemporaryTopic JavaDoc getTemporaryTopic(ConnectionToken dc) throws Exception JavaDoc
264     {
265         if (log.isTraceEnabled())
266         {
267             log.trace("getTemporaryTopic(ConnectionToken " + dc.toString() + ")");
268         }
269         HTTPILRequest request = new HTTPILRequest();
270         request.setMethodName("getTemporaryTopic");
271         request.setArguments(new Object JavaDoc[]
272         {dc}, new Class JavaDoc[]
273         {ConnectionToken.class});
274         return (TemporaryTopic JavaDoc)this.postRequest(request);
275     }
276     
277     public void ping(ConnectionToken dc, long clientTime) throws Exception JavaDoc
278     {
279         // This is never called because we don't do pings. It is here for completeness.
280
if (log.isTraceEnabled())
281         {
282             log.trace("ping(ConnectionToken " + dc.toString() + ", long " + String.valueOf(clientTime) + ")");
283         }
284         HTTPILRequest request = new HTTPILRequest();
285         request.setMethodName("ping");
286         request.setArguments(new Object JavaDoc[]
287         {dc, new Long JavaDoc(clientTime)}, new Class JavaDoc[]
288         {ConnectionToken.class, Long JavaDoc.class});
289         this.postRequest(request);
290     }
291     
292     public SpyMessage receive(ConnectionToken dc, int subscriberId, long wait) throws Exception JavaDoc
293     {
294         if (log.isTraceEnabled())
295         {
296             log.trace("receive(ConnectionToken " + dc.toString() + ", int " + String.valueOf(subscriberId) + ", long " + String.valueOf(wait) + ")");
297         }
298         HTTPILRequest request = new HTTPILRequest();
299         request.setMethodName("receive");
300         request.setArguments(new Object JavaDoc[]
301         {dc, new Integer JavaDoc(subscriberId), new Long JavaDoc(wait)}, new Class JavaDoc[]
302         {ConnectionToken.class, Integer JavaDoc.class, Long JavaDoc.class});
303         return (SpyMessage)this.postRequest(request);
304     }
305     
306     public void setConnectionToken(ConnectionToken newConnectionToken) throws Exception JavaDoc
307     {
308         // Since we're stateless, we don't cache the ConnectionToken.
309
}
310     
311     public void setEnabled(ConnectionToken dc, boolean enabled) throws Exception JavaDoc
312     {
313         if (log.isTraceEnabled())
314         {
315             log.trace("setEnabled(ConnectionToken " + dc.toString() + ", boolean " + String.valueOf(enabled) + ")");
316         }
317         HTTPILRequest request = new HTTPILRequest();
318         request.setMethodName("setEnabled");
319         request.setArguments(new Object JavaDoc[]
320         {dc, new Boolean JavaDoc(enabled)}, new Class JavaDoc[]
321         {ConnectionToken.class, Boolean JavaDoc.class});
322         this.postRequest(request);
323     }
324     
325     public void subscribe(ConnectionToken dc, Subscription s) throws Exception JavaDoc
326     {
327         if (log.isTraceEnabled())
328         {
329             log.trace("subscribe(ConnectionToken " + dc.toString() + ", Subscription " + s.toString() + ")");
330         }
331         HTTPILRequest request = new HTTPILRequest();
332         request.setMethodName("subscribe");
333         request.setArguments(new Object JavaDoc[]
334         {dc, s}, new Class JavaDoc[]
335         {ConnectionToken.class, Subscription.class});
336         this.postRequest(request);
337     }
338     
339     public void transact(ConnectionToken dc, TransactionRequest t) throws Exception JavaDoc
340     {
341         if (log.isTraceEnabled())
342         {
343             log.trace("transact(ConnectionToken " + dc.toString() + ", TransactionRequest " + t.toString() + ")");
344         }
345         HTTPILRequest request = new HTTPILRequest();
346         request.setMethodName("transact");
347         request.setArguments(new Object JavaDoc[]
348         {dc, t}, new Class JavaDoc[]
349         {ConnectionToken.class, TransactionRequest.class});
350         this.postRequest(request);
351     }
352     
353     public Xid JavaDoc[] recover(ConnectionToken dc, int flags) throws Exception JavaDoc
354     {
355         if (log.isTraceEnabled())
356             log.trace("recover(ConnectionToken " + dc + ", flags=" + flags + ")");
357         HTTPILRequest request = new HTTPILRequest();
358         request.setMethodName("recover");
359         request.setArguments
360         (
361            new Object JavaDoc[] { dc, new Integer JavaDoc(flags) },
362            new Class JavaDoc[] { ConnectionToken.class, Integer JavaDoc.class }
363         );
364         return (Xid JavaDoc[]) this.postRequest(request);
365     }
366     
367     public void unsubscribe(ConnectionToken dc, int subscriptionId) throws Exception JavaDoc
368     {
369         if (log.isTraceEnabled())
370         {
371             log.trace("unsubscribe(ConnectionToken " + dc.toString() + ", int " + String.valueOf(subscriptionId) + ")");
372         }
373         HTTPILRequest request = new HTTPILRequest();
374         request.setMethodName("unsubscribe");
375         request.setArguments(new Object JavaDoc[]
376         {dc, new Integer JavaDoc(subscriptionId)}, new Class JavaDoc[]
377         {ConnectionToken.class, Integer JavaDoc.class});
378         this.postRequest(request);
379     }
380     
381     private Object JavaDoc postRequest(HTTPILRequest request) throws Exception JavaDoc
382     {
383         if (log.isTraceEnabled())
384         {
385             log.trace("postRequest(HTTPILRequest " + request.toString() + ")");
386         }
387         if (this.serverUrl == null)
388         {
389             this.serverUrl = HTTPClient.resolveServerUrl(this.serverUrlValue);
390         }
391         return HTTPClient.post(this.serverUrl, request);
392     }
393 }
Popular Tags