0

我想在Google AppEngine上部署FCM XMPP應用程序。我正在使用這個庫https://github.com/thelong1EU/fcmxmppserver,但我在後端這邊是新手,所以我需要一些幫助。我設法部署它,但它不運行。我不知道如何使這裏的AppEngine調用主funtion:FCM XMPP java服務器應用程序

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(); 
     } 
    } 
} 

如果我跑得這種功能,它一切運作良好,但在部署時不啓動。我錯過了什麼?

回答

0

所以我發現閱讀本:

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

當應用程序加載它一個GET到/_ah/stop所以我需要把它添加到我的servlet映射。我這樣做是這樣的:

<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> 

而且在使用doGet()我這樣做:

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; 
     } 
    } 
} 

我不知道這是推薦的方式,但它適用於現在。如果我找到其他東西,我會發布。

相關問題