我有一个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());
}
}
}
}
如果我将POST请求发送到API端点,则类似:
@POST
@Path("attachments")
public void moveToMinio() throws Exception {
MigrationService migrationService = new MigrationService();
migrationService.insertAndUploadService();
}
它将根据需要进行工作并打印出详细信息。发送POST请求时,是否有可能从insertAndUploadService发送多个响应?例如,当newRow创建并上传== true时,是否可以返回HTTP 202?我是Java新手,非常感谢任何帮助/建议!
编辑: “多个响应”可能不是正确的用语。我想要返回基于请求操作选择的几种HTTP状态代码之一的选项。