简体   繁体   English

Websocket与Openshift中的Tyrus

[英]Websocket with Tyrus in Openshift

I deployed an Wildfly 8.1 java application using Tyrus to manage a websocket server, nothing too complicated, it just receives the message and respond the message reversed, well, it should work, everything is according to OpenShift tutorial, but on deploy, I get this message on the rhc tail: 我使用Tyrus部署了一个Wildfly 8.1 Java应用程序来管理Websocket服务器,没有什么太复杂的,它只是接收消息并响应反向消息,嗯,它应该可以工作,一切都根据OpenShift教程进行,但是在部署时,我得到了Rhc尾巴上的消息:

2015-01-02 21:16:19,314 ERROR [io.undertow.websockets.jsr] (MSC service thread 1
-2) UT026002: Unable to instantiate server configuration class org.glassfish.tyr
us.server.TyrusServerConfiguration: java.lang.InstantiationException: org.glassf
ish.tyrus.server.TyrusServerConfiguration
        at java.lang.Class.newInstance(Class.java:418) [rt.jar:1.8.0_05]
        at org.wildfly.extension.undertow.deployment.UndertowJSRWebSocketDeploym
entProcessor.doDeployment(UndertowJSRWebSocketDeploymentProcessor.java:213)
        at org.wildfly.extension.undertow.deployment.UndertowJSRWebSocketDeploym
entProcessor.deploy(UndertowJSRWebSocketDeploymentProcessor.java:165)
        at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(Deplo
ymentUnitPhaseService.java:159)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(Se
rviceControllerImpl.java:1948)
        at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceCont
rollerImpl.java:1881)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.
java:1142) [rt.jar:1.8.0_05]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor
.java:617) [rt.jar:1.8.0_05]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_05]
Caused by: java.lang.NoSuchMethodException: org.glassfish.tyrus.server.TyrusServ
erConfiguration.<init>()
        at java.lang.Class.getConstructor0(Class.java:2971) [rt.jar:1.8.0_05]
        at java.lang.Class.newInstance(Class.java:403) [rt.jar:1.8.0_05]
        ... 8 more

And when I try to connect to the socket, I can connect, but it work as a previous version of it(that didnt reverse). 当我尝试连接到套接字时,我可以连接,但是它可以作为它的早期版本使用(没有反向操作)。

Here is the Websocket server source: 这是Websocket服务器的来源:

@ServerEndpoint(value = "/socket")
public class WebSocket {

    private Logger logger = Logger.getLogger(this.getClass().getName());
    private Reconhecedor reconhecedor = new Reconhecedor();

    @OnOpen
    public void onOpen(Session session) {
        logger.info("Connected Recognizer ... " + session.getId());
    }

    @OnMessage
    public String onMessage(String message, Session session) {
        logger.info("String message arrived");

        return new StringBuilder(message).reverse().toString();
    }

    @OnMessage
    public String onMessage(ByteBuffer message, Session session) {
        logger.info("byte message arrived");
        String result = "";
        ByteArrayInputStream baiut = new ByteArrayInputStream(message.array());
        AudioInputStream ais;
        try {
            ais = AudioSystem.getAudioInputStream(baiut);
            result = reconhecedor.Recognize(ais);
            logger.info("returning: " + result);
            //session.close(new CloseReason(CloseCodes.NORMAL_CLOSURE, "Game ended"));
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;
    }

    @OnClose
    public void onClose(Session session, CloseReason closeReason) {
        logger.info(String.format("Session %s closed because of %s", session.getId(), closeReason));
    }
}

And also, my server source: 而且,我的服务器来源:

public class Programa {

    public static void main(String[] args) {
        runServer();
    }

    public static void runServer() {

        String ip = System.getenv("OPENSHIFT_WILDFLY_IP");
        int port = 8000; 

        Server server = new Server(ip, port, "", WebSocket.class);

        try {
            server.start();
            System.out.print("Please press a key to stop the server.");
            System.in.read();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            server.stop();
        }
    }
}

I'm kinda lost, dont know what else to do, seems like javascript websocket is so much simple and works well, but I need it java because I'm going to use that socket for Sphinx CMU. 我有点迷茫,不知道该怎么办,似乎javascript websocket非常简单并且运行良好,但是我需要Java,因为我将使用该套接字用于Sphinx CMU。

Any help is appreciated, thanks in advance! 任何帮助表示赞赏,在此先感谢!

Openshift有资源限制,我的堆栈占用大量资源,因为我使用的语音识别占用了太多的资源,因此,我没有使用Tyrus和Wildfly,而是使用了原始Java +纯套接字通信,从而解决了该问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM