// RawPostReq obtains the POST payload from the request and forwards it on to the endpoint amzTarget. func RawPostReq(w http.ResponseWriter, req *http.Request, amzTarget string) { if bbpd_runinfo.BBPDAbortIfClosed(w) { return } start := time.Now() bodybytes, read_err := ioutil.ReadAll(req.Body) req.Body.Close() if read_err != nil && read_err != io.EOF { e := fmt.Sprintf("raw_post_route.RawPostReq err reading req body: %s", read_err.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } resp_body, code, resp_err := authreq.RetryReqJSON_V4(bodybytes, amzTarget) if resp_err != nil { e := fmt.Sprintf("raw_post_route.RawPostReq: resp err calling %s err %s (input json: %s)", amzTarget, resp_err.Error(), string(bodybytes)) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } if ep.HttpErr(code) { e := fmt.Sprintf("raw_post_route.RawPostReq: http err %d calling %s (input json: %s)", code, amzTarget, string(bodybytes)) route_response.WriteError(w, code, e, resp_body) return } mr_err := route_response.MakeRouteResponse( w, req, resp_body, code, start, amzTarget) if mr_err != nil { e := fmt.Sprintf("raw_post_route.RawPostReq %s", mr_err.Error()) log.Printf(e) } }
// BBPD-only endpoint. // GetItemJSONHandler issues a GetItem request to aws and then transforms the Response into // a ResponseItemJSON. func GetItemJSONHandler(w http.ResponseWriter, req *http.Request) { if bbpd_runinfo.BBPDAbortIfClosed(w) { return } start := time.Now() bodybytes, read_err := ioutil.ReadAll(req.Body) req.Body.Close() if read_err != nil && read_err != io.EOF { e := fmt.Sprintf("get_item_route.GetItemJSONHandler err reading req body: %s", read_err.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } resp_body, code, resp_err := authreq.RetryReqJSON_V4(bodybytes, get.GETITEM_ENDPOINT) if resp_err != nil { e := fmt.Sprintf("get_item_route.GetItemJSONHandler: resp err calling %s err %s (input json: %s)", get.GETITEM_ENDPOINT, resp_err.Error(), string(bodybytes)) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } if ep.HttpErr(code) { e := fmt.Sprintf("get_item_route.GetItemJSONHandler: http err %d calling %s (input json: %s)", code, get.GETITEM_ENDPOINT, string(bodybytes)) route_response.WriteError(w, code, e, resp_body) return } // translate the Response to a ResponseItemJSON resp := get.NewResponse() um_err := json.Unmarshal([]byte(resp_body), resp) if um_err != nil { e := fmt.Sprintf("get_item_route.GetItemJSONHandler:err %s", um_err.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } resp_json, rerr := resp.ToResponseItemJSON() if rerr != nil { e := fmt.Sprintf("get_item_route.GetItemJSONHandler:err %s", rerr.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } json_body, jerr := json.Marshal(resp_json) if jerr != nil { e := fmt.Sprintf("get_item_route.GetItemJSONHandler:err %s", jerr.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } mr_err := route_response.MakeRouteResponse( w, req, json_body, http.StatusOK, start, get.ENDPOINT_NAME) if mr_err != nil { e := fmt.Sprintf("get_item_route.GetItemJSONHandler %s", mr_err.Error()) log.Printf(e) http.Error(w, e, http.StatusInternalServerError) return } }