1 16 17 package org.apache.axis.handlers.soap; 18 19 import org.apache.axis.AxisEngine; 20 import org.apache.axis.AxisFault; 21 import org.apache.axis.Constants; 22 import org.apache.axis.Handler; 23 import org.apache.axis.Message; 24 import org.apache.axis.MessageContext; 25 import org.apache.axis.SimpleTargetedChain; 26 import org.apache.axis.attachments.Attachments; 27 import org.apache.axis.components.logger.LogFactory; 28 import org.apache.axis.description.JavaServiceDesc; 29 import org.apache.axis.description.ServiceDesc; 30 import org.apache.axis.encoding.TypeMappingRegistry; 31 import org.apache.axis.encoding.TypeMapping; 32 import org.apache.axis.constants.Style; 33 import org.apache.axis.constants.Use; 34 import org.apache.axis.handlers.HandlerChainImpl; 35 import org.apache.axis.handlers.HandlerInfoChainFactory; 36 import org.apache.axis.message.SOAPEnvelope; 37 import org.apache.axis.message.SOAPFault; 38 import org.apache.axis.providers.BasicProvider; 39 import org.apache.axis.session.Session; 40 import org.apache.axis.utils.LockableHashtable; 41 import org.apache.axis.utils.Messages; 42 import org.apache.axis.utils.XMLUtils; 43 import org.apache.axis.utils.ClassUtils; 44 import org.apache.commons.logging.Log; 45 import org.w3c.dom.Document ; 46 47 import javax.xml.rpc.soap.SOAPFaultException ; 48 import java.io.File ; 49 import java.io.FileInputStream ; 50 import java.io.IOException ; 51 import java.io.InputStream ; 52 import java.util.ArrayList ; 53 import java.util.Hashtable ; 54 import java.util.Iterator ; 55 import java.util.Vector ; 56 import java.util.Map ; 57 import java.util.HashMap ; 58 import java.util.List ; 59 60 67 public class SOAPService extends SimpleTargetedChain 68 { 69 private static Log log = 70 LogFactory.getLog(SOAPService.class.getName()); 71 72 78 private Vector validTransports = null; 79 80 84 private boolean highFidelityRecording = true; 85 86 92 private int sendType = Attachments.SEND_TYPE_NOTSET; 93 94 98 private ServiceDesc serviceDescription = new JavaServiceDesc(); 99 private AxisEngine engine; 100 101 105 public Map serviceObjects = new HashMap (); 106 public int nextObjectID = 1; 107 108 111 static private Hashtable sessions = new Hashtable(); 112 113 private boolean isRunning = true; 114 115 118 public void addSession(Session session) { 119 Vector v = (Vector ) sessions.get( this.getName() ); 120 if ( v == null ) { 121 v = new Vector (); 122 sessions.put( this.getName(), v); 123 } 124 if ( !v.contains(session) ) v.add(session); 125 } 126 127 130 public void clearSessions() { 131 Vector v = (Vector ) sessions.get( this.getName() ); 132 if ( v == null ) return ; 133 Iterator iter = v.iterator(); 134 while ( iter.hasNext() ) { 135 Session session = (Session) iter.next(); 136 session.remove( this.getName() ); 137 } 138 } 139 140 143 ArrayList actors = new ArrayList (); 144 145 149 public ArrayList getServiceActors() { 150 return actors; 151 } 152 153 159 public ArrayList getActors() { 160 ArrayList acts = (ArrayList )actors.clone(); 162 if (engine != null) { 163 acts.addAll(engine.getActorURIs()); 164 } 165 166 return acts; 167 } 168 169 public List getRoles() { 170 return getActors(); 171 } 172 173 178 public void setRoles(List roles) { 179 actors = new ArrayList (roles); 180 } 181 182 184 public SOAPService() 185 { 186 setOptionsLockable(true); 187 initHashtable(); 188 189 actors.add(""); 191 } 192 193 197 public SOAPService(Handler reqHandler, Handler pivHandler, 198 Handler respHandler) { 199 this(); 200 init(reqHandler, new MustUnderstandChecker(this), pivHandler, null, respHandler); 201 } 202 203 public TypeMappingRegistry getTypeMappingRegistry() 204 { 205 return serviceDescription.getTypeMappingRegistry(); 206 } 207 208 211 public SOAPService(Handler serviceHandler) 212 { 213 this(); 214 init(null, new MustUnderstandChecker(this), serviceHandler, null, null); 215 } 216 217 220 public void setEngine(AxisEngine engine) 221 { 222 if (engine == null) 223 throw new IllegalArgumentException ( 224 Messages.getMessage("nullEngine")); 225 226 this.engine = engine; 227 ((LockableHashtable)options).setParent(engine.getOptions()); 228 TypeMappingRegistry tmr = engine.getTypeMappingRegistry(); 229 getTypeMappingRegistry().delegate(tmr); 230 } 231 232 public AxisEngine getEngine() { 233 return engine; 234 } 235 236 public boolean availableFromTransport(String transportName) 237 { 238 if (validTransports != null) { 239 for (int i = 0; i < validTransports.size(); i++) { 240 if (validTransports.elementAt(i).equals(transportName)) 241 return true; 242 } 243 return false; 244 } 245 246 return true; 247 } 248 249 public Style getStyle() { 250 return serviceDescription.getStyle(); 251 } 252 253 public void setStyle(Style style) { 254 serviceDescription.setStyle(style); 255 } 256 257 public Use getUse() { 258 return serviceDescription.getUse(); 259 } 260 261 public void setUse(Use style) { 262 serviceDescription.setUse(style); 263 } 264 265 public ServiceDesc getServiceDescription() { 266 return serviceDescription; 267 } 268 269 273 public synchronized ServiceDesc getInitializedServiceDesc( 274 MessageContext msgContext) 275 throws AxisFault { 276 277 if (!serviceDescription.isInitialized()) { 278 279 if (pivotHandler instanceof BasicProvider) { 285 ((BasicProvider)pivotHandler).initServiceDesc(this, msgContext); 286 } 287 288 } 289 290 return serviceDescription; 291 } 292 293 public void setServiceDescription(ServiceDesc serviceDescription) { 294 if (serviceDescription == null) { 295 return; 297 } 298 this.serviceDescription = serviceDescription; 299 } 301 302 public void setPropertyParent(Hashtable parent) 303 { 304 if (options == null) { 305 options = new LockableHashtable(); 306 } 307 ((LockableHashtable)options).setParent(parent); 308 } 309 310 316 public void generateWSDL(MessageContext msgContext) throws AxisFault { 317 if (serviceDescription == null || 318 serviceDescription.getWSDLFile() == null) { 319 super.generateWSDL(msgContext); 320 return; 321 } 322 InputStream instream = null; 323 324 try { 326 String filename= serviceDescription.getWSDLFile(); 327 File file=new File (filename); 328 if(file.exists()) { 329 instream = new FileInputStream (filename); 331 } else if(msgContext.getStrProp(Constants.MC_HOME_DIR)!=null){ 332 String path = msgContext.getStrProp(Constants.MC_HOME_DIR) +'/' + filename; 333 file = new File (path); 334 if(file.exists()) { 335 instream = new FileInputStream (path); 337 } 338 } 339 340 if(instream == null) { 341 instream = ClassUtils.getResourceAsStream(this.getClass(),filename); 343 if (instream == null) { 344 String errorText=Messages.getMessage("wsdlFileMissing",filename); 345 throw new AxisFault(errorText); 346 } 347 } 348 Document doc = XMLUtils.newDocument(instream); 349 msgContext.setProperty("WSDL", doc); 350 } catch (Exception e) { 351 throw AxisFault.makeFault(e); 352 } finally { 353 if(instream!=null) { 354 try { 355 instream.close(); 356 } catch (IOException e) { } 357 } 358 } 359 } 360 368 369 371 public void start() 372 { 373 isRunning = true; 374 } 375 376 378 public void stop() 379 { 380 isRunning = false; 381 } 382 383 387 public boolean isRunning() { 388 return isRunning; 389 } 390 391 394 public void enableTransport(String transportName) 395 { 396 if (log.isDebugEnabled()) { 397 log.debug(Messages.getMessage( 398 "enableTransport00", "" + this, transportName)); 399 } 400 401 if (validTransports == null) 402 validTransports = new Vector (); 403 validTransports.addElement(transportName); 404 } 405 406 409 public void disableTransport(String transportName) 410 { 411 if (validTransports != null) { 412 validTransports.removeElement(transportName); 413 } 414 } 415 416 public boolean needsHighFidelityRecording() { 417 return highFidelityRecording; 418 } 419 420 public void setHighFidelityRecording(boolean highFidelityRecording) { 421 this.highFidelityRecording = highFidelityRecording; 422 } 423 424 public int getSendType() { 426 return sendType; 427 } 428 429 public void setSendType(int sendType) { 430 this.sendType = sendType; 431 } 432 433 public void invoke(MessageContext msgContext) throws AxisFault { 434 HandlerInfoChainFactory handlerFactory = (HandlerInfoChainFactory) this.getOption(Constants.ATTR_HANDLERINFOCHAIN); 435 HandlerChainImpl handlerImpl = null; 436 if (handlerFactory != null) handlerImpl = (HandlerChainImpl) handlerFactory.createHandlerChain(); 437 boolean result = true; 438 439 try { 440 if (handlerImpl != null) { 441 try { 442 result = handlerImpl.handleRequest(msgContext); 443 } 444 catch (SOAPFaultException e) { 445 msgContext.setPastPivot(true); 446 handlerImpl.handleFault(msgContext); 447 return; 448 } 449 } 450 451 if (result) { 452 try { 453 super.invoke(msgContext); 454 } catch (AxisFault e) { 455 msgContext.setPastPivot(true); 456 if (handlerImpl != null) { 457 handlerImpl.handleFault(msgContext); 458 } 459 throw e; 460 } 461 } else { 462 msgContext.setPastPivot(true); 463 } 464 465 if ( handlerImpl != null) { 466 handlerImpl.handleResponse(msgContext); 467 } 468 } catch (SOAPFaultException e) { 469 msgContext.setPastPivot(true); 470 throw AxisFault.makeFault(e); 471 472 } catch (RuntimeException e) { 473 SOAPFault fault = new SOAPFault(new AxisFault("Server", "Server Error", null, null)); 474 SOAPEnvelope env = new SOAPEnvelope(); 475 env.addBodyElement(fault); 476 Message message = new Message(env); 477 message.setMessageType(Message.RESPONSE); 478 msgContext.setResponseMessage(message); 479 throw AxisFault.makeFault(e); 480 } 481 finally { 482 if (handlerImpl != null) { 483 handlerImpl.destroy(); 484 } 485 } 486 } 487 } 488 | Popular Tags |