1 7 8 package org.jboss.webservice.client; 10 11 13 import org.jboss.axis.AxisFault; 14 import org.jboss.axis.ConfigurationException; 15 import org.jboss.axis.EngineConfiguration; 16 import org.jboss.axis.Handler; 17 import org.jboss.axis.MessageContext; 18 import org.jboss.axis.client.AxisClient; 19 import org.jboss.axis.client.Call; 20 import org.jboss.axis.utils.Messages; 21 import org.jboss.logging.Logger; 22 import org.jboss.webservice.handler.ClientHandlerChain; 23 24 import javax.xml.rpc.JAXRPCException ; 25 import javax.xml.rpc.handler.HandlerChain ; 26 import java.util.HashMap ; 27 import java.util.List ; 28 import java.util.Map ; 29 import java.util.Set ; 30 31 39 public class ClientEngine extends AxisClient 40 { 41 42 static final long serialVersionUID = 53844570311989118L; 43 protected static Logger log = Logger.getLogger(ClientEngine.class); 44 45 private Map handlerChainMap = new HashMap (); 47 48 51 public ClientEngine(EngineConfiguration config) 52 { 53 super(config); 54 } 55 56 59 public void registerHandlerChain(String portName, List infos, Set roles) 60 { 61 ClientHandlerChain chain = new ClientHandlerChain(infos, roles); 62 handlerChainMap.put(portName, chain); 63 } 64 65 69 public void invoke(MessageContext msgContext) throws AxisFault 70 { 71 log.debug("invoke: " + msgContext); 72 73 String hName = null; 74 Handler handler = null; 75 76 MessageContext previousContext = getCurrentMessageContext(); 78 79 try 80 { 81 setCurrentMessageContext(msgContext); 83 84 94 msgContext.setPastPivot(false); 95 96 ClientHandlerChain handlerChain = (ClientHandlerChain)getHandlerChain(msgContext); 97 98 if (handlerChain.getState() == ClientHandlerChain.STATE_CREATED) 101 { 102 handlerChain.init(null); 104 } 105 106 if ((handler = getGlobalRequest()) != null) 109 handler.invoke(msgContext); 110 111 if (handlerChain.handleRequest(msgContext) == false) 113 { 114 log.warn("FIXME: handlerChain.handleRequest() returned false"); 116 return; 117 } 118 119 125 hName = msgContext.getTransportName(); 126 if (hName != null && (handler = getTransport(hName)) != null) 127 { 128 handler.invoke(msgContext); 129 } 130 else 131 { 132 throw new AxisFault(Messages.getMessage("noTransport00", hName)); 133 } 134 135 boolean isFaultMessage = false; 137 138 if (isFaultMessage && handlerChain.handleFault(msgContext) == false) 140 { 141 log.warn("FIXME: handlerChain.handleFault() returned false"); 143 return; 144 } 145 146 else if (handlerChain.handleResponse(msgContext) == false) 148 { 149 log.warn("FIXME: handlerChain.handleResponse() returned false"); 151 return; 152 } 153 154 155 156 if ((handler = getGlobalResponse()) != null) 157 { 158 handler.invoke(msgContext); 159 } 160 } 161 catch (ConfigurationException e) 162 { 163 throw new IllegalStateException (e.toString()); 164 } 165 finally 166 { 167 setCurrentMessageContext(previousContext); 169 } 170 } 171 172 177 private HandlerChain getHandlerChain(MessageContext msgContext) 178 { 179 HandlerChain handlerChain = null; 180 181 if (handlerChainMap.size() == 0) 183 handlerChain = new ClientHandlerChain(null, null); 184 185 if (handlerChainMap.size() == 1) 187 { 188 String portName = (String )handlerChainMap.keySet().iterator().next(); 189 handlerChain = (HandlerChain)handlerChainMap.get(portName); 190 log.debug("Using handler chain for port: " + portName); 191 } 192 193 Call call = (Call)msgContext.getProperty(MessageContext.CALL); 194 if (call == null) 195 throw new JAXRPCException ("Cannot obtain current call"); 196 197 if (call.getPortName() != null) 198 { 199 String portName = call.getPortName().getLocalPart(); 200 handlerChain = (HandlerChain)handlerChainMap.get(portName); 201 log.debug("Using handler chain for port: " + portName); 202 } 203 204 if (handlerChain == null) 206 { 207 handlerChain = new ClientHandlerChain(null, null); 208 log.debug("Using empty handler chain"); 209 } 210 211 return handlerChain; 212 } 213 } 214 215 | Popular Tags |