package com.google.error_analyzer.servlets;

import com.google.error_analyzer.backend.FileLogs;
import com.google.error_analyzer.backend.StoreLogs;
import com.google.error_analyzer.data.constant.FileConstants;
import com.google.error_analyzer.data.constant.LogFields;
import com.google.error_analyzer.data.constant.PageConstants;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import org.apache.http.HttpHost;

@WebServlet("/uploadFile")
@MultipartConfig
/*This class is for storing the logs provided by the user 
as files to the database*/
public class FileServlet extends HttpServlet {
    public static final FileLogs fileLogs = new FileLogs();

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException {
        response.setContentType(FileConstants.TEXT_HTML_CONTENT_TYPE);
        Part filePart = request.getPart(LogFields.FILE);
        InputStream fileContent = filePart.getInputStream();
        String fileName = request.getParameter(LogFields.FILE_NAME);
        request.getSession();
        String status =
            fileLogs.checkAndStoreFileLog(request, fileName, fileContent);
        response.getWriter().println(status);
        RequestDispatcher requestDispatcher =
            request.getRequestDispatcher(PageConstants.LANDING_PAGE);
        requestDispatcher.include(request, response);
    }
}
@@ -1,8 +1,596 @@
+// Copyright 2019 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//     https://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A
 package 
@@ -1515,16 +1515,100 @@
 ttpHost;
+%0Aimport org.apache.logging.log4j.Logger;%0Aimport org.apache.logging.log4j.LogManager;
 %0A%0A@WebSe
@@ -1778,16 +1778,98 @@
 rvlet %7B%0A
+    private static final Logger logger = LogManager.getLogger(FileServlet.class);%0A
     publ
@@ -2019,52 +2019,29 @@
 nse)
+ %7B
 %0A    
-throws IOException, ServletException %7B%0A
+    try %7B%0A    
     
@@ -2115,16 +2115,20 @@
         
+    
 Part fil
@@ -2176,16 +2176,20 @@
         
+ 
+   
 InputStr
@@ -2229,24 +2229,28 @@
 utStream();%0A
+    
         Stri
@@ -2306,32 +2306,36 @@
 _NAME);%0A        
+  
+  
 request.getSessi
@@ -2344,24 +2344,28 @@
 ();%0A        
+    
 String statu
@@ -2380,16 +2380,20 @@
         
+  
+  
 fileLogs
@@ -2447,32 +2447,36 @@
 ntent);%0A        
+    
 response.getWrit
@@ -2505,16 +2505,20 @@
         
+  
+  
 RequestD
@@ -2547,16 +2547,20 @@
 tcher =%0A
+    
         
@@ -2625,24 +2625,28 @@
 E);%0A        
+  
+  
 requestDispa
@@ -2679,15 +2679,110 @@
 ponse);%0A
+        %7D catch (Exception e) %7B%0A            logger.error(%22Could not store file%22, e);%0A        %7D%0A
     %7D%0A%7D

change Fileservlet