use of cn.taketoday.web.multipart.MultipartConfiguration in project today-framework by TAKETODAY.
the class LightRequestContext method getRequestParts.
/**
* @throws FileSizeExceededException
*/
private List<RequestPart> getRequestParts() {
if (requestParts == null) {
try {
final long contentLength = getContentLength();
final LightHttpConfig config = this.config;
final MultipartConfiguration multipartConfig = config.getMultipartConfig();
if (contentLength > multipartConfig.getMaxRequestSize().toBytes()) {
throw new FileSizeExceededException(multipartConfig.getMaxRequestSize(), null).setActual(DataSize.ofBytes(contentLength));
}
final MultipartIterator multipartIterator = new MultipartIterator(request);
final MultipartInputStream inputStream = multipartIterator.getInputStream();
final ArrayList<RequestPart> parts = new ArrayList<>();
while (multipartIterator.hasNext(inputStream)) {
parts.add(multipartIterator.obtainNext(config, multipartConfig));
}
requestParts = parts;
} catch (IOException e) {
throw new MultipartException("multipart read failed", e);
}
}
return requestParts;
}
use of cn.taketoday.web.multipart.MultipartConfiguration in project today-framework by TAKETODAY.
the class WebApplicationLoader method configureParameterResolving.
/**
* Configure {@link ParameterResolvingStrategy}s to resolve handler method arguments
*
* @param customizedStrategies Resolvers registry
* @param mvcConfiguration All {@link WebMvcConfiguration} object
*/
protected void configureParameterResolving(List<ParameterResolvingStrategy> customizedStrategies, WebMvcConfiguration mvcConfiguration) {
WebApplicationContext context = obtainApplicationContext();
ParameterResolvingRegistry registry = context.getBean(ParameterResolvingRegistry.class);
Assert.state(registry != null, "No ParameterResolvingRegistry in context");
// user customize multipartConfig
MultipartConfiguration multipartConfig = context.getBean(MultipartConfiguration.class);
mvcConfiguration.configureMultipart(multipartConfig);
// User customize parameter resolver
// ------------------------------------------
// user configure
mvcConfiguration.configureParameterResolving(registry, customizedStrategies);
registry.getCustomizedStrategies().add(customizedStrategies);
}
use of cn.taketoday.web.multipart.MultipartConfiguration in project today-framework by TAKETODAY.
the class DispatcherServletInitializer method configureMultipart.
@Override
protected void configureMultipart(Dynamic registration) {
MultipartConfigElement multipartConfig = getMultipartConfig();
if (multipartConfig == null) {
MultipartConfiguration configuration = getApplicationContext().getBean(MultipartConfiguration.class);
if (configuration != null) {
multipartConfig = new MultipartConfigElement(configuration.getLocation(), configuration.getMaxFileSize().toBytes(), configuration.getMaxRequestSize().toBytes(), (int) configuration.getFileSizeThreshold().toBytes());
log.info("configure dispatcher-servlet multipart: {}", configuration);
}
}
setMultipartConfig(multipartConfig);
super.configureMultipart(registration);
}
Aggregations