本文整理汇总了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, "/*");
}
示例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);
}
}
示例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;
}
示例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();
}
示例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("/");
}
示例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));
}
示例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 ();
}
示例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();
}
示例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);
}
示例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;
}
示例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 ();
}
示例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;
}
示例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");
}
示例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()));
});
}