1 /*** 2 * 3 * Copyright 2005 LogicBlaze, Inc. 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.impl; 19 20 import org.logicblaze.lingo.jms.ReplyHandler; 21 import org.logicblaze.lingo.jms.marshall.Marshaller; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.springframework.remoting.support.RemoteInvocation; 25 import org.springframework.remoting.support.RemoteInvocationBasedExporter; 26 27 import javax.jms.JMSException; 28 import javax.jms.Message; 29 import java.lang.reflect.InvocationTargetException; 30 31 /*** 32 * @version $Revision: 1.1 $ 33 */ 34 public class AsyncReplyHandler extends RemoteInvocationBasedExporter implements ReplyHandler { 35 private static final Log log = LogFactory.getLog(AsyncReplyHandler.class); 36 37 private Object pojo; 38 private Marshaller marshaller; 39 40 public AsyncReplyHandler(Object pojo, Marshaller marshaller) { 41 this.pojo = pojo; 42 this.marshaller = marshaller; 43 } 44 45 public boolean handle(Message message) throws JMSException { 46 RemoteInvocation invocation = marshaller.readRemoteInvocation(message); 47 try { 48 invoke(invocation, pojo); 49 } 50 catch (NoSuchMethodException e) { 51 onException(invocation, e); 52 } 53 catch (IllegalAccessException e) { 54 onException(invocation, e); 55 } 56 catch (InvocationTargetException e) { 57 onException(invocation, e); 58 } 59 return false; 60 } 61 62 63 protected void onException(RemoteInvocation invocation, Exception e) { 64 log.error("Failed to invoke: " + invocation + " on: " + pojo + ". Reason: " + e, e); 65 } 66 }