Skip to content

Instantly share code, notes, and snippets.

@mzimecki
Created April 22, 2017 14:49
Show Gist options
  • Save mzimecki/96fa514961a42230f35420c1dcdc7932 to your computer and use it in GitHub Desktop.
Save mzimecki/96fa514961a42230f35420c1dcdc7932 to your computer and use it in GitHub Desktop.
[medium] HelloService example
@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