0

grailsでチャットアプリを作ろうとしています。私はgrails 3.0.9とtomcat-8.0.28を使用しています

重複して申し訳ありません

私はこの質問これを読みました...しかし、それは私の問題を解決しません..

私はすでに javax.websocket-api を次のように提供されたものに変更しています:

provided 'javax.websocket:javax.websocket-api:1.0'

しかし、私はまだこのエラーが発生します:

Firefox: Firefox はhttp://103.56.148.50/chat/chatEndPoint/C001D939F2564251C86E646B9127495Dでサーバーへの接続を確立できません」

Chrome: WebSocket ハンドシェイク中のエラー: 予期しない応答コード: 404

あなたはこのサイトを見ることができます...

これは私のコードです

package com.akiong

import grails.util.Environment
import grails.util.Holders

import javax.servlet.ServletContext
import javax.servlet.ServletContextEvent
import javax.servlet.ServletContextListener
import javax.servlet.annotation.WebListener
import javax.websocket.EndpointConfig
import javax.websocket.OnClose
import javax.websocket.OnError
import javax.websocket.OnMessage
import javax.websocket.OnOpen
import javax.websocket.Session
import javax.websocket.server.PathParam
import javax.websocket.server.ServerContainer
import javax.websocket.server.ServerEndpoint
import com.akiong.services.ChatService
import javax.websocket.EncodeException
//import org.codehaus.groovy.grails.commons.ApplicationHolder as AH

import javax.servlet.annotation.WebListener
import java.util.concurrent.CopyOnWriteArraySet

@WebListener
@ServerEndpoint(value="/chat/chatEndPoint/{username}")

public class ServerEndPointDemo implements ServletContextListener {
    private static HashMap<String, String> usersMap = new HashMap<String, String>();
    private static final Set<ServerEndPointDemo> connections = new CopyOnWriteArraySet<>();
    private String username
    private Session session

    @OnOpen
    public void  handleOpen(Session session,@PathParam("username") String user){
        System.out.println("-------------------------------------");
        System.out.println(session.getId() + " has opened a connection");
        println "user = "+user
        connections.add(this);
        this.username   = user
        this.session    = session
    }

    @OnClose
    public void  handleClose(Session session){
        System.out.println("Session " +session.getId()+" has ended");
    }

    @OnMessage
    public String handleMessage(String message,Session session){
       println "message = "+message
       println "session= "+session.getId()

    }

    @OnError
    public void  handleError(Throwable t){
        connections.remove(this);
        println "username = "+username
        removeUserInMap(session.getId(), username);
    }
}

これはJavaScriptで

var wsUri = "ws://103.56.148.50/chat/chatEndPoint/"+room;
    var webSocket = new WebSocket(wsUri);



    webSocket.onopen    = function(message) {OnOpen(message);};
    webSocket.onclose   = function(message) {OnClose(message);};
    webSocket.onerror   = function(message) {OnError(message);};
    webSocket.onmessage = function(message) {OnMessage(message);};


function OnOpen(message){
    console.log("Open Socket");
}

function OnClose(message){
   console.log("Close = "+message);
    webSocket.close();
}

function OnError(message){
    console.log("ERROR = "+message);
}

function OnMessage(message){
  webSocket.send("success");
}

これはbuild.gradleの私の依存関係です

dependencies {
    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    provided "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"

    compile "org.grails.plugins:hibernate"
    compile "org.grails.plugins:cache"
    compile "org.hibernate:hibernate-ehcache"
    compile "org.grails.plugins:scaffolding"

    runtime "org.grails.plugins:asset-pipeline"

    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"

    console "org.grails:grails-console"

    //-----------------------------------here i add my code-------------------
    compile 'org.grails.plugins:spring-security-core:3.0.0.M1'

    runtime 'mysql:mysql-connector-java:5.1.20'

    compile "org.grails.plugins:mail:2.0.0.RC2"

    compile 'org.grails.plugins:jms:2.0.0.M1' //http://gpc.github.io/jms/snapshot/guide/introduction.html

    runtime 'org.apache.activemq:activemq-spring:5.11.1'

    provided 'javax.websocket:javax.websocket-api:1.0'

}

================================================== =================

実行しようとしました: grails prod run-app

私のウェブソケットが機能しなくなりました...

しかし、grails run-app を実行すると動作します

それはServerEndPointDemo.groovy私が入れたから/src/main/groovy/com.akiong/ServerEndPointDemo.groovy ですか?

================================================== ============================

削除後にこのエラーが発生しますif (Environment.current == Environment.DEVELOPMENT)

Configuring Spring Security Core ...
... finished configuring Spring Security Core

anc
Environment.current = PRODUCTION
Environment.DEVELOPMENT = DEVELOPMENT
Environment.current = PRODUCTION
Environment.DEVELOPMENT = DEVELOPMENT
26-Nov-2015 23:29:40.407 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal One or more listeners failed to start. Full details will be found in the appropriate container log file
26-Nov-2015 23:29:40.420 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [] startup failed due to previous errors
26-Nov-2015 23:29:40.769 SEVERE [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.checkThreadLocalMapForLeaks The web application [ROOT] created a ThreadLocal with key of type [org.grails.web.converters.configuration.ConvertersConfigurationHolder$2] (value [org.grails.web.converters.configuration.ConvertersConfigurationHolder$2@5ce7a180]) and a value of type [java.util.HashMap] (value [{}]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
26-Nov-2015 23:29:40.794 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /root/apache-tomcat-8.0.28/webapps/ROOT.war has finished in 94,084 ms
26-Nov-2015 23:29:40.796 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-80"]
26-Nov-2015 23:29:40.802 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
26-Nov-2015 23:29:40.803 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 94281 ms
4

0 に答える 0