1 25 26 package org.objectweb.jonas.ws.axis; 27 28 import java.io.File ; 29 import java.io.FileInputStream ; 30 import java.io.IOException ; 31 import java.io.InputStream ; 32 import java.io.StringWriter ; 33 34 import javax.servlet.ServletConfig ; 35 import javax.servlet.ServletContext ; 36 37 import org.w3c.dom.Document ; 38 39 import org.apache.axis.EngineConfiguration; 40 import org.apache.axis.EngineConfigurationFactory; 41 import org.apache.axis.configuration.EngineConfigurationFactoryServlet; 42 import org.apache.axis.deployment.wsdd.WSDDDeployment; 43 import org.apache.axis.encoding.SerializationContext; 44 import org.apache.axis.utils.XMLUtils; 45 46 import org.objectweb.jonas.common.Log; 47 48 import org.objectweb.util.monolog.api.BasicLevel; 49 import org.objectweb.util.monolog.api.Logger; 50 51 52 59 public class JServletEngineConfigurationFactory 60 implements EngineConfigurationFactory { 61 62 63 public static final String AXIS_SERVER_CONFIG_PARAM = "axis.serverConfigFile"; 64 65 66 public static final String SERVER_CONFIG_WSDD = "org/objectweb/jonas/ws/axis/server-config.wsdd"; 67 68 69 private static Logger logger = Log.getLogger(Log.JONAS_WS_PREFIX); 70 71 72 private String serverConfigFile; 73 74 75 private EngineConfigurationFactory delegate; 76 77 78 private ServletContext ctx; 79 80 81 private ServletConfig cfg; 82 83 84 90 protected JServletEngineConfigurationFactory(ServletConfig conf) { 91 cfg = conf; 93 ctx = conf.getServletContext(); 94 delegate = EngineConfigurationFactoryServlet.newFactory(conf); 95 } 96 97 109 public static EngineConfigurationFactory newFactory(Object param) { 110 111 if (param == null) { 112 return null; } 114 115 if (param instanceof ServletConfig ) { 116 return new JServletEngineConfigurationFactory((ServletConfig ) param); 117 } else { 118 return null; 119 } 120 } 121 122 129 public EngineConfiguration getServerEngineConfig() { 130 131 logger.log(BasicLevel.DEBUG, "Entering getServerEngineConfig for servlet " + cfg.getServletName()); 132 133 try { 134 135 serverConfigFile = cfg.getInitParameter(AXIS_SERVER_CONFIG_PARAM); 137 138 logger.log(BasicLevel.DEBUG, "serverConfigFile=" + serverConfigFile); 139 140 if (serverConfigFile == null) { 142 return delegate.getServerEngineConfig(); 143 } 144 145 if (logger.isLoggable(BasicLevel.DEBUG)) { 146 logger.log(BasicLevel.DEBUG, 147 "Loading server-config file '" + serverConfigFile + "'"); 148 } 149 150 154 String appWebInfPath = "/WEB-INF"; 155 156 Document deploy = null; 157 158 String realWebInfPath = ctx.getRealPath(appWebInfPath); 159 160 165 if (realWebInfPath == null 166 || !(new File (realWebInfPath, serverConfigFile)).exists()) { 167 168 String name = appWebInfPath + "/" + serverConfigFile; 169 InputStream is = ctx.getResourceAsStream(name); 170 171 if (is != null) { 172 deploy = XMLUtils.newDocument(is); 173 } 174 175 if (deploy == null) { 176 String err = "Cannot get config file '" + serverConfigFile + "' as Resource."; 177 logger.log(BasicLevel.ERROR, err); 178 } 179 } 180 181 186 if (deploy == null && realWebInfPath != null) { 187 try { 188 InputStream is = new FileInputStream (new File (realWebInfPath, serverConfigFile)); 189 deploy = XMLUtils.newDocument(is); 190 } catch (IOException e) { 191 String err = "Cannot get config file '" + serverConfigFile + "' as File Resource."; 192 logger.log(BasicLevel.ERROR, err); 193 } 194 } 195 196 if (deploy == null) { 198 return delegate.getServerEngineConfig(); 199 } 200 201 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 203 InputStream is = cl.getResourceAsStream(SERVER_CONFIG_WSDD); 204 Document base = XMLUtils.newDocument(is); 205 206 WSDDDeployment deployWSDD = new WSDDDeployment(deploy.getDocumentElement()); 208 WSDDDeployment configWSDD = new WSDDDeployment(base.getDocumentElement()); 209 210 deployWSDD.deployToRegistry(configWSDD); 211 212 if (logger.isLoggable(BasicLevel.DEBUG)) { 213 StringWriter sw = new StringWriter (); 214 SerializationContext ctx = new SerializationContext(sw); 215 216 try { 217 configWSDD.writeToContext(ctx); 218 } catch (Exception ioe) { 219 logger.log(BasicLevel.DEBUG, "Cannot serialize Axis wsdd for servlet " + cfg.getServletName()); 220 } 221 logger.log(BasicLevel.DEBUG, sw.getBuffer().toString()); 222 } 223 224 return configWSDD; 225 } catch (Exception e) { 226 String err = "Cannot configure axis server from '" + serverConfigFile + "'. Use axis default. Caused by : " + e.getMessage(); 228 e.printStackTrace(); 229 logger.log(BasicLevel.ERROR, err); 230 return delegate.getServerEngineConfig(); 231 } 232 } 233 234 239 public EngineConfiguration getClientEngineConfig() { 240 return null; 241 } 242 } 243 | Popular Tags |