2012-01-19 49 views
2

我有了一個懸浮方法的servlet和廣播之一:返回JSONP的懸浮大氣請求

@GET 
    @Path("/notification") 
    @Produces({ "application/x-javascript", MediaType.APPLICATION_JSON }) 
    @Suspend 
    public JSONWithPadding getNextNotification(
    @QueryParam("callback") @DefaultValue("callback") String callback) { 

    Random random = new Random(); 

    Notification n = new Notification(); 
    n.setMessage("Message is " + Long.toHexString(random.nextLong())); 
    n.setMessage("S-" + Long.toHexString(random.nextLong())); 

    return new JSONWithPadding(n, callback); 

    } 

我調用這從一個瀏覽器,看在我的瀏覽以下良好輸出:

<!-- ---------------------------------------------------------------- http://github.com/Atmosphere ------------------------------------------------------------------------ --> 
<!-- Welcome to the Atmosphere Framework..... 
<!-- --------------------------------------------------------------------------------------------------------------------------------------------------------------------- --> 
<!-- EOD -->callback({"message":"S-c897404ad5703dcc","sender":null} 

所以我的對象很好地序列化爲JSONP。

現在,我打電話給我的廣播方法:

@Context Broadcaster bc; 

    @Broadcast({JsonpFilter.class}) 
    @GET 
    @Path("/broadcast5") 
    public Broadcastable broadcast5() { 
    Random random = new Random(); 
    Notification n = new Notification(); 
    n.setMessage("Message is " + Long.toHexString(random.nextLong())); 
    n.setMessage("S-" + Long.toHexString(random.nextLong())); 
    return new Broadcastable(new JSONWithPadding(n, "callback111"), bc); 
    } 

在服務器端,我得到下面的異常,並沒有什麼廣播:

[#|2012-01-19T17:28:30.483+0100|WARNING|glassfish3.1.1|javax.enterprise.system.container.web.com.sun.enterprise.web|_Thr 
eadID=20;_ThreadName=http-thread-pool-8080(5);|StandardWrapperValve[AtmosphereServlet]: PWC1406: Servlet.service() for s 
ervlet AtmosphereServlet threw exception 
java.lang.RuntimeException: javax.servlet.ServletException: Throwable 
     at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:154) 
     at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:219) 
     at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:154) 
     at org.atmosphere.container.GrizzlyCometSupport.service(GrizzlyCometSupport.java:103) 
     at org.atmosphere.container.GlassFishWebSocketSupport.service(GlassFishWebSocketSupport.java:101) 
     at org.atmosphere.cpr.AtmosphereServlet.doCometSupport(AtmosphereServlet.java:1212) 
     at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:1171) 
     at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:1157) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:734) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 
     at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1539) 
     at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) 
     at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
     at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) 
     at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) 
     at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:98) 
     at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:91) 
     at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:162) 
     at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:330) 
     at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) 
     at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:174) 
     at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:828) 
     at com.sun.grizzly.comet.CometEngine.executeServlet(CometEngine.java:444) 
     at com.sun.grizzly.comet.CometEngine.handle(CometEngine.java:308) 
     at com.sun.grizzly.comet.CometAsyncFilter.doFilter(CometAsyncFilter.java:87) 
     at com.sun.grizzly.arp.DefaultAsyncExecutor.invokeFilters(DefaultAsyncExecutor.java:171) 
     at com.sun.grizzly.arp.DefaultAsyncExecutor.interrupt(DefaultAsyncExecutor.java:143) 
     at com.sun.grizzly.arp.AsyncProcessorTask.doTask(AsyncProcessorTask.java:94) 
     at com.sun.grizzly.http.TaskBase.run(TaskBase.java:193) 
     at com.sun.grizzly.http.TaskBase.execute(TaskBase.java:175) 
     at com.sun.grizzly.arp.DefaultAsyncHandler.handle(DefaultAsyncHandler.java:145) 
     at com.sun.grizzly.arp.AsyncProtocolFilter.execute(AsyncProtocolFilter.java:204) 
     at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 
     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 
     at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 
     at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) 
     at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 
     at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 
     at com.sun.grizzly.ContextTask.run(ContextTask.java:71) 
     at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) 
     at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 
     at java.lang.Thread.run(Thread.java:662) 
Caused by: javax.servlet.ServletException: Throwable 
     at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:165) 
     at org.atmosphere.util.AtmosphereFilterChain.invokeFilterChain(AtmosphereFilterChain.java:116) 
     at org.atmosphere.handler.ReflectorServletProcessor$FilterChainServletWrapper.service(ReflectorServletProcessor. 
java:293) 
     at org.atmosphere.handler.ReflectorServletProcessor.onRequest(ReflectorServletProcessor.java:151) 
     ... 41 more 
Caused by: java.lang.AbstractMethodError: org.atmosphere.commons.jersey.JsonpFilter.filter(Ljava/lang/Object;Ljava/lang/ 
Object;)Lorg/atmosphere/cpr/BroadcastFilter$BroadcastAction; 
     at org.atmosphere.cpr.BroadcasterConfig.filter(BroadcasterConfig.java:447) 
     at org.atmosphere.cpr.DefaultBroadcaster.filter(DefaultBroadcaster.java:890) 
     at org.atmosphere.cpr.DefaultBroadcaster.broadcast(DefaultBroadcaster.java:875) 
     at org.atmosphere.jersey.AtmosphereFilter$Filter.broadcast(AtmosphereFilter.java:632) 
     at org.atmosphere.jersey.AtmosphereFilter$Filter.filter(AtmosphereFilter.java:468) 
     at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1416) 
     at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) 
     at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) 
     at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) 
     at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 
     at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) 
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) 
     at org.atmosphere.util.AtmosphereFilterChain.doFilter(AtmosphereFilterChain.java:155) 
     ... 44 more 
|#] 

我如何才能讓我的工作播音員?我需要返回JSONWithPadding對象還是僅返回POJO?

回答

1

你得到一個AbstractMethodError。你的班級路線有沒有氣氛?

+0

是的,atmosphere-commons-0.6.5.jar在類路徑上... – jabal

+0

我刪除了它,現在stacktrace改爲:由org.atmosphere.cpr.BroadcasterConfig中的java.lang.AbstractMethodError 引起。過濾器(BroadcasterConfig.java:447) at org.atmosphere.cpr.DefaultBroadcaster.filter(DefaultBroadcaster.java:890)' – jabal

+0

我扔掉了每個罐子,只放入官方樣品。這樣就產生了氛圍 - 問題 - commons.jar,問題發生了變化。現在我在客戶端收到'com.sun.jersey.api.json.JSONWithPadding @ 180ce9c',所以現在只有序列化失蹤了:-) – jabal