Wildfly Websocket端点返回404

时间:2020-02-04 18:30:10

标签: java apache websocket wildfly wildfly-12

我想设置一个WebSocket连接以将很多非常小的文件(1kb-50mb)上传到Web应用程序。

我的Web应用程序在Wildfly中运行,其余基于https的组件运行正常,但是我的Websocket连接每次返回404或尝试返回200。

这是我的端点的代码:

for item in soup.select('[src]'):
    print(item)

我有一个想法,也许这是由Apache引起的,因为我们的Wildfly在作为反向代理的apache后面运行,所以我在https-gw.conf中添加了Websocket端点:

package com.my.package;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

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

import java.util.logging.Level;
import java.util.logging.Logger;

@ServerEndpoint("/smallfiles/socket")
public class WebsocketApi {

  private static final long serialVersionUID = 2356475533479775725L;
  private static final Logger logger = Logger.getLogger(WebsocketApi.class.getName());
  private static Set<Session> clients = Collections.synchronizedSet(new HashSet<Session>());


  @OnOpen
  public void onOpen(Session session) {
    // Set max buffer size
    session.setMaxBinaryMessageBufferSize(1024 * 512);
    // Add session to the connected sessions set
    clients.add(session);
    logger.log(Level.INFO,"Client " + session.getId() + " connected.");
  }

  @OnClose
  public void onClose(Session session) {
    // Remove session from the connected sessions set
    clients.remove(session);
    logger.log(Level.INFO,"Client " + session.getId() + " disconnected.");
  }

  @OnError
  public void onError(Throwable error) {
    logger.log(Level.SEVERE,error.getMessage());
  }

  @OnMessage
  public void processUpload(byte[] uploadData, Session session) {
    try {
      if (session.isOpen()) {
        // Wrap a byte array into a buffer
        ByteBuffer buf = ByteBuffer.wrap(uploadData);
        logger.log(Level.INFO,"Receiving Data");
        //session.getBasicRemote().sendBinary(buf);
      }
    } catch (Exception e) {
      try {
        session.close();
      } catch (Exception e1) {
        logger.log(Level.SEVERE,"Failed to close Session. ",e1);
      }
    }
  }
}

但是,每当我尝试通过Javascript访问Websocket时,都会遇到以下问题:

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerName repName
        SSLProxyEngine On
        ProxyRequests Off
        ProxyPreserveHost On

        ProxyPass                   /                           http://127.0.0.1:8080/
        ProxyPassReverse            /                           http://127.0.0.1:8080/
        ProxyPass                   /Application/               http://127.0.0.1:8080/Application/
        ProxyPassReverse            /Application/               http://127.0.0.1:8080/Application/
        ProxyPass                   /smallfiles/socket/                 ws://127.0.0.1:8080/websocket/
        ProxyPassReverse            /smallfiles/socket/                 ws://127.0.0.1:8080/websocket/
        ProxyPass                   /Application/smallfiles/socket/      ws://127.0.0.1:8080/Application/websocket/
        ProxyPassReverse            /Application/smallfiles/socket/      ws://127.0.0.1:8080/Application/websocket/

        SetEnv proxy-sendcl 10000000
        SetEnv  proxy-sendchunked

        #   Server Certificate:
        SSLCertificateFile /etc/apache2/ssl.crt/host.net.cer

        #   Server Private Key:
        SSLCertificateKeyFile /etc/apache2/ssl.key/host.net.key

        #   Certificate Authority (CA):
        SSLCACertificateFile /etc/apache2/ssl.crt/my_ca.crt
   </VirtualHost>
</IfModule>

与'wss://my.application.net/'的WebSocket连接失败:期间发生错误 WebSocket握手:意外的响应代码:200

ws = new WebSocket("wss://my.server.net/")
WebSocket {url: "wss://my.server.net/", readyState: 0, bufferedAmount: 0, onopen: null, onerror: null, …}

WebSocket与“ wss://my.server.net/smallfiles/socket”的连接失败: WebSocket握手期间出错:意外的响应代码:404

我还检查了@cayz用户的Post,但可惜的是我并没有真正看到用户解决方案的含义。

有人知道我要去哪里吗?


编辑: 我还检查了wildfly日志,然后wildfly注册了端点。

ws = new WebSocket("wss://my.server.net/smallfiles/socket")
WebSocket {url: "wss://my.server.net/smallfiles/socket", readyState: 0, bufferedAmount: 0, onopen: null, onerror: null, …}

0 个答案:

没有答案