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

thebti updated HTTPCLIENT-1243:
-------------------------------

    Description: 
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;

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


  was:
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;

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)));

Thanks.
Thebti


    
> 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;
> 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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to