2015-07-20 30 views
1

我想用java的WebSocket與就餐simphony,但它不工作,碼頭,當我得到以下錯誤:錯誤使用與就餐simphony

 
    java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.getServletContext()Ljavax/servlet/ServletContext; 
     at org.eclipse.jetty.websocket.servlet.UpgradeHttpServletRequest.(UpgradeHttpServletRequest.java:91) 
     at org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest.(ServletUpgradeRequest.java:52) 
     at org.eclipse.jetty.websocket.server.WebSocketServerFactory.acceptWebSocket(WebSocketServerFactory.java:156) 
     at org.eclipse.jetty.websocket.server.WebSocketServerFactory.acceptWebSocket(WebSocketServerFactory.java:148) 
     at org.eclipse.jetty.websocket.server.WebSocketHandler.handle(WebSocketHandler.java:97) 
     at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) 
     at org.eclipse.jetty.server.Server.handle(Server.java:497) 
     at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311) 
     at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248) 
     at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540) 
     at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:610) 
     at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:539) 
     at java.lang.Thread.run(Thread.java:745) 

有人能解釋我如何解決這個問題?謝謝

我測試了從互聯網上所採取的代碼,如果我不就餐simphony

我的服務器上運行它

 
    package webSocketTest; 

    import org.eclipse.jetty.server.Server; 
    import org.eclipse.jetty.websocket.server.WebSocketHandler; 
    import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory; 

    public class WebSocketTest { 

     public static void main(String[] args) throws Exception { 
      Server server = new Server(8080); 
      WebSocketHandler wsHandler = new WebSocketHandler() { 
       @Override 
       public void configure(WebSocketServletFactory factory) { 
        factory.register(MyWebSocketHandler.class); 
       } 
      }; 
      server.setHandler(wsHandler); 
      server.start(); 
      server.join(); 
     } 
    } 

 

    package webSocketTest; 

    import java.io.IOException; 
    import org.eclipse.jetty.websocket.api.Session; 
    import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose; 
    import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect; 
    import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError; 
    import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage; 
    import org.eclipse.jetty.websocket.api.annotations.WebSocket; 

    @WebSocket 
    public class MyWebSocketHandler { 

     @OnWebSocketClose 
     public void onClose(int statusCode, String reason) { 
      System.out.println("Close: statusCode=" + statusCode + ", reason=" + reason); 
     } 

     @OnWebSocketError 
     public void onError(Throwable t) { 
      System.out.println("Error: " + t.getMessage()); 
     } 

     @OnWebSocketConnect 
     public void onConnect(Session session) { 
      System.out.println("Connect: " + session.getRemoteAddress().getAddress()); 
      try { 
       session.getRemote().sendString("Hello Webbrowser"); 
      } catch (IOException e) { 
       e.printStackTrace(); 
      } 
     } 

     @OnWebSocketMessage 
     public void onMessage(String message) { 
      System.out.println("Message: " + message); 
     } 
    } 

回答

1

另一個替代常規罐子的去除: 事實上就餐Simphony 2.2使用servlet的API 2.4。不含有javax.servlet.http.HttpServletRequest.getServletContext()方法。 另一種解決方案是然後通過最近的javax servlet的API來替換由就餐Simphony默認使用的servlet的API JAR

0

我終於找到了解決方案它的工作原理。我刪除了所有的常規罐子它們是由存在於項目構建路徑默認情況下,它的工作原理。