Package javax.servlet.annotation

Examples of javax.servlet.annotation.WebServlet


      for (Annotation ann : annotated.getAnnotations()) {
        Class<?> annType = ann.annotationType();
       
        if (annType.equals(WebServlet.class)) {
          WebServlet webServlet = (WebServlet) ann;
     
          ServletMapping mapping = new ServletMapping();

          for (String value : webServlet.value()) {
            mapping.addURLPattern(value);
          }
         
          for (String value : webServlet.urlPatterns()) {
            mapping.addURLPattern(value);
          }
         
          mapping.setBean(bean);
       
View Full Code Here


  {
    String[] patterns = null;

    if (isServlet)
    {
      WebServlet servlet = getClass().getAnnotation(WebServlet.class);
      if (servlet != null)
      {
        if (servlet.urlPatterns().length > 0)
        {
          patterns = servlet.urlPatterns();
        }
        else
        {
          patterns = servlet.value();
        }
      }
    }
    else
    {
View Full Code Here

                }
            }
            context.addFilterMap(filterMap);
        }
        if (clazz.isAnnotationPresent(WebServlet.class)) {
            WebServlet annotation = clazz.getAnnotation(WebServlet.class);
            // Add servlet
            Wrapper wrapper = context.createWrapper();
            wrapper.setName(annotation.name());
            wrapper.setServletClass(clazz.getName());
            wrapper.setLoadOnStartup(annotation.loadOnStartup());
            WebInitParam[] params = annotation.initParams();
            for (int i = 0; i < params.length; i++) {
                wrapper.addInitParameter(params[i].name(), params[i].value());
            }
            context.addChild(wrapper);
            String[] urlPatterns = annotation.urlPatterns();
            if (urlPatterns != null) {
                for (int i = 0; i < urlPatterns.length; i++) {
                    context.addServletMapping(urlPatterns[i], annotation.name());
                }
            }
        }
        if (clazz.isAnnotationPresent(WebListener.class)) {
            // Add listener
View Full Code Here

    public void merge(Class<?>[] classes, WebApp webApp, MergeContext mergeContext) throws DeploymentException {
        for (Class<?> cls : classes) {
            if (!HttpServlet.class.isAssignableFrom(cls)) {
                throw new DeploymentException("The class " + cls.getName() + " with WebServlet annotation must extend javax.servlet.HttpServlet");
            }
            WebServlet webServlet = cls.getAnnotation(WebServlet.class);
            boolean valueAttributeConfigured = webServlet.value().length > 0;
            boolean urlPatternsAttributeConfigured = webServlet.urlPatterns().length > 0;
            if (valueAttributeConfigured && urlPatternsAttributeConfigured) {
                throw new DeploymentException("value and urlPatterns must not be configured on the same WebServlet annotation in the class " + cls.getName());
            }
            if (!valueAttributeConfigured && !urlPatternsAttributeConfigured) {
                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) {
View Full Code Here

      if (webFilter != null)
        addFilter(webFilter, filterClass.getName());
    }

    for (Class<? extends Servlet> servletClass : servlets) {
      WebServlet webServlet
        = servletClass.getAnnotation(WebServlet.class);

      if (webServlet != null)
        addServlet(webServlet, servletClass.getName());
View Full Code Here

        public boolean hasAsync() {
            if (isAsyncSupported()) return true;
            boolean result = false;
            Class<?> clazz = existing.getClass();
            if (clazz.isAnnotationPresent(WebServlet.class)) {
                WebServlet ws = clazz.getAnnotation(WebServlet.class);
                result = ws.asyncSupported();
            }
            return result;
        }
View Full Code Here

            for (final ClassListInfo info : webAppInfo.webAnnotatedClasses) {
                final String url = info.name;
                for (final String servletPath : info.list) {
                    final Class<?> clazz = loadFromUrls(webContext.getClassLoader(), url, servletPath);
                    final WebServlet annotation = clazz.getAnnotation(WebServlet.class);
                    if (annotation != null) {
                        for (final String mapping : annotation.urlPatterns()) {
                            try {
                                addServletMethod.invoke(null, clazz.getName(), webContext, mapping);
                                deployedWebObjects.mappings.add(mapping);
                            } catch (final Exception e) {
                                LOGGER.warning(e.getMessage(), e);
View Full Code Here

    public void merge(Class<?>[] classes, WebAppType webApp, MergeContext mergeContext) throws DeploymentException {
        for (Class<?> cls : classes) {
            if (!HttpServlet.class.isAssignableFrom(cls)) {
                throw new DeploymentException("The class " + cls.getName() + " with WebServlet annotation must extend javax.servlet.HttpServlet");
            }
            WebServlet webServlet = cls.getAnnotation(WebServlet.class);
            boolean valueAttributeConfigured = webServlet.value().length > 0;
            boolean urlPatternsAttributeConfigured = webServlet.urlPatterns().length > 0;
            if (valueAttributeConfigured && urlPatternsAttributeConfigured) {
                throw new DeploymentException("value and urlPatterns must not be configured on the same WebServlet annotation in the class " + cls.getName());
            }
            if (!valueAttributeConfigured && !urlPatternsAttributeConfigured) {
                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)) {
                ServletType 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;
                    }
                    ParamValueType newParamValue = targetServlet.addNewInitParam();
                    newParamValue.addNewDescription().setStringValue(webInitParam.description());
                    newParamValue.addNewParamName().setStringValue(webInitParam.name());
                    newParamValue.addNewParamValue().setStringValue(webInitParam.value());
                    ServletInitParamMergeHandler.addServletInitParam(servletName, newParamValue, ElementSource.ANNOTATION, mergeContext.getCurrentJarUrl(), mergeContext);
                }
            } else {
                //Add a new Servlet
                //create servlet element
                ServletType newServlet = webApp.addNewServlet();
                if (!webServlet.displayName().isEmpty()) {
                    newServlet.addNewDisplayName().setStringValue(webServlet.displayName());
                }
                newServlet.addNewServletClass().setStringValue(cls.getName());
                newServlet.addNewServletName().setStringValue(servletName);
                newServlet.addNewAsyncSupported().setBooleanValue(webServlet.asyncSupported());
                if (!webServlet.description().isEmpty()) {
                    newServlet.addNewDescription().setStringValue(webServlet.description());
                }
                if (webServlet.loadOnStartup() != -1) {
                    newServlet.setLoadOnStartup(webServlet.loadOnStartup());
                }
                for (WebInitParam webInitParam : webServlet.initParams()) {
                    ParamValueType paramValue = newServlet.addNewInitParam();
                    paramValue.addNewDescription().setStringValue(webInitParam.description());
                    paramValue.addNewParamName().setStringValue(webInitParam.name());
                    paramValue.addNewParamValue().setStringValue(webInitParam.value());
                }
                if (!webServlet.smallIcon().isEmpty() || !webServlet.largeIcon().isEmpty()) {
                    IconType iconType = newServlet.addNewIcon();
                    if (!webServlet.smallIcon().isEmpty()) {
                        iconType.addNewSmallIcon().setStringValue(webServlet.smallIcon());
                    }
                    if (!webServlet.largeIcon().isEmpty()) {
                        iconType.addNewLargeIcon().setStringValue(webServlet.largeIcon());
                    }
                }
                //TODO Figure out how to handle MultipartConfig annotation
                MultipartConfig multipartConfig = cls.getAnnotation(MultipartConfig.class);
                if (multipartConfig != null) {
View Full Code Here

        }

        private static boolean hasAsync(Servlet existing) {
            boolean result = false;
            Class<?> clazz = existing.getClass();
            WebServlet ws = clazz.getAnnotation(WebServlet.class);
            if (ws != null) {
                result = ws.asyncSupported();
            }
            return result;
        }
View Full Code Here

            throws AnnotationProcessorException {

        AnnotatedElementHandler aeHandler = ainfo.getProcessingContext().getHandler();
        if (aeHandler instanceof WebBundleContext) {
            WebBundleContext webBundleContext = (WebBundleContext)aeHandler;
            WebServlet webServletAn = (WebServlet)ainfo.getAnnotation();
            Class webCompClass = (Class)ainfo.getAnnotatedElement();
            String servletName = getServletName(webServletAn, webCompClass);

            // create a WebComponentDescriptor if there is none
            WebComponentDescriptor webCompDesc =
View Full Code Here

TOP

Related Classes of javax.servlet.annotation.WebServlet

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.