在您继续将其标记为重复之前,请注意,这不是一个重复的问题。我已经检查了所有以前接受的答案,但我在没有帮助的情况下添加了以下内容
@Produces("application/json"), @Consumes("application/json")
没有效果。我试过了
@Produces(MediaType.APPLICATION_JSON),@Consumes(MediaType.APPLICATION_JSON)
这是我的代码,我想知道在这种特殊情况下我哪里出错了。
@Path("/URLSigner")
public class UrlSigner {
@Path("/sign")
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response getSignedURL(UrlSignerRequest usRequest) {
String file_key = "";
SignURLResponse SUresponse = null;
SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
if(!( file_key = checkIfObjectExistsInS3(usRequest.getObject_name())).startsWith("FILE")) {
SUresponse = new SignURLResponse(getURLSigned(file_key), usRequest.getObject_name(), sdf.format(getExpiryDate()));
}else {
SUresponse = new SignURLResponse(file_key, usRequest.getObject_name(), "URL Not generated");
}
return Response.status(200).entity(SUresponse).build();
}
我的Request类看起来像这样。
import java.io.Serializable;
public class UrlSignerRequest implements Serializable {
private static final long serialVersionUID = 1L;
private String object_name;
public String getObject_name() {return object_name;}
public String toString() {
return "SignURLRequest [ "+ "object_name=" + object_name +"]";
}
}
网址:http://localhost:9999/MyRestApi/rest/URLSigner/sign
输入:
{
"object_name": "file1.xml"
}