You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Oleg Kalnichevski (JIRA)" <ji...@apache.org> on 2012/10/04 17:47:47 UTC

[jira] [Resolved] (HTTPCLIENT-1243) Processing Multipart Response entity - BUG

     [ https://issues.apache.org/jira/browse/HTTPCLIENT-1243?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oleg Kalnichevski resolved HTTPCLIENT-1243.
-------------------------------------------

    Resolution: Invalid

You could use MultipartEntity shipped with HttpClient [1] or use Apache Mime4J [2]

Oleg

[1] http://hc.apache.org/httpcomponents-client-ga/httpmime/apidocs/org/apache/http/entity/mime/MultipartEntity.html
[2] http://james.apache.org/mime4j/index.html
                
> Processing Multipart Response entity - BUG
> ------------------------------------------
>
>                 Key: HTTPCLIENT-1243
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1243
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>          Components: HttpClient, HttpMime
>    Affects Versions: 4.2.1
>         Environment: HttpClient 4.2.1, 
>            Reporter: thebti
>              Labels: patch
>
> Hi, I've upgraded my code from Http Commons to HttpClient 4.2.1. My code worked well tell this event. I got an arrayOutOfBound exception (multipart getCount() = 1) on the line 11 of the folowing code. The first InputStream inP1 was troncated (not complete).
> import javax.activation.DataSource;
> import javax.mail.BodyPart;
> import javax.mail.internet.MimeMultipart;
> import org.apache.http.Header;
> import org.apache.http.HttpResponse;
> import org.apache.http.HttpStatus;
> import org.apache.http.HttpVersion;
> import org.apache.http.client.HttpClient;
> import org.apache.http.client.methods.HttpPost;
> import org.apache.http.conn.ClientConnectionManager;
> import org.apache.http.entity.InputStreamEntity;
> import org.apache.http.entity.StringEntity;
> import org.apache.http.impl.client.DefaultHttpClient;
> 1 HttpClient httpclient = new DefaultHttpClient();
> 2 HttpResponse response = null;
> 3 try {
> 4     HttpPost httppost = new HttpPost("http://localhost:8080/HttpClientTest/servlet/MutipartExample");
> 5     response = client.execute(post);
> 6     InputStream responseAsStream = response.getEntity().getContent();
> 7     DataSource ds = new DataSourceForHttpResponseMultipart(responseAsStream);
> 8     MimeMultipart mp = new MimeMultipart(ds);
> 9     BodyPart bodyPart1 = mp.getBodyPart(0);
> 10   InputStream inP1 = bodyPart1.getInputStream();
> 11   BodyPart bodyPart2 = mp.getBodyPart(1);
> 12   InputStream inP2 = bodyPart2.getInputStream();
> }
> with DataSourceForHttpResponseMultipart implementation
> public class DataSourceForHttpResponseMultipart implements DataSource {
> 	InputStream in;
> 	public DataSourceForHttpResponseMultipart(InputStream in) {
> 		this.in = in;
> 	}
> 	public String getContentType() {
> 		return "multipart/mixed; boundary=Strs";
> 	}
> 	public InputStream getInputStream() throws IOException {
> 		return in;
> 	}
> 	public String getName() {
> 		return null;
> 	}
> 	public OutputStream getOutputStream() throws IOException {
> 		return null;
> 	}
> }
> I found a solution to patch this bug, by changing line 7, by this :
> 7   DataSource ds = new DataSourceForHttpResponseMultipart(new ByteArrayInputStream(IOUtils.toByteArray(responseAsStream)));
> I would like to find out why this happens and if it exists another solution by avoiding javax.mail and javax.activation...
> Thanks.
> Thebti

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org