Beispiel #1
0
//handleVerResp to handle verify request from client and forward it to the mock RM
func handleVerResp(w http.ResponseWriter, r *http.Request) error {

	req := getverifyPayload(r)

	resp := comdef.VerifyResp{}
	httpStatus, err := httputilfuncs.PostHTTPJSONString(verifyURL,
		req, &resp, 10*time.Second)

	if err != nil {
		log.Printf("Failed on send Record request! err:%v\n", err)
		return err
	}

	log.Printf("Http Status: %d, resp: %v", httpStatus, resp)
	if httpStatus == 200 {
		w.Write([]byte("Recording verified sucessfully:\n"))
		b, _ := json.Marshal(resp)
		w.Write(b)

	} else {
		w.Write([]byte("Recording not verified sucessfully please resubmit"))
	}

	return err

}
Beispiel #2
0
//Process Record Request from external source.  It will forward the request to Recorder Manager
//and forward the response received from RM to the external source.
func processBridgeRecord(input httpctxserver.HandlerProcessInput) (bool, int, error) {

	var (
		req   *comdef.RecordReq
		resp  *comdef.RecordResp
		found bool
	)

	//Sanity check to make sure req and resp data type are passed in correctly
	if req, found = input.Req.(*comdef.RecordReq); found != true || req == nil {
		err := errors.New("Unsupported req type for Bridge Record")
		log.Fatal(err)
		return false, http.StatusInternalServerError, err
	}

	if resp, found = input.Resp.(*comdef.RecordResp); found != true || resp == nil {
		err := errors.New("Unsupported resp type for Bridge Record")
		log.Fatal(err)
		return false, http.StatusInternalServerError, err
	}

	//sanity check if we have a URL for RM
	if len(rmURL) == 0 {
		log.Printf("Cannot Forward request to Recorder Manager, no RM URL available")
		err := errors.New("No RM URL is aviable")
		return false, http.StatusBadGateway, err
	}

	//fake request id
	req.RequestID = fmt.Sprintf("xxxxxxxx-aaaa-bbbb-cccc-%v", time.Now().UnixNano)

	//Send request to RM
	httpStatus, err := httputilfuncs.PostHTTPJSONString(rmURL, *req, resp, timeOut)
	if err != nil {
		log.Printf("Error when sending Update Request, err: %v", err)
		return false, http.StatusBadGateway, nil

	}

	//forward the RM response back to external source
	log.Printf("HttpStatus: %d, Resp: %v", httpStatus, *resp)
	if httpStatus == http.StatusOK {
		return true, httpStatus, nil
	}

	return false, httpStatus, nil

}
Beispiel #3
0
func postRecord(reqData comdef.RecordReq, r *http.Request) (httpStatus int, err error, resp *comdef.RecordResp) {

	//resp := comdef.RecordResp{}
	httpStatus, err = httputilfuncs.PostHTTPJSONString(rmURL,
		reqData, &resp, 10*time.Second)

	if err != nil {

		log.Printf("Failed on send Record request! err:%v\n", err)

	}
	if httpStatus == 204 {
		log.Printf("Recording Submitted sucessfully to RM")

	}
	if httpStatus == 200 {
		log.Printf("One of the fields is missing in the request")
	}

	return httpStatus, err, resp

}