Este contenido no está disponible en el idioma seleccionado.

20.11. @MultipartForm and POJOs


If you are familiar with your multipart/form-data packets, you can map them to and from a POJO class with the @org.jboss.resteasy.annotations.providers.multipart.MultipartForm annotation and the @FormParam JAX-RS annotation. To do so, define a POJO with a default constructor (at least), and annotate its fields, properties, or both, with @FormParams. These @FormParams must also be annotated with @org.jboss.resteasy.annotations.providers.multipart.PartType to be output. For example:
   public class CustomerProblemForm {
      @FormData("customer")
      @PartType("application/xml")
      private Customer customer;

      @FormData("problem")
      @PartType("text/plain")
      private String problem;

      public Customer getCustomer() { return customer; }
      public void setCustomer(Customer cust) { this.customer = cust; }
      public String getProblem() { return problem; }
      public void setProblem(String problem) { this.problem = problem; }
   }
Copy to Clipboard Toggle word wrap
Once you have defined your POJO class, you can use it to represent multipart/form-data. The following code sends a CustomerProblemForm using the RESTEasy client framework:
   @Path("portal")
   public interface CustomerPortal {

      @Path("issues/{id}")
      @Consumes("multipart/form-data")
      @PUT
      public void putProblem(@MultipartForm CustomerProblemForm,
                             @PathParam("id") int id);
   }

   {
       CustomerPortal portal = ProxyFactory.create(CustomerPortal.class, "http://example.com");
       CustomerProblemForm form = new CustomerProblemForm();
       form.setCustomer(...);
       form.setProblem(...);

       portal.putProblem(form, 333);
   }
Copy to Clipboard Toggle word wrap
Note that the @MultipartForm annotation tells RESTEasy that the object has @FormParam, and that it should be marshalled from that parameter. You can use the same object to receive multipart data. Here is an example of the server-side counterpart to the customer portal.
   @Path("portal")
   public class CustomerPortalServer {

      @Path("issues/{id})
      @Consumes("multipart/form-data")
      @PUT
      public void putIssue(@MultipartForm CustomerProblemForm,
                           @PathParam("id") int id) {
         ... write to database...
      }
   }
Copy to Clipboard Toggle word wrap
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat