當前位置: 首頁>>代碼示例>>Java>>正文


Java MultipartConfigElement類代碼示例

本文整理匯總了Java中javax.servlet.MultipartConfigElement的典型用法代碼示例。如果您正苦於以下問題:Java MultipartConfigElement類的具體用法?Java MultipartConfigElement怎麽用?Java MultipartConfigElement使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MultipartConfigElement類屬於javax.servlet包,在下文中一共展示了MultipartConfigElement類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addApplication

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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, "/*");
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:23,代碼來源:Minijax.java

示例2: handle

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
@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);
  }
}
 
開發者ID:GoogleCloudPlatform,項目名稱:google-cloud-eclipse,代碼行數:26,代碼來源:TestHttpServer.java

示例3: init

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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;
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:21,代碼來源:TestStandardContext.java

示例4: multipartConfigElement

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
@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();
}
 
開發者ID:oembedler,項目名稱:graphql-spring-boot,代碼行數:18,代碼來源:GraphQLWebAutoConfiguration.java

示例5: createMultipartConfig

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
/**
 * 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();
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:21,代碼來源:MultipartProperties.java

示例6: onStartup

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
@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("/");
}
 
開發者ID:bonitasoft,項目名稱:bonita-ui-designer,代碼行數:25,代碼來源:SpringWebApplicationInitializer.java

示例7: containerWithAutomatedMultipartUndertowConfiguration

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
@Test
public void containerWithAutomatedMultipartUndertowConfiguration() {
	this.context = new AnnotationConfigEmbeddedWebApplicationContext(
			ContainerWithEverythingUndertow.class, BaseConfiguration.class);
	this.context.getBean(MultipartConfigElement.class);
	verifyServletWorks();
	assertSame(this.context.getBean(DispatcherServlet.class).getMultipartResolver(),
			this.context.getBean(StandardServletMultipartResolver.class));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:10,代碼來源:MultipartAutoConfigurationTests.java

示例8: start

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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 ();
}
 
開發者ID:eclipse,項目名稱:packagedrone,代碼行數:25,代碼來源:DispatcherServletInitializer.java

示例9: UploadLayout

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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();
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:19,代碼來源:UploadLayout.java

示例10: UploadArtifactView

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
@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);
}
 
開發者ID:eclipse,項目名稱:hawkbit,代碼行數:25,代碼來源:UploadArtifactView.java

示例11: processArticleAndImage

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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;
    }
 
開發者ID:halvards,項目名稱:sparkjava-spike,代碼行數:19,代碼來源:ArticleApi.java

示例12: start

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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 ();
}
 
開發者ID:ctron,項目名稱:package-drone,代碼行數:21,代碼來源:DispatcherServletInitializer.java

示例13: createPippoHandler

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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;
}
 
開發者ID:decebals,項目名稱:pippo,代碼行數:26,代碼來源:JettyServer.java

示例14: createSpringServlet

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
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");
    }
 
開發者ID:bjornharvold,項目名稱:bearchoke,代碼行數:26,代碼來源:AbstractWebApplicationInitializer.java

示例15: register

import javax.servlet.MultipartConfigElement; //導入依賴的package包/類
@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()));
    });
}
 
開發者ID:javaBin,項目名稱:Switcharoo,代碼行數:24,代碼來源:FileUpload.java


注:本文中的javax.servlet.MultipartConfigElement類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。