public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);
if (authenticate(request, response) == true) {}
}
//------------------------------------
private boolean authenticate(HttpServletRequest request, HttpServletResponse response) {
boolean isLogin = false;
try {
ResourceBundle bundle = ResourceBundle.getBundle("com.xx.mil.application.xxx.HttpConnection");
String uid = bundle.getString("username");
String pwd = bundle.getString("password");
String authentication = request.getHeader("Authorization");
if (authentication != null) {
String userpass = Base64.decode(authentication.substring(6));
String username = userpass.substring(0,userpass.indexOf(":"));
String password = userpass.substring(userpass.indexOf(":") + 1);
if (username.equals(uid) && password.equals(pwd)) {
isLogin = true;
}
}
}
catch (Exception e) {
try {
PrintWriter out = (PrintWriter) response.getWriter();
out.write("<result>FAIL</result>");
out.flush();
// Logger.logError(e.getClass().getName(), e);
logger.logError(logAction + ":" + e.getMessage());
SendEmail mail = new SendEmail();
mail.sendErrorEmail(e);
}
catch(Exception ex) {}
}
return isLogin;
//return true; //Set true for debug
}