2011-09-07 151 views
3

上發佈訂閱例如獲取錯誤我正在關注的教程這裏 http://jfarcand.wordpress.com/2011/06/29/rest-websocket-applications-why-not-using-the-atmosphere-framework/使用大氣+新澤西

我已經有一個項目新澤西州啓動和運行,並使用JBoss 7.一個區別,我有是我很好的工作使用澤西與春天。所以我JQueryPubSub看起來像這樣

@Service <-- For Spring component Scan 
@Path("/pubsub/{topic}") 
@Produces("text/html;charset=ISO-8859-1") 
public class JQueryPubSub { 

@PathParam("topic") 
Broadcaster topic; 

@GET 
public SuspendResponse<String> subscribe() { 
    return new SuspendResponse.SuspendResponseBuilder<String>() 
      .broadcaster(topic) 
      .outputComments(true) 
      .addListener(new EventsLogger()) 
      .build(); 
} 

@POST 
@Broadcast 
public Broadcastable publish(@FormParam("message") String message) { 
    return new Broadcastable(message, "", topic); 
} 
} 

,所以我想添加這個例子,但我越來越

22:55:27381嚴重[com.sun.jersey.spi.inject.Errors(MSC服務線程1-3)與資源 和/或供應商類已檢測到以下錯誤和警告: 重度:現場缺少相關性:org.atmosphere.cpr.Broadcaster com.order.resources.JQueryPubSub.topic

任何想法我怎麼能解決這個問題,以及爲什麼澤西似乎積極地向廣播公司注入價值? ?

+0

我不知道,如果彈簧或球衣是這裏的問題。 你有更多的日誌輸出顯示嗎? – Christian

回答

2

我有同樣的問題,並能夠通過更新澤西罐從1.4到1.6來解決它 如果您使用maven,您可以添加以下依賴項。

<dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-server</artifactId> 
     <version>1.6</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-core</artifactId> 
     <version>1.6</version> 
    </dependency> 
    <dependency> 
     <groupId>com.sun.jersey</groupId> 
     <artifactId>jersey-json</artifactId> 
     <version>1.6</version> 
    </dependency> 
1

接聽後不久time..but人誰試圖仍然可以採取一些優勢,這項

,你可以用下面的嘗試。 我只是想和它的工作對我來說

第1步
如果您使用的是WebLogic 12c分別作如下改動

function subscribe() { 
     var request = { 
      url :document.location.origin+'/<your-context-path>/ws/pubsub/' + getElementByIdValue('topic'), 

步驟2
在web.xml中添加下面的配置

<servlet> 
<description>AtmosphereServlet</description> 
<servlet-name>AtmosphereServlet</servlet-name> 
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class> 
<init-param> 
    <param-name>com.sun.jersey.config.property.packages</param-name> 
    <param-value>*******package name where your handler is**********</param-value> 
</init-param> 
<init-param> 
    <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name> 
    <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value> 
</init-param> 
<init-param> 
    <param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name> 
    <param-value>org.atmosphere.client.TrackMessageSizeFilter 
     </param-value> 
</init-param> 
    <init-param> 
    <param-name>WEBSOCKET_PROTOCOL_EXECUTION</param-name> 
    <param-value>true</param-value> 
</init-param> 
<load-on-startup>0</load-on-startup> 
<async-supported>true</async-supported> 
</servlet> 
<servlet-mapping> 
<servlet-name>AtmosphereServlet</servlet-name> 
<url-pattern>/pubsub/*</url-pattern> 
</servlet-mapping> 

step- 3

粘貼到您在上述步驟中定義的包的Java文件下面的代碼(也可以在大氣中的git的網站上找到)

import java.io.IOException; 
import org.atmosphere.client.TrackMessageSizeInterceptor; 
import org.atmosphere.config.service.AtmosphereHandlerService; 
import org.atmosphere.config.service.Singleton; 
import org.atmosphere.cpr.AtmosphereResourceEvent; 
import org.atmosphere.handler.AtmosphereHandlerAdapter; 
import org.atmosphere.interceptor.AtmosphereResourceLifecycleInterceptor; 
import org.atmosphere.interceptor.BroadcastOnPostAtmosphereInterceptor; 
import org.atmosphere.interceptor.SuspendTrackerInterceptor; 
import org.atmosphere.util.SimpleBroadcaster; 


@Singleton 
@AtmosphereHandlerService(path = "/{chat}", 
    interceptors = { 
     AtmosphereResourceLifecycleInterceptor.class, 
     TrackMessageSizeInterceptor.class, 
     BroadcastOnPostAtmosphereInterceptor.class, 
     SuspendTrackerInterceptor.class}, 
    broadcaster = SimpleBroadcaster.class) 
public class AtmosphereHandler extends AtmosphereHandlerAdapter { 

@Override 
public void onStateChange(AtmosphereResourceEvent event) throws IOException { 
    if (event.isSuspended()) { 
     String message = event.getMessage() == null ? null : event.getMessage().toString(); 
     if (message != null && message.indexOf("message") != -1) { 
      event.getResource().write(message.substring("message=".length())); 
     } else { 
      event.getResource().write("=error="); 
     } 
    } 
} 

} 

立即部署它的工作耳朵。 。

Jar文件

atmosphere-annotations-2.1.1.jar 
atmosphere-jersey-2.1.1.jar 
atmosphere-runtime-2.1.1.jar 
atmosphere-weblogic-2.1.1.jar 
commons-collections-3.2.1.jar 
commons-dbutils-1.5.jar 
commons-io-2.4.jar 
jersey-core-1.17.1.jar 
jersey-json-1.17.1.jar 
jersey-server-1.17.1.jar 
jersey-servlet-1.17.1.jar 
log4j-1.2.15.jar