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, "/*"); }
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; }
@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); } }
@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(); }
/** * 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(); }
@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("/"); }
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 (); }
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(); }
@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); }
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; }
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 (); }
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; }
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"); }
@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())); }); }
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; }
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; }
@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/*"); } }
@Bean public MultipartConfigElement multipartConfigElement(){ MultipartConfigFactory factory=new MultipartConfigFactory(); factory.setMaxFileSize("1MB"); factory.setMaxRequestSize("2MB"); return factory.createMultipartConfig(); }
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; }
@Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize("128MB"); factory.setMaxRequestSize("500MB"); return factory.createMultipartConfig(); }
@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; }
@Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize("50MB"); //KB,MB factory.setMaxRequestSize("100MB"); return factory.createMultipartConfig(); }
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); } }
@Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize("10MB"); factory.setMaxRequestSize("10MB"); return factory.createMultipartConfig(); }
@Bean public MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize("5MB"); factory.setMaxRequestSize("5MB"); return factory.createMultipartConfig(); }
/** * Parses a multipart request and returns a Map with the parsed Parts as values and the parts names as keys. *Folder - The files will be saved in this folder. *MaxSize - The request maximum size. */ public Map GetMultipartData(String Folder, long MaxSize) throws IOException, ServletException { MultipartConfigElement config = new MultipartConfigElement(Folder, MaxSize, MaxSize, 81920); MultiPartInputStreamParser in = new MultiPartInputStreamParser(getObject().getInputStream(), getObject().getContentType(), config, new File(Folder)); Collection<Part> parts = in.getParts(); Map m = new Map(); m.Initialize(); for (Part p : parts) { MultiPartInputStreamParser.MultiPart mp = (MultiPartInputStreamParser.MultiPart)p; m.Put(mp.getName(), mp); } return m; }
@Override protected void customizeRegistration(ServletRegistration.Dynamic registration) { String location = "/tmp"; long maxFileSize = 2097152; long maxRequestSize = 4194304; int fileSizeThreshold = 0; registration.setMultipartConfig( new MultipartConfigElement(location, maxFileSize, maxRequestSize, fileSizeThreshold)); }
@Bean public MultipartConfigElement multipartConfigElement(){ MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize("256MB"); factory.setMaxRequestSize("256MB"); return factory.createMultipartConfig(); }
@Bean public MultipartConfigElement multipartConfigElement(){ MultipartConfigFactory factory = new MultipartConfigFactory(); factory.setMaxFileSize("10MB"); factory.setMaxRequestSize("10MB"); return factory.createMultipartConfig(); }
@Override public void startUp(ServletContext servletContext) { if (servletContext != null) { String servletName = "MCRUploadViaFormServlet"; MultipartConfigElement multipartConfig = getMultipartConfig(); try { checkTempStoragePath(multipartConfig.getLocation()); } catch (IOException e) { throw new MCRConfigurationException("Could not setup " + servletName + "!", e); } Dynamic uploadServlet = servletContext.addServlet(servletName, MCRUploadViaFormServlet.class); uploadServlet.addMapping("/servlets/MCRUploadViaFormServlet"); uploadServlet.setMultipartConfig(multipartConfig); } }
private MultipartConfigElement getMultipartConfig() { String location = MCRConfiguration2.getStringOrThrow(MCR_FILE_UPLOAD_TEMP_STORAGE_PATH); long maxFileSize = MCRConfiguration2.getLong("MCR.FileUpload.MaxSize").orElse(5000000L); int fileSizeThreshold = MCRConfiguration2.getInt("MCR.FileUpload.MemoryThreshold").orElse(1000000); LogManager.getLogger() .info(() -> MCRUploadViaFormServlet.class.getSimpleName() + " accept files and requests up to " + maxFileSize + " bytes and uses " + location + " as tempory storage for files larger " + fileSizeThreshold + " bytes."); return new MultipartConfigElement(location, maxFileSize, maxFileSize, fileSizeThreshold); }
@BeforeClass public static void startServer() throws Exception { // Let server pick its own random, available port. server = new Server(0); ServletContextHandler handler = new ServletContextHandler(); handler.setContextPath("/"); Class<?> config = CommonsMultipartResolverTestConfig.class; ServletHolder commonsResolverServlet = new ServletHolder(DispatcherServlet.class); commonsResolverServlet.setInitParameter("contextConfigLocation", config.getName()); commonsResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); handler.addServlet(commonsResolverServlet, "/commons-resolver/*"); config = StandardMultipartResolverTestConfig.class; ServletHolder standardResolverServlet = new ServletHolder(DispatcherServlet.class); standardResolverServlet.setInitParameter("contextConfigLocation", config.getName()); standardResolverServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); standardResolverServlet.getRegistration().setMultipartConfig(new MultipartConfigElement("")); handler.addServlet(standardResolverServlet, "/standard-resolver/*"); server.setHandler(handler); server.start(); Connector[] connectors = server.getConnectors(); NetworkConnector connector = (NetworkConnector) connectors[0]; baseUrl = "http://localhost:" + connector.getLocalPort(); }