1

Use following deps. Spring boot jersey starter use Jersey version 2.26

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
</dependency>

 <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-multipart</artifactId>
            <version>2.26</version>
            <scope>compile</scope>
</dependency>

In JerseyConfig following config is added.

register(MultiPartFeature.class);

Below is how the Rest method looks like

@POST
    @Path("/logos2")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    Response uploadLogo2(@FormDataParam("uploadFile") InputStream stream){
}

executed following Curl command

curl -X POST "http://localhost:7070/service-manager/services/logos2" -H  "accept: application/json" -H  "Content-Type: multipart/form-data" -F "uploadFile=@1.png;type=image/png"

Following error see in the logs

018-04-26 17:13:11.777 DEBUG 30454 --- [nio-7070-exec-2] o.g.j.m.i.ReaderInterceptorExecutor      : Message body reader (class org.glassfish.jersey.media.multipart.internal.MultiPartReaderServerSide) is trying to close the entity input stream. Not closing.
2018-04-26 17:13:11.778 DEBUG 30454 --- [nio-7070-exec-2] o.g.j.m.m.i.MultiPartReaderClientSide    : Exception occurred during parsing MultiPart message. Performing cleanup.

org.jvnet.mimepull.MIMEParsingException: Missing start boundary
    at org.jvnet.mimepull.MIMEParser.skipPreamble(MIMEParser.java:318) ~[mimepull-1.9.6.jar:1.9.6]

Dependency tree

Below give the dependency tree. Stack over flow asking putting more text.

[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:2.0.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:2.0.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.1.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.1.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] |  |  |  +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] |  |  |  |  \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] |  |  |  \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] |  |  \- org.springframework:spring-core:jar:5.0.5.RELEASE:compile
[INFO] |  |     \- org.springframework:spring-jcl:jar:5.0.5.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-json:jar:2.0.1.RELEASE:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.5:compile
[INFO] |  |  +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.5:compile
[INFO] |  |  \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.5:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.1.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.29:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.29:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.29:compile
[INFO] |  +- org.hibernate.validator:hibernate-validator:jar:6.0.9.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- org.springframework:spring-web:jar:5.0.5.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-beans:jar:5.0.5.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:5.0.5.RELEASE:compile
[INFO] |     +- org.springframework:spring-aop:jar:5.0.5.RELEASE:compile
[INFO] |     +- org.springframework:spring-context:jar:5.0.5.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:5.0.5.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jersey:jar:2.0.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-validation:jar:2.0.1.RELEASE:compile
[INFO] |  +- org.glassfish.jersey.core:jersey-server:jar:2.26:compile
[INFO] |  |  +- javax.ws.rs:javax.ws.rs-api:jar:2.1:compile
[INFO] |  |  \- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.26:compile
[INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.26:compile
[INFO] |  +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.26:compile
[INFO] |  +- org.glassfish.jersey.ext:jersey-bean-validation:jar:2.26:compile
[INFO] |  +- org.glassfish.jersey.ext:jersey-spring4:jar:2.26:compile
[INFO] |  |  +- org.glassfish.jersey.inject:jersey-hk2:jar:2.26:compile
[INFO] |  |  |  \- org.glassfish.hk2:hk2-locator:jar:2.5.0-b42:compile
[INFO] |  |  |     \- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.5.0-b42:compile
[INFO] |  |  +- org.glassfish.hk2:hk2:jar:2.5.0-b42:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-utils:jar:2.5.0-b42:compile
[INFO] |  |  |  |  \- javax.inject:javax.inject:jar:1:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-api:jar:2.5.0-b42:compile
[INFO] |  |  |  +- org.glassfish.hk2:config-types:jar:2.5.0-b42:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-core:jar:2.5.0-b42:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-config:jar:2.5.0-b42:compile
[INFO] |  |  |  +- org.glassfish.hk2:hk2-runlevel:jar:2.5.0-b42:compile
[INFO] |  |  |  \- org.glassfish.hk2:class-model:jar:2.5.0-b42:compile
[INFO] |  |  |     \- org.glassfish.hk2.external:asm-all-repackaged:jar:2.5.0-b42:compile
[INFO] |  |  \- org.glassfish.hk2:spring-bridge:jar:2.5.0-b42:compile
[INFO] |  \- org.glassfish.jersey.media:jersey-media-json-jackson:jar:2.26:compile
[INFO] |     +- org.glassfish.jersey.ext:jersey-entity-filtering:jar:2.26:compile
[INFO] |     \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.9.5:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.0.1.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:2.0.1.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.13:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.1.RELEASE:compile
[INFO] |  |  +- com.zaxxer:HikariCP:jar:2.7.8:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:5.0.5.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.2.16.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.22.0-GA:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:2.0.6.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:2.0.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:5.0.5.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:5.0.5.RELEASE:compile
[INFO] |  |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] |  \- org.springframework:spring-aspects:jar:5.0.5.RELEASE:compile
[INFO] +- org.glassfish.jersey.media:jersey-media-multipart:jar:2.26:compile
[INFO] |  +- org.glassfish.jersey.core:jersey-common:jar:2.26:compile
[INFO] |  |  +- org.glassfish.hk2.external:javax.inject:jar:2.5.0-b42:compile
[INFO] |  |  \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.1:compile
[INFO] |  \- org.jvnet.mimepull:mimepull:jar:1.9.6:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.4:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.9:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.7:compile
[INFO] +- commons-validator:commons-validator:jar:1.6:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] |  +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] +- com.h2database:h2:jar:1.4.196:compile
[INFO] +- org.liquibase:liquibase-core:jar:3.5.5:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.19:compile
[INFO] +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] +- org.projectlombok:lombok:jar:1.16.20:compile
[INFO] +- io.swagger:swagger-jersey2-jaxrs:jar:1.5.19:compile
[INFO] |  \- io.swagger:swagger-jaxrs:jar:1.5.19:compile
[INFO] |     +- io.swagger:swagger-core:jar:1.5.19:compile
[INFO] |     |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.9.5:compile
[INFO] |     |  \- io.swagger:swagger-models:jar:1.5.19:compile
[INFO] |     +- org.reflections:reflections:jar:0.9.11:compile
[INFO] |     \- com.google.guava:guava:jar:20.0:compile
[INFO] +- io.swagger:swagger-annotations:jar:1.5.19:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.2.4:compile
[INFO] |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- org.apache.commons:commons-csv:jar:1.5:compile
[INFO] +- org.mockito:mockito-all:jar:2.0.2-beta:test
[INFO] \- org.junit.jupiter:junit-jupiter-api:jar:5.1.0:test
[INFO]    +- org.apiguardian:apiguardian-api:jar:1.0.0:test
[INFO]    +- org.opentest4j:opentest4j:jar:1.0.0:test
[INFO]    \- org.junit.platform:junit-platform-commons:jar:1.1.0:test
era
  • 305
  • 2
  • 16
  • Try _not_ setting the `Content-type` header in the request. cURL will set it for for you _and_ add the [boundary](https://stackoverflow.com/q/3508338/2587435). Not sure if they will override it if you set it. I may be wrong – Paul Samsotha Apr 26 '18 at 13:56
  • Actually, nevermind. Just tested it and it _does_ add the boundary. So I can't reproduce the problem. – Paul Samsotha Apr 26 '18 at 14:03
  • 1
    Can you create a small repo that reproduces this problem. I'd like to test it out. I just tested with [this project](https://github.com/psamsotha/jersey-boot-upload-example) – Paul Samsotha Apr 26 '18 at 19:12
  • Thanks Paul. I created an independent project like you did and then upload working fine. But in my working project when 'spring-webmvc' jar in the path upload fails with above error. I need 'spring-webmvc' in path to generate swagger UI. I have tried adding same set of deps to my example but again in there upload working fine. I don't know why 'spring-webmvc' create 'Missing start boundary' in my original project. – era Apr 27 '18 at 11:47
  • Jus add the spring-boot-starter-web. It's pulls in spring-mvc – Paul Samsotha Apr 27 '18 at 12:39
  • Yes. When add 'spring-boot-starter-web' I am getting error. When I exclude 'spring-webmvc' from spring-boot-starter-web it works fine. – era Apr 27 '18 at 12:50
  • Can you check your dependencies? You may have a transitive dependency to an older version of Apache CXF. There was an issue with Apache CXF converting headers to lower case. – M. Rizzo Apr 27 '18 at 14:35
  • Apache CXF not in the dependency tree. I have updated question with dependency tree. – era Apr 28 '18 at 02:25
  • Sorry. I formatted dependency output. – era Apr 28 '18 at 03:34
  • Mistakenly there were two configuration files (application.properties and application.yml) in the path. Once 'application.yml' removed this start working fine. I took your project and add following application.yml. Then it start to report error. spring: jersey: type: filter Million thanks for your help. – era May 11 '18 at 09:17

2 Answers2

0

I believe the problem is you are using curl and you are not setting a boundary in the content-header for your multipart/form-data.

Try something like

curl -X POST "http://localhost:7070/service-manager/services/logos2" -H  "accept: application/json" -H  "Content-Type: multipart/form-data; boundary=------------------------d74496d66958873e" -F "uploadFile=@1.png;type=image/png"

Notice the addition of the boundary string in your -H option.

M. Rizzo
  • 1,293
  • 10
  • 19
  • I tried this option. But not working. – era May 08 '18 at 12:14
  • It didn't work and you still got the same error? – M. Rizzo May 08 '18 at 13:26
  • Yes. I was tried to remove Spring web mvc then my swagger UI won't work. But upload seems ok. – era May 08 '18 at 13:31
  • You can also try curl without the header options and it should take care of the headers for you automatically. Can you try curl -F "uploadFile=@1.png;type=image/png" "http://localhost:7070/service-manager/services/logos2" ? I'm assuming your form only has two fields it's expecting: type and uploadFile. It might be helpful to post the source of the form as well. – M. Rizzo May 08 '18 at 13:56
  • I am getting same error with curl as well. I tried form, curl and swagger. In all clients getting same error. – era May 09 '18 at 12:48
0

Mistakenly there were two configuration files (application.properties and application.yml) in the path. Once 'application.yml' removed this start working fine.

era
  • 305
  • 2
  • 16
  • 1
    Hey, you were right about this problem. It is not that you have two property files. It's that you were configuring Jersey as a filter, with the property `spring.jersey.type=filter`. You can follow [this post](https://stackoverflow.com/q/50387638/2587435), where the OP reproduced the problem in a repo. You can see my comment where I linked to another issue where I think the cause was narrowed down to Spring consuming the stream. – Paul Samsotha May 19 '18 at 07:28
  • Yes. YAML file (extra config file) contained only spring.jersey.type=filter. Later whole file removed. – era May 21 '18 at 04:43