public WarBasedAxisConfigurator(ServletConfig servletConfig) throws DeploymentException {
try {
this.config = servletConfig;
InputStream axis2Stream = null;
try {
// when the module is an unpacked war file,
// we can set the web location path in the deployment engine.
// This will let us
String webpath = config.getServletContext().getRealPath("");
if (webpath == null || webpath.length() == 0) {
webpath = config.getServletContext().getRealPath("/");
}
if (webpath != null && !"".equals(webpath)) {
log.debug("setting web location string: " + webpath);
File weblocation = new File(webpath);
setWebLocationString(weblocation.getAbsolutePath());
} // if webpath not null
String axis2xmlpath = config.getInitParameter(PARAM_AXIS2_XML_PATH);
if (axis2xmlpath != null) {
// when init parameter was present.
axis2Stream = new FileInputStream(axis2xmlpath);
log.debug("using axis2.xml from path: " + axis2xmlpath);
}
if (axis2Stream == null) {
String axisurl = config.getInitParameter(PARAM_AXIS2_XML_URL);
if (axisurl != null) {
axis2Stream = new URL(axisurl).openStream();
axisConfig = populateAxisConfiguration(axis2Stream);
log.debug("loading axis2.xml from URL: " + axisurl);
}
}
if (axis2Stream == null) {
// both the axis2.xml.path and axis2.xml.url init parameters were not present
// try to find the default /WEB-INF/conf/axis2.xml
axis2Stream = config.getServletContext()
.getResourceAsStream("/WEB-INF/conf/axis2.xml");
log.debug("trying to load axis2.xml from module: /WEB-INF/conf/axis2.xml");
}
if (axis2Stream == null) {
// Simple deployment, no need for conf directory either
axis2Stream = config.getServletContext()
.getResourceAsStream("/WEB-INF/axis2.xml");
log.debug("trying to load axis2.xml from module: /WEB-INF/conf/axis2.xml");
}
} // try
catch (Exception e) {
log.error(e, e);
log.warn("Using default configuration: " + DeploymentConstants
.AXIS2_CONFIGURATION_RESOURCE);
// not there, use default configuration from class path resource.
} // catch
if (axis2Stream == null) {
log.info("Could not find axis2.xml, loading default "
+ DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE + " from classpath");
axis2Stream =
Loader.getResourceAsStream(DeploymentConstants.AXIS2_CONFIGURATION_RESOURCE);
}
axisConfig = populateAxisConfiguration(axis2Stream);
if(axis2Stream != null){
axis2Stream.close();
}
Parameter param = new Parameter();
param.setName(Constants.Configuration.ARTIFACTS_TEMP_DIR);
File f = new File((File) config.getServletContext().getAttribute("javax.servlet.context.tempdir"), "_axis2");
if (f.exists() || f.mkdirs()) {
param.setValue(f);
} else {
f = new File(System.getProperty("java.io.tmpdir"), "_axis2");
if (f.exists() || f.mkdirs()) {
param.setValue(f);
} else {
throw new DeploymentException("Unable to create a temporary working directory");
}
}
try {
axisConfig.addParameter(param);
} catch (AxisFault axisFault) {
log.error(axisFault.getMessage(), axisFault);
}
} catch (DeploymentException e) {
log.error(e.getMessage(), e);
throw e;
} catch (IOException e) {
log.error(e.getMessage(), e);
}
}
Default constructor for configurator.
This determines the axis2.xml file to be used from the init parameters for the AxisServlet in the web.xml.
The order of initialization is according the the following precedence:
- If the parameter axis2.xml.path is present, the value is webapp relative path to be used as the location to the axis2.xml file.
- Otherwise, if the parameter axis2.xml.url is present, the URL is used as the location to the axis2.xml file.
- Otherwise, when both of the above init parameters are not present, file is attempted to be loaded from <repo>/WEB-INF/axis2.xml.
- When none of the above could be found, the axis2.xml is loaded from the classpath resource, the value of DeploymenConstants.AXIS2_CONFIGURATION_RESOURCE.
Parameters:
servletConfig - the ServletConfig object from the AxisServlet. This method is called from the init() of the AxisServlet.
|