SpringSession

Session Management using Spring Session with JDBC DataStore

In web applications, user session management is very crucial for managing user state. In this article, we are going to learn about what are the approaches we have been following to manage user sessions in a clustered environment and how we can use Spring Session to implement it in a much simpler and more scalable way. Typically in production environments, we will have multiple server nodes with a load balancer in front of them and all the client traffic will be coming through the load balancer to one of the server nodes. So we need some mechanism to make the

Continue reading »

Spring Cloud Tutorials – Auto Refresh Config Changes using Spring Cloud Bus

Problem In the previous article Introduction to Spring Cloud Config Server (http://sivalabs.in/2017/08/spring-cloud-tutorials-introduction-to-spring-cloud-config-server/) we have seen how to use Spring Cloud Config Server. But, the problem is to reload the config changes in Config Client applications we need to trigger /refresh endpoint manually. This is not practical and viable if you have large number of applications. Solution Spring Cloud Bus module can be used to link multiple applications with a message broker and we can broadcast configuration changes. Let us see how we can use RabbitMQ as message broker and connect multiple applications to receive the configuration change events and refresh

Continue reading »

Spring Cloud Tutorials – Introduction to Spring Cloud Config Server

Problem SpringBoot provides lot of flexibility in externalizing configuration properties via properties or YAML files. We can also configure properties for each environment (dev, qa, prod etc) separately using profile specific configuration files such as application.properties, application-dev.properties, application-prod.properties etc. But once the application is started we can not update the properties at runtime. If we change the properties we need to restart the application to use the updated configuration properties. Also, in the context of large number of MicroService based applications, we want the ability to configure and manage the configuration properties of all MicroServices from a centralized place. Solution

Continue reading »

JCart : Iteration-8

In this Iteration#8 we will implement showing the Customer Account and Order History functionality in our ShoppingCart application. Customer MyAccount Page Profile Order History Once the customer is logged in our system he can click on MyAccount link at the top of the header and view his profile details and order history. First let us write the Controller handler method in our CustomerController to show myAccount details. @Controller public class CustomerController extends JCartSiteBaseController { @Autowired private CustomerService customerService; … … @RequestMapping(value=”/myAccount”, method=RequestMethod.GET) protected String myAccount(Model model) { String email = getCurrentUser().getCustomer().getEmail(); Customer customer = customerService.getCustomerByEmail(email); model.addAttribute(“customer”, customer); List<Order> orders =

Continue reading »

JCart : Manage Customers

For Managing Customers we need a provision to see all the list of customers and view any Customers details. Let us start with implementing the back-end Customer service. public interface CustomerRepository extends JpaRepository<Customer, Integer> { Customer findByEmail(String email); @Query(“select o from Order o where o.customer.email=?1”) List<Order> getCustomerOrders(String email); } @Service @Transactional public class CustomerService { @Autowired CustomerRepository customerRepository; public Customer getCustomerByEmail(String email) { return customerRepository.findByEmail(email); } public Customer createCustomer(Customer customer) { return customerRepository.save(customer); } public List<Customer> getAllCustomers() { return customerRepository.findAll(); } public Customer getCustomerById(Integer id) { return customerRepository.findOne(id); } public List<Order> getCustomerOrders(String email) { return customerRepository.getCustomerOrders(email); } } Now let

Continue reading »

JCart : Manage Orders

For Managing Orders we need a provision to see all the list of orders and view an order details and updating the order status. Let us start with implementing the back-end order service. @Service @Transactional public class OrderService { @Autowired EmailService emailService; @Autowired OrderRepository orderRepository; … … public Order getOrder(String orderNumber) { return orderRepository.findByOrderNumber(orderNumber); } public List<Order> getAllOrders() { Sort sort = new Sort(Direction.DESC, “createdOn”); return orderRepository.findAll(sort); } public Order updateOrder(Order order) { Order o = getOrder(order.getOrderNumber()); o.setStatus(order.getStatus()); Order savedOrder = orderRepository.save(o); return savedOrder; } } Now let us implement OrderController to handle the requests to display list of orders,

Continue reading »

JCart : Iteration-7

In Iteration#6 we have implemented features in ShoppingCart application to enable Customers place orders. In this Iteration#7 we will implement the features in Administration application to view and manage the Customers and Orders. As part of Iteration#7 we will implement the following usecases: Manage Orders List all Orders View Order details Update Order status Manage Customers List all customers View customer details

Continue reading »

JCart : Billing and Delivery Page

Once the customer reviewed his cart items details and clicks on Checkout we should display Billing & Delivery page where customer enters delivery address details, payment details etc and place the order. Let us create a OrderDTO.java as follows: public class OrderDTO implements Serializable { private static final long serialVersionUID = 1L; @NotEmpty(message=”FirstName is required”) private String firstName; @NotEmpty(message=”LastName is required”) private String lastName; @NotEmpty(message=”EmailId is required”) @Email private String emailId; @NotEmpty(message=”Phone is required”) private String phone; @NotEmpty(message=”Address Line1 is required”) private String addressLine1; private String addressLine2; @NotEmpty(message=”City is required”) private String city; @NotEmpty(message=”State is required”) private String state; @NotEmpty(message=”ZipCode

Continue reading »

JCart : Customer Registration

To facilitate new customer registration we will provide a new Registration form where customer provide his details and register with our system. Let us implement the back-end customer service operations. public interface CustomerRepository extends JpaRepository<Customer, Integer>{ Customer findByEmail(String email); } @Service @Transactional public class CustomerService { @Autowired CustomerRepository customerRepository; public Customer getCustomerByEmail(String email) { return customerRepository.findByEmail(email); } public Customer createCustomer(Customer customer) { return customerRepository.save(customer); } } @Component public class CustomerValidator implements Validator { @Autowired private CustomerService custmoerService; @Override public boolean supports(Class<?> clazz) { return Customer.class.isAssignableFrom(clazz); } @Override public void validate(Object target, Errors errors) { Customer customer = (Customer) target; Customer

Continue reading »

JCart : Customer Login

So far we have implemented the functionality where customers can browse the categories, add products to cart, view Cart and update/remove items. But to checkout the cart the customer should login into the system. So if the customer is not yet loggedin we should redirect customer to login page. If customer is already registered with our system he can login or he should be able to register. So, we will┬ástart implementing Customer Login/Registration usecases. Let us create login form thymeleaf view jcart-site/src/main/resources/templates/login.html as follows: <!DOCTYPE html> <html xmlns=”http://www.w3.org/1999/xhtml” xmlns:th=”http://www.thymeleaf.org” xmlns:sec=”http://www.thymeleaf.org/thymeleaf-extras-springsecurity3″ layout:decorator=”layout/mainLayout”> <head> <title>Login</title> </head> <body> <div layout:fragment=”content”> <div class=”single-product-area”> <div

Continue reading »