Author: echatellier Date: 2013-04-10 14:35:43 +0200 (Wed, 10 Apr 2013) New Revision: 1111 Url: http://forge.codelutin.com/projects/coser/repository/revisions/1111 Log: fixes #2280: POST request must have a Content-Length header Added: trunk/coser-business/src/main/java/fr/ifremer/coser/util/InputStreamKnownSizeBody.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java Modified: trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2013-03-05 16:56:50 UTC (rev 1110) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/services/WebService.java 2013-04-10 12:35:43 UTC (rev 1111) @@ -5,7 +5,7 @@ * $Id$ * $HeadURL$ * %% - * Copyright (C) 2010 - 2012 Ifremer, Codelutin, Chatellier Eric + * Copyright (C) 2010 - 2013 Ifremer, Codelutin, Chatellier Eric * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -76,7 +76,6 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.HttpMultipartMode; import org.apache.http.entity.mime.MultipartEntity; -import org.apache.http.entity.mime.content.InputStreamBody; import org.apache.http.entity.mime.content.StringBody; import org.apache.http.impl.client.DefaultHttpClient; import org.nuiton.util.FileUtil; @@ -99,6 +98,7 @@ import fr.ifremer.coser.storage.DataStorage; import fr.ifremer.coser.storage.MemoryDataStorage; import fr.ifremer.coser.util.DataType; +import fr.ifremer.coser.util.InputStreamKnownSizeBody; import fr.ifremer.coser.util.ProgressMonitor; import fr.ifremer.coser.util.ProgressStream; import freemarker.cache.ClassTemplateLoader; @@ -456,7 +456,8 @@ // file param ProgressStream stream = new ProgressStream(new FileInputStream(prepareZip), progress); - InputStreamBody fileBody = new InputStreamBody(stream, "application/zip", prepareZip.getName()); + InputStreamKnownSizeBody fileBody = new InputStreamKnownSizeBody(stream, prepareZip.length(), + "application/zip", prepareZip.getName()); reqEntity.addPart("resultFile", fileBody); HttpPost httppost = new HttpPost(config.getWebUploadURL()); Added: trunk/coser-business/src/main/java/fr/ifremer/coser/util/InputStreamKnownSizeBody.java =================================================================== --- trunk/coser-business/src/main/java/fr/ifremer/coser/util/InputStreamKnownSizeBody.java (rev 0) +++ trunk/coser-business/src/main/java/fr/ifremer/coser/util/InputStreamKnownSizeBody.java 2013-04-10 12:35:43 UTC (rev 1111) @@ -0,0 +1,67 @@ +/* + * #%L + * Coser :: Business + * $Id$ + * $HeadURL$ + * %% + * Copyright (C) 2013 Ifremer, Codelutin, Chatellier Eric + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +package fr.ifremer.coser.util; + +import java.io.InputStream; + +import org.apache.http.entity.mime.content.InputStreamBody; + +/** + * Override of apache httpcomponent's InputStreamBody to fix content length of + * input stream. + * + * Otherwize, this result in request blocked by modsecurity. + * + * See : http://www.radomirml.com/blog/2009/02/13/file-upload-with-httpcomponents-suc... + * + * @author echatellier + * @since 1.4.2 + */ +public class InputStreamKnownSizeBody extends InputStreamBody { + + /** Input stream length. */ + private long lenght; + + /** + * Constructor with length. + * + * @param in input stream + * @param lenght length + * @param mimeType mime type + * @param filename file name + */ + public InputStreamKnownSizeBody(InputStream in, long lenght, String mimeType, String filename) { + super(in, mimeType, filename); + this.lenght = lenght; + } + + /** + * {@inheritDoc} + */ + @Override + public long getContentLength() { + return this.lenght; + } +} Property changes on: trunk/coser-business/src/main/java/fr/ifremer/coser/util/InputStreamKnownSizeBody.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision HeadURL