【问题标题】:Accept:application/json fails with Atmosphere using Jersey with DropwizardAccept:application/json 使用带有 Dropwizard 的 Jersey 失败,Atmosphere 失败
【发布时间】:2016-01-04 16:05:06
【问题描述】:

我正在尝试使用 Dropwizard 和 Atmosphere 设置一些启用 websocket 的资源。我的设置基于这里的代码:https://cvwjensen.wordpress.com/2014/08/02/websockets-in-dropwizard/

我使用以下代码在 Dropwizard 中设置 Atmosphere:

AtmosphereServlet atmosphere = new AtmosphereServlet();
atmosphere.framework().addInitParameter(ApplicationConfig.ANNOTATION_PACKAGE, "my.classes");
atmosphere.framework().addInitParameter(ApplicationConfig.WEBSOCKET_SUPPORT, "true");
atmosphere.framework().addInitParameter(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true");
atmosphere.framework().addInitParameter(ApplicationConfig.PROPERTY_COMET_SUPPORT, "org.atmosphere.container.Jetty9AsyncSupportWithWebSocket");
ServletRegistration.Dynamic servlet = environment.servlets().addServlet("atmosphere", atmosphere);
servlet.addMapping("/APIWS/*");

我用来测试它的资源是这样的:

@GET
@Produces({"application/xml", "application/json"})
public SuspendResponse<JAXBElement<CustomerListType>> getUpdates(@Context BroadcasterFactory bf) {
    Broadcaster bc = getBroadcaster(bf, hash);
    registerBroadcaster(hash, query, apiContext.getUser());
    return new SuspendResponse.SuspendResponseBuilder<JAXBElement<CustomerListType>>()
            .broadcaster(bc)
            .build();
}

它主要工作,但如果我在我的 Websocket 请求中设置标头Accept: application/json,当服务器尝试推送某些东西时它会失败。设置Accept: application/xml 工作正常。

我使用以下 curl 命令对其进行测试:

 curl -i -N -H "Accept: application/json"  -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Sec-Websocket-Version: 13" -H "Sec-WebSocket-Key: 258E" http://localhost:8080/APIWS/customers

一旦服务器推送一些数据,它就会失败并显示以下消息:

* STATE: PERFORM => DONE handle 0x80048248; line 1617 (connection #0)
* Curl_done
* Empty reply from server
* Connection #0 to host localhost left intact
curl: (52) Empty reply from server

【问题讨论】:

    标签: websocket jersey dropwizard atmosphere


    【解决方案1】:

    【讨论】:

    • 感谢让弗朗索瓦的回答!您的意思是将org.atmosphere.websocket.messageContentType 初始化参数设置为application/json?我试过设置,但不幸的是它没有任何区别。
    • 将日志转到 TRACE 以查看泽西岛内部发生了什么。我怀疑泽西的标题有问题,因为 Atmosphere 没有使用它。
    • 谢谢!我在所有涉及的模块上将日志记录设置为 TRACE,结果发现我们的一个提供程序实际上存在错误。不知道为什么异常只出现在 TRACE 日志中,但我很高兴它现在可以工作了! :) 感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-24
    • 2011-08-20
    • 2017-08-16
    • 2017-09-30
    • 1970-01-01
    相关资源
    最近更新 更多