I successfully deployed a Java servlet on glassfish5 in my Raspberry PI3. Now I wanted to use another servlet for a Telegram bot, but in this case I need to use HTTPS.
I tried to define a new servlet with in the web.xml, but when I try to reach the servlet via https connection from a browser the result is an ERR_CONNECTION_REFUSED.
My 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");
}
}
And my 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>
In case it be a raspberry config problem, this is the result of 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 port is not mentioned, but in case it is closed I don't know how to open it
Please try with port 8181 which is the default port for secured communication on Payara and Glassfish. Please also see here: https://blog.payara.fish/securing-payara-server-with-custom-ssl-certificate