From 7128df991d737d23ee77f89bfe79ec4b79a362df Mon Sep 17 00:00:00 2001 From: Alexander Alexeev Date: Fri, 18 Nov 2016 13:48:45 +0700 Subject: one way for inititialization and finalization: using constructor's initialization or method init() and AutoCloseable inteface and method close() --- juick-api/src/main/java/com/juick/api/Main.java | 31 ++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'juick-api/src/main/java/com/juick/api') diff --git a/juick-api/src/main/java/com/juick/api/Main.java b/juick-api/src/main/java/com/juick/api/Main.java index 6d7deeac..669dc11d 100644 --- a/juick-api/src/main/java/com/juick/api/Main.java +++ b/juick-api/src/main/java/com/juick/api/Main.java @@ -55,8 +55,8 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Properties; + /** - * * @author Ugnich Anton */ @WebServlet(name = "Main", urlPatterns = {"/"}) @@ -103,6 +103,19 @@ public class Main extends HttpServlet { } } + @Override + public void destroy() { + try { + if (xmpp != null) + xmpp.close(); + + log("ExternalComponent on juick-api destroyed"); + } catch (Exception e) { + log("Exception occurs on juick-api destroy", e); + } + + } + public void setupXmppComponent(final String host, final int port, final String jid, final String password) { XmppSessionConfiguration configuration = XmppSessionConfiguration.builder() .extensions(Extension.of(com.juick.Message.class)) @@ -115,12 +128,13 @@ public class Main extends HttpServlet { } } - /** + /** * Handles the HTTP GET method. - * @param request servlet request + * + * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs + * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -182,12 +196,13 @@ public class Main extends HttpServlet { } } - /** + /** * Handles the HTTP POST method. - * @param request servlet request + * + * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs - * @throws IOException if an I/O error occurs + * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -272,7 +287,7 @@ public class Main extends HttpServlet { } String paramImg = request.getParameter("img"); - if (attachmentFName == null && paramImg != null && paramImg.length() > 10 ) { + if (attachmentFName == null && paramImg != null && paramImg.length() > 10) { try { URL imgUrl = new URL(paramImg); attachmentFName = Utils.downloadImage(imgUrl); -- cgit v1.2.3