2017-01-30 24 views
-1

=== Консоль Java журнала ===Jboss EAP 6,4 - WebSocket 500 Внутренняя ошибка сервера

JBWEB000236: Servlet.service() for servlet default threw exception: java.lang.IllegalStateException: JBWEB000034: Cannot upgrade from HTTP/1.1 without IO events 

=== Код HTML ===

<body> 
    <div> 
     <div id="connect-container"> 
      <div> 
       <fieldset> 
        <legend>Connect or disconnect using WebSocket :</legend> 
        <input type="button" id="connect" onclick="connect();" 
         value="Open Connection" /> <input type="button" id="disconnect" 
         onclick="disconnect();" value="Close Connection" /> 
       </fieldset> 
      </div> 
      <div> 
       <fieldset> 
        <legend>Type your name below. then click the `Say Hello` 
         button :</legend> 
        <input id="name" type="text" size="40" style="width: 40%" /> <input 
         type="button" id="sayHello" onclick="sendMessage();" 
         value="Say Hello" disabled="disabled" /> 
       </fieldset> 
      </div> 
      <div> 
       Current WebSocket Connection Status: 
       <output id="currentstatus" class="message">Closed</output> 
      </div> 
      <div> 
       <output id="hellomessage" /> 
      </div> 
     </div> 
    </div> 
</body> 

=== Javascript код ===

var websocket = null; 

    function connect() { 

     var wsURI = "ws://localhost:8380/websockets-server/helloName"; 
     websocket = new WebSocket(wsURI); 

     websocket.onopen = function() { 
      displayStatus('Open'); 
      document.getElementById('sayHello').disabled = false; 
      displayMessage('Connection is now open. Type a name and click Say Hello to send a message.'); 
     }; 
     websocket.onmessage = function(event) { 
      // log the event     
      displayMessage('The response was received! ' + event.data, 
        'success'); 
     }; 
     websocket.onerror = function(event) { 
      // log the event 
      displayMessage('Error! ' + event.data, 'error'); 
     }; 
     websocket.onclose = function() { 
      displayStatus('Closed'); 
      displayMessage('The connection was closed or timed out. Please click the Open Connection button to reconnect.'); 
      document.getElementById('sayHello').disabled = true; 
     }; 
    } 

    function disconnect() { 
     if (websocket !== null) { 
      websocket.close(); 
      websocket = null; 
     } 
     message.setAttribute("class", "message"); 
     message.value = 'WebSocket closed.'; 
     // log the event 
    } 

    function sendMessage() { 
     if (websocket !== null) { 
      var content = document.getElementById('name').value; 
      websocket.send(content); 
     } else { 
      displayMessage(
        'WebSocket connection is not established. Please click the Open Connection button.', 
        'error'); 
     } 
    } 

    function displayMessage(data, style) { 
     var message = document.getElementById('hellomessage'); 
     message.setAttribute("class", style); 
     message.value = data; 
    } 

    function displayStatus(status) { 
     var currentStatus = document.getElementById('currentstatus'); 
     currentStatus.value = status; 
    } 

=== Java Class Code ===

package org.jboss.as.quickstarts.websocket_hello; 

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

@ServerEndpoint("/helloName") 
public class HelloName { 

    @OnMessage 
    public String sayHello(String name) { 
     System.out.println("Say hello to '" + name + "'"); 
     return ("Hello" + name); 
    } 

    @OnOpen 
    public void helloOnOpen(Session session) { 
     System.out.println("WebSocket opened: " + session.getId()); 
    } 

    @OnClose 
    public void helloOnClose(CloseReason reason) { 
     System.out.println("Closing a WebSocket due to " + reason.getReasonPhrase()); 
    } 
} 

Библиотека и XML File

WEB-INF/lib/jboss-websocket-api_1.0_spec-1.0.0.Final.jar 
WEB-INF/jboss-web.xml 

JBoss-web.xml

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-web> 
    <enable-websockets>true</enable-websockets> 
</jboss-web> 

Браузер: Сеть> WS> Заголовки

=== Общие сведения ===

Request URL:ws://localhost:8380/websockets-server/helloName 
Request Method:GET 
Status Code:500 Internal Server Error 

=== Заголовки запроса ===

Accept-Encoding:gzip, deflate, sdch, br 
Accept-Language:th-TH,th;q=0.8,en;q=0.6 
Cache-Control:no-cache 
Connection:Upgrade 
Cookie:JSESSIONID=b+Xfkitt-KYWiRl99vmbubUN 
Host:localhost:8380 
Origin:http://localhost:8380 
Pragma:no-cache 
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits 
Sec-WebSocket-Key:NH/fCYRMJge2+3WGz9gcLg== 
Sec-WebSocket-Version:13 
Upgrade:websocket 
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36 

=== Ответные Заголовки ===

Connection:close 
Content-Length:1885 
Content-Type:text/html;charset=utf-8 
Date:Mon, 30 Jan 2017 08:54:00 GMT 
Server:Apache-Coyote/1.1 

=== Tab Frames ===

(Opcode -1) 

ответ

0

Спасибо: @SubOptimal

Я решил этот путь.

Этот файл: Сервер> XML Configuration> standalone.xml

Добавить линии.

<subsystem xmlns="urn:jboss:domain:web:2.1" default-virtual-server="default-host" native="false"> 
    <connector name="http" protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="http" socket-binding="http"/> 
    <virtual-server name="default-host" enable-welcome-root="true"> 
     <alias name="websockets-server"/> 
    </virtual-server> 
</subsystem> 
1

Я верю, что вы забыли настроить HTTP-коннектор для использования NIO. Что необходимо для использования веб-узлов.

Цитата JBoss EAP documentation - create a websocket application

Настройте HTTP в веб-подсистеме файла конфигурации сервера для использования протокола NiO2.
...
<connector name="http" protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="http" socket-binding="http"/>

 Смежные вопросы

  • Нет связанных вопросов^_^