簡體   English   中英

我無法連接到 Liferay 7.2 中的 websocket“wss”協議

[英]I can't make a connection to the websocket "wss" protocol in Liferay 7.2

我通知您該代碼可以在沒有證書的情況下使用“ws”協議正常工作。 我最近將證書添加到門戶,確保頁面的連接是安全的。

我現在遇到的問題是它不適用於安全的“wss”協議,它已經在 firefox 和 chrome 上進行了測試。 我不知道該怎么辦。

接下來我將放置 portlet 中的代碼片段。 (它不會放完整的代碼,而是放最重要的部分)。

查看.jsp

$(document).ready(function() {

    $('#conexion-chat').on('click', function(){  
        $('#display-chat-overlay').fadeIn('slow');
        initWebSocket();
        return false;     
    });      
        
    $('#close').on('click', function(){         
        $('#display-chat-overlay').fadeOut('slow');
        $('#conexion-chat').css('display', '');
        $('.msg-incoming-outgoing').children().remove();
        $('.msg-incoming-outgoing').text('');
        websocket.close();
        return false;     
    }); 
    
});

function initWebSocket(){
    $('#conexion-chat').css('display', 'none');
    $('#display-chat-overlay').css('display', '');
    $('.cloud_messages_unread').css('display','none');
    
    if('${currentUserRol}' != '${rolPreferences}'){
        $('.container').addClass('display-visitor');
        $('.header-chat').addClass('display-visitor');
        $('.inbox_people').addClass('display-visitor');
        $('.mesgs').addClass('display-visitor');
        $('.recent_heading.logo-sponsor').addClass('display-visitor');
        $('.mesgs').find('h4').text('${rolPreferences}');
        $('#sendField').prop('disabled', '');
        startTimeSession();
        
    }else{
        $('.header-chat').addClass('display-sponsor');
        $('.inbox_chat').children().remove();
        $('.mesgs').find('h4').text('');
        visitorNameHeader();
        $('.mesgs .recent_heading.logo-sponsor').addClass('display-sponsor');
        $('.inbox_people .recent_heading').addClass('visitor-list');
        $('#display-chat-overlay').addClass('display-sponsor');
    }
    
    $('.title-header').text('${messageHeaderChat}' + ' ' + substringNameHeader('${rolPreferences}'));
    
    websocket = new WebSocket('wss://my-domain.es/o/echo');
    
    websocket.onopen = function (event) {
        websocket.send(json_user());
    };
    
    websocket.onclose = function(event) {
        console.log("DESCONECTADO");
    };
    
    websocket.onmessage = function(event) {
        var message = event.data;
        processMessage(message);
    };
    
    websocket.onerror = function(event) {
        console.log("ERROR: " + event.data);
    };
}

Websocket.java

@Component(
    immediate = true,
    property = {
        "org.osgi.http.websocket.endpoint.path=/o/echo"
    },
    service = Endpoint.class
)
public class WebSocket extends Endpoint {

    private static Log _log = LogFactoryUtil.getLog(WebSocket.class);

在 view.js 文件中創建了一個 websocket,並向其傳遞以下參數:

“wss://my-domain.es/o/echo”

端點是“/o/echo”,它是在“@Component”內部的class“Websocket.java”中獲得的。

“org.osgi.http.websocket.endpoint.path = /o/ echo”

控制台火狐

網絡火狐

我已經解決了我在使用安全 Websocket (wss) 協議時遇到的問題。 我必須配置 apache web 服務器來反向 websocket 代理。 此配置已按照以下 web 頁面上的步驟執行:

https://www.serverlab.ca/tutorials/linux/web-servers-linux/how-to-reverse-proxy-websockets-with-apache-2-4/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM