Hi everyone,
I am developing a workshop for the Eclipse Foundation on Jakarta 10 REST 3.1 services. The workshop is divided into 8 modules. There is one module I cannot get my code to work and that is using MultiPart to either upload
or download an image file.
It should be straightforward. I have modules that take advantage of the automatic conversion from an object to a JSON serialized version of the object and vice versa. I show both SeBootstrap and server-based REST services
and REST clients. I even show code using either Jersey or RESTEasy.
Things have fallen apart when it comes to MultiPart. Let us begin with where I am stuck. Many have written about MultiPart, but I have yet to find any working examples. There are articles that show how to code the rest
service end point and articles on how to write clients. What I have not found is an article or text that presents both the service endpoint and a matching client for MultiPart. Here is an example of what I mean from the official Eclipse documentation:
https://jakarta.ee/specifications/restful-ws/3.1/jakarta-restful-ws-spec-3.1.html#consuming_multipart_formdata
In the text is this code fragment:
@Path("widgets4")
public class WidgetsResource4 {
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response postWidget(@FormParam("part1Name") String part1,
@FormParam("part2Name") InputStream part2,
@FormParam("part3Name") EntityPart part3) {...}
}
There is no example how you might call this service. If I place this code in an SeBootstrap service and have it return Response.ok().build() I get:
WARNING: No injection source found for a parameter of type public jakarta.ws.rs.core.Response com.eclipse.restsebootstrap.FileUploadService.postWidget(java.lang.String,java.io.InputStream,jakarta.ws.rs.core.EntityPart)
at index 2.
WARNING: No injection source found for a parameter of type public jakarta.ws.rs.core.Response com.eclipse.restsebootstrap.FileUploadService.uploadFile(java.lang.String,jakarta.ws.rs.core.EntityPart) at index 1.
I do not get any warnings when deployed as part of a server-based endpoint, but it just won’t work, throwing exceptions due to a null EntityPart. While they may be just warnings for a specific POST service, any other
services that would normally run, fail as well. Remove this POST service and the remaining services work.
I suspect that there is a library I am missing in my dependencies. I discovered just yesterday that there are two Response classes, one for Servlets & family and one for web services. Rarely do online examples discuss
dependencies. When there is code to download from a Git repo it is usually part of a project where numerous demos all use the same pom file with an overwhelming number of dependencies and plugins. Every example I am developing has its own repo.
All I am begging/pleading/asking for is a simple example of uploading and downloading binary files in a web service. While it should not make a difference, I work on Windows.
Ken Fogel
Java Champion
JChampions Conference Organizer
JCP Executive Committee Member
Research Scholar in Residence, Dawson College
Author of Transitioning to Java
All around nice guy, usually.