简体   繁体   中英

JAX-RS forward post request

I have a need where one api receives a form-data post request and after some processing I need forward the request to another api.

My first api is :

    @Path("/integrator/api") 
    public class IntegratorREST {

    @Context private HttpServletRequest request;
    @Context private HttpServletResponse response;

    @Context private ServletContext _context;

    @POST
    @Path("/go")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    public Object forwardLink(@Context UriInfo info) throws URISyntaxException, ServletException, IOException {


        (... my code ...)

        // For simple CORS requests, the server only needs to add these 2 header parameters that allow access to any client.
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Access-Control-Allow-Credentials", "true");

        RequestDispatcher rd = _context.getRequestDispatcher("/uploadfile/api/send");
        rd.forward(request, response);

        return null;

    }

}

The second api is:

@Path("/uploadfile/api")
public class UploadFileREST {

private String DIRECTORY = 
        "../../pentaho-solutions/system/uploadfile/";

@SuppressWarnings("unchecked")
@POST
@Path("/send")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces("application/json")
public Output uploadFile(
        @Context UriInfo info,
        @FormDataParam("file") InputStream uploadedInputStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail) {

    (... code to upload a file to server ...)

}

So, the rd.forward() in the first api is executed, but nothing happen in the second one, I mean, I have breakpoint in the first line but the code is not executed.

Also, I dont get no warning/error message in the console.

How can I forward my post request to another endpoint ?

Thanks for any help.

Kleyson Rios.

I think you will have to call the second API using REST service call, using API's like Apache HTTPClient or something similar.

Regards, Hunaid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM