首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >用于自动执行POST请求的Java后台服务

用于自动执行POST请求的Java后台服务
EN

Stack Overflow用户
提问于 2018-08-26 02:34:16
回答 1查看 603关注 0票数 1

我有一个Java服务,它从表'A‘读取数据(包括BLOB),将这些数据写入表'B’,然后将BLOB作为ByteArrayInputStream上传到存储服务器(基本上是一个小型迁移服务)。成功完成上载过程后,两个表上的布尔列都设置为1。该服务的工作方式是将POST请求发送到REST服务器,并且对于复制的每一行,都会返回一个location头作为响应。处理POST请求的资源方法如下所示。

代码语言:javascript
复制
@POST
@Produces({MediaType.APPLICATION_JSON})
public Response migrateToMinio(@Context UriInfo uriInfo) throws Exception {
    tiedostoService = new TiedostoService();
    attachmentService = new AttachmentService();
    List<Tiedosto> tiedostoList = tiedostoService.getAllFiles();
    List<String> responseList = new ArrayList<>();
    Response r;
    Integer newRow;
    String responseData = null;
    int i=1;
    for (Tiedosto tiedosto : tiedostoList) {
        Attachment attachment = new Attachment();
        attachment.setCustomerId(tiedosto.getCustomerId());
        attachment.setSize(tiedosto.getFileSize());
        newRow = attachmentService.createNew(attachment);
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        if (newRow == 1) {
            builder.path(Integer.toString(i));
            r = Response.created(builder.build()).build();
            responseData = r.getLocation().toString();
            i++;
        }
        responseList.add(responseData);
    }
    String jsonString = new Gson().toJson(responseList);
    return Response.status(Response.Status.OK).entity(jsonString).build();
}

首先,通过POST生成一个JWT到api,并使用该作为持有者令牌,另一个POST被发送到"/rest/attachments",它在花费一段时间进行处理后返回状态200,如下所示。

我的问题是,我如何实现一个java后台服务(就像运行在与服务器相同的物理机上的客户端),它会自动将POST请求发送到REST服务器进行迁移过程?在第一次运行时,后台服务应该处理整个表,然后后台服务需要定期运行,以检查是否向表中添加了新行,并对其进行相应的处理。我是一个Java新手,真的很感谢任何形式的帮助/建议。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52020174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档