|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved |
| 3 | + * |
| 4 | + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 5 | + * |
| 6 | + * Modifications copyright (C) 2017 Uber Technologies, Inc. |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not |
| 9 | + * use this file except in compliance with the License. A copy of the License is |
| 10 | + * located at |
| 11 | + * |
| 12 | + * http://aws.amazon.com/apache2.0 |
| 13 | + * |
| 14 | + * or in the "license" file accompanying this file. This file is distributed on |
| 15 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 16 | + * express or implied. See the License for the specific language governing |
| 17 | + * permissions and limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package io.temporal.samples.springboot; |
| 21 | + |
| 22 | +import io.temporal.client.WorkflowClient; |
| 23 | +import io.temporal.client.WorkflowOptions; |
| 24 | +import io.temporal.samples.springboot.hello.HelloWorkflow; |
| 25 | +import io.temporal.samples.springboot.hello.model.Person; |
| 26 | +import org.springframework.beans.factory.annotation.Autowired; |
| 27 | +import org.springframework.http.HttpStatus; |
| 28 | +import org.springframework.http.MediaType; |
| 29 | +import org.springframework.http.ResponseEntity; |
| 30 | +import org.springframework.stereotype.Controller; |
| 31 | +import org.springframework.ui.Model; |
| 32 | +import org.springframework.web.bind.annotation.*; |
| 33 | + |
| 34 | +@Controller |
| 35 | +public class SamplesController { |
| 36 | + |
| 37 | + @Autowired WorkflowClient client; |
| 38 | + |
| 39 | + @GetMapping("/hello") |
| 40 | + public String hello(Model model) { |
| 41 | + model.addAttribute("sample", "Say Hello"); |
| 42 | + return "hello"; |
| 43 | + } |
| 44 | + |
| 45 | + @PostMapping( |
| 46 | + value = "/hello", |
| 47 | + consumes = {MediaType.APPLICATION_JSON_VALUE}, |
| 48 | + produces = {MediaType.TEXT_HTML_VALUE}) |
| 49 | + ResponseEntity<String> helloSample(@RequestBody Person person) { |
| 50 | + HelloWorkflow workflow = |
| 51 | + client.newWorkflowStub( |
| 52 | + HelloWorkflow.class, |
| 53 | + WorkflowOptions.newBuilder() |
| 54 | + .setTaskQueue("HelloSampleTaskQueue") |
| 55 | + .setWorkflowId("HelloSample") |
| 56 | + .build()); |
| 57 | + |
| 58 | + // bypass thymeleaf, don't return template name just result |
| 59 | + return new ResponseEntity<>("\"" + workflow.sayHello(person) + "\"", HttpStatus.OK); |
| 60 | + } |
| 61 | +} |
0 commit comments