[英]How can I return the location of http created resource along with a response status message in JAX-RS?
客戶端使用一些參數將POST請求發送到REST服務器。
REST服務器處理該請求,將數據插入表中,並創建一個具有ID的新行。
然后,REST服務器向FileServer發送一個關於uploadlink的請求,然后FileServer將uploadLink返回給REST服務器。
最后,REST服務器將步驟2中ID為ID的新創建資源的位置返回給客戶端。
這是POST處理程序:
@POST
public Response postFilesByCustomerId(AbstractPrincipal user, Attachment attachment) {
Integer id = new AttachmentService(user).createNew(attachment);
String uploadLink = FileServer.getUploadLinkForFile(user.getDB(), attachment.getUuid(), attachment.getFileName());
return Response.created(LinkBuilder.getUriFromResource(this.getClass(), id)).build();
}
我的問題是,如何在響應中包含uploadLink? 我真的很感謝任何建議或意見,這里的java noob。
如何在響應中包含
uploadLink
?
如果您打算在響應的有效負載中發送URI,則可以使用以下命令:
URI uri = LinkBuilder.getUriFromResource(this.getClass(), id);
return Response.created(uri).entity(uploadLink).build();
如果要添加Link
標頭,請嘗試以下操作:
return Response.created(uri).link(uploadLink, "upload").build();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.