用json体的Grizzly PUT请求失败

时间:2017-03-15 18:53:54

标签: java http server jersey grizzly

我在云上运行java服务器。使用GET和DELETE请求一切正常,但PUT请求不行。我有以下PUT请求处理程序

class LinkedStack<T> {
    // references to T refer to LinkedStack's T.

    class Node {
        // references to T refer to LinkedStack's T.
        T data;
    }

    // ...
    Node node;
}

这是Server类

@PUT
@JSONP(queryParam = "callback")
public void putEvent(String eventJson) throws Exception {
    Event event = new ObjectMapper().readValue(eventJson, Event.class);
    EventDao.getInstance().saveOrUpdateEvent(event);
}    

当我发送带有以下JSON正文的PUT请求时

public static final String BASE_API_URI = "http://localhost:8080/myrest-api/";

public boolean getFileCacheEnabled() {
    return false;
}

public static void main(String[] args) throws Exception {
    Server server = new Server();
    final HttpServer httpServer = server.startServer();
    System.out.println("Press enter to stop the server...");
    System.in.read();
    httpServer.shutdown();
}

public HttpServer startServer() {
    final ResourceConfig rc = new ResourceConfig().packages("com.myrest.events");
    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_API_URI), rc);
    server.getServerConfiguration().addHttpHandler(getHttpHandler(), "/page");
    return server;
}

public HttpHandler getHttpHandler() {
    StaticHttpHandler handler = new StaticHttpHandler("src/main/resources/webapp/");
    handler.setFileCacheEnabled(getFileCacheEnabled());
    return handler;
}

我得到了

{
    "name":"SimpleName",
    "description":"SimpleDescription",
    "author":"Me"
}

虽然当我在本地部署应用程序时,尝试相同的一切都很好。顺便说一句,我尝试了POST请求,我得到了同样的错误。

0 个答案:

没有答案