Exercise 17: Controller Methods - jkneal/spring-angular-train GitHub Wiki

Goals

Learn how to form different controller method signatures

Instructions

  1. In edu.train.shop.ShopController, create a new method named 'getNewsletter' that maps to '/shop/newsletter' and accepts Get Http methods

  2. Add the following code to the method body, then adapt the method signature as needed:

   Resource resource = new ClassPathResource("public/newsletter.pdf");
   try {
     InputStream inputStream = resource.getInputStream();
     OutputStream outputStream = httpServletResponse.getOutputStream();
     IOUtils.copy(inputStream, outputStream);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }

VERIFICATION

  1. Start the training application and go to the app home page
  2. Click on the link 'Exercise 17'. Verify a PDF with newsletter content is returned