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.junit; 018 019import java.io.Serializable; 020import java.net.URI; 021import java.util.Map; 022import javax.jms.BytesMessage; 023import javax.jms.IllegalStateException; 024import javax.jms.JMSException; 025import javax.jms.MapMessage; 026import javax.jms.Message; 027import javax.jms.ObjectMessage; 028import javax.jms.TextMessage; 029 030import org.apache.activemq.ActiveMQConnectionFactory; 031import org.apache.activemq.command.ActiveMQDestination; 032 033public class ActiveMQDynamicQueueSenderResource extends AbstractActiveMQProducerResource { 034 public ActiveMQDynamicQueueSenderResource(ActiveMQConnectionFactory connectionFactory) { 035 super(connectionFactory); 036 } 037 038 public ActiveMQDynamicQueueSenderResource(URI brokerURI) { 039 super(brokerURI); 040 } 041 042 public ActiveMQDynamicQueueSenderResource(EmbeddedActiveMQBroker embeddedActiveMQBroker) { 043 super(embeddedActiveMQBroker); 044 } 045 046 public ActiveMQDynamicQueueSenderResource(URI brokerURI, String userName, String password) { 047 super(brokerURI, userName, password); 048 } 049 050 public ActiveMQDynamicQueueSenderResource(String defaultDestinationName, ActiveMQConnectionFactory connectionFactory) { 051 super(defaultDestinationName, connectionFactory); 052 } 053 054 public ActiveMQDynamicQueueSenderResource(String defaultDestinationName, URI brokerURI) { 055 super(defaultDestinationName, brokerURI); 056 } 057 058 public ActiveMQDynamicQueueSenderResource(String destinationName, EmbeddedActiveMQBroker embeddedActiveMQBroker) { 059 super(destinationName, embeddedActiveMQBroker); 060 } 061 062 public ActiveMQDynamicQueueSenderResource(String defaultDestinationName, URI brokerURI, String userName, String password) { 063 super(defaultDestinationName, brokerURI, userName, password); 064 } 065 066 @Override 067 protected void createClient() throws JMSException { 068 producer = session.createProducer(null); 069 } 070 071 @Override 072 public byte getDestinationType() { 073 return ActiveMQDestination.QUEUE_TYPE; 074 } 075 076 @Override 077 public void sendMessage(Message message) throws JMSException { 078 if (destination == null) { 079 throw new IllegalStateException("Destination is not specified"); 080 } 081 082 producer.send(destination, message); 083 } 084 085 public void sendMessage(String destinationName, Message message) throws JMSException { 086 producer.send(createDestination(destinationName), message); 087 } 088 089 public BytesMessage sendMessage(String destinationName, byte[] body) throws JMSException { 090 BytesMessage message = this.createMessage(body); 091 sendMessage(destinationName, message); 092 return message; 093 } 094 095 public TextMessage sendMessage(String destinationName, String body) throws JMSException { 096 TextMessage message = this.createMessage(body); 097 sendMessage(destinationName, message); 098 return message; 099 } 100 101 public MapMessage sendMessage(String destinationName, Map<String, Object> body) throws JMSException { 102 MapMessage message = this.createMessage(body); 103 sendMessage(destinationName, message); 104 return message; 105 } 106 107 public ObjectMessage sendMessage(String destinationName, Serializable body) throws JMSException { 108 ObjectMessage message = this.createMessage(body); 109 sendMessage(destinationName, message); 110 return message; 111 } 112 113 public BytesMessage sendMessageWithProperties(String destinationName, byte[] body, Map<String, Object> properties) throws JMSException { 114 BytesMessage message = this.createMessage(body, properties); 115 sendMessage(destinationName, message); 116 return message; 117 } 118 119 public TextMessage sendMessageWithProperties(String destinationName, String body, Map<String, Object> properties) throws JMSException { 120 TextMessage message = this.createMessage(body, properties); 121 sendMessage(destinationName, message); 122 return message; 123 } 124 125 public MapMessage sendMessageWithProperties(String destinationName, Map<String, Object> body, Map<String, Object> properties) throws JMSException { 126 MapMessage message = this.createMessage(body, properties); 127 sendMessage(destinationName, message); 128 return message; 129 } 130 131 public ObjectMessage sendMessageWithProperties(String destinationName, Serializable body, Map<String, Object> properties) throws JMSException { 132 ObjectMessage message = this.createMessage(body, properties); 133 sendMessage(destinationName, message); 134 return message; 135 } 136 137}