Created
April 22, 2017 14:49
-
-
Save mzimecki/96fa514961a42230f35420c1dcdc7932 to your computer and use it in GitHub Desktop.
[medium] HelloService example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Controller | |
@RequestMapping("service") | |
public class HelloService { | |
@Autowired | |
private ProducerTemplate producer; | |
@Autowired | |
private CamelContext camelContext; | |
@PostMapping(value = "/hello", consumes={MediaType.TEXT_PLAIN_VALUE}, produces = {MediaType.TEXT_PLAIN_VALUE}) | |
@ResponseBody | |
public ResponseEntity<?> hello(final HttpServletRequest request, @RequestBody String requestBody) { | |
final Exchange requestExchange = ExchangeBuilder.anExchange(camelContext).withBody(requestBody).build(); | |
final Exchange responseExchange = producer.send(ServiceConstants.HELLO_SERVICE_ENDPOINT, requestExchange); | |
final String responseBody = responseExchange.getOut().getBody(String.class); | |
final int responseCode = responseExchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE, Integer.class).intValue(); | |
return ResponseEntity.status(responseCode).body(responseBody); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment