Package org.wgrus.web

Source Code of org.wgrus.web.StoreFront

package org.wgrus.web;

import java.util.concurrent.atomic.AtomicLong;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.core.MessagingTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.wgrus.Order;

/**
* Handles order requests.
*/
@Controller
@RequestMapping(value="/")
public class StoreFront {

  private final AtomicLong orderIdCounter = new AtomicLong(1);

  @Autowired @Qualifier("orderChannel")
  private MessageChannel orderChannel;

  @RequestMapping(method=RequestMethod.GET)
  public String displayForm() {
    return "order";
  }

  @RequestMapping(method=RequestMethod.POST)
  public String placeOrder(@RequestParam String email, @RequestParam int quantity, @RequestParam String productId, Model model) {
    long orderId = orderIdCounter.getAndIncrement();
    Order order = new Order(orderId);
    order.setEmail(email);
    order.setQuantity(quantity);
    order.setProductId(productId);
    MessagingTemplate template = new MessagingTemplate(this.orderChannel);
    template.convertAndSend(order);
    model.addAttribute("orderId", orderId);
    return "order";
  }

}
TOP

Related Classes of org.wgrus.web.StoreFront

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.