// CreateRequestMessage creates the request json message using the given input. // Note, the input *MUST* be a pointer to a valid backend type that this // client recognises. func (cs *ClientServerImpl) CreateRequestMessage(input interface{}) ([]byte, error) { msg := &RequestMessage{} recognizedTypes := cs.GetRecognizedTypes() for typeStr, typeVal := range recognizedTypes { if reflect.TypeOf(input) == reflect.PtrTo(typeVal) { msg.Type = typeStr break } } if msg.Type == "" { return nil, &UnrecognizedWSRequestType{reflect.TypeOf(input).String()} } messageData, err := jsonutil.BuildJSON(input) if err != nil { return nil, &NotMarshallableWSRequest{msg.Type, err} } msg.Message = json.RawMessage(messageData) send, err := json.Marshal(msg) if err != nil { return nil, &NotMarshallableWSRequest{msg.Type, err} } return send, nil }
// Build builds a JSON payload for a JSON RPC request. func Build(req *aws.Request) { var buf []byte var err error if req.ParamsFilled() { buf, err = jsonutil.BuildJSON(req.Params) if err != nil { req.Error = apierr.New("Marshal", "failed encoding JSON RPC request", err) return } } else { buf = emptyJSON } if req.Service.TargetPrefix != "" || string(buf) != "{}" { req.SetBufferBody(buf) } if req.Service.TargetPrefix != "" { target := req.Service.TargetPrefix + "." + req.Operation.Name req.HTTPRequest.Header.Add("X-Amz-Target", target) } if req.Service.JSONVersion != "" { jsonVersion := req.Service.JSONVersion req.HTTPRequest.Header.Add("Content-Type", "application/x-amz-json-"+jsonVersion) } }
func BenchmarkBuildJSON(b *testing.B) { for i := 0; i < b.N; i++ { for _, test := range jsonTests { jsonutil.BuildJSON(test.in) } } }
func TestBuildJSON(t *testing.T) { for _, test := range jsonTests { out, err := jsonutil.BuildJSON(test.in) if test.err != "" { assert.Error(t, err) assert.Contains(t, err.Error(), test.err) } else { assert.NoError(t, err) assert.Equal(t, string(out), test.out) } } }
func BenchmarkJSONUtilBuild_Simple_dynamodbPutItem(b *testing.B) { svc := service.New(nil) params := getDynamodbPutItemParams(b) for i := 0; i < b.N; i++ { r := svc.NewRequest(&request.Operation{Name: "Operation"}, params, nil) _, err := jsonutil.BuildJSON(r.Params) if err != nil { b.Fatal("Unexpected error", err) } } }
func TaskFromACS(acsTask *ecsacs.Task, envelope *ecsacs.PayloadMessage) (*Task, error) { data, err := jsonutil.BuildJSON(acsTask) if err != nil { return nil, err } task := &Task{} err = json.Unmarshal(data, task) if err != nil { return nil, err } if task.DesiredStatus == TaskRunning && envelope.SeqNum != nil { task.StartSequenceNumber = *envelope.SeqNum } else if task.DesiredStatus == TaskStopped && envelope.SeqNum != nil { task.StopSequenceNumber = *envelope.SeqNum } return task, nil }
/* Get Run Report */ func runReport(svc *devicefarm.DeviceFarm, runArn string) { infoReq := &devicefarm.GetRunInput{ Arn: aws.String(runArn), } resp, err := svc.GetRun(infoReq) failOnErr(err, "error getting run info") fmt.Printf("Reporting on run %s\n", *resp.Run.Name) fmt.Printf("Run arn %s\n", runArn) //fmt.Println(awsutil.Prettify(resp)) jobReq := &devicefarm.ListJobsInput{ Arn: aws.String(runArn), } // Find all artifacts artifactReq := &devicefarm.ListArtifactsInput{ Arn: aws.String(runArn), } types := []string{"LOG", "SCREENSHOT", "FILE"} artifacts := map[string][]devicefarm.ListArtifactsOutput{} for _, artifactType := range types { artifactReq.Type = aws.String(artifactType) artifactResp, err := svc.ListArtifacts(artifactReq) failOnErr(err, "error getting run info") // Store type artifacts artifacts[artifactType] = append(artifacts[artifactType], *artifactResp) } respJob, err := svc.ListJobs(jobReq) failOnErr(err, "error getting jobs") // Find all jobs within this run for _, job := range respJob.Jobs { fmt.Println("==========================================") time.Sleep(2 * time.Second) jobFriendlyName := fmt.Sprintf("%s - %s - %s", *job.Name, *job.Device.Model, *job.Device.Os) fmt.Println(awsutil.Prettify(job)) suiteReq := &devicefarm.ListSuitesInput{ Arn: aws.String(*job.Arn), } suiteResp, err := svc.ListSuites(suiteReq) failOnErr(err, "error getting run info") for _, suite := range suiteResp.Suites { message := "" if suite.Message != nil { message = *suite.Message } debug := true if debug { fmt.Printf("%s -> %s : %s \n----> %s\n", jobFriendlyName, *suite.Name, message, *suite.Arn) } dirPrefix := fmt.Sprintf("report/%s/%s", jobFriendlyName, *suite.Name) downloadArtifactsForSuite(dirPrefix, artifacts, *suite) } fmt.Println(awsutil.Prettify(suiteResp)) } params := &devicefarm.ListUniqueProblemsInput{ Arn: aws.String(runArn), // Required } problems, err := svc.ListUniqueProblems(params) if err != nil { // Print the error, cast err to awserr.Error to get the Code and // Message from an error. fmt.Println(err.Error()) return } // Pretty-print the response data. fmt.Println(awsutil.Prettify(problems)) problemsJson, _ := jsonutil.BuildJSON(problems) writeFile(problemsJson, "./report/unique_problems.json") }