问题描述
我需要一个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)。
1楼
我认为您将不得不使用REST服务调用来调用第二个API,例如使用Apache HTTPClient之类的API。
问候,耐奈德。