Search in sources :

Example 1 with MultipartConfig

use of javax.servlet.annotation.MultipartConfig in project Payara by payara.

the class DynamicWebServletRegistrationImpl method processServletAnnotations.

private void processServletAnnotations(Class<? extends Servlet> clazz, WebBundleDescriptor webBundleDescriptor, WebComponentDescriptor wcd, StandardWrapper wrapper) {
    // Process DeclareRoles annotation
    if (clazz.isAnnotationPresent(DeclareRoles.class)) {
        DeclareRoles declareRoles = (DeclareRoles) clazz.getAnnotation(DeclareRoles.class);
        for (String roleName : declareRoles.value()) {
            webBundleDescriptor.addRole(new Role(roleName));
            webModule.declareRoles(roleName);
        }
    }
    // Process MultipartConfig annotation
    if (clazz.isAnnotationPresent(MultipartConfig.class)) {
        MultipartConfig mpConfig = (MultipartConfig) clazz.getAnnotation(MultipartConfig.class);
        wrapper.setMultipartLocation(mpConfig.location());
        wrapper.setMultipartMaxFileSize(mpConfig.maxFileSize());
        wrapper.setMultipartMaxRequestSize(mpConfig.maxRequestSize());
        wrapper.setMultipartFileSizeThreshold(mpConfig.fileSizeThreshold());
    }
}
Also used : Role(org.glassfish.security.common.Role) MultipartConfig(javax.servlet.annotation.MultipartConfig) DeclareRoles(javax.annotation.security.DeclareRoles)

Example 2 with MultipartConfig

use of javax.servlet.annotation.MultipartConfig in project Payara by payara.

the class MultipartConfigHandler method processAnnotation.

private HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebComponentDescriptor webCompDesc) throws AnnotationProcessorException {
    MultipartConfig multipartConfigAn = (MultipartConfig) ainfo.getAnnotation();
    com.sun.enterprise.deployment.web.MultipartConfig multipartConfig = webCompDesc.getMultipartConfig();
    if (multipartConfig == null) {
        multipartConfig = new MultipartConfigDescriptor();
        webCompDesc.setMultipartConfig(multipartConfig);
    }
    if (multipartConfig.getLocation() == null) {
        multipartConfig.setLocation(multipartConfigAn.location());
    }
    if (multipartConfig.getMaxFileSize() == null) {
        multipartConfig.setMaxFileSize(multipartConfigAn.maxFileSize());
    }
    if (multipartConfig.getMaxRequestSize() == null) {
        multipartConfig.setMaxRequestSize(multipartConfigAn.maxRequestSize());
    }
    if (multipartConfig.getFileSizeThreshold() == null) {
        multipartConfig.setFileSizeThreshold(multipartConfigAn.fileSizeThreshold());
    }
    return getDefaultProcessedResult();
}
Also used : MultipartConfig(javax.servlet.annotation.MultipartConfig) MultipartConfigDescriptor(org.glassfish.web.deployment.descriptor.MultipartConfigDescriptor)

Example 3 with MultipartConfig

use of javax.servlet.annotation.MultipartConfig in project jetty.project by eclipse.

the class MultiPartConfigAnnotationHandler method doHandle.

/** 
     * @see org.eclipse.jetty.annotations.AnnotationIntrospector.AbstractIntrospectableAnnotationHandler#doHandle(java.lang.Class)
     */
public void doHandle(Class clazz) {
    if (!Servlet.class.isAssignableFrom(clazz))
        return;
    MultipartConfig multi = (MultipartConfig) clazz.getAnnotation(MultipartConfig.class);
    if (multi == null)
        return;
    MetaData metaData = _context.getMetaData();
    //TODO: The MultipartConfigElement needs to be set on the ServletHolder's Registration.
    //How to identify the correct Servlet?  If the Servlet has no WebServlet annotation on it, does it mean that this MultipartConfig
    //annotation applies to all declared instances in web.xml/programmatically?
    //Assuming TRUE for now.
    ServletHolder holder = getServletHolderForClass(clazz);
    if (holder != null) {
        Descriptor d = metaData.getOriginDescriptor(holder.getName() + ".servlet.multipart-config");
        //let the annotation override it
        if (d == null) {
            metaData.setOrigin(holder.getName() + ".servlet.multipart-config", multi, clazz);
            holder.getRegistration().setMultipartConfig(new MultipartConfigElement(multi));
        }
    }
}
Also used : MultipartConfigElement(javax.servlet.MultipartConfigElement) MultipartConfig(javax.servlet.annotation.MultipartConfig) MetaData(org.eclipse.jetty.webapp.MetaData) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) Servlet(javax.servlet.Servlet) Descriptor(org.eclipse.jetty.webapp.Descriptor)

Example 4 with MultipartConfig

use of javax.servlet.annotation.MultipartConfig in project tomcat70 by apache.

the class StandardWrapper method loadServlet.

/**
 * Load and initialize an instance of this servlet, if there is not already
 * at least one initialized instance.  This can be used, for example, to
 * load servlets that are marked in the deployment descriptor to be loaded
 * at server startup time.
 */
public synchronized Servlet loadServlet() throws ServletException {
    if (unloading) {
        throw new ServletException(sm.getString("standardWrapper.unloading", getName()));
    }
    // Nothing to do if we already have an instance or an instance pool
    if (!singleThreadModel && (instance != null))
        return instance;
    PrintStream out = System.out;
    if (swallowOutput) {
        SystemLogHandler.startCapture();
    }
    Servlet servlet;
    try {
        long t1 = System.currentTimeMillis();
        // Complain if no servlet class has been specified
        if (servletClass == null) {
            unavailable(null);
            throw new ServletException(sm.getString("standardWrapper.notClass", getName()));
        }
        InstanceManager instanceManager = ((StandardContext) getParent()).getInstanceManager();
        try {
            servlet = (Servlet) instanceManager.newInstance(servletClass);
        } catch (ClassCastException e) {
            unavailable(null);
            // Restore the context ClassLoader
            throw new ServletException(sm.getString("standardWrapper.notServlet", servletClass), e);
        } catch (Throwable e) {
            e = ExceptionUtils.unwrapInvocationTargetException(e);
            ExceptionUtils.handleThrowable(e);
            unavailable(null);
            // http://bz.apache.org/bugzilla/show_bug.cgi?id=36630
            if (log.isDebugEnabled()) {
                log.debug(sm.getString("standardWrapper.instantiate", servletClass), e);
            }
            // Restore the context ClassLoader
            throw new ServletException(sm.getString("standardWrapper.instantiate", servletClass), e);
        }
        if (multipartConfigElement == null) {
            MultipartConfig annotation = servlet.getClass().getAnnotation(MultipartConfig.class);
            if (annotation != null) {
                multipartConfigElement = new MultipartConfigElement(annotation);
            }
        }
        // Special handling for ContainerServlet instances
        if ((servlet instanceof ContainerServlet) && (isContainerProvidedServlet(servletClass) || ((Context) getParent()).getPrivileged())) {
            ((ContainerServlet) servlet).setWrapper(this);
        }
        classLoadTime = (int) (System.currentTimeMillis() - t1);
        if (servlet instanceof SingleThreadModel) {
            if (instancePool == null) {
                instancePool = new Stack<Servlet>();
            }
            singleThreadModel = true;
        }
        initServlet(servlet);
        fireContainerEvent("load", this);
        loadTime = System.currentTimeMillis() - t1;
    } finally {
        if (swallowOutput) {
            String log = SystemLogHandler.stopCapture();
            if (log != null && log.length() > 0) {
                if (getServletContext() != null) {
                    getServletContext().log(log);
                } else {
                    out.println(log);
                }
            }
        }
    }
    return servlet;
}
Also used : PrintStream(java.io.PrintStream) InstanceManager(org.apache.tomcat.InstanceManager) ContainerServlet(org.apache.catalina.ContainerServlet) ServletException(javax.servlet.ServletException) MultipartConfigElement(javax.servlet.MultipartConfigElement) MultipartConfig(javax.servlet.annotation.MultipartConfig) Servlet(javax.servlet.Servlet) ContainerServlet(org.apache.catalina.ContainerServlet) SingleThreadModel(javax.servlet.SingleThreadModel)

Aggregations

MultipartConfig (javax.servlet.annotation.MultipartConfig)4 MultipartConfigElement (javax.servlet.MultipartConfigElement)2 Servlet (javax.servlet.Servlet)2 PrintStream (java.io.PrintStream)1 DeclareRoles (javax.annotation.security.DeclareRoles)1 ServletException (javax.servlet.ServletException)1 SingleThreadModel (javax.servlet.SingleThreadModel)1 ContainerServlet (org.apache.catalina.ContainerServlet)1 InstanceManager (org.apache.tomcat.InstanceManager)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 Descriptor (org.eclipse.jetty.webapp.Descriptor)1 MetaData (org.eclipse.jetty.webapp.MetaData)1 Role (org.glassfish.security.common.Role)1 MultipartConfigDescriptor (org.glassfish.web.deployment.descriptor.MultipartConfigDescriptor)1