【问题标题】:Consume byte[] in GET using resty GWT使用 resty GWT 在 GET 中使用 byte[]
【发布时间】:2019-01-20 06:37:52
【问题描述】:

在我的服务器端,我有以下内容:

@ApiOperation(value = "myValue", tags = "{mytag}")
@GET
@Path("mypath")
@Produces("image/jpeg")
public Response getImage(@ApiParam(hidden = true) @HeaderParam("Accept-Language") String acceptLanguage,
        @ApiParam(hidden = true) @HeaderParam("accountId") Long accountId,
        @PathParam("var1Id") Long var1, @PathParam("imageId") Long documentId,
        @PathParam("var2Id") Long var2Id) throws SyncException {
    return Response.ok(ImageService.getImage(acceptLanguage, ImageId)).build();
}

其中 getImage 返回类型为 byte[] 。

在我的客户端并使用 resty GWT 我有以下内容:

@GET
@Path(mypath)
@Produces("image/jpeg")
public void getImage( @PathParam("var1Id") Long var1id, @PathParam("var2Id") Long var2Id , @PathParam("imageId") Long imageId, MethodCallback<T> callback);

我的问题是我应该在 MethodeCallback 中添加什么才能使用服务器端发送的 byte[] ?

【问题讨论】:

  • 通过 REST 请求传输 byte[],我认为更好的方法是将 byte[] 编码为 Base64
  • 这会增加图像大小。我让它成为最后的解决方案。

标签: gwt jax-rs resty-gwt


【解决方案1】:

对我有用的解决方案是创建一个 byteResponse 类,其中 byte[] 数组是一个属性。那么这个类现在是 serverSide 中 getImage 的返回类型和 gwt 端 methodeCallback 中的类型。

【讨论】:

    猜你喜欢
    • 2017-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 1970-01-01
    相关资源
    最近更新 更多