1 package org.codehaus.xfire.plexus; 2 3 import java.io.File; 4 import javax.servlet.ServletException; 5 import org.codehaus.xfire.XFire; 6 import org.codehaus.xfire.service.ServiceRegistry; 7 import org.codehaus.xfire.transport.TransportManager; 8 import org.codehaus.xfire.transport.http.XFireServlet; 9 10 /*** 11 * Creates an embedded version of XFire within a servlet. For most 12 * applications this will probably be sufficient. For more advanced 13 * container usages, see the XFireServlet and Plexus documentation. 14 * 15 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a> 16 */ 17 public class StandaloneXFireServlet 18 extends XFireServlet 19 { 20 StandaloneXFire xfire; 21 22 public XFire getXFire() throws ServletException 23 { 24 try 25 { 26 return xfire.getXFire(); 27 } 28 catch (Exception e) 29 { 30 e.printStackTrace(); 31 throw new ServletException("Couldn't find XFire service. Check configuration.", e); 32 } 33 } 34 35 public void init() throws ServletException 36 { 37 File config = new File(getWebappBase(), getInitParameter("config")); 38 39 System.setProperty("xfire.config", config.getAbsolutePath()); 40 System.out.println("Configuration file: " + config.getAbsolutePath()); 41 42 String plexusConfig = getInitParameter("plexus-config"); 43 if ( plexusConfig != null ) 44 { 45 System.setProperty("xfire.plexusConfig", plexusConfig); 46 } 47 48 try 49 { 50 xfire = StandaloneXFire.getInstance(); 51 } 52 catch (Exception e) 53 { 54 e.printStackTrace(); 55 throw new ServletException("Couldn't start XFire service. Check configuration.", e); 56 } 57 58 super.init(); 59 } 60 61 /*** 62 * @return 63 * @throws Exception 64 */ 65 protected TransportManager getTransportManager() 66 throws ServletException 67 { 68 try 69 { 70 return xfire.getTransportService(); 71 } 72 catch (Exception e) 73 { 74 throw new ServletException("No transport service found!", e); 75 } 76 } 77 78 public ServiceRegistry getServiceRegistry() 79 throws ServletException 80 { 81 try 82 { 83 return xfire.getServiceRegistry(); 84 } 85 catch (Exception e) 86 { 87 throw new ServletException("No service registry found!", e); 88 } 89 } 90 91 public void destroy() 92 { 93 xfire = null; 94 95 super.destroy(); 96 } 97 }