eclipse-ee4j / eclipse-ee4j/metro-mimepull

java.lang.IllegalStateException in BodyPartEntity getInputStream() using RESTful POST request

Open
#14 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
5
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Hello,

I am trying to download multiple attachments in REST mode using FormDataMultiPart (app1 to app2). I am facing an exception when I try to extract the input stream from BodyPartEntity on the REST based application side.
At first glance, it looks like the input stream in the MIMEParser of BodyPartEntity seems to be already parsed. Surprisingly this is working fine in the other way around (app2 to app1). I am using mimepull version 1.9.3.

Kindly help me in resolving this issue.

Stacktrace is:

java.lang.IllegalStateException: No such MIME Part: Part=0:binary
at org.jvnet.mimepull.DataHead.read(DataHead.java:145)
at org.jvnet.mimepull.MIMEPart.read(MIMEPart.java:94)
at org.glassfish.jersey.media.multipart.BodyPartEntity.getInputStream(BodyPartEntity.java:80)

The code to construct the inputStream and attach it to FormDataMultiPart:

for(int i = 0; i < attachments.length; i++) {
InputStream inputStream = new FileInputStream(new File("sample.xml"));
formDataMultiPart.field("files", inputStream, MediaType.TEXT_XML_TYPE);
}

The code to get the inputStream is:

List bodyParts = attachments.getFields("files");
for(int i = 1; i < bodyParts.size(); i++) {
BodyPartEntity bodyPartEntity = (BodyPartEntity) bodyParts.get(i).getEntity();
InputStream is = bodyPartEntity.getInputStream();
}

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the multipart upload shown in the issue, using multiple files and BodyPartEntity.getInputStream(). Trace the failure through org.jvnet.mimepull.DataHead.read, MIMEPart.read, and BodyPartEntity.getInputStream; done means identifying the parsing-state problem and adding a regression test that reads every attachment successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.