0

I have a microservice that receives a Rest Post call, and must return a MultipartFormDataOutput (or something equivalent) with json and several bytes of images. I have another microservice that makes a Rest Post call to this service, it needs to receive and decode this multipart. This is done with Quarkus 3.2 and Reasteasy, but I didn't manage to make this call, and decode the multipart returned from the first microservice, is there a way with RestEasy or something?

    @Path("/fillAll")
    @POST
    @Consumes(APPLICATION_JSON)
    @Produces(MULTIPART_FORM_DATA)
    public MultipartFormDataOutput fillAll(
        @Valid FillTemplateRequest request
    ) {
        FillTemplateResponse fillTemplateResponse = new FillTemplateResponse();

        byte[] a = "drd3434".getBytes();
        byte[] b = "dr43434d3434".getBytes();

        Template template1 = new Template();
        template1.setVersion("1");
        template1.setData(a);
        template1.setData(b);

        ArrayList list = new ArrayList<>();
        list.add(template1);

        fillTemplateResponse.setTemplates(list);

        MultipartFormDataOutput res = new MultipartFormDataOutput();
        for (Template template : fillTemplateResponse.getTemplates()) {
            res.addFormData(template.getName(), template.getData(), MULTIPART_FORM_DATA_TYPE);
            template.setData(null);
        }
        res.addFormData("json", fillTemplateResponse, APPLICATION_JSON_TYPE);

        return res;
    }
    
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = PRIVATE)
public class FillTemplateRequest {

    @NotNull @NotEmpty @Valid
    private List<Template> templates;
    private List<User> users;
    private List<Doctor> doctors;
    private Company company;

}

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = PRIVATE)
public class FillTemplateResponse {

    private Long executionTime;
    private Long affectedRecords;
    private Long startExecution;
    private Long endExecution;
    private String version;
    private String transactionId;
    private String hostName;
    private List<Template> templates;

}


@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = PRIVATE)
public class Template {

    private String name;
    private String code;   
    private String version;
    private String language;
    private Long contentWidth;
    private String fileName;
    private byte[] data;
   

}

// pom.xml
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-client-reactive-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy-reactive</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-resteasy-reactive-jackson</artifactId>
        </dependency>
        <dependency>
            <groupId>io.quarkus</groupId>
            <artifactId>quarkus-rest-client-reactive</artifactId>
        </dependency>
    
Regolus
  • 1
  • 1
  • Does make a call from POSTMAN or equivalent to `fillAll()` works and produces the correct the expected response? If so, it's just a matter of your restclient interface configuration;: just create a client interface,mark with `@RegisterRestClient` and update OP – Luca Basso Ricci Jul 26 '23 at 14:26

0 Answers0