Reputation: 165
I have a web application (Java / spring / hibernate) running in production on Tomcat7.
I manage to upload files easily but now I need to be able to upload large files (I have a 36MB file to upload).
Whenever I upload a large file I get 405 (Method Not Allowed) error
The log show the following lines:
415157 2014-11-19 14:53:03,662 INFO [http-bio-443-exec-52] com.eloan.controller.api.UploadFileController WFPIRSUM.PRN uploaded!
428860 2014-11-19 14:53:17,365 WARN [http-bio-443-exec-52] org.springframework.web.servlet.PageNotFound Request method 'POST' not supported
The first line is from my code:
@RequestMapping(value = "/boi", method = RequestMethod.POST)
@CheckSessionAnnotation(type = 99)
@ResponseBody
public Integer upload(MultipartHttpServletRequest request, HttpServletResponse response) throws E000EloanException {
LenderDetails anss = usService.getCurrentUserLenderDetails();
int totalLines = 0;
if (null == anss) { // user not in session...
throw new E666UserNotInSessionException("User not in Session");
}
// this is a fix for IE
response.setContentType("text/html");
// 1. build an iterator
Iterator<String> itr = request.getFileNames();
MultipartFile mpf = null;
String doc_type = request.getParameter("doc_type");
List<String> lines = new ArrayList<String>();
// 2. get each file
while (itr.hasNext()) {
mpf = request.getFile(itr.next());
LOG.info(mpf.getOriginalFilename() + " uploaded! ");
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(mpf.getInputStream(), "Windows-1255"));
String line = null;
while ((line = reader.readLine()) != null) {
// LOG.info("read [" + line + "] doc_tyep [" + doc_type +
// "]");
lines.add(line);
// boiService.addBankOfIsraelEntry(line, doc_type);
totalLines++;
}
} catch (IOException e) {
LOG.error("File upload error for ", e);
throw new E107IllegalCallException("File Upload Error");
}
} ...
In order to support large files I've tried the following (set the max size in the multipart config as annotation and as function call:
@EnableWebMvc
@Configuration
@EnableAsync
@MultipartConfig(maxFileSize = 52428800)
public class EloanApiWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
/**
* Supports FileUploads.
*/
@Bean
public MultipartResolver multipartResolver() {
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
multipartResolver.setMaxUploadSize(52428800);
return multipartResolver;
}
}
I've tried to set it in the server.xml connector:
<Connector port="443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true" maxPostSize="52428800"
keystoreFile="/var/lib/tomcat7/conf/keystore" keystorePass="Lj6xK8sk"
clientAuth="false" sslProtocol="TLS" server="eLoanSecureBSD-Server" />
And in the web.xml file:
<multipart-config>
<max-file-size>52428800</max-file-size>
<max-request-size>52428800</max-request-size>
<file-size-threshold>52428800</file-size-threshold>
</multipart-config>
It won't work!
BTW - when I run in eclipse (using JETTY server from a main) it runs perfectly without any issues...
Thank guys!
Upvotes: 0
Views: 5201
Reputation: 165
At the end the problem was simply with the memory configuration of the Tomcat. I was getting out of memory exception that I didnt C in the logs until I've set the org.springframework logs to debug (really can't understand why it was the situation).
After giving the process more memory it simply started to work well.
I'm adding here the log that I've seen if its interest any one...
112361 2014-11-19 16:23:42,500 INFO [http-bio-443-exec-22] com.eloan.controller.api.UploadFileController wfpirsum.zip uploaded!
120026 2014-11-19 16:23:50,165 DEBUG [http-bio-443-exec-22] org.springframework.web.multipart.commons.CommonsMultipartResolver Cleaning up multipart file [files[]] with original filename [wfpirsum.zip], stored at [/var/lib/tomcat7/work/Catalina/localhost/_/upload_54d020ea_b425_473f_a2c7_3dc7d8d4a330_00000001.tmp]
120043 2014-11-19 16:23:50,182 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.DispatcherServlet Could not complete request
org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.OutOfMemoryError: Java heap space
at org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1259) ~[spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945) ~[spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856) ~[spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:915) [spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:822) [spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:646) [tomcat-servlet-api-3.0.jar:na]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:796) [spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727) [tomcat-servlet-api-3.0.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:610) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) [tomcat-catalina-7.0.52.jar:7.0.52]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040) [tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607) [tomcat-coyote-7.0.52.jar:7.0.52]
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315) [tomcat-coyote-7.0.52.jar:7.0.52]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_65]
at java.lang.Thread.run(Thread.java:745) [na:1.7.0_65]
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:2694) ~[na:1.7.0_65]
at java.lang.String.<init>(String.java:203) ~[na:1.7.0_65]
at java.io.BufferedReader.readLine(BufferedReader.java:349) ~[na:1.7.0_65]
at java.io.BufferedReader.readLine(BufferedReader.java:382) ~[na:1.7.0_65]
at com.eloan.controller.api.UploadFileController.uploadBankOfIsrael(UploadFileController.java:91) ~[UploadFileController.class:na]
at com.eloan.controller.api.UploadFileController$$FastClassByCGLIB$$aa339559.invoke(<generated>) ~[spring-core-3.2.0.RELEASE.jar:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:698) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at com.eloan.aspect.CheckSessionAspect.checkSession(CheckSessionAspect.java:53) ~[CheckSessionAspect.class:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_65]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_65]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:610) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:161) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:90) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631) ~[spring-aop-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at com.eloan.controller.api.UploadFileController$$EnhancerByCGLIB$$9a9d7ba.uploadBankOfIsrael(<generated>) ~[spring-core-3.2.0.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_65]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_65]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_65]
at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_65]
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132) ~[spring-web-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104) ~[spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:746) ~[spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:687) ~[spring-webmvc-3.2.0.RELEASE.jar:3.2.0.RELEASE]
120056 2014-11-19 16:23:50,195 DEBUG [QuartzScheduler_quartzScheduler-ip-10-101-11-1001416406956159_ClusterManager] org.springframework.jdbc.datasource.DataSourceUtils Returning JDBC Connection to DataSource
120056 2014-11-19 16:23:50,195 DEBUG [QuartzScheduler_quartzScheduler-ip-10-101-11-1001416406956159_ClusterManager] org.springframework.scheduling.quartz.LocalDataSourceJobStore ClusterManager: Check-in complete.
120089 2014-11-19 16:23:50,228 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.DispatcherServlet DispatcherServlet with name 'appServlet' processing POST request for [/404.html]
120089 2014-11-19 16:23:50,228 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping Looking up handler method for path /404.html
120103 2014-11-19 16:23:50,242 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping Did not find handler method for [/404.html]
120104 2014-11-19 16:23:50,243 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Matching patterns for request [/404.html] are [/*.html]
120104 2014-11-19 16:23:50,243 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping URI Template variables for request [/404.html] are {}
120104 2014-11-19 16:23:50,243 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.handler.SimpleUrlHandlerMapping Mapping [/404.html] to HandlerExecutionChain with handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@507f1f06] and 1 interceptor
120105 2014-11-19 16:23:50,244 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver Resolving exception from handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@507f1f06]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
120106 2014-11-19 16:23:50,245 DEBUG [http-bio-443-exec-22] org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver Resolving exception from handler [org.springframework.web.servlet.resource.ResourceHttpRequestHandler@507f1f06]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
120106 2014-11-19 16:23:50,245 WARN [http-bio-443-exec-22] org.springframework.web.servlet.PageNotFound Request method 'POST' not supported
Upvotes: 0