java类javax.servlet.MultipartConfigElement的实例源码

Minijax.java 文件源码 项目:minijax 阅读 29 收藏 0 点赞 0 评论 0
private void addApplication(final ServletContextHandler context, final MinijaxApplication application)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    // (0) Sort the resource methods by literal length
    application.sortResourceMethods();

    // (1) Add Minijax filter (must come before websocket!)
    context.addFilter(new FilterHolder(new MinijaxFilter(application)), "/*", EnumSet.of(DispatcherType.REQUEST));

    // (2) WebSocket endpoints
    if (OptionalClasses.WEB_SOCKET_UTILS != null) {
        OptionalClasses.WEB_SOCKET_UTILS
                .getMethod("init", ServletContextHandler.class, MinijaxApplication.class)
                .invoke(null, context, application);
    }

    // (3) Dynamic JAX-RS content
    final MinijaxServlet servlet = new MinijaxServlet(application);
    final ServletHolder servletHolder = new ServletHolder(servlet);
    servletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(""));
    context.addServlet(servletHolder, "/*");
}
TestStandardContext.java 文件源码 项目:tomcat7 阅读 30 收藏 0 点赞 0 评论 0
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
TestStandardContext.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 33 收藏 0 点赞 0 评论 0
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
TestHttpServer.java 文件源码 项目:google-cloud-eclipse 阅读 37 收藏 0 点赞 0 评论 0
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
    HttpServletResponse response) throws IOException, ServletException {
  Preconditions.checkState(!requestHandled);

  if (request.getContentType() != null
      && request.getContentType().startsWith("multipart/form-data")) {
    request.setAttribute(Request.__MULTIPART_CONFIG_ELEMENT,
        new MultipartConfigElement(System.getProperty("java.io.tmpdir")));
  }

  if (target.equals("/" + expectedPath)) {
    requestHandled = true;
    requestMethod = request.getMethod();
    requestParameters = request.getParameterMap();
    for (Enumeration<String> headers = request.getHeaderNames(); headers.hasMoreElements(); ) {
      String header = headers.nextElement();
      requestHeaders.put(header, request.getHeader(header));
    }

    baseRequest.setHandled(true);
    response.getOutputStream().write(responseBytes);
    response.setStatus(HttpServletResponse.SC_OK);
  }
}
GraphQLWebAutoConfiguration.java 文件源码 项目:graphql-spring-boot 阅读 109 收藏 0 点赞 0 评论 0
@Bean
@ConditionalOnMissingBean(MultipartConfigElement.class)
public MultipartConfigElement multipartConfigElement(GraphQLProperties graphQLProperties) {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setMaxFileSize(DEFAULT_UPLOAD_MAX_FILE_SIZE);
    factory.setMaxRequestSize(DEFAULT_UPLOAD_MAX_REQUEST_SIZE);

    String temp = graphQLProperties.getServer().getUploadMaxFileSize();
    if (StringUtils.hasText(temp))
        factory.setMaxFileSize(temp);

    temp = graphQLProperties.getServer().getUploadMaxRequestSize();
    if (StringUtils.hasText(temp))
        factory.setMaxRequestSize(temp);

    return factory.createMultipartConfig();
}
MultipartProperties.java 文件源码 项目:https-github.com-g0t4-jenkins2-course-spring-boot 阅读 42 收藏 0 点赞 0 评论 0
/**
 * Create a new {@link MultipartConfigElement} using the properties.
 * @return a new {@link MultipartConfigElement} configured using there properties
 */
public MultipartConfigElement createMultipartConfig() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    if (StringUtils.hasText(this.fileSizeThreshold)) {
        factory.setFileSizeThreshold(this.fileSizeThreshold);
    }
    if (StringUtils.hasText(this.location)) {
        factory.setLocation(this.location);
    }
    if (StringUtils.hasText(this.maxRequestSize)) {
        factory.setMaxRequestSize(this.maxRequestSize);
    }
    if (StringUtils.hasText(this.maxFileSize)) {
        factory.setMaxFileSize(this.maxFileSize);
    }
    return factory.createMultipartConfig();
}
MultipartProperties.java 文件源码 项目:spring-boot-concourse 阅读 36 收藏 0 点赞 0 评论 0
/**
 * Create a new {@link MultipartConfigElement} using the properties.
 * @return a new {@link MultipartConfigElement} configured using there properties
 */
public MultipartConfigElement createMultipartConfig() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    if (StringUtils.hasText(this.fileSizeThreshold)) {
        factory.setFileSizeThreshold(this.fileSizeThreshold);
    }
    if (StringUtils.hasText(this.location)) {
        factory.setLocation(this.location);
    }
    if (StringUtils.hasText(this.maxRequestSize)) {
        factory.setMaxRequestSize(this.maxRequestSize);
    }
    if (StringUtils.hasText(this.maxFileSize)) {
        factory.setMaxFileSize(this.maxFileSize);
    }
    return factory.createMultipartConfig();
}
SpringWebApplicationInitializer.java 文件源码 项目:bonita-ui-designer 阅读 28 收藏 0 点赞 0 评论 0
@Override
public void onStartup(ServletContext servletContext) throws ServletException {

    for (String line : BANNER) {
        logger.info(line);
    }
    logger.info(Strings.repeat("=", 100));
    logger.info(String.format("UI-DESIGNER : %s edition v.%s", prop.getProperty("designer.edition"), prop.getProperty("designer.version")));
    logger.info(Strings.repeat("=", 100));

    // Create the root context Spring
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(new Class<?>[] { ApplicationConfig.class });

    // Manage the lifecycle of the root application context
    servletContext.addListener(new ContextLoaderListener(rootContext));

    // Register and map the dispatcher servlet
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.setMultipartConfig(new MultipartConfigElement(System.getProperty("java.io.tmpdir")));
    dispatcher.setAsyncSupported(true);
    dispatcher.addMapping("/");
}
MultipartProperties.java 文件源码 项目:contestparser 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Create a new {@link MultipartConfigElement} using the properties.
 * @return a new {@link MultipartConfigElement} configured using there properties
 */
public MultipartConfigElement createMultipartConfig() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    if (StringUtils.hasText(this.fileSizeThreshold)) {
        factory.setFileSizeThreshold(this.fileSizeThreshold);
    }
    if (StringUtils.hasText(this.location)) {
        factory.setLocation(this.location);
    }
    if (StringUtils.hasText(this.maxRequestSize)) {
        factory.setMaxRequestSize(this.maxRequestSize);
    }
    if (StringUtils.hasText(this.maxFileSize)) {
        factory.setMaxFileSize(this.maxFileSize);
    }
    return factory.createMultipartConfig();
}
DispatcherServletInitializer.java 文件源码 项目:packagedrone 阅读 30 收藏 0 点赞 0 评论 0
public void start () throws ServletException, NamespaceException
{
    final BundleContext bundleContext = FrameworkUtil.getBundle ( DispatcherServletInitializer.class ).getBundleContext ();
    this.context = Dispatcher.createContext ( bundleContext );

    this.errorHandler = new ErrorHandlerTracker ();

    Dictionary<String, String> initparams = new Hashtable<> ();

    final MultipartConfigElement multipart = Servlets.createMultiPartConfiguration ( PROP_PREFIX_MP );
    final DispatcherServlet servlet = new DispatcherServlet ();
    servlet.setErrorHandler ( this.errorHandler );
    this.webContainer.registerServlet ( servlet, "dispatcher", new String[] { "/" }, initparams, 1, false, multipart, this.context );

    this.proxyFilter = new FilterTracker ( bundleContext );
    this.webContainer.registerFilter ( this.proxyFilter, new String[] { "/*" }, null, null, this.context );

    initparams = new Hashtable<> ();
    initparams.put ( "filter-mapping-dispatcher", "request" );
    this.webContainer.registerFilter ( new BundleFilter (), new String[] { "/bundle/*" }, null, initparams, this.context );

    this.jspTracker = new BundleTracker<> ( bundleContext, Bundle.INSTALLED | Bundle.ACTIVE, new JspBundleCustomizer ( this.webContainer, this.context ) );
    this.jspTracker.open ();
}
UploadLayout.java 文件源码 项目:hawkbit 阅读 30 收藏 0 点赞 0 评论 0
public UploadLayout(final VaadinMessageSource i18n, final UINotification uiNotification, final UIEventBus eventBus,
        final ArtifactUploadState artifactUploadState, final MultipartConfigElement multipartConfigElement,
        final ArtifactManagement artifactManagement, final SoftwareModuleManagement softwareManagement) {
    this.uploadInfoWindow = new UploadStatusInfoWindow(eventBus, artifactUploadState, i18n);
    this.i18n = i18n;
    this.uiNotification = uiNotification;
    this.eventBus = eventBus;
    this.artifactUploadState = artifactUploadState;
    this.multipartConfigElement = multipartConfigElement;
    this.artifactManagement = artifactManagement;
    this.softwareModuleManagement = softwareManagement;

    createComponents();
    buildLayout();
    restoreState();
    eventBus.subscribe(this);
    ui = UI.getCurrent();
}
UploadArtifactView.java 文件源码 项目:hawkbit 阅读 38 收藏 0 点赞 0 评论 0
@Autowired
UploadArtifactView(final UIEventBus eventBus, final SpPermissionChecker permChecker, final VaadinMessageSource i18n,
        final UINotification uiNotification, final ArtifactUploadState artifactUploadState,
        final EntityFactory entityFactory, final SoftwareModuleManagement softwareModuleManagement,
        final SoftwareModuleTypeManagement softwareModuleTypeManagement,
        final UploadViewClientCriterion uploadViewClientCriterion,
        final MultipartConfigElement multipartConfigElement, final ArtifactManagement artifactManagement) {
    this.eventBus = eventBus;
    this.permChecker = permChecker;
    this.i18n = i18n;
    this.uiNotification = uiNotification;
    this.artifactUploadState = artifactUploadState;
    this.filterByTypeLayout = new SMTypeFilterLayout(artifactUploadState, i18n, permChecker, eventBus,
            entityFactory, uiNotification, softwareModuleTypeManagement, uploadViewClientCriterion);
    this.smTableLayout = new SoftwareModuleTableLayout(i18n, permChecker, artifactUploadState, uiNotification,
            eventBus, softwareModuleManagement, softwareModuleTypeManagement, entityFactory,
            uploadViewClientCriterion);
    this.artifactDetailsLayout = new ArtifactDetailsLayout(i18n, eventBus, artifactUploadState, uiNotification,
            artifactManagement, softwareModuleManagement);
    this.uploadLayout = new UploadLayout(i18n, uiNotification, eventBus, artifactUploadState,
            multipartConfigElement, artifactManagement, softwareModuleManagement);
    this.deleteActionsLayout = new SMDeleteActionsLayout(i18n, permChecker, eventBus, uiNotification,
            artifactUploadState, softwareModuleManagement, softwareModuleTypeManagement, uploadViewClientCriterion);
}
ArticleApi.java 文件源码 项目:sparkjava-spike 阅读 26 收藏 0 点赞 0 评论 0
private Article processArticleAndImage(spark.Request request, String id) throws IOException, ServletException {
        request.raw().setAttribute(Request.__MULTIPART_CONFIG_ELEMENT, new MultipartConfigElement(System.getProperty("java.io.tmpdir")));
        Part articlePart = request.raw().getPart("article");
//        Article article = objectMapper.readValue(articlePart.getInputStream(), Article.class);
        Object articlePartJson = Configuration.defaultConfiguration().jsonProvider().parse(articlePart.getInputStream(), "UTF-8");
        String title = JsonPath.read(articlePartJson, "$.title");
        String body = JsonPath.read(articlePartJson, "$.body");
        Article article = new Article(title, body);
        articles.put(id, article);
        MultiPartInputStreamParser.MultiPart imagePart = (MultiPartInputStreamParser.MultiPart) request.raw().getPart("image");
        String filename = imagePart.getContentDispositionFilename();
        byte[] image = IOUtils.toByteArray(imagePart.getInputStream());
        HashMap<String, byte[]> imageMap = new HashMap<String, byte[]>() {{
            put(filename, image);
        }};
        images.put(id, imageMap);
        return article;
    }
TestStandardContext.java 文件源码 项目:class-guard 阅读 41 收藏 0 点赞 0 评论 0
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
DispatcherServletInitializer.java 文件源码 项目:package-drone 阅读 36 收藏 0 点赞 0 评论 0
public void start () throws ServletException, NamespaceException
{
    final BundleContext bundleContext = FrameworkUtil.getBundle ( DispatcherServletInitializer.class ).getBundleContext ();
    this.context = Dispatcher.createContext ( bundleContext );

    Dictionary<String, String> initparams = new Hashtable<> ();

    final MultipartConfigElement multipart = JspServletInitializer.createMultiPartConfiguration ( PROP_PREFIX_MP );
    this.webContainer.registerServlet ( new DispatcherServlet (), "dispatcher", new String[] { "/" }, initparams, 1, false, multipart, this.context );

    this.proxyFilter = new FilterTracker ( bundleContext );
    this.webContainer.registerFilter ( this.proxyFilter, new String[] { "/*" }, null, null, this.context );

    initparams = new Hashtable<> ();
    initparams.put ( "filter-mapping-dispatcher", "request" );
    this.webContainer.registerFilter ( new BundleFilter (), new String[] { "/bundle/*" }, null, initparams, this.context );

    this.jspTracker = new BundleTracker<> ( bundleContext, Bundle.INSTALLED | Bundle.ACTIVE, new JspBundleCustomizer ( this.webContainer, this.context ) );
    this.jspTracker.open ();
}
TestStandardContext.java 文件源码 项目:apache-tomcat-7.0.57 阅读 31 收藏 0 点赞 0 评论 0
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
TestStandardContext.java 文件源码 项目:apache-tomcat-7.0.57 阅读 33 收藏 0 点赞 0 评论 0
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
JettyServer.java 文件源码 项目:pippo 阅读 32 收藏 0 点赞 0 评论 0
protected ServletContextHandler createPippoHandler() {
    MultipartConfigElement multipartConfig = createMultipartConfigElement();
    ServletContextHandler handler = new PippoHandler(ServletContextHandler.SESSIONS, multipartConfig);
    handler.setContextPath(getSettings().getContextPath());

    // inject application as context attribute
    handler.setAttribute(PIPPO_APPLICATION, getApplication());

    // add pippo filter
    addPippoFilter(handler);

    // add initializers
    handler.addEventListener(new PippoServletContextListener());

    // all listeners
    listeners.forEach(listener -> {
        try {
            handler.addEventListener(listener.newInstance());
        } catch (InstantiationException | IllegalAccessException e) {
            throw new PippoRuntimeException(e);
        }
    });

    return handler;
}
AbstractWebApplicationInitializer.java 文件源码 项目:bearchoke 阅读 25 收藏 0 点赞 0 评论 0
protected void createSpringServlet(ServletContext servletContext) {
        log.info("Creating Spring Servlet started....");

        AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext();
        appContext.register(
                WebMvcConfig.class
        );

        DispatcherServlet sc = new DispatcherServlet(appContext);

        ServletRegistration.Dynamic appServlet = servletContext.addServlet("DispatcherServlet", sc);
        appServlet.setLoadOnStartup(1);
        appServlet.addMapping("/");

        // for serving up asynchronous events in tomcat
        appServlet.setInitParameter("dispatchOptionsRequest", "true");
        appServlet.setAsyncSupported(true);

        // enable multipart file upload support
        // file size limit is 10Mb
        // max file request size = 20Mb
        appServlet.setMultipartConfig(new MultipartConfigElement("/tmp", 10000000l, 20000000l, 0));

//        log.info("Creating Spring Servlet completed");
    }
FileUpload.java 文件源码 项目:Switcharoo 阅读 39 收藏 0 点赞 0 评论 0
@Override
public void register(Gson gson) {
    uploadDir.mkdir();

    post("/image", (req, res) -> {
        req.attribute("org.eclipse.jetty.multipartConfig", new MultipartConfigElement("/temp"));
        Part part = req.raw().getPart("image");
        String[] filename = getFilenameParts(part.getSubmittedFileName());
        Path tempFile = Files.createTempFile(uploadDir.toPath(), filename[0], "." + filename[1]);

        try (InputStream input = part.getInputStream()) {
            Files.copy(input, tempFile, StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            LOG.error("Error while uploading file", e);
            res.status(500);
            return "";
        }

        LOG.info("File uploaded: {}", tempFile.toString());
        res.type("application/json");
        return String.format("{\"location\":\"/%s\", \"filetype\":\"%s\"}", tempFile.toString(), getFiletype(part.getContentType()));
    });
}
TestSwallowAbortedUploads.java 文件源码 项目:WBSAirback 阅读 29 收藏 0 点赞 0 评论 0
private synchronized void init(boolean limited, boolean swallow)
        throws Exception {
    if (init)
        return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Wrapper w;
    w = Tomcat.addServlet(context, servletName,
                          new AbortedUploadServlet());
    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    // Choose upload file size limit.
    if (limited) {
        w.setMultipartConfigElement(new MultipartConfigElement("",
                limitSize, -1, -1));
    } else {
        w.setMultipartConfigElement(new MultipartConfigElement(""));
    }
    context.addServletMapping(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    tomcat.start();

    init = true;
}
TestStandardContext.java 文件源码 项目:WBSAirback 阅读 37 收藏 0 点赞 0 评论 0
private synchronized void init() throws Exception {
    if (init) return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Tomcat.addServlet(context, "regular", new Bug49711Servlet());
    Wrapper w = Tomcat.addServlet(context, "multipart", new Bug49711Servlet_multipart());

    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    w.setMultipartConfigElement(new MultipartConfigElement(""));

    context.addServletMapping("/regular", "regular");
    context.addServletMapping("/multipart", "multipart");
    tomcat.start();

    init = true;
}
ALSServingInitListener.java 文件源码 项目:oryx 阅读 31 收藏 0 点赞 0 评论 0
@Override
public void addServlets(Context context) {
  addServlet(context, new RecommendServlet(), "/recommend/*");
  addServlet(context, new RecommendToManyServlet(), "/recommendToMany/*");
  addServlet(context, new RecommendToAnonymousServlet(), "/recommendToAnonymous/*");
  addServlet(context, new SimilarityServlet(), "/similarity/*");
  addServlet(context, new SimilarityToItemServlet(), "/similarityToItem/*");
  addServlet(context, new EstimateServlet(), "/estimate/*");
  addServlet(context, new EstimateForAnonymousServlet(), "/estimateForAnonymous/*");
  addServlet(context, new BecauseServlet(), "/because/*");
  addServlet(context, new ReadyServlet(), "/ready/*");
  addServlet(context, new MostPopularItemsServlet(), "/mostPopularItems/*");
  if (!ConfigUtils.getDefaultConfig().getBoolean("serving-layer.api.read-only")) {
    addServlet(context, new PreferenceServlet(), "/pref/*");
    Wrapper ingestWrapper = addServlet(context, new IngestServlet(), "/ingest/*");
    ingestWrapper.setMultipartConfigElement(new MultipartConfigElement("/tmp"));
    addServlet(context, new RefreshServlet(), "/refresh/*");
  }
}
PersonApplication.java 文件源码 项目:personspringclouddemo 阅读 29 收藏 0 点赞 0 评论 0
@Bean
public MultipartConfigElement multipartConfigElement(){
    MultipartConfigFactory factory=new MultipartConfigFactory();
    factory.setMaxFileSize("1MB");
    factory.setMaxRequestSize("2MB");
    return factory.createMultipartConfig();
}
TestSwallowAbortedUploads.java 文件源码 项目:tomcat7 阅读 33 收藏 0 点赞 0 评论 0
private synchronized void init(boolean limited, boolean swallow)
        throws Exception {
    if (init)
        return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Wrapper w;
    w = Tomcat.addServlet(context, servletName,
                          new AbortedUploadServlet());
    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    // Choose upload file size limit.
    if (limited) {
        w.setMultipartConfigElement(new MultipartConfigElement("",
                limitSize, -1, -1));
    } else {
        w.setMultipartConfigElement(new MultipartConfigElement(""));
    }
    context.addServletMapping(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    tomcat.start();
    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
FileUploadController.java 文件源码 项目:RedisClusterManager 阅读 39 收藏 0 点赞 0 评论 0
@Bean
public MultipartConfigElement multipartConfigElement() {
    MultipartConfigFactory factory = new MultipartConfigFactory();
    factory.setMaxFileSize("128MB");
    factory.setMaxRequestSize("500MB");
    return factory.createMultipartConfig();
}
ServletContextImpl.java 文件源码 项目:lams 阅读 29 收藏 0 点赞 0 评论 0
@Override
public Void run() {
    final ServletSecurity security = servletInfo.getServletClass().getAnnotation(ServletSecurity.class);
    if (security != null) {

        ServletSecurityInfo servletSecurityInfo = new ServletSecurityInfo()
                .setEmptyRoleSemantic(security.value().value() == ServletSecurity.EmptyRoleSemantic.DENY ? SecurityInfo.EmptyRoleSemantic.DENY : SecurityInfo.EmptyRoleSemantic.PERMIT)
                .setTransportGuaranteeType(security.value().transportGuarantee() == ServletSecurity.TransportGuarantee.CONFIDENTIAL ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE)
                .addRolesAllowed(security.value().rolesAllowed());
        for (HttpMethodConstraint constraint : security.httpMethodConstraints()) {
            servletSecurityInfo.addHttpMethodSecurityInfo(new HttpMethodSecurityInfo()
                    .setMethod(constraint.value()))
                    .setEmptyRoleSemantic(constraint.emptyRoleSemantic() == ServletSecurity.EmptyRoleSemantic.DENY ? SecurityInfo.EmptyRoleSemantic.DENY : SecurityInfo.EmptyRoleSemantic.PERMIT)
                    .setTransportGuaranteeType(constraint.transportGuarantee() == ServletSecurity.TransportGuarantee.CONFIDENTIAL ? TransportGuaranteeType.CONFIDENTIAL : TransportGuaranteeType.NONE)
                    .addRolesAllowed(constraint.rolesAllowed());
        }
        servletInfo.setServletSecurityInfo(servletSecurityInfo);
    }
    final MultipartConfig multipartConfig = servletInfo.getServletClass().getAnnotation(MultipartConfig.class);
    if (multipartConfig != null) {
        servletInfo.setMultipartConfig(new MultipartConfigElement(multipartConfig.location(), multipartConfig.maxFileSize(), multipartConfig.maxRequestSize(), multipartConfig.fileSizeThreshold()));
    }
    final RunAs runAs = servletInfo.getServletClass().getAnnotation(RunAs.class);
    if (runAs != null) {
        servletInfo.setRunAs(runAs.value());
    }
    final DeclareRoles declareRoles = servletInfo.getServletClass().getAnnotation(DeclareRoles.class);
    if (declareRoles != null) {
        deploymentInfo.addSecurityRoles(declareRoles.value());
    }
    return null;
}
Application.java 文件源码 项目:uckefu 阅读 31 收藏 0 点赞 0 评论 0
@Bean   
public MultipartConfigElement multipartConfigElement() {   
        MultipartConfigFactory factory = new MultipartConfigFactory();  
        factory.setMaxFileSize("50MB"); //KB,MB  
        factory.setMaxRequestSize("100MB");   
        return factory.createMultipartConfig();   
}
TestSwallowAbortedUploads.java 文件源码 项目:apache-tomcat-7.0.73-with-comment 阅读 30 收藏 0 点赞 0 评论 0
private synchronized void init(boolean limited, boolean swallow)
        throws Exception {
    if (init)
        return;

    Tomcat tomcat = getTomcatInstance();
    context = tomcat.addContext("", TEMP_DIR);
    Wrapper w;
    w = Tomcat.addServlet(context, servletName,
                          new AbortedUploadServlet());
    // Tomcat.addServlet does not respect annotations, so we have
    // to set our own MultipartConfigElement.
    // Choose upload file size limit.
    if (limited) {
        w.setMultipartConfigElement(new MultipartConfigElement("",
                limitSize, -1, -1));
    } else {
        w.setMultipartConfigElement(new MultipartConfigElement(""));
    }
    context.addServletMapping(URI, servletName);
    context.setSwallowAbortedUploads(swallow);

    tomcat.start();
    setPort(tomcat.getConnector().getLocalPort());

    init = true;
}
JettyServer.java 文件源码 项目:GroupControlDroidClient 阅读 35 收藏 0 点赞 0 评论 0
public void run() {
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletContextHandler.setContextPath("/");
    servletContextHandler.setResourceBase("./res");
    servletContextHandler.addFilter(CommonFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));//增加过滤器
    servletContextHandler.addServlet(LoginServlet.class, "/login.cgi");
    servletContextHandler.addServlet(UserinfoServlet.class, "/userinfo.cgi");
    servletContextHandler.addServlet(FileBrowseServlet.class, "/file_browse.cgi");
    servletContextHandler.addServlet(DefaultServlet.class, "/");
    servletContextHandler.addServlet(ChangePassword.class, "/changepassword.cgi");
    servletContextHandler.addServlet(AddDeviceToGroupServlet.class, "/device/add_device_to_group.cgi");
    servletContextHandler.addServlet(AddGroupServlet.class, "/group/add_group.cgi");
    servletContextHandler.addServlet(GetGroupsServlet.class , "/group/get_groups.cgi");
    servletContextHandler.addServlet(EditGroupServlet.class, "/group/edit_group.cgi");
    servletContextHandler.addServlet(GetAllGroupsServlet.class, "/group/get_all_groups.cgi");
    servletContextHandler.addServlet(DeteleGroupServlet.class, "/group/delete_group.cgi");
    servletContextHandler.addServlet(AddDeviceToGroupServlet.class, "/group/add_device_to_group.cgi");
    servletContextHandler.addServlet(DeleteDeviceFromGroupServlet.class,"/group/delete_device_from_group.cgi");

    ServletHolder fileUploadServletHolder = new ServletHolder(new UploadServlet());
    fileUploadServletHolder.getRegistration().setMultipartConfig(new MultipartConfigElement(System.getProperty("user.dir") +JettyConfig.UPLOAD_TMP_PATH));
    servletContextHandler.addServlet(fileUploadServletHolder, "/upload.cgi");

    servletContextHandler.setClassLoader(Thread.currentThread().getContextClassLoader());

       server.setHandler(servletContextHandler);
       try {
        server.start();
        server.join();

    } catch (Exception e) {
        logger.error("",e);
    }
}


问题


面经


文章

微信
公众号

扫码关注公众号