View Javadoc

1   /*** 
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * 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  package org.codehaus.activemq.transport.http;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.codehaus.activemq.message.TextWireFormat;
23  import org.codehaus.activemq.message.WireFormat;
24  import org.codehaus.activemq.transport.TransportChannel;
25  import org.codehaus.activemq.transport.TransportChannelFactorySupport;
26  import org.codehaus.activemq.transport.xstream.XStreamWireFormat;
27  import org.codehaus.activemq.util.JMSExceptionHelper;
28  
29  import javax.jms.JMSException;
30  import java.net.MalformedURLException;
31  import java.net.URI;
32  import java.net.URISyntaxException;
33  
34  /***
35   * @version $Revision: 1.2 $
36   */
37  public class HttpTransportChannelFactory extends TransportChannelFactorySupport {
38      private static final Log log = LogFactory.getLog(HttpTransportChannelFactory.class);
39  
40      public TransportChannel create(WireFormat wireFormat, URI remoteLocation) throws JMSException {
41          try {
42              return create(wireFormat, remoteLocation, new URI("http://localhost:0"));
43          }
44          catch (URISyntaxException e) {
45              throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
46          }
47      }
48  
49      public TransportChannel create(WireFormat wireFormat, URI remoteLocation, URI localLocation) throws JMSException {
50          try {
51              HttpTransportChannel channel = new HttpTransportChannel(asTextWireFormat(wireFormat), remoteLocation.toString());
52              return populateProperties(channel, remoteLocation);
53          }
54          catch (MalformedURLException e) {
55              throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
56          }
57      }
58  
59      protected TextWireFormat asTextWireFormat(WireFormat wireFormat) {
60          if (wireFormat instanceof TextWireFormat) {
61              return (TextWireFormat) wireFormat;
62          }
63          log.trace("Not created with a TextWireFromat: " + wireFormat);
64          return new XStreamWireFormat();
65      }
66  
67      public boolean requiresEmbeddedBroker() {
68          return false;
69      }
70  
71  }