001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. 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 */ 017package org.apache.activemq.transport.amqp; 018 019import java.io.IOException; 020import java.net.MalformedURLException; 021import java.net.URI; 022import java.net.UnknownHostException; 023import java.util.Map; 024 025import org.apache.activemq.broker.BrokerService; 026import org.apache.activemq.broker.BrokerServiceAware; 027import org.apache.activemq.transport.Transport; 028import org.apache.activemq.transport.TransportFactory; 029import org.apache.activemq.transport.TransportServer; 030import org.apache.activemq.util.IntrospectionSupport; 031import org.apache.activemq.wireformat.WireFormat; 032 033/** 034 * Factory for creating WebSocket aware AMQP Transports. 035 */ 036public class AmqpWSTransportFactory extends TransportFactory implements BrokerServiceAware { 037 038 private BrokerService brokerService = null; 039 040 @Override 041 protected String getDefaultWireFormatType() { 042 return "amqp"; 043 } 044 045 @Override 046 public TransportServer doBind(URI location) throws IOException { 047 throw new IOException("doBind() method not implemented! No Server over WS implemented."); 048 } 049 050 @Override 051 @SuppressWarnings("rawtypes") 052 public Transport compositeConfigure(Transport transport, WireFormat format, Map options) { 053 AmqpTransportFilter amqpTransport = new AmqpTransportFilter(transport, format, brokerService); 054 055 Map<String, Object> wireFormatOptions = IntrospectionSupport.extractProperties(options, "wireFormat."); 056 057 IntrospectionSupport.setProperties(amqpTransport, options); 058 IntrospectionSupport.setProperties(amqpTransport.getWireFormat(), wireFormatOptions); 059 060 // Now wrap the filter with the monitor 061 transport = createInactivityMonitor(amqpTransport, format); 062 IntrospectionSupport.setProperties(transport, options); 063 064 return super.compositeConfigure(transport, format, options); 065 } 066 067 /** 068 * Factory method to create a new transport 069 * 070 * @throws IOException 071 * @throws UnknownHostException 072 */ 073 @Override 074 protected Transport createTransport(URI location, WireFormat wireFormat) throws MalformedURLException, UnknownHostException, IOException { 075 return new AmqpWSTransport(location, wireFormat); 076 } 077 078 @Override 079 public void setBrokerService(BrokerService brokerService) { 080 this.brokerService = brokerService; 081 } 082 083 protected Transport createInactivityMonitor(AmqpTransportFilter transport, WireFormat format) { 084 AmqpInactivityMonitor monitor = new AmqpInactivityMonitor(transport, format); 085 transport.setInactivityMonitor(monitor); 086 return monitor; 087 } 088}