private void processServletConfig(DeploymentDescriptor webDD, Servlet servlet) {
        String servletName = servlet.getServletName();
        Map<String, ConfigItem<ServletConfig>> servletMap = configurator.getConfigItemMap("servlet");
        ConfigItem<ServletConfig> existedServlet = servletMap.get(servletName);

        ServletConfig servletConfig = null;
        if (existedServlet == null) {
            String servletId = webDD.getIdForComponent(servlet);
            if (servletId == null) {
                servletId = "ServletGeneratedId" + configurator.generateUniqueId();
            }
            servletConfig = webAppConfiguration.createServletConfig(servletId, servletName);

            configureTargetConfig(servletConfig, servlet.getServletClass(), "Servlet", servlet);

            String jspFile = servlet.getJSPFile();
            if (jspFile != null) {
                servletConfig.setIsJsp(true);
                servletConfig.setFileName(jspFile);
            }
            if (servlet.isSetEnabled()) {
                servletConfig.setEnabled(servlet.isEnabled());
            }

            webAppConfiguration.addServletInfo(servletName, servletConfig);

            servletMap.put(servletName, createConfigItem(servletConfig));

        } else {
            servletConfig = existedServlet.getValue();
        }

        configureInitParams(servletConfig, servlet.getInitParams(), "servlet");

        if (servlet.isSetLoadOnStartup()) {
            Map<String, ConfigItem<Integer>> servletLoadOnStartupMap = configurator.getConfigItemMap("servlet.load-on-startup");

            ConfigItem<Integer> existedLoadOnStartup = servletLoadOnStartupMap.get(servletName);

            if (existedLoadOnStartup == null) {
                servletConfig.setStartUpWeight(servlet.isNullLoadOnStartup() ? null : Integer.valueOf(servlet.getLoadOnStartup()));
                servletLoadOnStartupMap.put(servletName, createConfigItem(Integer.valueOf(servlet.getLoadOnStartup())));
            } else {
                validateDuplicateConfiguration("servlet", "load-on-startup", servlet.isNullLoadOnStartup() ? null : Integer.valueOf(servlet.getLoadOnStartup()),
                                               existedLoadOnStartup);
            }
        }

        if (servlet.getMultipartConfig() != null) {
            Map<String, ConfigItem<MultipartConfig>> servletMultipartConfigMap = configurator.getConfigItemMap("servlet.multipart-config");
            if (existedServlet == null || !servletMultipartConfigMap.containsKey(servletName)) {
                servletConfig.setMultipartConfig(createMultipartConfigElement(servlet.getMultipartConfig()));
                servletMultipartConfigMap.put(servletName, createConfigItem(servlet.getMultipartConfig()));
            } else {
                ConfigItem<MultipartConfig> existedMultipartConfig = servletMultipartConfigMap.get(servletName);
                if (existedMultipartConfig.getSource() == ConfigSource.WEB_FRAGMENT && configurator.getConfigSource() == ConfigSource.WEB_FRAGMENT) {
                    if (!isSameMultipartConfigs(existedMultipartConfig.getValue(), servlet.getMultipartConfig())) {
                        // TODO: What goes here?
                    }
                } else if (existedMultipartConfig.getSource() == ConfigSource.WEB_XML && configurator.getConfigSource() == ConfigSource.WEB_FRAGMENT) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "multipart-config for servlet {0} is configured in web.xml, the value from web-fragment.xml in {1}  is ignored", servletName,
                                 configurator.getLibraryURI());
                    }
                }
            }
        }

        if (servlet.isSetAsyncSupported()) {
            configureAsyncSupported(servletConfig, servlet.isAsyncSupported(), "servlet");
        }
        com.ibm.ws.javaee.dd.common.RunAs runAs = servlet.getRunAs();
        if (runAs != null) {
            servletConfig.setRunAsRole(runAs.getRoleName());
        }
    }
private void processServletConfig ( DeploymentDescriptor webDD , Servlet servlet ) { String servletName = servlet . getServletName ( ) ; Map < String , ConfigItem < ServletConfig > > servletMap = configurator . getConfigItemMap ( "servlet" ) ; ConfigItem < ServletConfig > existedServlet = servletMap . get ( servletName ) ; ServletConfig servletConfig = null ; if ( existedServlet == null ) { String servletId = webDD . getIdForComponent ( servlet ) ; if ( servletId == null ) { servletId = "ServletGeneratedId" + configurator . generateUniqueId ( ) ; } servletConfig = webAppConfiguration . createServletConfig ( servletId , servletName ) ; configureTargetConfig ( servletConfig , servlet . getServletClass ( ) , "Servlet" , servlet ) ; String jspFile = servlet . getJSPFile ( ) ; if ( jspFile != null ) { servletConfig . setIsJsp ( true ) ; servletConfig . setFileName ( jspFile ) ; } if ( servlet . isSetEnabled ( ) ) { servletConfig . setEnabled ( servlet . isEnabled ( ) ) ; } webAppConfiguration . addServletInfo ( servletName , servletConfig ) ; servletMap . put ( servletName , createConfigItem ( servletConfig ) ) ; } else { servletConfig = existedServlet . getValue ( ) ; } configureInitParams ( servletConfig , servlet . getInitParams ( ) , "servlet" ) ; if ( servlet . isSetLoadOnStartup ( ) ) { Map < String , ConfigItem < Integer > > servletLoadOnStartupMap = configurator . getConfigItemMap ( "servlet.load-on-startup" ) ; ConfigItem < Integer > existedLoadOnStartup = servletLoadOnStartupMap . get ( servletName ) ; if ( existedLoadOnStartup == null ) { servletConfig . setStartUpWeight ( servlet . isNullLoadOnStartup ( ) ? null : Integer . valueOf ( servlet . getLoadOnStartup ( ) ) ) ; servletLoadOnStartupMap . put ( servletName , createConfigItem ( Integer . valueOf ( servlet . getLoadOnStartup ( ) ) ) ) ; } else { validateDuplicateConfiguration ( "servlet" , "load-on-startup" , servlet . isNullLoadOnStartup ( ) ? null : Integer . valueOf ( servlet . getLoadOnStartup ( ) ) , existedLoadOnStartup ) ; } } if ( servlet . getMultipartConfig ( ) != null ) { Map < String , ConfigItem < MultipartConfig > > servletMultipartConfigMap = configurator . getConfigItemMap ( "servlet.multipart-config" ) ; if ( existedServlet == null || ! servletMultipartConfigMap . containsKey ( servletName ) ) { servletConfig . setMultipartConfig ( createMultipartConfigElement ( servlet . getMultipartConfig ( ) ) ) ; servletMultipartConfigMap . put ( servletName , createConfigItem ( servlet . getMultipartConfig ( ) ) ) ; } else { ConfigItem < MultipartConfig > existedMultipartConfig = servletMultipartConfigMap . get ( servletName ) ; if ( existedMultipartConfig . getSource ( ) == ConfigSource . WEB_FRAGMENT && configurator . getConfigSource ( ) == ConfigSource . WEB_FRAGMENT ) { if ( ! isSameMultipartConfigs ( existedMultipartConfig . getValue ( ) , servlet . getMultipartConfig ( ) ) ) { } } else if ( existedMultipartConfig . getSource ( ) == ConfigSource . WEB_XML && configurator . getConfigSource ( ) == ConfigSource . WEB_FRAGMENT ) { if ( TraceComponent . isAnyTracingEnabled ( ) && tc . isDebugEnabled ( ) ) { Tr . debug ( tc , "multipart-config for servlet {0} is configured in web.xml, the value from web-fragment.xml in {1}  is ignored" , servletName , configurator . getLibraryURI ( ) ) ; } } } } if ( servlet . isSetAsyncSupported ( ) ) { configureAsyncSupported ( servletConfig , servlet . isAsyncSupported ( ) , "servlet" ) ; } com . ibm . ws . javaee . dd . common . RunAs runAs = servlet . getRunAs ( ) ; if ( runAs != null ) { servletConfig . setRunAsRole ( runAs . getRoleName ( ) ) ; } }
Merging Rules :
a. Once a servlet configuration exists, the following ones with the same servlet name are ignored
b. If init-param/loadOnStartup/multipartConfig/asyncSupported is configured in web.xml, all the values from web-fagment.xml and annotation are ignored
b. If init-param/loadOnStartup/multipartConfig/asyncSupported is NOT configured in web.xml,
b1. Those values from web-fragment.xml and annotation will be considered
b2. If they are configured in different web-fragment.xml, their values should be the same, or will trigger a warning