Erro WebSocket durante o código inesperado Handshake 200

Eu tenho usado o Glassfish 4 como meu servidor. Estou abrindo uma conexão WebSocket usando esta declaração:

webSocket = new WebSocket(link); 

Onde:

 link = 'ws://localhost:8080/CollabEdit/Document/file333B1CDF85-DDDC-E411-8299-F82FA8BE8622'; 

E no arquivo do servidor:

 @ServerEndpoint(value="/file333B1CDF85-DDDC-E411-8299-F82FA8BE8622", encoders = {MessageEncoder.class}, decoders = {MessageDecoder.class}) 

Na verdade, também tenho usado o mapeamento de URLs, mas ” file333B1CDF85-DDDC-E411-8299-F82FA8BE8622 ” é na verdade para o usuário, mas no back-end, o controle está no arquivo ” main.jsp “. Durante a execução, o erro gerado é:

 WebSocket connection to 'ws://localhost:8080/CollabEdit/Document/file333B1CDF85-DDDC-E411-8299-F82FA8BE8622' failed: Error during WebSocket handshake: Unexpected response code: 200 

StackTrace of Exception no servidor GlassFish:

 SEVERE: WebModule[/CollabEdit]Exception starting filter WebSocket filter java.lang.InstantiationException at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:135) at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:5297) at org.apache.catalina.core.StandardContext.start(StandardContext.java:5909) at com.sun.enterprise.web.WebModule.start(WebModule.java:691) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2278) at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1924) at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139) at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122) at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:291) at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:352) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:497) at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:219) at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:491) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:527) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:523) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:356) at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:522) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:546) at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1423) at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1500(CommandRunnerImpl.java:108) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1762) at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1674) at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:534) at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:224) at org.glassfish.grizzly.http.server.StaticHttpHandler.service(StaticHttpHandler.java:297) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:246) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544) at java.lang.Thread.run(Thread.java:744) Caused by: javax.servlet.ServletException: Web socket server initialization failed. at org.glassfish.tyrus.servlet.TyrusServletFilter.init(TyrusServletFilter.java:135) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275) at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:131) ... 46 more Caused by: javax.websocket.DeploymentException: Decoder for type: class com.CollabEdit.Message has not been registered. Decoder for type: class com.CollabEdit.Message has not been registered. at org.glassfish.tyrus.core.ErrorCollector.composeComprehensiveException(ErrorCollector.java:83) at org.glassfish.tyrus.server.TyrusServerContainer.start(TyrusServerContainer.java:144) at org.glassfish.tyrus.servlet.TyrusServletFilter.init(TyrusServletFilter.java:133) ... 48 more 

Message.java:

 package com.CollabEdit; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.StringWriter; import javax.json.Json; import javax.json.JsonObject; public class Message { private JsonObject json; public Message(JsonObject json) { this.json = json; } public JsonObject getJson() { return json; } public void setJson(JsonObject json) { this.json = json; } @Override public String toString(){ StringWriter writer = new StringWriter(); Json.createWriter(writer).write(json); return writer.toString(); } } 

MessageDecoder.java:

 package com.CollabEdit; import java.io.StringReader; import javax.json.Json; import javax.json.JsonException; import javax.json.JsonObject; import javax.websocket.DecodeException; import javax.websocket.Decoder; import javax.websocket.EndpointConfig; /** * Decodes a client-sent string into a Message class */ public class MessageDecoder implements Decoder.Text { /** * Transform the input string into a Message */ @Override public Message decode(String string) throws DecodeException { JsonObject json = Json.createReader(new StringReader(string)).readObject(); return new Message(json); } /** * Checks whether the input can be turned into a valid Message object * in this case, if we can read it as a Json object, we can. */ @Override public boolean willDecode(String string) { try{ Json.createReader(new StringReader(string)).read(); return true; }catch (JsonException ex){ ex.printStackTrace(); return false; } } /** * The following two methods are placeholders as we don't need to do anything * special for init or destroy. */ @Override public void init(EndpointConfig config) { System.out.println("init"); } @Override public void destroy() { System.out.println("destroy"); } } 

Intereting Posts