如何在 glassfish 上设置 HTTPS Java servlet

How to set a HTTPS Java servlet on glassfish

我在 Raspberry PI3 的 glassfish5 上成功部署了 Java servlet。 现在我想为 Telegram 机器人使用另一个 servlet,但在这种情况下我需要使用 HTTPS。

我试图在 web.xml 中定义一个新的 servlet,但是当我尝试从浏览器通过 https 连接访问 servlet 时,结果是 ERR_CONNECTION_REFUSED.

我的 servlet

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;

@WebServlet("/telegramUpdate")

public class TelegramUpdate extends HttpServlet {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public TelegramUpdate() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("doGet");

    }

    protected void doPost (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        System.out.println("doPost");

    }

}

还有我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
  <display-name>Smarthome</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>telegram webhook</web-resource-name>
      <url-pattern>/telegramMessage</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
</web-app>

如果是 raspberry 配置问题,这是 netcat -lptn

的结果
pi@raspberrypi:~/glassfish5/glassfish/domains/domain1/logs$ netstat -lptn
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:5939          0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:53              0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -               
tcp        0      0 0.0.0.0:1883            0.0.0.0:*               LISTEN      -               
tcp6       0      0 :::8686                 :::*                    LISTEN      -               
tcp6       0      0 :::80                   :::*                    LISTEN      -               
tcp6       0      0 :::4848                 :::*                    LISTEN      -               
tcp6       0      0 :::8080                 :::*                    LISTEN      -               
tcp6       0      0 :::3700                 :::*                    LISTEN      -               
tcp6       0      0 :::8181                 :::*                    LISTEN      -               
tcp6       0      0 :::53                   :::*                    LISTEN      -               
tcp6       0      0 :::22                   :::*                    LISTEN      -               
tcp6       0      0 :::1527                 :::*                    LISTEN      -               
tcp6       0      0 :::1883                 :::*                    LISTEN      -

443端口没说,万一关闭不知道怎么打开

请尝试使用端口 8181,这是 Payara 和 Glassfish 上安全通信的默认端口。 另请参阅此处:https://blog.payara.fish/securing-payara-server-with-custom-ssl-certificate