FCM XMPP java server app

173 Views Asked by At

I want to deploy a FCM XMPP app on Google AppEngine. I'm using this library https://github.com/thelong1EU/fcmxmppserver but I'm new on this backend side so I need some help. I managed to deploy it but it doesn't run. I don't know how to make the AppEngine call the main funtion here:

public class EntryPoint {
    public static void main(String[] args) {
        final String fcmProjectSenderId = senderID;
        final String fcmServerKey = key;

        CcsClient ccsClient = CcsClient.prepareClient(fcmProjectSenderId, fcmServerKey, false);

        try {
            ccsClient.connect();
        } catch (XMPPException e) {
            e.printStackTrace();
        }
    }
}

If i run just this function it all works well, but when deployed it doesn't start. What am I missing?

1

There are 1 best solutions below

0
On BEST ANSWER

So I found out reading this:

https://cloud.google.com/appengine/docs/standard/java/an-overview-of-app-engine#scaling_types_and_instance_classes

When the app load it does a GET to /_ah/stop so I needed to add this to my servlet mapping. I did it like this:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
    <servlet>
        <servlet-name>Start</servlet-name>
        <servlet-class>eu.long1.jwnotes.fcmserver.StartServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Start</servlet-name>
        <url-pattern>/_ah/start</url-pattern>
        <url-pattern>/_ah/stop</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

And the in the doGet() I do this:

public class StartServlet extends HttpServlet {

    private static final String GET_START = "/_ah/start";
    private static final String GET_STOP = "/_ah/stop";

    @Override
    public void init() throws ServletException {
     //init the servlet
    }

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws IOException {
        switch (req.getRequestURI()) {
            case GET_START:
                //do something
                resp.setStatus(SC_OK);
                break;

            case GET_STOP:
                //do something else
                break;
        }
    }
}

I don't know if this is the recommended way but it works for now. If I find something else I will post.