Guest User

Untitled

a guest
Jul 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. package springapp.web;
  2.  
  3. import org.springframework.web.servlet.mvc.Controller;
  4. import org.springframework.web.servlet.ModelAndView;
  5.  
  6. import javax.servlet.ServletContext;
  7. import javax.servlet.ServletException;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10.  
  11. import java.io.IOException;
  12. import java.rmi.Naming;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.HashMap;
  16.  
  17. import org.apache.commons.logging.Log;
  18. import org.apache.commons.logging.LogFactory;
  19.  
  20. import fr.promogest.Directory;
  21. import fr.promogest.IDirectory;
  22. import fr.promogest.modeles.Promotion;
  23.  
  24. import springapp.service.ProductManager;
  25. import java.rmi.Naming;
  26. import java.rmi.NotBoundException;
  27. import java.rmi.RemoteException;
  28.  
  29. public class InventoryController implements Controller {
  30.  
  31. protected final Log logger = LogFactory.getLog(getClass());
  32.  
  33. private ProductManager productManager;
  34.  
  35. public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
  36. throws ServletException, IOException, RemoteException{
  37.  
  38. String url = "rmi://localhost/Directory";
  39. IDirectory directory = null;
  40. try {
  41. directory = (IDirectory) Naming.lookup(url);
  42. } catch (NotBoundException e) {
  43. // TODO Auto-generated catch block
  44. e.printStackTrace();
  45. }
  46.  
  47. //IDirectory directory = new Directory();
  48. List<Promotion> promotions = directory.listPromotions();
  49.  
  50. ServletContext context = request.getServletContext();
  51. context.setAttribute("directory", directory);
  52. context.setAttribute("promotions", promotions);
  53.  
  54. System.out.println(promotions.size());
  55.  
  56. String now = (new java.util.Date()).toString();
  57. logger.info("returning hello view with " + now);
  58.  
  59. Map<String, Object> myModel = new HashMap<String, Object>();
  60. myModel.put("now", now);
  61. myModel.put("products", this.productManager.getProducts());
  62.  
  63. return new ModelAndView("hello", "model", myModel);
  64. }
  65.  
  66.  
  67. public void setProductManager(ProductManager productManager) {
  68. this.productManager = productManager;
  69. }
  70.  
  71. }
Add Comment
Please, Sign In to add comment