E aí galera blz. Não estou conseguindo tratar essa exception abaixo, que ultrapassa o limite que eu setei para o tamanho máximo de upload que é de 7 mb. Abaixo minhas classes. Desde já agradeço.
15:10:47,187 WARN MultipartRequestInterceptor:73 - There was some problem parsing this multipart request, or someone is not sending a RFC1867 compatible multipart request.
org.apache.commons.fileupload.FileUploadBase$SizeLimitExceededException: the request was rejected because its size (9788668) exceeds the configured maximum (7340032)
at org.apache.commons.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:310)
at org.apache.commons.fileupload.servlet.ServletFileUpload.parseRequest(ServletFileUpload.java:116)
at br.com.radio.interceptor.MultipartRequestInterceptor.intercept(MultipartRequestInterceptor.java:70)
at org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
at br.com.radio.interceptor.DaoInterceptor.intercept(DaoInterceptor.java:20)
at org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
at br.com.radio.logic.AutorizadorInterceptor.intercept(AutorizadorInterceptor.java:34)
at org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
at org.vraptor.interceptor.FlashScopeInterceptor.intercept(FlashScopeInterceptor.java:22)
at org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
at org.vraptor.interceptor.RegisterAttributesInteceptor.intercept(RegisterAttributesInteceptor.java:38)
at org.vraptor.core.InterceptorsLogicFlow.execute(InterceptorsLogicFlow.java:72)
at org.vraptor.core.VRaptorExecution.execute(VRaptorExecution.java:98)
at org.vraptor.core.DefaultController.execute(DefaultController.java:46)
at org.vraptor.VRaptorServlet.service(VRaptorServlet.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)
MultipartRequestInterceptor
[code]package br.com.radio.interceptor;
import java.io.File;
import java.io.IOException;
import java.util.List;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.log4j.Logger;
import org.apache.tomcat.jni.Directory;
import org.vraptor.Interceptor;
import org.vraptor.LogicException;
import org.vraptor.LogicFlow;
import org.vraptor.http.VRaptorServletRequest;
import org.vraptor.interceptor.BasicUploadedFileInformation;
import org.vraptor.interceptor.UploadedFileInformation;
import org.vraptor.view.ViewException;
/**
-
Interceptor capable of parsing the input stream.
-
@author Guilherme Silveira
-
@author Paulo Silveira
*/
public class MultipartRequestInterceptor implements Interceptor {
private static final Logger LOG = Logger.getLogger(MultipartRequestInterceptor.class);private final File temporaryDirectory;
private final File mydir = new File(“C:/musicas”);private final long sizeLimit;
public MultipartRequestInterceptor() throws IOException {
this.sizeLimit = 7 * 1024 * 1024;
// this directory must be configurable through the properties
this.temporaryDirectory = File.createTempFile(“musica”, “.mp3”, mydir).getParentFile();
}@SuppressWarnings(“unchecked”)
public void intercept(LogicFlow flow) throws LogicException, ViewException {if (!ServletFileUpload.isMultipartContent(flow.getLogicRequest().getRequest())) { flow.execute(); return; } VRaptorServletRequest servletRequest = (VRaptorServletRequest) flow.getLogicRequest().getRequest(); LOG.debug("Trying to parse multipart request."); // Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(4096 * 16, this.temporaryDirectory); LOG.debug("Using repository [" + factory.getRepository() + "]"); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // TODO: variables in raptor.properties upload.setSizeMax(sizeLimit); List<FileItem> fileItems; // assume we know there are two files. The first file is a small // text file, the second is unknown and is written to a file on // the server try { fileItems = upload.parseRequest(servletRequest); } catch (FileUploadException e) { LOG .warn( "There was some problem parsing this multipart request, or someone is not sending a RFC1867 compatible multipart request.", e); flow.execute(); return; } if (LOG.isDebugEnabled()) { LOG.debug("Found [" + fileItems.size() + "] attributes in the multipart form submission. Parsing them."); } for (FileItem item : fileItems) { if (item.isFormField()) { servletRequest.overwriteParameters(item.getFieldName(), item.getString()); } else { if (!item.getName().trim().equals("")) { try { File file = File.createTempFile("musica.", ".mp3", mydir); System.out.println("----> "+file); file.deleteOnExit(); item.write(file); UploadedFileInformation fileInformation = new BasicUploadedFileInformation(file, item.getName(), item.getContentType()); servletRequest.setAttribute(item.getFieldName(), fileInformation); LOG.info("Uploaded file: " + item.getFieldName() + " with " + fileInformation); } catch (Exception e) { LOG.error("Nasty uploaded file " + item.getName(), e); } } else { LOG.info("A file field was empy: " + item.getFieldName()); } } } flow.execute(); // should we delete the temporary files afterwards or onExit as done by // now? // maybe also a config in .properties
}
}[/code]
MusicaLogic
[code]@In(required=false)
private UploadedFileInformation arquivo;
@Validate(params={"musica"})
public String adiciona(Musica musica) {
try{
File uploadedFile = arquivo.getFile();
String arquivo1 = uploadedFile.getAbsolutePath();
if (uploadedFile.getAbsoluteFile().length()== 0){
return "erro";
}
Session session = HibernateUtil.getSession();
Transaction tx = session.beginTransaction();
musica.setArtista(musica.getArtista());
musica.setTitulo(musica.getTitulo());
musica.setDisco(arquivo1);
musica.setUsuario(musica.getUsuario());
session.save(musica);
tx.commit();
session.close();
return "ok";
}
catch (HibernateException e ){
return "invalido";
}
}
[/code]