* @throws UnavailableException if any error occurs that stops the mapper from being created
*/
private Map createServiceDefinitions(HttpServlet servlet) throws UnavailableException {
// set up JiBX unmarshalling for service configuration files
IUnmarshallingContext ctx = null;
try {
IBindingFactory factory = BindingDirectory.getFactory(ServiceDefinition.class);
ctx = factory.createUnmarshallingContext();
} catch (JiBXException e) {
logger.error("Unable to initialize unmarshalling", e);
throw new UnavailableException("Unable to initialize unmarshalling. \n" + getErrorDetails(e));
}
// read and validate service definitions
String path = null;
String file = null;
try {
// loop through all initialization parameter pairs
HashMap map = new HashMap();
Enumeration pnum = servlet.getInitParameterNames();
ServletContext serv = servlet.getServletContext();
while (pnum.hasMoreElements()) {
// parameter name is path and value is service definition file
path = (String) pnum.nextElement();
file = "/WEB-INF/" + servlet.getInitParameter(path);
InputStream is = null;
try {
is = serv.getResourceAsStream(file);
if (is == null) {
logger.error("Service definition not found for service " + path + " at " + file);
throw new UnavailableException("Service definition not found for service " + path + " at "
+ file + ". Check configuration of servlet " + servlet.getServletName()
+ " in WEB-INF/web.xml.");
}
ServiceDefinition sdef = (ServiceDefinition) ctx.unmarshalDocument(is, null);
if (!path.startsWith("/")) {
path = "/" + path;
}
map.put(path, sdef);