1 16 17 package org.apache.axis.transport.http; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.axis.components.logger.LogFactory; 21 import org.apache.axis.deployment.wsdd.WSDDDocument; 22 import org.apache.axis.deployment.wsdd.WSDDDeployment; 23 import org.apache.axis.utils.XMLUtils; 24 import org.apache.axis.AxisEngine; 25 import org.apache.axis.AxisFault; 26 import org.apache.axis.ConfigurationException; 27 import org.apache.axis.EngineConfiguration; 28 import org.apache.axis.WSDDEngineConfiguration; 29 import org.apache.axis.i18n.Messages; 30 import org.w3c.dom.Document ; 31 import org.xml.sax.SAXException ; 32 33 import javax.xml.parsers.ParserConfigurationException ; 34 import java.io.InputStream ; 35 import java.io.IOException ; 36 import java.io.FileNotFoundException ; 37 import java.io.File ; 38 import java.io.BufferedInputStream ; 39 import java.io.FileInputStream ; 40 41 47 public class AutoRegisterServlet extends AxisServletBase { 48 49 private static Log log = 50 LogFactory.getLog(AutoRegisterServlet.class.getName()); 51 52 55 public void init() throws javax.servlet.ServletException { 56 log.debug(Messages.getMessage("autoRegServletInit00")); 57 autoRegister(); 58 } 59 60 67 public void registerStream(InputStream instream) throws SAXException , ParserConfigurationException , IOException { 68 try { 69 Document doc=XMLUtils.newDocument(instream); 70 WSDDDocument wsddDoc = new WSDDDocument(doc); 71 WSDDDeployment deployment; 72 deployment = getDeployment(); 73 if(deployment!=null) { 74 wsddDoc.deploy(deployment); 75 } 76 } finally { 77 instream.close(); 78 } 79 } 80 81 88 public void registerResource(String resourcename) 89 throws SAXException , ParserConfigurationException , IOException { 90 InputStream in=getServletContext().getResourceAsStream(resourcename); 91 if(in==null) { 92 throw new FileNotFoundException (resourcename); 93 } 94 registerStream(in); 95 } 96 97 104 public void registerFile(File file) throws IOException , SAXException , ParserConfigurationException { 105 InputStream in=new BufferedInputStream (new FileInputStream (file)); 106 registerStream(in); 107 } 108 109 113 public String [] getResourcesToRegister() { 114 return null; 115 } 116 117 118 119 124 private WSDDDeployment getDeployment() throws AxisFault { 125 WSDDDeployment deployment; 126 AxisEngine engine = getEngine(); 127 EngineConfiguration config = engine.getConfig(); 128 if (config instanceof WSDDEngineConfiguration) { 129 deployment = ((WSDDEngineConfiguration) config).getDeployment(); 130 } else { 131 deployment=null; 132 } 133 return deployment; 134 } 135 136 141 protected void logSuccess(String item) { 142 log.debug(Messages.getMessage("autoRegServletLoaded01",item)); 143 } 144 145 148 protected void autoRegister() { 149 String [] resources=getResourcesToRegister(); 150 if(resources==null || resources.length==0) { 151 return; 152 } 153 for(int i=0;i<resources.length;i++) { 154 final String resource = resources[i]; 155 registerAndLogResource(resource); 156 } 157 registerAnythingElse(); 158 try { 159 applyAndSaveSettings(); 160 } catch (Exception e) { 161 log.error(Messages.getMessage("autoRegServletApplyAndSaveSettings00"), e); 162 } 163 } 164 165 168 protected void registerAnythingElse() { 169 } 170 171 175 public void registerAndLogResource(final String resource) { 176 try { 177 registerResource(resource); 178 logSuccess(resource); 179 } catch (Exception e) { 180 log.error(Messages.getMessage("autoRegServletLoadFailed01",resource),e); 181 } 182 } 183 184 189 protected void applyAndSaveSettings() 190 throws AxisFault, ConfigurationException { 191 AxisEngine engine = getEngine(); 192 engine.refreshGlobalOptions(); 193 engine.saveConfiguration(); 194 } 195 } 196 | Popular Tags |