1 /***
2 *
3 * Copyright 2005 AgilaSoft 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.logicblaze.lingo.jms;
19
20 import org.springframework.remoting.support.RemoteInvocationResult;
21 import org.logicblaze.lingo.jms.impl.DefaultJmsProducer;
22 import org.logicblaze.lingo.jms.impl.OneWayRequestor;
23
24 import javax.jms.JMSException;
25 import javax.jms.Message;
26 import javax.jms.ConnectionFactory;
27
28 /***
29 * A regular JMS message listener which can be used from inside a message driven object
30 * container.
31 *
32 * @version $Revision: 1.2 $
33 */
34 public class JmsServiceExporterMessageListener extends JmsServiceExporterSupport {
35 private JmsProducer producer;
36 private ConnectionFactory connectionFactory;
37
38 public void afterPropertiesSet() throws Exception {
39 if (producer == null) {
40 if (connectionFactory == null) {
41 throw new IllegalArgumentException("requestor or connectionFactory is required");
42 }
43 else {
44 producer = DefaultJmsProducer.newInstance(connectionFactory);
45 }
46 }
47 Requestor responseRequestor = getResponseRequestor();
48 if (responseRequestor == null) {
49 setResponseRequestor(new OneWayRequestor(producer, null));
50 }
51 super.afterPropertiesSet();
52 }
53
54 public JmsProducer getProducer() {
55 return producer;
56 }
57
58 public void setProducer(JmsProducer producer) {
59 this.producer = producer;
60 }
61
62 public ConnectionFactory getConnectionFactory() {
63 return connectionFactory;
64 }
65
66 public void setConnectionFactory(ConnectionFactory connectionFactory) {
67 this.connectionFactory = connectionFactory;
68 }
69
70 protected void writeRemoteInvocationResult(Message message, RemoteInvocationResult result) throws JMSException {
71 Message responseMessage = createResponseMessage(producer.getSession(), message, result);
72 producer.getMessageProducer().send(message.getJMSReplyTo(), responseMessage);
73 }
74 }