Search in sources :

Example 6 with ServletDef

use of org.apache.catalina.deploy.ServletDef in project tomcat70 by apache.

the class ContextConfig method convertJsps.

private void convertJsps(WebXml webXml) {
    Map<String, String> jspInitParams;
    ServletDef jspServlet = webXml.getServlets().get("jsp");
    if (jspServlet == null) {
        jspInitParams = new HashMap<String, String>();
        Wrapper w = (Wrapper) context.findChild("jsp");
        if (w != null) {
            String[] params = w.findInitParameters();
            for (String param : params) {
                jspInitParams.put(param, w.findInitParameter(param));
            }
        }
    } else {
        jspInitParams = jspServlet.getParameterMap();
    }
    for (ServletDef servletDef : webXml.getServlets().values()) {
        if (servletDef.getJspFile() != null) {
            convertJsp(servletDef, jspInitParams);
        }
    }
}
Also used : Wrapper(org.apache.catalina.Wrapper) ServletDef(org.apache.catalina.deploy.ServletDef)

Example 7 with ServletDef

use of org.apache.catalina.deploy.ServletDef in project tomcat70 by apache.

the class ContextConfig method processAnnotationWebServlet.

protected void processAnnotationWebServlet(String className, AnnotationEntry ae, WebXml fragment) {
    String servletName = null;
    // must search for name s. Spec Servlet API 3.0 - 8.2.3.3.n.ii page 81
    List<ElementValuePair> evps = ae.getElementValuePairs();
    for (ElementValuePair evp : evps) {
        String name = evp.getNameString();
        if ("name".equals(name)) {
            servletName = evp.getValue().stringifyValue();
            break;
        }
    }
    if (servletName == null) {
        // classname is default servletName as annotation has no name!
        servletName = className;
    }
    ServletDef servletDef = fragment.getServlets().get(servletName);
    boolean isWebXMLservletDef;
    if (servletDef == null) {
        servletDef = new ServletDef();
        servletDef.setServletName(servletName);
        servletDef.setServletClass(className);
        isWebXMLservletDef = false;
    } else {
        isWebXMLservletDef = true;
    }
    boolean urlPatternsSet = false;
    String[] urlPatterns = null;
    // List<ElementValuePair> evps = ae.getElementValuePairs();
    for (ElementValuePair evp : evps) {
        String name = evp.getNameString();
        if ("value".equals(name) || "urlPatterns".equals(name)) {
            if (urlPatternsSet) {
                throw new IllegalArgumentException(sm.getString("contextConfig.urlPatternValue", "WebServlet", className));
            }
            urlPatternsSet = true;
            urlPatterns = processAnnotationsStringArray(evp.getValue());
        } else if ("description".equals(name)) {
            if (servletDef.getDescription() == null) {
                servletDef.setDescription(evp.getValue().stringifyValue());
            }
        } else if ("displayName".equals(name)) {
            if (servletDef.getDisplayName() == null) {
                servletDef.setDisplayName(evp.getValue().stringifyValue());
            }
        } else if ("largeIcon".equals(name)) {
            if (servletDef.getLargeIcon() == null) {
                servletDef.setLargeIcon(evp.getValue().stringifyValue());
            }
        } else if ("smallIcon".equals(name)) {
            if (servletDef.getSmallIcon() == null) {
                servletDef.setSmallIcon(evp.getValue().stringifyValue());
            }
        } else if ("asyncSupported".equals(name)) {
            if (servletDef.getAsyncSupported() == null) {
                servletDef.setAsyncSupported(evp.getValue().stringifyValue());
            }
        } else if ("loadOnStartup".equals(name)) {
            if (servletDef.getLoadOnStartup() == null) {
                servletDef.setLoadOnStartup(evp.getValue().stringifyValue());
            }
        } else if ("initParams".equals(name)) {
            Map<String, String> initParams = processAnnotationWebInitParams(evp.getValue());
            if (isWebXMLservletDef) {
                Map<String, String> webXMLInitParams = servletDef.getParameterMap();
                for (Map.Entry<String, String> entry : initParams.entrySet()) {
                    if (webXMLInitParams.get(entry.getKey()) == null) {
                        servletDef.addInitParameter(entry.getKey(), entry.getValue());
                    }
                }
            } else {
                for (Map.Entry<String, String> entry : initParams.entrySet()) {
                    servletDef.addInitParameter(entry.getKey(), entry.getValue());
                }
            }
        }
    }
    if (!isWebXMLservletDef && urlPatterns != null) {
        fragment.addServlet(servletDef);
    }
    if (urlPatterns != null) {
        if (!fragment.getServletMappings().containsValue(servletName)) {
            for (String urlPattern : urlPatterns) {
                fragment.addServletMapping(urlPattern, servletName);
            }
        }
    }
}
Also used : AnnotationEntry(org.apache.tomcat.util.bcel.classfile.AnnotationEntry) ElementValuePair(org.apache.tomcat.util.bcel.classfile.ElementValuePair) ServletDef(org.apache.catalina.deploy.ServletDef) FilterMap(org.apache.catalina.deploy.FilterMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ServletDef (org.apache.catalina.deploy.ServletDef)7 File (java.io.File)5 WebXml (org.apache.catalina.deploy.WebXml)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Wrapper (org.apache.catalina.Wrapper)1 FilterMap (org.apache.catalina.deploy.FilterMap)1 AnnotationEntry (org.apache.tomcat.util.bcel.classfile.AnnotationEntry)1 ElementValuePair (org.apache.tomcat.util.bcel.classfile.ElementValuePair)1