Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [rest-dev] MultiPart Problems

Ken,

 

your cases proofs the actual challenge with all Jakarta specs: One gets stuck rather easily as the self-certified implementations are far from being perfectly documented or bug-free. :-(

 

The counterpart to RESTEasy's resteasy-multipart-provider is Jersey's jersey-media-multipart (https://search.maven.org/search?q=a:jersey-media-multipart). Jan please chime in if I am wrong.

 

-Markus

 

 

Von: rest-dev [mailto:rest-dev-bounces@xxxxxxxxxxx] Im Auftrag von James Perkins via rest-dev
Gesendet: Donnerstag, 24. August 2023 00:30
An: Jakarta Rest project developer discussions
Cc: James Perkins
Betreff: Re: [rest-dev] MultiPart Problems

 

Hello,

I can only speak from the RESTEasy perspective, but there are a few things needed to get RESTEasy working with an example like this. I did find some bugs as well, so hopefully we can get those resolved soon and make the process a bit easier :)

 

I created a standalone example here [1]. The main three points are:

  1. You need to include the org.jboss.resteasy:resteasy-multipart-provider. Note in WildFly you DO NOT need to do this.
  2. For now until [2] is resolved you need to add jakarta.servlet.annotation.MultipartConfig to the application.
  3. In a CDI container, again until [2] is fixed, you'd need to @Veto your application.

I will work on an example in WildFly as well. If you've got any further questions, please let me know.

 

 

On Wed, Aug 23, 2023 at 12:35 PM omniprof--- via rest-dev <rest-dev@xxxxxxxxxxx> wrote:

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.

 

_______________________________________________
rest-dev mailing list
rest-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://accounts.eclipse.org


 

--

James R. Perkins

JBoss by Red Hat


Back to the top