diff --git a/APIServer.exe b/APIServer.exe index f7534c7..9df9a72 100644 Binary files a/APIServer.exe and b/APIServer.exe differ diff --git a/APIServer.go b/APIServer.go index 71f5a5b..1671fd9 100644 --- a/APIServer.go +++ b/APIServer.go @@ -182,8 +182,6 @@ func startSvc() { http.HandleFunc("/fileinfo/", handleFileInfo) http.HandleFunc("/setuutinfo/", handleSetUutInfo) http.HandleFunc("/getuutinfo/", handleGetUutInfo) - http.HandleFunc("/getdefectinfo/", handleGetDefectInfo) - http.HandleFunc("/getofflineinfo/", handleGetOfflineInfo) logger.Printf("[MSG] Starting HTTP Server On Port: %s\r\n", cfg.Settings.ListenPort) err := http.ListenAndServe(":"+cfg.Settings.ListenPort, nil) if err != nil { @@ -399,84 +397,29 @@ func handleGetUutInfo(w http.ResponseWriter, r *http.Request) { return } - params := make(map[string]string, 0) - if len(r.Form) > 0 { - for k, v := range r.Form { - params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0]) - } - } - ews := new(ews.EWS) - rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params) - if rst["RESULT"] != "OK" { - w.WriteHeader(http.StatusInternalServerError) - } else { - w.WriteHeader(http.StatusOK) - } - fmt.Fprintf(w, "%v", rst["ErrMsg"]) -} - -func handleGetDefectInfo(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - if r.RequestURI == "/favicon.ico" { - return - } - host := strings.Split(r.Host, ":")[0] - addr := strings.Split(r.RemoteAddr, ":")[0] - uri := r.RequestURI - rst := map[string]string{"RESULT": ""} - - if err := r.ParseForm(); err != nil { - logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error()) + params, err := parseReqParams(r) + if err != nil { + logger.Printf("[ERR] %s; %s; %#v; %s\r\n", r.RemoteAddr, r.RequestURI, params, rst["ErrMsg"]) rst["RESULT"] = "NG" rst["ErrMsg"] = err.Error() - w.WriteHeader(http.StatusInternalServerError) + w.WriteHeader(http.StatusBadRequest) fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", "")) return } - params := make(map[string]string, 0) - if len(r.Form) > 0 { - for k, v := range r.Form { - params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0]) - } - } ews := new(ews.EWS) - rst = ews.GetDefectUuts(cfg, logger, host, addr, uri, params) - if rst["RESULT"] != "OK" { - w.WriteHeader(http.StatusInternalServerError) - } else { - w.WriteHeader(http.StatusOK) - } - fmt.Fprintf(w, "%v", rst["ErrMsg"]) -} -func handleGetOfflineInfo(w http.ResponseWriter, r *http.Request) { - defer r.Body.Close() - if r.RequestURI == "/favicon.ico" { - return - } - host := strings.Split(r.Host, ":")[0] - addr := strings.Split(r.RemoteAddr, ":")[0] - uri := r.RequestURI - rst := map[string]string{"RESULT": ""} - - if err := r.ParseForm(); err != nil { - logger.Printf("[ERR] %s; %s; %s\r\n", r.RemoteAddr, r.RequestURI, err.Error()) - rst["RESULT"] = "NG" - rst["ErrMsg"] = err.Error() - w.WriteHeader(http.StatusInternalServerError) - fmt.Fprintf(w, "%v", strings.ReplaceAll(fmt.Sprintf("%#v", rst), "map[string]string", "")) - return + switch params["ACTION"] { + case "QueryByFilter": + rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params) + case "GetDefectReport": + rst = ews.GetDefectReport(cfg, logger, host, addr, uri, params) + case "GetOfflineReport": + rst = ews.GetOfflineReport(cfg, logger, host, addr, uri, params) + default: + rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params) } - params := make(map[string]string, 0) - if len(r.Form) > 0 { - for k, v := range r.Form { - params[strings.ToUpper(strings.TrimSpace(k))] = strings.TrimSpace(v[0]) - } - } - ews := new(ews.EWS) - rst = ews.GetOfflineUuts(cfg, logger, host, addr, uri, params) if rst["RESULT"] != "OK" { w.WriteHeader(http.StatusInternalServerError) } else { diff --git a/Index.html b/Index.html index bebb5ad..dc26552 100644 --- a/Index.html +++ b/Index.html @@ -6,7 +6,7 @@