2016-09-13 13 views
0

私はwebsocketでアプリケーションを試しています。私がGlassfishに使用するサーバーとして、うまく動作しますが、websocketに問題があります。Glassfish websocketが動作しない

私はコンソールにJavaScriptが含まれるHTMLを実行する404

web.xmlのエラーです

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0"> 

    <display-name>Simple web application </display-name> 

</web-app> 

build.gradle

repositories { 
    mavenCentral() 
    mavenLocal() 
    jcenter() 
} 
apply plugin: "java" 
apply plugin: 'application' 
apply plugin: 'war' 

mainClassName = "websockets.WebSocketServer" 
version = '1.0' 


dependencies { 
    compile 'javax.inject:javax.inject:1' 
    compile 'com.google.inject:guice:4.0' 
    compile 'javax.websocket:javax.websocket-api:1.0' 
    compile 'org.glassfish.tyrus:tyrus-server:1.1' 
    compile 'org.glassfish.tyrus:tyrus-client:1.0' 
    compile 'org.glassfish.tyrus:tyrus-container-grizzly:1.0' 
    compile 'javax:javaee-api:7.0' 

    testCompile 'info.cukes:cucumber-java:1.2.4' 
    testCompile 'info.cukes:cucumber-junit:1.2.4' 
    testCompile 'junit:junit:4.11' 
    testCompile "org.mockito:mockito-core:2.0.86-beta" 
} 

sourceSets { 
    main.java.srcDir "src/java" 
    test.java.srcDir "src/test" 
    main.resources.srcDir 'src/resources' 
    main.resources.include '**/*.xml' 
    main.resources.include 'META-INF/services/**' 
} 

processResources.doLast { 
    copy { 
     from 'build/resources/main/META-INF/beans.xml' 
     into 'build/classes/main/META-INF/' 
    } 
} 
task fatJar(type: Jar) { 
    manifest { 
     attributes 'Implementation-Title': 'Gradle Jar File Example', 
       'Implementation-Version': version, 
       'Main-Class': 'websockets.WebSocketServer' 
    } 
    baseName = project.name + '-all' 
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } { 
     exclude "META-INF/*.SF" 
     exclude "META-INF/*.DSA" 
    } 
     with jar 
} 

war { 
manifest { 
    attributes 'Main-Class': 'websockets.WebSocketServer' 
    } 
} 

のsrc /メイン/ javaの/ WebSocketを私は持っているWebSocketServerに.java

package websockets; 


import java.io.BufferedReader; 
import java.io.InputStreamReader; 
import java.net.ServerSocket; 
import java.net.Socket; 
import java.io.IOException; 

import javax.websocket.OnClose; 
import javax.websocket.OnMessage; 
import javax.websocket.OnOpen; 
import javax.websocket.Session; 
import javax.websocket.OnOpen; 
import javax.websocket.OnError; 
import javax.websocket.server.ServerEndpoint; 

@ServerEndpoint("/websocket") 
public class WebSocketServer { 

    @OnMessage 
    public void onMessage(String message, Session session) 
    throws IOException, InterruptedException { 

     // Print the client message for testing purposes 
     System.out.println("Received: " + message); 

     // Send the first message to the client 
     session.getBasicRemote().sendText("This is the first server message"); 

     // Send 3 messages to the client every 5 seconds 
     int sentMessages = 0; 
     while(sentMessages < 3){ 
      Thread.sleep(5000); 
      session.getBasicRemote(). 
      sendText("This is an intermediate server message. Count: " 
        + sentMessages); 
      sentMessages++; 
     } 

     // Send a final message to the client 
     session.getBasicRemote().sendText("This is the last server message"); 
    } 

    @OnOpen 
    public void onOpen() { 
     System.out.println("Client connected"); 
    } 

    @OnClose 
    public void onClose() { 
     System.out.println("Connection closed"); 
    } 

    @OnError 
    public void onError(Session aclientSession, Throwable aThrowable) { 
     System.out.println("Error : " + aclientSession); System.out.println("Error :" + aThrowable); 
    } 
} 

エラーなしで構築されたGradle。私はhttp://192.168.37.10:8080/web/page.htmlでアプリケーション(放浪のVirtualMachine)を実行すると

スローエラー:

'WS:// localhostを:8080 /ウェブ/のWebSocket' へのWebSocket接続に失敗しました:のWebSocketハンドシェイク中 エラー:予期しない応答コードを:GlassFishので404

は、コンテキストルートにアプリケーションを追加:ウェブ

が間違っていますか?手伝って頂けますか?お願いします。

atmosphere.addInitParameter(ApplicationConfig.PROPERTY_NATIVE_COMETSUPPORT, "true"); 
atmosphere.addInitParameter(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true"); 

またはweb.xmlのを:それは、次のオプションを追加した後に動作してくれてありがとう、あなた:)

答えて

-1

<init-param> 
    <param-name>org.atmosphere.useNative</param-name> 
    <param-value>true</param-value> 
</init-param> 
+0

を誰もがコメントしてくださいすることができ、この溶液を用いて彼の不快感は何ですか? – Tires

関連する問題