java - 在 Java 中返回多个响应
问题描述
我有一个 java 方法,它从表 A(带有 BLOB)读取,将某些数据写入表 B,最后将 BLOB 上传到文件服务器。这是代码:
public void insertAndUploadService() throws Exception {
List<Tiedosto> tiedostoList = new ArrayList<>();
Integer newRow = 0;
boolean uploaded;
try {
tiedostoList = tiedostoService.getAllFiles();
} catch (Exception e) {
e.printStackTrace();
}
for (Tiedosto tiedosto : tiedostoList){
Attachment attachment = new Attachment();
attachment.setCustomerId(tiedosto.getCustomerId());
attachment.setSize(tiedosto.getFileSize());
try {
newRow = attachmentService.createNew(attachment);
System.out.println("************ NEW ROW CREATED IN attachments ******************************");
} catch (Exception e) {
e.printStackTrace();
}
if (newRow == 1 && tiedosto.getContent() != null){
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(tiedosto.getContent());
minioFileServer.uploadFile("test", attachment.getUuid(), tiedosto.getFileName().substring(tiedosto.getFileName().lastIndexOf("/") + 1), byteArrayInputStream,
byteArrayInputStream.available(), tiedostoService.getMimeType(tiedosto.getContent()));
System.out.println("********************** Generating Upload Link ************************************ "+"\n"+
minioFileServer.getUploadLinkForFile("test", attachment.getUuid(), tiedosto.getFileName().substring(tiedosto.getFileName().lastIndexOf("/") + 1) ));
uploaded = minioFileServer.fileExists("test", attachment.getUuid(), tiedosto.getFileName().substring(tiedosto.getFileName().lastIndexOf("/") + 1));
if (uploaded == true){
System.out.println("*********** UPLOAD SUCCESSFUL ***************");
tiedostoService.updateService(tiedosto.getCustomerId(), tiedosto.getId());
attachmentService.update(attachment.getUuid());
}
}
}
}
如果我向 API 端点发送 POST 请求,例如:
@POST
@Path("attachments")
public void moveToMinio() throws Exception {
MigrationService migrationService = new MigrationService();
migrationService.insertAndUploadService();
}
它根据需要完成工作并打印出详细信息。发送 POST 请求时,是否有可能从 insertAndUploadService 发送多个响应?例如当 newRow 创建并上传 == true 时,是否可以返回 HTTP 202?我是 Java 新手,非常感谢任何形式的帮助/建议!
编辑:“多重回应”可能不是正确的术语。我想要返回基于请求操作选择的几个 HTTP 状态代码之一的选项。
解决方案
推荐阅读
- php - 使用laravel中的队列将数据导出到excel
- react-native - 开玩笑地使用 async/await 调用 api 总是得到状态 200
- cmake - 我通过 apt-get 安装了 libsdl2-image-dev,但 cmake 找不到它
- javascript - UnhandledPromiseRejectionWarning: SyntaxError: React Native
- ajax - checkmarx Client_Reflected_File_Download
- javascript - 仅处理数组中的按下项目
- laravel - Laravel 通过 href 发送数据
- testing - Flutter:测试未来的构建器
- c# - 我需要通过解析 Json 后得到的循环计算值的总数,但不能使其与控制台应用程序一起使用)
- c++ - Doxygen - 如何在不生成图表的情况下生成文本调用关系结果