我正在使用Grizzly 2.3.11测试Atmosphere 2.1.3。我已经创建了一个 ManagedService(path =“/ chat”),但是我收到了这个错误:'没有AtmosphereHandler映射请求/ chat状态500消息服务器错误'。如果我将路径更改为 ManagedService(path =“/”),则可以正常工作。我调试了一下,似乎org.atmosphere.cpr.AtmosphereRequest.getServletPath()返回null,因此使用默认路径“/”,这是使我的测试工作的原因 ManagedService(path = “/”)
我将非常感谢您的帮助,因为我需要使用类似ManagedService(path =“/ chat”)的路径。
注意:此帖子与Atmosphere + Grizzly: No AtmosphereHandler maps request for /chat Status 500 Message Server Error
相关PD:这是我的主要测试类:
package com.dweb.atmosphere.grizzly;
import java.io.IOException;
import org.atmosphere.container.Grizzly2CometSupport;
import org.atmosphere.cpr.AtmosphereServlet;
import org.glassfish.grizzly.comet.CometAddOn;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.grizzly.http.server.NetworkListener;
import org.glassfish.grizzly.http.server.StaticHttpHandler;
import org.glassfish.grizzly.servlet.ServletRegistration;
import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.grizzly.websockets.WebSocketAddOn;
public class Main {
public static void main(String[] args) throws IOException {
final HttpServer server = HttpServer.createSimpleServer(".", 8181);
final WebappContext ctx = new WebappContext("ctx", "/");
// enable web socket support
final WebSocketAddOn addon = new WebSocketAddOn();
for (NetworkListener listener : server.getListeners()) {
listener.registerAddOn(addon);
}
// add atmosphere servlet support
final AtmosphereServlet atmosphereServlet = new AtmosphereServlet();.
final ServletRegistration atmosphereServletRegistration = ctx.addServlet("AtmosphereServlet", atmosphereServlet);
atmosphereServletRegistration.setInitParameter(
"org.atmosphere.websocket.messageContentType",
"application/json");
atmosphereServletRegistration.addMapping("/chat/*");
atmosphereServletRegistration.setLoadOnStartup(1);
// deploy
ctx.deploy(server);
try {
server.start();
System.out.println("Press enter to stop the server...");
System.in.read();
} finally {
server.shutdownNow();
}
}
}
PD2:这是我的ChatRoom测试类:
package com.dweb.atmosphere.grizzly;
import static org.atmosphere.cpr.ApplicationConfig.MAX_INACTIVE;
import java.io.IOException;
import org.atmosphere.config.service.Disconnect;
import org.atmosphere.config.service.Get;
import org.atmosphere.config.service.ManagedService;
import org.atmosphere.config.service.Ready;
import org.atmosphere.cpr.AtmosphereResource;
import org.atmosphere.cpr.AtmosphereResourceEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Simple annotated class that demonstrate the power of Atmosphere. This class supports all transports, support
* message length garantee, heart beat, message cache thanks to the {@link ManagedService}.
*/
@Config
@ManagedService(path = "/chat", atmosphereConfig = MAX_INACTIVE + "=120000")
public class ChatRoom {
private final Logger logger = LoggerFactory.getLogger(ChatRoom.class);
/**
* Invoked when the connection as been fully established and suspended, e.g ready for receiving messages.
*
* @param r
*/
@Ready
public void onReady(final AtmosphereResource r) {
logger.debug("Browser {} connected.", r.uuid());
}
/**
* Invoked when the client disconnect or when an unexpected closing of the underlying connection happens.
*
* @param event
*/
@Disconnect
public void onDisconnect(AtmosphereResourceEvent event) {
if (event.isCancelled()) {
logger.info("Browser {} unexpectedly disconnected", event.getResource().uuid());
} else if (event.isClosedByClient()) {
logger.info("Browser {} closed the connection", event.getResource().uuid());
}
}
/**
* Simple annotated class that demonstrate how {@link org.atmosphere.config.managed.Encoder} and {@link org.atmosphere.config.managed.Decoder
* can be used.
*
* @param message an instance of {@link Message}
* @return
* @throws IOException
*/
@org.atmosphere.config.service.Message
public String onMessage(String message) throws IOException {
logger.info("just send() {}", message);
return message;
}
}
PD3:这是我的服务器日志
Apr 23, 2014 2:16:46 PM org.glassfish.grizzly.servlet.WebappContext deploy
INFO: Starting application [ctx] ...
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Atmosphere is using org.atmosphere.cpr.DefaultAnnotationProcessor for processing annotation
[main] INFO org.atmosphere.cpr.DefaultAnnotationProcessor - AnnotationProcessor class org.atmosphere.cpr.DefaultAnnotationProcessor$BytecodeBasedAnnotationProcessor being used
[main] INFO org.atmosphere.cpr.DefaultAnnotationProcessor - Found Annotation in com.dweb.atmosphere.grizzly.ChatAtmosphereHandler being scanned: interface org.atmosphere.config.service.AtmosphereHandlerService
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Installed AtmosphereHandler com.dweb.atmosphere.grizzly.ChatAtmosphereHandler mapped to context-path /chat2 and Broadcaster Class org.atmosphere.cpr.DefaultBroadcaster
[main] INFO org.atmosphere.cpr.DefaultAnnotationProcessor - Found Annotation in com.dweb.atmosphere.grizzly.ChatRoom being scanned: interface org.atmosphere.config.service.ManagedService
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Installed AtmosphereHandler org.atmosphere.config.managed.ManagedAtmosphereHandler mapped to context-path /chat and Broadcaster Class org.atmosphere.cpr.DefaultBroadcaster
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Installed AtmosphereInterceptor [@ManagedService Interceptor, Atmosphere LifeCycle, Track Message Size Interceptor using |, UUID Tracking Interceptor] mapped to AtmosphereHandler org.atmosphere.config.managed.ManagedAtmosphereHandler
[main] INFO org.atmosphere.cpr.DefaultAnnotationProcessor - Found Annotation in com.dweb.atmosphere.grizzly.Chat being scanned: interface org.atmosphere.config.service.ManagedService
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Installed AtmosphereHandler org.atmosphere.config.managed.ManagedAtmosphereHandler mapped to context-path /chatzz and Broadcaster Class org.atmosphere.cpr.DefaultBroadcaster
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Installed AtmosphereInterceptor [@ManagedService Interceptor, Atmosphere LifeCycle, Track Message Size Interceptor using |, UUID Tracking Interceptor] mapped to AtmosphereHandler org.atmosphere.config.managed.ManagedAtmosphereHandler
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Auto detecting WebSocketHandler in /WEB-INF/classes/
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Installed WebSocketProtocol org.atmosphere.websocket.protocol.SimpleHttpProtocol
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Installing Default AtmosphereInterceptor
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.CorsInterceptor : CORS Interceptor Support
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.CacheHeadersInterceptor : Default Response's Headers Interceptor
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.PaddingAtmosphereInterceptor : Browser Padding Interceptor Support
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.AndroidAtmosphereInterceptor : Android Interceptor Support
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.HeartbeatInterceptor : Heartbeat Interceptor Support
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.SSEAtmosphereInterceptor : SSE Interceptor Support
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.JSONPAtmosphereInterceptor : JSONP Interceptor Support
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.JavaScriptProtocol : Atmosphere JavaScript Protocol
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.WebSocketMessageSuspendInterceptor : org.atmosphere.interceptor.WebSocketMessageSuspendInterceptor
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.OnDisconnectInterceptor : Browser disconnection detection
[main] INFO org.atmosphere.cpr.AtmosphereFramework - org.atmosphere.interceptor.IdleResourceInterceptor : org.atmosphere.interceptor.IdleResourceInterceptor
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Set org.atmosphere.cpr.AtmosphereInterceptor.disableDefaults to disable them.
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Using EndpointMapper class org.atmosphere.util.DefaultEndpointMapper
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Using BroadcasterCache: org.atmosphere.cache.UUIDBroadcasterCache
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Default Broadcaster Class: org.atmosphere.cpr.DefaultBroadcaster
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Broadcaster Polling Wait Time 100
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Shared ExecutorService supported: true
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Messaging Thread Pool Size: Unlimited
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Async I/O Thread Pool Size: 200
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Using BroadcasterFactory: org.atmosphere.cpr.DefaultBroadcasterFactory
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Using WebSocketProcessor: org.atmosphere.websocket.DefaultWebSocketProcessor
[main] INFO org.atmosphere.cpr.AtmosphereFramework - HttpSession supported: false
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Atmosphere is using DefaultAtmosphereObjectFactory for dependency injection and object creation
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Atmosphere is using async support: org.atmosphere.container.GlassFishServ30WebSocketSupport running under container: Grizzly 2.3.11 with WebSocket enabled.
[main] INFO org.atmosphere.cpr.AtmosphereFramework - Atmosphere Framework 2.1.3 started.
[main] INFO org.atmosphere.cpr.AtmosphereFramework -
For Atmosphere Framework Commercial Support, visit
http://www.async-io.org/ or send an email to support@async-io.org
Apr 23, 2014 2:16:46 PM org.glassfish.grizzly.servlet.WebappContext initServlets
INFO: [ctx] Servlet [org.atmosphere.cpr.AtmosphereServlet] registered for url pattern(s) [[/chat/*]].
Apr 23, 2014 2:16:46 PM org.glassfish.grizzly.servlet.WebappContext deploy
INFO: Application [ctx] is ready to service requests. Root: [/].
Apr 23, 2014 2:16:46 PM org.glassfish.grizzly.http.server.NetworkListener start
INFO: Started listener bound to [0.0.0.0:8181]
Apr 23, 2014 2:16:46 PM org.glassfish.grizzly.http.server.HttpServer start
INFO: [HttpServer] Started.
Press enter to stop the server...
[Thread-1] INFO org.atmosphere.cpr.AtmosphereFramework - Latest version of Atmosphere's JavaScript Client 2.1.5
[Grizzly(7) SelectorRunner] WARN org.atmosphere.websocket.DefaultWebSocketProcessor - Failed invoking AtmosphereFramework.doCometSupport()
org.atmosphere.cpr.AtmosphereMappingException: No AtmosphereHandler maps request for /chat
at org.atmosphere.cpr.AsynchronousProcessor.map(AsynchronousProcessor.java:329)
at org.atmosphere.cpr.AsynchronousProcessor.action(AsynchronousProcessor.java:133)
at org.atmosphere.cpr.AsynchronousProcessor.suspended(AsynchronousProcessor.java:95)
at org.atmosphere.container.GlassFishServ30WebSocketSupport.service(GlassFishServ30WebSocketSupport.java:60)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1805)
at org.atmosphere.websocket.DefaultWebSocketProcessor.dispatch(DefaultWebSocketProcessor.java:432)
at org.atmosphere.websocket.DefaultWebSocketProcessor.open(DefaultWebSocketProcessor.java:186)
at org.atmosphere.container.GlassFishServ30WebSocketSupport$Grizzly2WebSocketApplication.onConnect(GlassFishServ30WebSocketSupport.java:144)
at org.glassfish.grizzly.websockets.SimpleWebSocket.onConnect(SimpleWebSocket.java:135)
at org.glassfish.grizzly.websockets.WebSocketEngine.upgrade(WebSocketEngine.java:185)
at org.glassfish.grizzly.websockets.WebSocketEngine.upgrade(WebSocketEngine.java:143)
at org.glassfish.grizzly.websockets.WebSocketFilter.doServerUpgrade(WebSocketFilter.java:104)
at org.glassfish.grizzly.websockets.WebSocketFilter.handleServerHandshake(WebSocketFilter.java:87)
at org.glassfish.grizzly.websockets.WebSocketFilter.handleHandshake(WebSocketFilter.java:68)
at org.glassfish.grizzly.websockets.BaseWebSocketFilter.handleRead(BaseWebSocketFilter.java:197)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:291)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:209)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:137)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:115)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:550)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
at org.glassfish.grizzly.strategies.SameThreadIOStrategy.executeIoEvent(SameThreadIOStrategy.java:103)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.executeIoEvent(AbstractIOStrategy.java:89)
at org.glassfish.grizzly.nio.SelectorRunner.iterateKeyEvents(SelectorRunner.java:412)
at org.glassfish.grizzly.nio.SelectorRunner.iterateKeys(SelectorRunner.java:381)
at org.glassfish.grizzly.nio.SelectorRunner.doSelect(SelectorRunner.java:345)
at org.glassfish.grizzly.nio.SelectorRunner.run(SelectorRunner.java:276)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:744)
[Grizzly(7) SelectorRunner] WARN org.atmosphere.websocket.protocol.SimpleHttpProtocol - org.atmosphere.cpr.AtmosphereMappingException: No AtmosphereHandler maps request for /chat Status 500 Message Server Error
嗨Alexey,
我正在调试这个问题,这些是我的测试&结果:
- 当我在内部调用“http://localhost:8181/chat/a/b/c
”时,会构建此请求:“AtmosphereRequest{ contextPath= servletPath=/chat pathInfo=/a/b/c requestURI=/chat/a/b/c destroyable=true}
”好吧,Http Get请求似乎工作正常。
- 当我在内部调用'new WebSocket('ws://localhost:8181/chat/a/b/c')
'时,此请求构建为“AtmosphereRequest{ contextPath= servletPath=null pathInfo=null requestURI=/chat/a/b/c destroyable=true}
”我认为问题(servletPath& pathInfo为空)仅在我使用websockets时发生
我正在调整方法org.glassfish.grizzly.websockets.WebSocketEngine.upgrade(FilterChainContext ctx,HttpContent requestContent,Mapper mapper)并且param requestContent接收此值:
HttpRequestPacket (
method=GET
url=/chat/a/b/c
query=null
protocol=HTTP/1.1
content-length=-1
headers=[
upgrade=websocket
connection=Upgrade
host=localhost:8181
origin=http://localhost:8080
pragma=no-cache
cache-control=no-cache
sec-websocket-key=3pRm4vKnwqvRO8G0/WUNBw==
sec-websocket-version=13
sec-websocket-extensions=permessage-deflate; client_max_window_bits, x-webkit-deflate-frame
user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36]
)
但在我的调试会话结束时,方法org.atmosphere.util.DefaultEndpointMapper.computePath(AtmosphereRequest req)接收带有此值的param req:AtmosphereRequest {contextPath = servletPath = null pathInfo = null requestURI = / chat / a / b / c destroyable = true}
嗯,我希望这些测试对你有一些价值,无论如何你需要更多的测试随时问。