├── api ├── src │ ├── main │ │ ├── resources │ │ │ └── application.properties │ │ └── java │ │ │ └── com │ │ │ └── apiDemo │ │ │ ├── util │ │ │ └── UtilConstants.java │ │ │ ├── repository │ │ │ └── AccountRepository.java │ │ │ ├── model │ │ │ ├── AccountListWrapper.java │ │ │ └── Account.java │ │ │ ├── ApiApplication.java │ │ │ ├── service │ │ │ └── BanksService.java │ │ │ └── controller │ │ │ ├── BanksSessionController.java │ │ │ └── BanksController.java │ └── test │ │ └── java │ │ └── com │ │ └── apiDemo │ │ └── controller │ │ ├── BanksSessionControllerTest.java │ │ └── BanksControllerTest.java └── pom.xml ├── .travis.yml ├── .gitignore ├── web ├── src │ └── main │ │ ├── resources │ │ └── application.properties │ │ ├── java │ │ └── com │ │ │ └── webDemo │ │ │ ├── WebApplication.java │ │ │ ├── WebMvcConfig.java │ │ │ └── controller │ │ │ └── BanksMvcController.java │ │ └── webapp │ │ └── WEB-INF │ │ └── pages │ │ └── index.jsp └── pom.xml ├── .github └── workflows │ ├── maven.yml │ └── aws.yml ├── readme.rst └── pom.xml /api/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | script: mvn clean install -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /*/target 3 | /.settings 4 | .classpath 5 | .project 6 | .idea 7 | *.iml -------------------------------------------------------------------------------- /web/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.mvc.view.prefix:WEB-INF/pages/ 2 | spring.mvc.view.suffix:.jsp -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/util/UtilConstants.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.util; 2 | 3 | /** 4 | * Created by p.bell on 31.01.2016. 5 | */ 6 | public class UtilConstants { 7 | public static final String ACCOUNT_LIST_WRAPPER="accountListWrapper"; 8 | } 9 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v2 12 | - name: Set up JDK 1.8 13 | uses: actions/setup-java@v1 14 | with: 15 | java-version: 1.8 16 | - name: Build with Maven 17 | run: mvn -B package --file pom.xml 18 | -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.repository; 2 | 3 | import com.apiDemo.model.Account; 4 | import org.springframework.data.jpa.repository.Query; 5 | import org.springframework.data.repository.CrudRepository; 6 | import org.springframework.stereotype.Repository; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by p.bell on 31.01.2016. 12 | */ 13 | @Repository 14 | public interface AccountRepository extends CrudRepository { 15 | 16 | @Query("select a from Account a where sessionId=?") 17 | public List getBySessionId(String sessionId); 18 | } 19 | -------------------------------------------------------------------------------- /readme.rst: -------------------------------------------------------------------------------- 1 | .. image:: https://travis-ci.org/mokarakaya/spring-boot-multi-module-maven.svg?branch=master 2 | :target: https://travis-ci.org/mokarakaya/spring-boot-multi-module-maven 3 | 4 | 5 | spring-boot-multi-module-maven 6 | ~~~~~~~~~~~~ 7 | 8 | This project is a multi module maven project. Modules are api and web. 9 | 10 | Steps to run; 11 | 12 | First please navigate to webDemoProject folder and build the project as; 13 | 14 | webDemoProject>mvn clean install 15 | 16 | If everything works fine navigate to web folder and run spring boot project as; 17 | 18 | webDemoProject>cd web 19 | 20 | webDemoProject/web>mvn spring-boot:run 21 | 22 | 23 | Then go to; localhost:8080 24 | 25 | This project has 2 spring boot projects; api, web. 26 | When web project runs it creates itself and it also creates api project. So, both modules run in single tomcat server. 27 | Additionally, api module can run by itself since it's not dependent to web module. 28 | 29 | 30 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | pom 7 | 8 | UTF-8 9 | UTF-8 10 | 1.8 11 | 12 | 13 | api 14 | web 15 | 16 | 17 | org.springframework.boot 18 | spring-boot-starter-parent 19 | 1.2.4.RELEASE 20 | 21 | webDemo 22 | webDemo 23 | 1.0-SNAPSHOT 24 | 25 | -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/model/AccountListWrapper.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.model; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by p.bell on 25.01.2016. 8 | */ 9 | public class AccountListWrapper { 10 | private List accountList; 11 | private String storageType; 12 | 13 | public AccountListWrapper(){ 14 | accountList=new ArrayList<>(); 15 | } 16 | 17 | public AccountListWrapper(List accountList,String storageType){ 18 | this.accountList=accountList; 19 | this.storageType=storageType; 20 | } 21 | public void add(Account account){ 22 | this.accountList.add(account); 23 | } 24 | 25 | public List getAccountList() { 26 | return accountList; 27 | } 28 | 29 | public void setAccountList(List accountList) { 30 | this.accountList = accountList; 31 | } 32 | 33 | public String getStorageType() { 34 | return storageType; 35 | } 36 | 37 | public void setStorageType(String storageType) { 38 | this.storageType = storageType; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /web/src/main/java/com/webDemo/WebApplication.java: -------------------------------------------------------------------------------- 1 | package com.webDemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.web.SpringBootServletInitializer; 6 | 7 | import org.springframework.context.annotation.ComponentScan; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.context.annotation.Import; 10 | 11 | import javax.servlet.ServletContext; 12 | import javax.servlet.ServletException; 13 | 14 | /** 15 | * since basePackage includes com.apiDemo.* and api module is imported, api components will also be invoked. 16 | */ 17 | @Configuration 18 | @ComponentScan(basePackages = "com.*") 19 | @SpringBootApplication 20 | public class WebApplication extends SpringBootServletInitializer { 21 | 22 | public static void main(String[] args) throws Exception { 23 | SpringApplication.run(WebApplication.class, args); 24 | } 25 | @Override 26 | public void onStartup(ServletContext servletContext) throws ServletException { 27 | servletContext.setInitParameter("com.sun.faces.expressionFactory", "org.apache.el.ExpressionFactoryImpl"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/ApiApplication.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.context.web.SpringBootServletInitializer; 6 | 7 | import org.springframework.context.annotation.ComponentScan; 8 | import org.springframework.context.annotation.Configuration; 9 | import org.springframework.data.jpa.repository.config.EnableJpaRepositories; 10 | 11 | import javax.servlet.ServletContext; 12 | import javax.servlet.ServletException; 13 | 14 | /** 15 | * this module which consists of rest services can also run without web module. 16 | */ 17 | @Configuration 18 | @ComponentScan("com.apiDemo.*") 19 | @SpringBootApplication 20 | @EnableJpaRepositories 21 | public class ApiApplication extends SpringBootServletInitializer { 22 | 23 | public static void main(String[] args) throws Exception { 24 | SpringApplication.run(ApiApplication.class, args); 25 | } 26 | @Override 27 | public void onStartup(ServletContext servletContext) throws ServletException { 28 | servletContext.setInitParameter("com.sun.faces.expressionFactory", "org.apache.el.ExpressionFactoryImpl"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /web/src/main/java/com/webDemo/WebMvcConfig.java: -------------------------------------------------------------------------------- 1 | package com.webDemo; 2 | 3 | import org.springframework.context.annotation.Bean; 4 | import org.springframework.context.annotation.Configuration; 5 | import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; 6 | import org.springframework.web.servlet.config.annotation.EnableWebMvc; 7 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; 8 | import org.springframework.web.servlet.view.InternalResourceViewResolver; 9 | import org.springframework.beans.factory.annotation.Value; 10 | 11 | import java.lang.System; 12 | 13 | @Configuration 14 | @EnableWebMvc 15 | public class WebMvcConfig extends WebMvcConfigurerAdapter{ 16 | 17 | 18 | @Value("${spring.mvc.view.prefix}") 19 | private String location; 20 | 21 | @Value("${spring.mvc.view.suffix}") 22 | private String suffix; 23 | 24 | @Override 25 | public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) { 26 | configurer.enable(); 27 | } 28 | 29 | @Bean 30 | public InternalResourceViewResolver viewResolver() { 31 | InternalResourceViewResolver resolver = new InternalResourceViewResolver(); 32 | resolver.setPrefix(location); 33 | resolver.setSuffix(suffix); 34 | return resolver; 35 | } 36 | 37 | 38 | 39 | } -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/service/BanksService.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.service; 2 | 3 | import com.apiDemo.model.Account; 4 | import com.apiDemo.repository.AccountRepository; 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * Created by p.bell on 31.01.2016. 12 | */ 13 | @Service 14 | public class BanksService { 15 | 16 | @Autowired 17 | private AccountRepository accountRepository; 18 | 19 | public Account get(long index){ 20 | return accountRepository.findOne(index); 21 | } 22 | 23 | public List getBySessionId(String sessionId) { 24 | return accountRepository.getBySessionId(sessionId); 25 | } 26 | 27 | public void update(long index,String iban, String businessIdentifierCode) { 28 | Account account = accountRepository.findOne(index); 29 | account.setBusinessIdentifierCode(businessIdentifierCode); 30 | account.setIban(iban); 31 | accountRepository.save(account); 32 | } 33 | 34 | public long create(String iban, String businessIdentifierCode ,String sessionId) { 35 | Account account = new Account(sessionId,iban,businessIdentifierCode); 36 | accountRepository.save(account); 37 | return account.getId(); 38 | } 39 | 40 | public void delete(long index) { 41 | accountRepository.delete(index); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/model/Account.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.model; 2 | 3 | import javax.persistence.Entity; 4 | import javax.persistence.GeneratedValue; 5 | import javax.persistence.GenerationType; 6 | import javax.persistence.Id; 7 | 8 | /** 9 | * Created by p.bell on 25.01.2016. 10 | */ 11 | @Entity 12 | public class Account { 13 | 14 | @Id 15 | @GeneratedValue(strategy = GenerationType.AUTO) 16 | private Long id; 17 | private String sessionId; 18 | private String iban; 19 | private String businessIdentifierCode; 20 | 21 | public Account(){} 22 | 23 | public Account(String iban,String businessIdentifierCode){ 24 | this.iban=iban; 25 | this.businessIdentifierCode=businessIdentifierCode; 26 | } 27 | 28 | public Account(String sessionId,String iban,String businessIdentifierCode){ 29 | this.sessionId=sessionId; 30 | this.iban=iban; 31 | this.businessIdentifierCode=businessIdentifierCode; 32 | } 33 | 34 | public String getIban() { 35 | return iban; 36 | } 37 | 38 | public void setIban(String iban) { 39 | this.iban = iban; 40 | } 41 | 42 | public String getBusinessIdentifierCode() { 43 | return businessIdentifierCode; 44 | } 45 | 46 | public void setBusinessIdentifierCode(String businessIdentifierCode) { 47 | this.businessIdentifierCode = businessIdentifierCode; 48 | } 49 | 50 | public String getSessionId() { 51 | return sessionId; 52 | } 53 | 54 | public void setSessionId(String sessionId) { 55 | this.sessionId = sessionId; 56 | } 57 | 58 | public Long getId() { 59 | return id; 60 | } 61 | 62 | public void setId(Long id) { 63 | this.id = id; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /api/src/test/java/com/apiDemo/controller/BanksSessionControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.controller; 2 | 3 | import com.apiDemo.ApiApplication; 4 | import com.apiDemo.model.Account; 5 | import com.apiDemo.model.AccountListWrapper; 6 | import com.apiDemo.util.UtilConstants; 7 | import junit.framework.TestCase; 8 | import org.easymock.EasyMock; 9 | import org.junit.Test; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpSession; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | import static org.easymock.EasyMock.createNiceMock; 17 | import static org.easymock.EasyMock.expect; 18 | 19 | /** 20 | * Created by p.bell on 31.01.2016. 21 | */ 22 | 23 | public class BanksSessionControllerTest extends TestCase { 24 | 25 | 26 | private BanksSessionController banksSessionController; 27 | 28 | private HttpSession mockedSession; 29 | 30 | 31 | public void setUp() throws Exception { 32 | banksSessionController=new BanksSessionController(); 33 | List accountList= new ArrayList<>(); 34 | accountList.add(0, new Account("1", "test")); 35 | AccountListWrapper accountListWrapper=new AccountListWrapper(); 36 | accountListWrapper.setAccountList(accountList); 37 | mockedSession = createNiceMock(HttpSession.class); 38 | expect(mockedSession.getAttribute(UtilConstants.ACCOUNT_LIST_WRAPPER)).andReturn(accountListWrapper); 39 | EasyMock.replay(mockedSession); 40 | } 41 | 42 | 43 | 44 | @Test 45 | public void testAddData() { 46 | banksSessionController.create("2","test2",mockedSession); 47 | } 48 | 49 | @Test 50 | public void testUpdate() { 51 | banksSessionController.update(0,"2","test2",mockedSession); 52 | } 53 | 54 | @Test 55 | public void testDeleteData() throws Exception { 56 | banksSessionController.delete(0,mockedSession); 57 | } 58 | 59 | } -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/controller/BanksSessionController.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.controller; 2 | 3 | import com.apiDemo.model.Account; 4 | import com.apiDemo.model.AccountListWrapper; 5 | import com.apiDemo.util.UtilConstants; 6 | import org.springframework.web.bind.annotation.RequestMapping; 7 | import org.springframework.web.bind.annotation.RequestMethod; 8 | import org.springframework.web.bind.annotation.RequestParam; 9 | import org.springframework.web.bind.annotation.RestController; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpSession; 13 | import java.util.List; 14 | 15 | /** 16 | * Created by p.bell on 26.01.2016. 17 | * this class consists of rest services for session operations 18 | */ 19 | @RestController 20 | @RequestMapping("/sessionOperations") 21 | public class BanksSessionController { 22 | 23 | @RequestMapping(value="/", method = RequestMethod.PUT) 24 | public void update(@RequestParam(value="index") int index,@RequestParam(value="iban") String iban, 25 | @RequestParam(value="businessIdentifierCode") String businessIdentifierCode ,HttpSession session) { 26 | AccountListWrapper accountListWrapper = (AccountListWrapper) session.getAttribute(UtilConstants.ACCOUNT_LIST_WRAPPER); 27 | accountListWrapper.getAccountList().set(index, new Account(iban, businessIdentifierCode)); 28 | } 29 | 30 | @RequestMapping(value="/",method = RequestMethod.POST) 31 | public void create(@RequestParam(value="iban") String iban, 32 | @RequestParam(value="businessIdentifierCode") String businessIdentifierCode ,HttpSession session) { 33 | AccountListWrapper accountListWrapper = (AccountListWrapper) session.getAttribute(UtilConstants.ACCOUNT_LIST_WRAPPER); 34 | accountListWrapper.getAccountList().add(new Account(iban, businessIdentifierCode)); 35 | } 36 | 37 | @RequestMapping(value="/",method = RequestMethod.DELETE) 38 | public void delete(@RequestParam(value="index") int index,HttpSession session) { 39 | AccountListWrapper accountListWrapper = (AccountListWrapper) session.getAttribute(UtilConstants.ACCOUNT_LIST_WRAPPER); 40 | accountListWrapper.getAccountList().remove(index); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /api/src/test/java/com/apiDemo/controller/BanksControllerTest.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.controller; 2 | 3 | import com.apiDemo.ApiApplication; 4 | import com.apiDemo.service.BanksService; 5 | import junit.framework.TestCase; 6 | import org.junit.Before; 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.boot.test.SpringApplicationConfiguration; 11 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 12 | import org.springframework.test.context.web.WebAppConfiguration; 13 | import org.springframework.test.web.servlet.MockMvc; 14 | import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 15 | import org.springframework.test.web.servlet.result.MockMvcResultMatchers; 16 | import org.springframework.test.web.servlet.setup.MockMvcBuilders; 17 | import org.springframework.web.context.WebApplicationContext; 18 | 19 | /** 20 | * Created by p.bell on 31.01.2016. 21 | */ 22 | @RunWith(SpringJUnit4ClassRunner.class) 23 | @SpringApplicationConfiguration(classes = ApiApplication.class) 24 | @WebAppConfiguration 25 | public class BanksControllerTest extends TestCase { 26 | private MockMvc mockMvc; 27 | 28 | @Autowired 29 | private WebApplicationContext webApplicationContext; 30 | 31 | @Autowired 32 | BanksService banksService; 33 | 34 | @Before 35 | public void setup() throws Exception { 36 | this.mockMvc = MockMvcBuilders 37 | .webAppContextSetup(webApplicationContext).build(); 38 | } 39 | 40 | @Test 41 | public void testAddData() throws Exception { 42 | mockMvc.perform(MockMvcRequestBuilders.post("/operations/?iban=1&businessIdentifierCode=test")).andExpect(MockMvcResultMatchers.status().isOk()); 43 | } 44 | 45 | @Test 46 | public void testUpdate() throws Exception { 47 | long id = banksService.create("2", "test2", null); 48 | mockMvc.perform(MockMvcRequestBuilders.put("/operations/?index="+id+"&iban=2&businessIdentifierCode=test1")) 49 | .andExpect(MockMvcResultMatchers.status().isOk()); 50 | } 51 | 52 | @Test 53 | public void testDeleteData() throws Exception { 54 | long id = banksService.create("2", "test2", null); 55 | mockMvc.perform(MockMvcRequestBuilders.delete("/operations/?index="+id)).andExpect(MockMvcResultMatchers.status().isOk()); 56 | } 57 | 58 | } -------------------------------------------------------------------------------- /api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | webDemo 7 | webDemo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | jar 12 | 13 | api 14 | api 15 | 1.0-SNAPSHOT 16 | 17 | 18 | 19 | org.springframework.boot 20 | spring-boot-starter-web 21 | 22 | 23 | org.apache.tomcat.embed 24 | tomcat-embed-jasper 25 | provided 26 | 27 | 28 | org.springframework.boot 29 | spring-boot-starter-data-jpa 30 | 31 | 32 | org.hsqldb 33 | hsqldb 34 | 2.3.3 35 | 36 | 37 | junit 38 | junit 39 | 4.12 40 | test 41 | 42 | 43 | org.easymock 44 | easymock 45 | 3.4 46 | test 47 | 48 | 49 | org.springframework.boot 50 | spring-boot-starter-test 51 | test 52 | 53 | 54 | 55 | 56 | 57 | org.springframework.boot 58 | spring-boot-maven-plugin 59 | 60 | com.apiDemo.ApiApplication 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /api/src/main/java/com/apiDemo/controller/BanksController.java: -------------------------------------------------------------------------------- 1 | package com.apiDemo.controller; 2 | 3 | import com.apiDemo.model.Account; 4 | import com.apiDemo.model.AccountListWrapper; 5 | import com.apiDemo.service.BanksService; 6 | import com.apiDemo.util.UtilConstants; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.web.bind.annotation.RequestMapping; 9 | import org.springframework.web.bind.annotation.RequestMethod; 10 | import org.springframework.web.bind.annotation.RequestParam; 11 | import org.springframework.web.bind.annotation.RestController; 12 | 13 | import javax.servlet.http.HttpServletRequest; 14 | 15 | /** 16 | * Created by p.bell on 26.01.2016. 17 | * this class consists of rest services for database operations 18 | */ 19 | @RestController 20 | @RequestMapping("/operations") 21 | public class BanksController { 22 | 23 | @Autowired 24 | private BanksService banksService; 25 | 26 | @RequestMapping(value="/", method = RequestMethod.PUT) 27 | public void update(@RequestParam(value="index") long index,@RequestParam(value="iban") String iban, 28 | @RequestParam(value="businessIdentifierCode") String businessIdentifierCode ,HttpServletRequest request) throws Exception { 29 | checkSessionId(index, request); 30 | banksService.update(index,iban,businessIdentifierCode); 31 | } 32 | 33 | @RequestMapping(value="/",method = RequestMethod.POST) 34 | public void create(@RequestParam(value="iban") String iban, 35 | @RequestParam(value="businessIdentifierCode") String businessIdentifierCode ,HttpServletRequest request) { 36 | banksService.create(iban, businessIdentifierCode, request.getRequestedSessionId()); 37 | } 38 | 39 | @RequestMapping(value="/",method = RequestMethod.DELETE) 40 | public void delete(@RequestParam(value="index") long index,HttpServletRequest request) throws Exception { 41 | checkSessionId(index,request); 42 | banksService.delete(index); 43 | } 44 | 45 | /** 46 | * checks if the request is from the proper session 47 | * @param index 48 | * @param request 49 | * @throws Exception 50 | */ 51 | private void checkSessionId(long index, HttpServletRequest request) throws Exception { 52 | Account account = banksService.get(index); 53 | if(account.getSessionId()!=null && !account.getSessionId().equals(request.getRequestedSessionId())){ 54 | throw new Exception("invalid session id"); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /web/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | webDemo 7 | webDemo 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | war 12 | 13 | web 14 | web 15 | 1.0-SNAPSHOT 16 | 17 | 18 | UTF-8 19 | UTF-8 20 | 1.8 21 | 22 | 23 | 24 | api 25 | api 26 | 1.0-SNAPSHOT 27 | 28 | 29 | org.springframework.boot 30 | spring-boot-starter-web 31 | 32 | 33 | org.springframework 34 | spring-webmvc 35 | 36 | 37 | org.apache.tomcat.embed 38 | tomcat-embed-jasper 39 | provided 40 | 41 | 42 | org.apache.tomcat 43 | tomcat-jasper-el 44 | 8.0.1 45 | 46 | 47 | javax.servlet 48 | jstl 49 | 1.2 50 | 51 | 52 | junit 53 | junit 54 | 4.12 55 | test 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | javax 64 | javaee-api 65 | 7.0 66 | 67 | 68 | -------------------------------------------------------------------------------- /web/src/main/java/com/webDemo/controller/BanksMvcController.java: -------------------------------------------------------------------------------- 1 | package com.webDemo.controller; 2 | 3 | import com.apiDemo.controller.BanksController; 4 | import com.apiDemo.model.Account; 5 | import com.apiDemo.model.AccountListWrapper; 6 | import com.apiDemo.service.BanksService; 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Controller; 9 | import org.springframework.ui.ModelMap; 10 | import org.springframework.web.bind.annotation.RequestMapping; 11 | import org.springframework.web.bind.annotation.RequestMethod; 12 | import org.springframework.web.bind.annotation.RequestParam; 13 | 14 | import javax.servlet.http.HttpSession; 15 | import java.util.List; 16 | 17 | /** 18 | * Created by p.bell on 25.01.2016. 19 | */ 20 | @Controller 21 | public class BanksMvcController { 22 | 23 | @Autowired 24 | private BanksService banksService; 25 | 26 | public static final String ACCOUNT_LIST_WRAPPER="accountListWrapper"; 27 | private static final String INIT_IBAN="initIban"; 28 | private static final String INIT_BUSINESS_IDENTIFER_CODE="initBusinessIdentifierCode"; 29 | private static final String SESSION="session"; 30 | private static final String DATABASE="database"; 31 | 32 | @RequestMapping(value = "/", method = RequestMethod.GET) 33 | public String getAccountListWrapper(HttpSession session,ModelMap model, @RequestParam(value="storageType",required = false) String storageType) { 34 | AccountListWrapper accountListWrapper=null; 35 | if(storageType==null || SESSION.equals(storageType)) { 36 | accountListWrapper = sessionSelected(session, storageType); 37 | }else if(DATABASE.equals(storageType)){ 38 | accountListWrapper = databaseSelected(session, storageType); 39 | } 40 | model.addAttribute(ACCOUNT_LIST_WRAPPER, accountListWrapper); 41 | return "index"; 42 | } 43 | 44 | private AccountListWrapper databaseSelected(HttpSession session, String storageType) { 45 | List accountList = banksService.getBySessionId(session.getId()); 46 | if(accountList.size()==0){ 47 | banksService.create(INIT_IBAN,INIT_BUSINESS_IDENTIFER_CODE,session.getId()); 48 | accountList = banksService.getBySessionId(session.getId()); 49 | } 50 | return new AccountListWrapper(accountList,DATABASE); 51 | } 52 | 53 | private AccountListWrapper sessionSelected(HttpSession session, String storageType) { 54 | AccountListWrapper accountListWrapper = (AccountListWrapper) session.getAttribute(ACCOUNT_LIST_WRAPPER); 55 | if(accountListWrapper==null){ 56 | accountListWrapper= new AccountListWrapper(); 57 | accountListWrapper.add(new Account(INIT_IBAN, INIT_BUSINESS_IDENTIFER_CODE)); 58 | } 59 | accountListWrapper.setStorageType(SESSION); 60 | session.setAttribute(ACCOUNT_LIST_WRAPPER, accountListWrapper); 61 | return accountListWrapper; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /.github/workflows/aws.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build and push a new container image to Amazon ECR, 2 | # and then will deploy a new task definition to Amazon ECS, on every push 3 | # to the master branch. 4 | # 5 | # To use this workflow, you will need to complete the following set-up steps: 6 | # 7 | # 1. Create an ECR repository to store your images. 8 | # For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`. 9 | # Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name. 10 | # Replace the value of `aws-region` in the workflow below with your repository's region. 11 | # 12 | # 2. Create an ECS task definition, an ECS cluster, and an ECS service. 13 | # For example, follow the Getting Started guide on the ECS console: 14 | # https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun 15 | # Replace the values for `service` and `cluster` in the workflow below with your service and cluster names. 16 | # 17 | # 3. Store your ECS task definition as a JSON file in your repository. 18 | # The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`. 19 | # Replace the value of `task-definition` in the workflow below with your JSON file's name. 20 | # Replace the value of `container-name` in the workflow below with the name of the container 21 | # in the `containerDefinitions` section of the task definition. 22 | # 23 | # 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. 24 | # See the documentation for each action used below for the recommended IAM policies for this IAM user, 25 | # and best practices on handling the access key credentials. 26 | 27 | on: 28 | push: 29 | branches: 30 | - master 31 | 32 | name: Deploy to Amazon ECS 33 | 34 | jobs: 35 | deploy: 36 | name: Deploy 37 | runs-on: ubuntu-latest 38 | 39 | steps: 40 | - name: Checkout 41 | uses: actions/checkout@v2 42 | 43 | - name: Configure AWS credentials 44 | uses: aws-actions/configure-aws-credentials@v1 45 | with: 46 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 47 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 48 | aws-region: us-east-2 49 | 50 | - name: Login to Amazon ECR 51 | id: login-ecr 52 | uses: aws-actions/amazon-ecr-login@v1 53 | 54 | - name: Build, tag, and push image to Amazon ECR 55 | id: build-image 56 | env: 57 | ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} 58 | ECR_REPOSITORY: my-ecr-repo 59 | IMAGE_TAG: ${{ github.sha }} 60 | run: | 61 | # Build a docker container and 62 | # push it to ECR so that it can 63 | # be deployed to ECS. 64 | docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . 65 | docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG 66 | echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" 67 | 68 | - name: Fill in the new image ID in the Amazon ECS task definition 69 | id: task-def 70 | uses: aws-actions/amazon-ecs-render-task-definition@v1 71 | with: 72 | task-definition: task-definition.json 73 | container-name: sample-app 74 | image: ${{ steps.build-image.outputs.image }} 75 | 76 | - name: Deploy Amazon ECS task definition 77 | uses: aws-actions/amazon-ecs-deploy-task-definition@v1 78 | with: 79 | task-definition: ${{ steps.task-def.outputs.task-definition }} 80 | service: sample-app-service 81 | cluster: default 82 | wait-for-service-stability: true 83 | -------------------------------------------------------------------------------- /web/src/main/webapp/WEB-INF/pages/index.jsp: -------------------------------------------------------------------------------- 1 | 2 | <%@page import="java.util.ArrayList"%> 3 | <%@page import="com.apiDemo.model.Account"%> 4 | <%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> 5 | <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 6 | <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 21 |
15 | 16 | Session 17 | Database 18 | 19 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 |
35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 |
46 |
47 | 90 | 91 | --------------------------------------------------------------------------------