boolean useScannedClass = false;
String servletName;
if (resteasy.getScannedApplicationClass() == null) {
//if there is no scanned application we must add a servlet with a name of
//javax.ws.rs.core.Application
JBossServletMetaData servlet = new JBossServletMetaData();
servlet.setName(JAX_RS_SERVLET_NAME);
servlet.setServletClass(HttpServlet30Dispatcher.class.getName());
servlet.setAsyncSupported(true);
addServlet(webdata, servlet);
servletName = JAX_RS_SERVLET_NAME;
} else {
if (servletMappingsExist(webdata, JAX_RS_SERVLET_NAME)) {
throw new DeploymentUnitProcessingException(MESSAGES.conflictUrlMapping());
}
//now there are two options.
//if there is already a servlet defined with an init param
//we don't do anything.
//Otherwise we install our filter
//JAVA-RS seems somewhat confused about the difference between a context param
//and an init param.
ParamValueMetaData param = findInitParam(webdata, SERVLET_INIT_PARAM);
if (param != null) {
//we need to promote the init param to a context param
servletName = param.getParamValue();
setContextParameter(webdata, "javax.ws.rs.Application", servletName);
} else {
ParamValueMetaData contextParam = findContextParam(webdata, "javax.ws.rs.Application");
if (contextParam == null) {
setContextParameter(webdata, "javax.ws.rs.Application", resteasy.getScannedApplicationClass().getName());
useScannedClass = true;
servletName = resteasy.getScannedApplicationClass().getName();
} else {
servletName = contextParam.getParamValue();
}
}
}
boolean mappingSet = false;
if (useScannedClass) {
//look for servlet mappings
if (!servletMappingsExist(webdata, servletName)) {
//no mappings, add our own
List<String> patterns = new ArrayList<String>();
if (resteasy.getScannedApplicationClass().isAnnotationPresent(ApplicationPath.class)) {
ApplicationPath path = resteasy.getScannedApplicationClass().getAnnotation(ApplicationPath.class);
String pathValue = path.value().trim();
if (!pathValue.startsWith("/")) {
pathValue = "/" + pathValue;
}
String prefix = pathValue;
if (pathValue.endsWith("/")) {
pathValue += "*";
} else {
pathValue += "/*";
}
patterns.add(pathValue);
setContextParameter(webdata, "resteasy.servlet.mapping.prefix", prefix);
mappingSet = true;
} else {
JAXRS_LOGGER.noServletMappingFound(servletName);
return;
}
ServletMappingMetaData mapping = new ServletMappingMetaData();
mapping.setServletName(servletName);
mapping.setUrlPatterns(patterns);
if (webdata.getServletMappings() == null) {
webdata.setServletMappings(new ArrayList<ServletMappingMetaData>());
}
webdata.getServletMappings().add(mapping);
}
//add a servlet named after the application class
JBossServletMetaData servlet = new JBossServletMetaData();
servlet.setName(servletName);
servlet.setServletClass(HttpServlet30Dispatcher.class.getName());
servlet.setAsyncSupported(true);
addServlet(webdata, servlet);
}
if (!mappingSet) {