1 16 17 package org.apache.axis.ime.internal.util.handler; 18 19 import org.apache.axis.Handler; 20 import org.apache.axis.MessageContext; 21 import org.apache.axis.TargetedChain; 22 import org.apache.axis.components.logger.LogFactory; 23 import org.apache.axis.ime.MessageExchangeCorrelator; 24 import org.apache.axis.ime.MessageExchangeEvent; 25 import org.apache.axis.ime.MessageExchangeEventListener; 26 import org.apache.axis.ime.event.MessageFaultEvent; 27 import org.apache.axis.ime.event.MessageSendEvent; 28 import org.apache.axis.ime.internal.FirstComeFirstServeDispatchPolicy; 29 import org.apache.axis.ime.internal.MessageExchangeProvider; 30 import org.apache.axis.ime.internal.MessageExchangeSendContext; 31 import org.apache.axis.ime.internal.ReceivedMessageDispatchPolicy; 32 import org.apache.commons.logging.Log; 33 34 import java.util.Hashtable ; 35 36 41 public class HandlerMessageExchange 42 extends MessageExchangeProvider { 43 44 protected static Log log = 45 LogFactory.getLog(HandlerMessageExchange.class.getName()); 46 47 private Handler handler; 48 49 public HandlerMessageExchange(Handler handler) { 50 this.handler = handler; 51 } 52 53 56 protected MessageExchangeEventListener getMessageExchangeEventListener() { 57 return new Listener(handler); 58 } 59 60 protected ReceivedMessageDispatchPolicy getReceivedMessageDispatchPolicy() { 61 return new FirstComeFirstServeDispatchPolicy( 62 RECEIVE, 63 RECEIVE_REQUESTS); 64 } 65 66 public Handler getSendHandler() { 67 Handler h = super.getSendHandler(); 68 if (h == null && handler instanceof TargetedChain) { 69 h = ((TargetedChain)handler).getRequestHandler(); 70 } 71 return h; 72 } 73 74 public Handler getReceiveHandler() { 75 Handler h = super.getReceiveHandler(); 76 if (h == null && handler instanceof TargetedChain) { 77 h = ((TargetedChain)handler).getResponseHandler(); 78 } 79 return h; 80 } 81 82 public class Listener 83 implements MessageExchangeEventListener { 84 85 private Handler handler; 86 87 public Listener(Handler handler) { 88 this.handler = handler; 89 } 90 91 94 public void onEvent( 95 MessageExchangeEvent event) { 96 if (!(event instanceof MessageSendEvent)) 97 return; 98 99 MessageSendEvent sendEvent = (MessageSendEvent)event; 100 MessageExchangeSendContext context = sendEvent.getMessageExchangeSendContext(); 101 102 if (log.isDebugEnabled()) { 103 log.debug("Enter: HandlerMessageExchange.Listener::onSend"); 104 } 105 MessageExchangeEventListener listener = 106 context.getMessageExchangeEventListener(); 107 try { 108 MessageContext msgContext = 109 context.getMessageContext(); 110 MessageExchangeCorrelator correlator = 111 context.getMessageExchangeCorrelator(); 112 113 if (handler instanceof TargetedChain) { 114 ((TargetedChain)handler).getPivotHandler().invoke(msgContext); 115 } else { 116 handler.invoke(msgContext); 117 } 118 119 120 RECEIVE.put(correlator, context); 121 } catch (Exception exception) { 122 if (listener != null) { 123 MessageFaultEvent faultEvent = new MessageFaultEvent( 124 context.getMessageExchangeCorrelator(), 125 exception); 126 listener.onEvent(faultEvent); 127 } 128 } finally { 129 if (log.isDebugEnabled()) { 130 log.debug("Exit: HandlerMessageExchange.Listener::onSend"); 131 } 132 } 133 } 134 } 135 136 public void clearOptions() { 137 handler.setOptions(null); 138 } 139 140 public Hashtable getOptions() { 141 return handler.getOptions(); 142 } 143 144 public Object getOption(String propertyId, Object defaultValue) { 145 Object value = getOption(propertyId); 146 return (value == null) ? defaultValue : value; 147 } 148 149 public Object getOption(String propertyId) { 150 return handler.getOption(propertyId); 151 } 152 153 public void setOptions(Hashtable properties) { 154 handler.setOptions(properties); 155 } 156 157 public void setOption(String propertyId, Object propertyValue) { 158 handler.setOption(propertyId, propertyValue); 159 } 160 161 } 162 | Popular Tags |