aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api
diff options
context:
space:
mode:
authorGravatar Alexander Alexeev2016-11-18 13:48:45 +0700
committerGravatar Vitaly Takmazov2016-11-18 10:07:20 +0300
commit7128df991d737d23ee77f89bfe79ec4b79a362df (patch)
treee02cdb213fb52f2215919f38d0b3244d50a3e94b /juick-api/src/main/java/com/juick/api
parent5af964e05a79e64f02ebcfb3e1b19f109e32deaf (diff)
one way for inititialization and finalization: using constructor's initialization or method init() and AutoCloseable inteface and method close()
Diffstat (limited to 'juick-api/src/main/java/com/juick/api')
-rw-r--r--juick-api/src/main/java/com/juick/api/Main.java31
1 files changed, 23 insertions, 8 deletions
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 <code>GET</code> 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 <code>POST</code> 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);