%@ page contentType="text/html; charset=utf-8" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%
/**
* factory.wplushttphead API를 통해서 호출되는 웹 서비스 모듈
* Test URL: http://127.0.0.1:8080/xframe5/template/HTML5/UTIL/WEBPLUS/webplus_httphead.jsp?type=screen&url=/1.xml
*
* @param type url에 대한 파일 구분 ("screen"/"picklist")
* @param url xFrame5에서 사용하는 파일 URL 정보 ("/" 부터 시작, 예시: /BIZ/007190.xml)
* @returns {string} Format : FileByteSize^FileLastModifyGMTDateTime^FileLastModifyLocalDateTime
* -1 : file not exist
* -2 : error
* -3 : invalid paramter
* n : file byte size
*/
out.clearBuffer();
String fileType = ""; // screen/picklist
String fileUrl = "";
try {
System.out.println("webplus_httphead> start ===============================================");
// Set CORS HTTP Header Start
response.setHeader("Access-Control-Allow-Credentials", "true");
response.setHeader("Access-Control-Allow-Headers", "X-Requested-With");
// a String containing the value of the requested header, or null if the request does not have a header of that name
String origin = request.getHeader("Origin");
System.out.println("request origin = " + origin);
if (origin == null) { response.setHeader("Access-Control-Allow-Origin", "*"); }
else { response.setHeader("Access-Control-Allow-Origin", origin); }
// Set CORS HTTP Header End
fileType = request.getParameter("type"); // screen/picklist
fileUrl = request.getParameter("url");
System.out.println("webplus_httphead> fileType = [" + fileType + "], fileUrl = [" + fileUrl + "]");
if (fileType == null || fileUrl == null) {
out.println("{");
out.println("\"result\" : \"" + "0" + "\",");
out.println("\"err_code\" : \"" + "1" + "\",");
out.println("\"err_msg\" : \"" + "invalid parameter value" + "\",");
out.println("\"file_type\" : \"" + fileType + "\",");
out.println("\"file_url\" : \"" + fileUrl + "\",");
out.println("\"file_size\" : \"" + "0" + "\",");
out.println("\"gmt_time\" : \"" + "" + "\",");
out.println("\"local_time\" : \"" + "" + "\"");
out.println("}");
return;
}
// TODO: 프로젝트 환경에서 변경해야 함.
String fileAbsolutePath = "D:\\SOFTBASE\\HTML\\xframe5\\project\\terminal\\";
fileAbsolutePath += fileType + fileUrl;
System.out.println("webplus_httphead> fileAbsolutePath = [" + fileAbsolutePath + "]");
File file = new File(fileAbsolutePath);
if (file.exists() == false) {
out.println("{");
out.println("\"result\" : \"" + "0" + "\",");
out.println("\"err_code\" : \"" + "2" + "\",");
out.println("\"err_msg\" : \"" + "file not exist" + "\",");
out.println("\"file_type\" : \"" + fileType + "\",");
out.println("\"file_url\" : \"" + fileUrl + "\",");
out.println("\"file_size\" : \"" + "0" + "\",");
out.println("\"gmt_time\" : \"" + "" + "\",");
out.println("\"local_time\" : \"" + "" + "\"");
out.println("}");
}
else {
long fileSize = file.length();
// A long value representing the time the file was last modified, measured in milliseconds
// since the epoch (00:00:00 GMT, January 1, 1970), or 0L if the file does not exist or if an I/O error occurs
long lLocalDateTime = file.lastModified();
Calendar calendar = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat();
format.applyPattern("yyyyMMddHHmmss");
// lFileModifyDateTime: the new time in UTC milliseconds from the epoch.
calendar.setTimeInMillis(lLocalDateTime);
String fileLocaDateTime = format.format(calendar.getTime());
// Local Time -> GMT Time
TimeZone timeZone = TimeZone.getDefault();
int offset = timeZone.getOffset(lLocalDateTime); // The offset includes daylight savings time
long lUTCDateTime = lLocalDateTime - offset;
calendar.setTimeInMillis(lUTCDateTime);
String fileGmtDateTime = format.format(calendar.getTime());
System.out.println("webplus_httphead> Size = " + fileSize + ", GMT = " + fileGmtDateTime + ", Local = " + fileLocaDateTime);
out.println("{");
out.println("\"result\" : \"" + "1" + "\",");
out.println("\"err_code\" : \"" + "0" + "\",");
out.println("\"err_msg\" : \"" + "" + "\",");
out.println("\"file_type\" : \"" + fileType + "\",");
out.println("\"file_url\" : \"" + fileUrl + "\",");
out.println("\"file_size\" : \"" + fileSize + "\",");
out.println("\"gmt_time\" : \"" + fileGmtDateTime + "\",");
out.println("\"local_time\" : \"" + fileLocaDateTime + "\"");
out.println("}");
}
System.out.println("webplus_httphead> success end ===============================================");
}
catch (Exception e) {
System.out.println("webplus_httphead> " + e.getMessage());
e.printStackTrace();
out.println("{");
out.println("\"result\" : \"" + "0" + "\",");
out.println("\"err_code\" : \"" + "9" + "\",");
out.println("\"err_msg\" : \"" + e.getMessage() + "\",");
out.println("\"file_type\" : \"" + fileType + "\",");
out.println("\"file_url\" : \"" + fileUrl + "\",");
out.println("\"file_size\" : \"" + "0" + "\",");
out.println("\"gmt_time\" : \"" + "" + "\",");
out.println("\"local_time\" : \"" + "" + "\"");
out.println("}");
System.out.println("webplus_httphead> error end ===============================================");
}
%>