001 /**
002 *
003 * Copyright 2004 Protique Ltd
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 *
017 **/
018 package org.activemq.transport.http;
019
020 import org.apache.commons.logging.Log;
021 import org.apache.commons.logging.LogFactory;
022 import org.activemq.io.TextWireFormat;
023 import org.activemq.io.WireFormat;
024 import org.activemq.transport.TransportChannel;
025 import org.activemq.transport.TransportChannelFactorySupport;
026 import org.activemq.transport.xstream.XStreamWireFormat;
027 import org.activemq.util.JMSExceptionHelper;
028
029 import javax.jms.JMSException;
030 import java.net.MalformedURLException;
031 import java.net.URI;
032 import java.net.URISyntaxException;
033
034 /**
035 * @version $Revision$
036 */
037 public class HttpTransportChannelFactory extends TransportChannelFactorySupport {
038 private static final Log log = LogFactory.getLog(HttpTransportChannelFactory.class);
039
040 public TransportChannel create(WireFormat wireFormat, URI remoteLocation) throws JMSException {
041 try {
042 return create(wireFormat, remoteLocation, new URI("http://localhost:0"));
043 }
044 catch (URISyntaxException e) {
045 throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
046 }
047 }
048
049 public TransportChannel create(WireFormat wireFormat, URI remoteLocation, URI localLocation) throws JMSException {
050 try {
051 HttpTransportChannel channel = new HttpTransportChannel(asTextWireFormat(wireFormat), remoteLocation.toString());
052 return populateProperties(channel, remoteLocation);
053 }
054 catch (MalformedURLException e) {
055 throw JMSExceptionHelper.newJMSException(e.getMessage(), e);
056 }
057 }
058
059 protected TextWireFormat asTextWireFormat(WireFormat wireFormat) {
060 if (wireFormat instanceof TextWireFormat) {
061 return (TextWireFormat) wireFormat;
062 }
063 log.trace("Not created with a TextWireFromat: " + wireFormat);
064 return new XStreamWireFormat();
065 }
066
067 public boolean requiresEmbeddedBroker() {
068 return false;
069 }
070
071 }