throw new DeploymentException("At least one of value and urlPatterns attribute should be configured on the WebServlet annotation in the class " + cls.getName());
}
String servletName = webServlet.name().length() == 0 ? cls.getName() : webServlet.name();
String[] urlPatterns = valueAttributeConfigured ? webServlet.value() : webServlet.urlPatterns();
if (ServletMergeHandler.isServletConfigured(servletName, mergeContext)) {
Servlet targetServlet = ServletMergeHandler.getServlet(servletName, mergeContext);
//merge init-params, we only merge those init-param that are not explicitly configured in the web.xml or web-fragment.xml
for (WebInitParam webInitParam : webServlet.initParams()) {
String paramName = webInitParam.name();
if (ServletInitParamMergeHandler.isServletInitParamConfigured(servletName, paramName, mergeContext)) {
continue;
}
ParamValue newParamValue = WebFilterAnnotationMergeHandler.newParamValue(webInitParam);
targetServlet.getInitParam().add(newParamValue);
ServletInitParamMergeHandler.addServletInitParam(servletName, newParamValue, ElementSource.ANNOTATION, mergeContext.getCurrentJarUrl(), mergeContext);
}
} else {
//Add a new Servlet
//create servlet element
Servlet newServlet = new Servlet();
if (!webServlet.displayName().isEmpty()) {
newServlet.addDisplayName(new Text(null, webServlet.displayName()));
}
newServlet.setServletClass(cls.getName());
newServlet.setServletName(servletName);
newServlet.setAsyncSupported(webServlet.asyncSupported());
if (!webServlet.description().isEmpty()) {
newServlet.addDescription(new Text(null, webServlet.description()));
}
if (webServlet.loadOnStartup() != -1) {
newServlet.setLoadOnStartup(webServlet.loadOnStartup());
}
for (WebInitParam webInitParam : webServlet.initParams()) {
newServlet.getInitParam().add(WebFilterAnnotationMergeHandler.newParamValue(webInitParam));
}
if (!webServlet.smallIcon().isEmpty() || !webServlet.largeIcon().isEmpty()) {
Icon icon = new Icon();
if (!webServlet.smallIcon().isEmpty()) {
icon.setSmallIcon(webServlet.smallIcon());
}
if (!webServlet.largeIcon().isEmpty()) {
icon.setLargeIcon(webServlet.largeIcon());
}
newServlet.getIconMap().put(null, icon);
}
MultipartConfig multipartConfig = cls.getAnnotation(MultipartConfig.class);
if (multipartConfig != null) {
org.apache.openejb.jee.MultipartConfig mpc = new org.apache.openejb.jee.MultipartConfig();
mpc.setFileSizeThreshold(multipartConfig.fileSizeThreshold());
mpc.setLocation(multipartConfig.location());
mpc.setMaxFileSize(multipartConfig.maxFileSize());
mpc.setMaxRequestSize(multipartConfig.maxRequestSize());
newServlet.setMultipartConfig(mpc);
}
webApp.getServlet().add(newServlet);
ServletMergeHandler.addServlet(newServlet, mergeContext);
}
if (!ServletMappingMergeHandler.isServletMappingConfigured(servletName, mergeContext)) {