示例#1
0
func (dispatcher *Dispatcher) postService(w http.ResponseWriter, r *http.Request) {

	/*body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	mIn, err := piazza.NewMessageFromBytes(body)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	log.Print(mIn)*/

	mOut := piazza.NewMessage()
	{
		mOut.Id = piazza.BadId // left empty
		mOut.Type = piazza.CreateJobResponseMessage
		mOut.Status = piazza.SuccessStatus

		mOut.CreateJobResponsePayload = &piazza.CreateJobResponsePayload{piazza.NewId(), piazza.JobStatusSubmitted}
	}

	buf, err := json.Marshal(mOut)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	w.Write(buf)
}
示例#2
0
func TestGateway(t *testing.T) {

	gatewayProxy := setup(t)

	m := piazza.NewMessage()
	{
		m.Id = piazza.BadId
		m.Type = piazza.CreateJobMessage
		m.User = nil
		m.Status = 0 // left empty

		params := map[string]piazza.Any{"A": "alpha", "B": 222}
		m.CreateJobPayload = &piazza.CreateJobPayload{ServiceType: piazza.EchoService, Parameters: params, Comment: "a run of the echo service"}
	}

	pid, err := gatewayProxy.Send(m)
	if err != nil {
		t.Error(err)
	}
	log.Print(pid)

	/*
		// send job to gateway
		var myHost = fmt.Sprintf("http://%s/service", gatewayHost)
		resp, err := http.Post(myHost, "application/json", bytes.NewBufferString(payload))
		if err != nil {
			t.Fatal(err)
		}
		defer resp.Body.Close()

		if resp.StatusCode != http.StatusOK {
			t.Fatal("bonk")
		}

		buf, err := ioutil.ReadAll(resp.Body)
		if err != nil {
			t.Fatal(err)
		}
		if buf == nil {
			t.Fatal(err)
		}

		m2, err := piazza.NewMessageFromBytes(buf)
		if err != nil {
			t.Fatal(err)
		}

		t.Log(m2)
	*/
}