1 16 17 package org.apache.axis.client ; 18 19 import javax.xml.namespace.QName ; 20 import javax.xml.rpc.handler.HandlerChain ; 21 22 import org.apache.axis.AxisEngine; 23 import org.apache.axis.AxisFault; 24 import org.apache.axis.Constants; 25 import org.apache.axis.EngineConfiguration; 26 import org.apache.axis.Handler; 27 import org.apache.axis.MessageContext; 28 import org.apache.axis.components.logger.LogFactory; 29 import org.apache.axis.configuration.EngineConfigurationFactoryFinder; 30 import org.apache.axis.handlers.HandlerInfoChainFactory; 31 import org.apache.axis.handlers.soap.MustUnderstandChecker; 32 import org.apache.axis.handlers.soap.SOAPService; 33 import org.apache.axis.utils.Messages; 34 import org.apache.commons.logging.Log; 35 36 45 public class AxisClient extends AxisEngine { 46 protected static Log log = 47 LogFactory.getLog(AxisClient.class.getName()); 48 49 MustUnderstandChecker checker = new MustUnderstandChecker(null); 50 51 public AxisClient(EngineConfiguration config) { 52 super(config); 53 } 54 55 public AxisClient() { 56 this(EngineConfigurationFactoryFinder.newFactory(). 57 getClientEngineConfig()); 58 } 59 60 63 public AxisEngine getClientEngine () { 64 return this; 65 } 66 67 75 public void invoke(MessageContext msgContext) throws AxisFault { 76 if (log.isDebugEnabled()) { 77 log.debug("Enter: AxisClient::invoke"); 78 } 79 String hName = null; 80 Handler h = null; 81 HandlerChain handlerImpl = null; 82 83 MessageContext previousContext = getCurrentMessageContext(); 85 try { 86 setCurrentMessageContext(msgContext); 88 hName = msgContext.getStrProp(MessageContext.ENGINE_HANDLER); 89 if (log.isDebugEnabled()) { 90 log.debug("EngineHandler: " + hName); 91 } 92 if (hName != null) { 93 h = getHandler(hName); 94 if (h != null) 95 h.invoke(msgContext); 96 else 97 throw new AxisFault("Client.error", 98 Messages.getMessage("noHandler00", 99 hName), 100 null, null); 101 } else { 102 103 104 105 106 107 108 109 110 111 112 SOAPService service = null; 113 msgContext.setPastPivot(false); 114 115 116 117 service = msgContext.getService(); 118 if (service != null) { 119 h = service.getRequestHandler(); 120 if (h != null) 121 h.invoke(msgContext); 122 } 123 124 125 126 if ((h = getGlobalRequest()) != null) 127 h.invoke(msgContext); 128 129 140 handlerImpl = getJAXRPChandlerChain(msgContext); 141 if (handlerImpl != null) { 142 try { 143 if (!handlerImpl.handleRequest(msgContext)) { 144 msgContext.setPastPivot(true); 145 } 146 } catch (RuntimeException re) { 147 handlerImpl.destroy(); throw re; 149 } 150 } 151 152 161 if (!msgContext.getPastPivot()) { 162 hName = msgContext.getTransportName(); 163 if (hName != null && (h = getTransport(hName)) != null) { 164 try { 165 h.invoke(msgContext); 166 } catch (AxisFault e) { 167 throw e; 168 } 169 } else { 170 throw new AxisFault(Messages.getMessage("noTransport00", 171 hName)); 172 } 173 } 174 175 msgContext.setPastPivot(true); 176 if (!msgContext.isPropertyTrue(Call.ONE_WAY)) { 177 if ((handlerImpl != null) && 178 !msgContext.isPropertyTrue(Call.ONE_WAY)) { 179 try { 180 handlerImpl.handleResponse(msgContext); 181 } catch (RuntimeException ex) { 182 handlerImpl.destroy(); throw ex; 184 } 185 } 186 187 188 189 if ((h = getGlobalResponse()) != null) { 190 h.invoke(msgContext); 191 } 192 193 194 195 if (service != null) { 196 h = service.getResponseHandler(); 197 if (h != null) { 198 h.invoke(msgContext); 199 } 200 } 201 202 if (msgContext.isPropertyTrue(Call.CHECK_MUST_UNDERSTAND, 205 true)) { 206 checker.invoke(msgContext); 207 } 208 } 209 } 210 } catch (Exception e) { 211 if (e instanceof AxisFault) { 213 throw (AxisFault) e; 214 } else { 215 log.debug(Messages.getMessage("exception00"), e); 216 throw AxisFault.makeFault(e); 217 } 218 } finally { 219 if (handlerImpl != null) { 220 handlerImpl.destroy(); 221 } 222 setCurrentMessageContext(previousContext); 224 } 225 if (log.isDebugEnabled()) { 226 log.debug("Exit: AxisClient::invoke"); 227 } 228 } 229 230 234 protected HandlerChain getJAXRPChandlerChain(MessageContext context) { 235 java.util.List chain = null; 236 HandlerInfoChainFactory hiChainFactory = null; 237 boolean clientSpecified = false; 238 239 Service service = (Service) context.getProperty(Call.WSDL_SERVICE); 240 if(service == null) { 241 return null; 242 } 243 244 QName portName = (QName ) context.getProperty(Call.WSDL_PORT_NAME); 245 if(portName == null) { 246 return null; 247 } 248 249 javax.xml.rpc.handler.HandlerRegistry registry; 250 registry = service.getHandlerRegistry(); 251 if(registry != null) { 252 chain = registry.getHandlerChain(portName); 253 if ((chain != null) && (!chain.isEmpty())) { 254 hiChainFactory = new HandlerInfoChainFactory(chain); 255 clientSpecified = true; 256 } 257 } 258 259 if (!clientSpecified) { 261 SOAPService soapService = context.getService(); 262 if (soapService != null) { 263 hiChainFactory = (HandlerInfoChainFactory) 266 soapService.getOption(Constants.ATTR_HANDLERINFOCHAIN); 267 } 268 } 269 270 if (hiChainFactory == null) { 271 return null; 272 } 273 274 return hiChainFactory.createHandlerChain(); 275 } 276 277 } 278 | Popular Tags |