-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoogleDriveServlet.java
More file actions
63 lines (50 loc) · 2.6 KB
/
Copy pathGoogleDriveServlet.java
File metadata and controls
63 lines (50 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package com.securefileshare.servlets;
import com.securefileshare.models.User;
import com.securefileshare.services.CloudStorageService;
import com.securefileshare.services.GoogleDriveService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
public class GoogleDriveServlet extends HttpServlet {
private CloudStorageService cloudStorageService;
private GoogleDriveService googleDriveService;
@Override
public void init() throws ServletException {
try {
this.cloudStorageService = CloudStorageService.getInstance();
this.googleDriveService = GoogleDriveService.getInstance();
System.out.println("✓ GoogleDriveServlet initialized successfully");
} catch (Exception e) {
System.err.println("✗ GoogleDriveServlet initialization failed: " + e.getMessage());
e.printStackTrace();
}
}
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
HttpSession session = request.getSession(false);
if (session == null || session.getAttribute("user") == null) {
response.sendRedirect(request.getContextPath() + "/jsp/login.jsp");
return;
}
User user = (User) session.getAttribute("user");
System.out.println("\n=== GOOGLE DRIVE REQUEST ===");
System.out.println("User: " + user.getUsername() + " (ID: " + user.getUserId() + ")");
boolean isAvailable = cloudStorageService.isServiceAvailable();
String connectionStatus = cloudStorageService.testConnection();
request.setAttribute("isAvailable", isAvailable);
request.setAttribute("connectionStatus", connectionStatus);
request.setAttribute("storageUsed", "1.62 GB");
request.setAttribute("storageTotal", "15 GB");
request.setAttribute("storagePercent", "10");
RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/user/google-drive.jsp");
dispatcher.forward(request, response);
} catch (Exception e) {
System.err.println("✗ GoogleDriveServlet error: " + e.getMessage());
e.printStackTrace();
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to load Google Drive info");
}
}
}