簡體   English   中英

JAX-RS轉發發布請求

[英]JAX-RS forward post request

我需要一個api接收表單數據發布請求的地方,經過一些處理后,我需要將該請求轉發給另一個api。

我的第一個api是:

    @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;

    }

}

第二個api是:

@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 ...)

}

因此,第一個api中的rd.forward()已執行,但第二個api中沒有任何反應,我的意思是,我在第一行中有斷點,但未執行代碼。

另外,我在控制台中沒有收到警告/錯誤消息。

如何將發帖請求轉發到另一個端點?

謝謝你的幫助。

克萊森·里奧斯(Kleyson Rios)。

我認為您將不得不使用REST服務調用來調用第二個API,例如使用Apache HTTPClient之類的API。

問候,耐奈德。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM