Skip to content

Commit f8e5740

Browse files
committed
A workaround to injection problems in servlets (ConsoleProxyServlet and RegisterCompletionServlet) classes
1 parent b63b7dd commit f8e5740

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

server/src/com/cloud/servlet/ConsoleProxyServlet.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,29 @@ public class ConsoleProxyServlet extends HttpServlet {
7171
@Inject ManagementServer _ms;
7272
@Inject IdentityService _identityService;
7373

74+
static AccountManager s_accountMgr;
75+
static VirtualMachineManager s_vmMgr;
7476
static ManagementServer s_ms;
77+
static IdentityService s_identityService;
78+
7579
public ConsoleProxyServlet() {
7680
}
7781

7882
@PostConstruct
79-
void initComponent() {
80-
s_ms = _ms;
83+
void initComponent() {
84+
// Servlet injection does not always work for servlet container
85+
// We use a hacking here to initialize static variables at Spring wiring time
86+
if(_accountMgr != null) {
87+
s_accountMgr = _accountMgr;
88+
s_vmMgr = _vmMgr;
89+
s_ms = _ms;
90+
s_identityService = _identityService;
91+
} else {
92+
_accountMgr = s_accountMgr;
93+
_vmMgr = s_vmMgr;
94+
_ms = s_ms;
95+
_identityService = s_identityService;
96+
}
8197
}
8298

8399
@Override

server/src/com/cloud/servlet/RegisterCompleteServlet.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.net.URLEncoder;
2020
import java.util.List;
2121

22+
import javax.annotation.PostConstruct;
2223
import javax.inject.Inject;
2324
import javax.servlet.ServletContextEvent;
2425
import javax.servlet.ServletContextListener;
@@ -48,6 +49,27 @@ public class RegisterCompleteServlet extends HttpServlet implements ServletConte
4849
@Inject ConfigurationDao _configDao;
4950
@Inject UserDao _userDao;
5051

52+
static AccountService s_accountSvc;
53+
static ConfigurationDao s_configDao;
54+
static UserDao s_userDao;
55+
56+
public RegisterCompleteServlet() {
57+
}
58+
59+
@PostConstruct
60+
void initComponent() {
61+
// Hakcing way to make servlet injection work for now
62+
if(_accountSvc != null) {
63+
s_accountSvc = _accountSvc;
64+
s_configDao = _configDao;
65+
s_userDao = _userDao;
66+
} else {
67+
_accountSvc = s_accountSvc;
68+
_configDao = s_configDao;
69+
_userDao = s_userDao;
70+
}
71+
}
72+
5173
@Override
5274
public void contextInitialized(ServletContextEvent sce) {
5375
}

0 commit comments

Comments
 (0)