diff --git a/spring-security-rest-custom/src/test/java/org/baeldung/live/HttpLiveServiceTemp.java b/httpclient/src/test/java/org/baeldung/httpclient/HttpClientUnshortenLiveTest.java similarity index 98% rename from spring-security-rest-custom/src/test/java/org/baeldung/live/HttpLiveServiceTemp.java rename to httpclient/src/test/java/org/baeldung/httpclient/HttpClientUnshortenLiveTest.java index 19f8f5325e..7eef1cade8 100644 --- a/spring-security-rest-custom/src/test/java/org/baeldung/live/HttpLiveServiceTemp.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/HttpClientUnshortenLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.live; +package org.baeldung.httpclient; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; @@ -25,7 +25,7 @@ import org.junit.Test; import com.google.common.base.Preconditions; import com.google.common.collect.Lists; -public class HttpLiveServiceTemp { +public class HttpClientUnshortenLiveTest { private CloseableHttpClient client; diff --git a/spring-security-rest-custom/README.md b/spring-security-rest-custom/README.md index 690d80a009..3ec8cf92c7 100644 --- a/spring-security-rest-custom/README.md +++ b/spring-security-rest-custom/README.md @@ -5,4 +5,3 @@ ### Relevant Articles: - [Spring Security Authentication Provider](http://www.baeldung.com/spring-security-authentication-provider) -- [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient) diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/config/MainWebAppInitializer.java b/spring-security-rest-custom/src/main/java/org/baeldung/config/MainWebAppInitializer.java new file mode 100644 index 0000000000..0d2c2be770 --- /dev/null +++ b/spring-security-rest-custom/src/main/java/org/baeldung/config/MainWebAppInitializer.java @@ -0,0 +1,48 @@ +package org.baeldung.config; + +import java.util.Set; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.servlet.DispatcherServlet; + +public class MainWebAppInitializer implements WebApplicationInitializer { + + public MainWebAppInitializer() { + super(); + } + + // + + /** + * Register and configure all Servlet container components necessary to power the web application. + */ + @Override + public void onStartup(final ServletContext sc) throws ServletException { + System.out.println("MyWebAppInitializer.onStartup()"); + + // Create the 'root' Spring application context + final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); + root.scan("org.baeldung.config.parent"); + // root.getEnvironment().setDefaultProfiles("embedded"); + + // Manages the lifecycle of the root application context + sc.addListener(new ContextLoaderListener(root)); + + // Handles requests into the application + final AnnotationConfigWebApplicationContext childWebApplicationContext = new AnnotationConfigWebApplicationContext(); + childWebApplicationContext.scan("org.baeldung.config.child"); + final ServletRegistration.Dynamic appServlet = sc.addServlet("api", new DispatcherServlet(childWebApplicationContext)); + appServlet.setLoadOnStartup(1); + final Set mappingConflicts = appServlet.addMapping("/"); + if (!mappingConflicts.isEmpty()) { + throw new IllegalStateException("'appServlet' could not be mapped to '/' due " + "to an existing mapping. This is a known issue under Tomcat versions " + "<= 7.0.14; see https://issues.apache.org/bugzilla/show_bug.cgi?id=51278"); + } + } + +} diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/spring/WebConfig.java b/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java similarity index 96% rename from spring-security-rest-custom/src/main/java/org/baeldung/spring/WebConfig.java rename to spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java index 8c3d677af6..bbddbe2bae 100644 --- a/spring-security-rest-custom/src/main/java/org/baeldung/spring/WebConfig.java +++ b/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package org.baeldung.config.child; import java.util.List; diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java similarity index 77% rename from spring-security-rest-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java index 4ce80dab9f..ee9b0868e7 100644 --- a/spring-security-rest-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package org.baeldung.config.parent; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -7,9 +7,9 @@ import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource({ "classpath:webSecurityConfig.xml" }) @ComponentScan("org.baeldung.security") -public class SecSecurityConfig { +public class SecurityConfig { - public SecSecurityConfig() { + public SecurityConfig() { super(); } diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/ServiceConfig.java b/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/ServiceConfig.java new file mode 100644 index 0000000000..11ff616f88 --- /dev/null +++ b/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/ServiceConfig.java @@ -0,0 +1,14 @@ +package org.baeldung.config.parent; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan("org.baeldung.service") +public class ServiceConfig { + + public ServiceConfig() { + super(); + } + +} \ No newline at end of file diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/service/FooService.java b/spring-security-rest-custom/src/main/java/org/baeldung/service/FooService.java new file mode 100644 index 0000000000..0709426e1f --- /dev/null +++ b/spring-security-rest-custom/src/main/java/org/baeldung/service/FooService.java @@ -0,0 +1,20 @@ +package org.baeldung.service; + +import org.baeldung.web.dto.Foo; +import org.springframework.stereotype.Service; + +@Service +public class FooService implements IFooService { + + public FooService() { + super(); + } + + // API + + @Override + public Foo findOne(final Long id) { + return new Foo(); + } + +} diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/service/IFooService.java b/spring-security-rest-custom/src/main/java/org/baeldung/service/IFooService.java new file mode 100644 index 0000000000..de234b1b45 --- /dev/null +++ b/spring-security-rest-custom/src/main/java/org/baeldung/service/IFooService.java @@ -0,0 +1,9 @@ +package org.baeldung.service; + +import org.baeldung.web.dto.Foo; + +public interface IFooService { + + Foo findOne(final Long id); + +} diff --git a/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/FooController.java index ff5a00fd95..4fa8b8094e 100644 --- a/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/FooController.java @@ -1,8 +1,8 @@ package org.baeldung.web.controller; +import org.baeldung.service.IFooService; import org.baeldung.web.dto.Foo; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.ApplicationEventPublisher; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.ResponseBody; public class FooController { @Autowired - private ApplicationEventPublisher eventPublisher; + private IFooService service; public FooController() { super(); @@ -25,7 +25,7 @@ public class FooController { @RequestMapping(value = "/{id}", method = RequestMethod.GET) @ResponseBody public Foo findOne(@PathVariable("id") final Long id) { - return new Foo(); + return service.findOne(id); } } diff --git a/spring-security-rest-custom/src/main/webapp/WEB-INF/api-servlet.xml b/spring-security-rest-custom/src/main/webapp/WEB-INF/api-servlet.xml index a675fc6d95..d6e8f7549a 100644 --- a/spring-security-rest-custom/src/main/webapp/WEB-INF/api-servlet.xml +++ b/spring-security-rest-custom/src/main/webapp/WEB-INF/api-servlet.xml @@ -1,6 +1,5 @@ - + \ No newline at end of file diff --git a/spring-security-rest-custom/src/main/webapp/WEB-INF/web.xml b/spring-security-rest-custom/src/main/webapp/WEB-INF/web_old.xml similarity index 85% rename from spring-security-rest-custom/src/main/webapp/WEB-INF/web.xml rename to spring-security-rest-custom/src/main/webapp/WEB-INF/web_old.xml index 372688c8d8..950bbab505 100644 --- a/spring-security-rest-custom/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-rest-custom/src/main/webapp/WEB-INF/web_old.xml @@ -15,7 +15,7 @@ contextConfigLocation - org.baeldung.spring + org.baeldung.config.parent @@ -26,6 +26,10 @@ api org.springframework.web.servlet.DispatcherServlet + + + + 1 @@ -44,8 +48,4 @@ /* - - - - \ No newline at end of file