List of usage examples for javax.servlet MultipartConfigElement MultipartConfigElement
public MultipartConfigElement(MultipartConfig annotation)
From source file:com.crushpaper.Servlet.java
/** * Creates the context that handle HTTP requests. * /*from w ww .j a va2 s .c o m*/ * @throws IOException */ public ContextHandlerCollection createContexts(File temporaryDirectory, File sessionStoreDirectory) throws IOException { // Enable HTTP session tracking with cookies. final ExposedShutdownServletContextHandler htmlJsonContext = new ExposedShutdownServletContextHandler( ServletContextHandler.SESSIONS); if (sessionStoreDirectory != null) { sessionManager = ((ExposedShutdownHashSessionManager) htmlJsonContext.getSessionHandler() .getSessionManager()); sessionManager.setStoreDirectory(sessionStoreDirectory); sessionManager.setSavePeriod(30); } htmlJsonContext.setContextPath("/"); // Enable uploading files. final ServletHolder holder = new ServletHolder(this); holder.getRegistration().setMultipartConfig(new MultipartConfigElement(temporaryDirectory.getPath())); htmlJsonContext.addServlet(holder, "/"); // Get the location static files will be served from. final URL location = Servlet.class.getProtectionDomain().getCodeSource().getLocation(); final File installRootDirectory = new File(location.getFile()); isInJar = getClassResourceName().startsWith("jar:"); int dynamicContexExpiresInSeconds = 2 * 60; final ContextHandler cssContextHandler = createContextHandler("css", isInJar, installRootDirectory, dynamicContexExpiresInSeconds); final ContextHandler jsContextHandler = createContextHandler("js", isInJar, installRootDirectory, dynamicContexExpiresInSeconds); final ContextHandler imagesContextHandler = createContextHandler("images", isInJar, installRootDirectory, 3600); helpDirectoryResource = getDirectoryResource("doc", isInJar, installRootDirectory); // Create a ContextHandlerCollection and set the context handlers to it. final ContextHandlerCollection contextHandlers = new ContextHandlerCollection(); contextHandlers.setHandlers( new Handler[] { imagesContextHandler, jsContextHandler, cssContextHandler, htmlJsonContext }); return contextHandlers; }
From source file:org.codice.ddf.catalog.ui.metacard.ListApplication.java
@Override public void init() { post("/list/import", (request, response) -> { MultipartConfigElement multipartConfigElement = new MultipartConfigElement(""); request.raw().setAttribute("org.eclipse.jetty.multipartConfig", multipartConfigElement); String listType = request.headers(LIST_TYPE_HEADER); if (StringUtils.isBlank(listType)) { String exceptionMessage = String.format("The header %s must be set.", LIST_TYPE_HEADER); LOGGER.info(exceptionMessage); createBadRequestResponse(exceptionMessage, response); return null; }//from w ww.j av a 2s .c om List<Part> parts = new ArrayList<>(request.raw().getParts()); Map.Entry<AttachmentInfo, Metacard> attachmentInfo = catalogService.parseParts(parts, null); if (attachmentInfo == null) { String exceptionMessage = "Unable to parse the attachments."; LOGGER.debug(exceptionMessage); createBadRequestResponse(exceptionMessage, response); return null; } try (TemporaryFileBackedOutputStream temporaryFileBackedOutputStream = new TemporaryFileBackedOutputStream()) { IOUtils.copy(attachmentInfo.getKey().getStream(), temporaryFileBackedOutputStream); for (Splitter splitter : lookupSplitters(attachmentInfo.getKey().getContentType())) { try { if (attemptToSplitAndStore(response, listType, attachmentInfo, temporaryFileBackedOutputStream, splitter)) break; } catch (StopSplitterExecutionException e) { LOGGER.debug("Failed to split file.", e); createBadRequestResponse("Attached files do not contain the correct mimetypes", response); return null; } } } IOUtils.closeQuietly(attachmentInfo.getKey().getStream()); return ""; }); }