From 377c71e9d74be665b147406e494d1ab6109c5927 Mon Sep 17 00:00:00 2001 From: DOHA Date: Fri, 29 Jan 2016 12:05:15 +0200 Subject: [PATCH 1/2] add zuul module --- spring-zuul/.project | 17 +++ spring-zuul/pom.xml | 102 ++++++++++++++++++ .../spring-zuul-foos-resource/.classpath | 32 ++++++ .../spring-zuul-foos-resource/.project | 48 +++++++++ spring-zuul/spring-zuul-foos-resource/pom.xml | 38 +++++++ .../config/ResourceServerApplication.java | 14 +++ .../config/ResourceServerWebConfig.java | 13 +++ .../web/controller/FooController.java | 35 ++++++ .../main/java/org/baeldung/web/dto/Foo.java | 36 +++++++ .../src/main/resources/application.properties | 2 + spring-zuul/spring-zuul-ui/.classpath | 37 +++++++ spring-zuul/spring-zuul-ui/.project | 48 +++++++++ spring-zuul/spring-zuul-ui/pom.xml | 91 ++++++++++++++++ .../org/baeldung/config/CustomZuulFilter.java | 33 ++++++ .../org/baeldung/config/UiApplication.java | 14 +++ .../java/org/baeldung/config/UiWebConfig.java | 39 +++++++ .../src/main/resources/application.yml | 9 ++ .../src/main/resources/templates/index.html | 90 ++++++++++++++++ .../resources/angular-utf8-base64.min.js | 1 + .../test/java/org/baeldung/web/LiveTest.java | 30 ++++++ .../src/test/resources/.gitignore | 13 +++ .../resources/persistence-mysql.properties | 10 ++ .../spring-zuul-users-resource/.classpath | 32 ++++++ .../spring-zuul-users-resource/.project | 48 +++++++++ .../spring-zuul-users-resource/pom.xml | 38 +++++++ .../config/ResourceServerApplication.java | 14 +++ .../config/ResourceServerWebConfig.java | 13 +++ .../web/controller/UserController.java | 30 ++++++ .../main/java/org/baeldung/web/dto/User.java | 46 ++++++++ .../src/main/resources/application.properties | 2 + 30 files changed, 975 insertions(+) create mode 100644 spring-zuul/.project create mode 100644 spring-zuul/pom.xml create mode 100644 spring-zuul/spring-zuul-foos-resource/.classpath create mode 100644 spring-zuul/spring-zuul-foos-resource/.project create mode 100644 spring-zuul/spring-zuul-foos-resource/pom.xml create mode 100644 spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java create mode 100644 spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java create mode 100644 spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/controller/FooController.java create mode 100644 spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/dto/Foo.java create mode 100644 spring-zuul/spring-zuul-foos-resource/src/main/resources/application.properties create mode 100644 spring-zuul/spring-zuul-ui/.classpath create mode 100644 spring-zuul/spring-zuul-ui/.project create mode 100644 spring-zuul/spring-zuul-ui/pom.xml create mode 100644 spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/CustomZuulFilter.java create mode 100644 spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiApplication.java create mode 100644 spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiWebConfig.java create mode 100644 spring-zuul/spring-zuul-ui/src/main/resources/application.yml create mode 100755 spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html create mode 100644 spring-zuul/spring-zuul-ui/src/main/webapp/resources/angular-utf8-base64.min.js create mode 100644 spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java create mode 100644 spring-zuul/spring-zuul-ui/src/test/resources/.gitignore create mode 100644 spring-zuul/spring-zuul-ui/src/test/resources/persistence-mysql.properties create mode 100644 spring-zuul/spring-zuul-users-resource/.classpath create mode 100644 spring-zuul/spring-zuul-users-resource/.project create mode 100644 spring-zuul/spring-zuul-users-resource/pom.xml create mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java create mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java create mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java create mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java create mode 100644 spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties diff --git a/spring-zuul/.project b/spring-zuul/.project new file mode 100644 index 0000000000..cc40816960 --- /dev/null +++ b/spring-zuul/.project @@ -0,0 +1,17 @@ + + + spring-zuul + + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + + diff --git a/spring-zuul/pom.xml b/spring-zuul/pom.xml new file mode 100644 index 0000000000..57ad3dfd30 --- /dev/null +++ b/spring-zuul/pom.xml @@ -0,0 +1,102 @@ + + 4.0.0 + org.baeldung + spring-zuul + 1.0.0-SNAPSHOT + + spring-zuul + pom + + + org.springframework.boot + spring-boot-starter-parent + 1.3.1.RELEASE + + + + spring-zuul-foos-resource + spring-zuul-users-resource + spring-zuul-ui + + + + spring-zuul + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + true + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + + + + + + + 4.2.2.RELEASE + 4.0.3.RELEASE + + + + 2.5.1 + + + 1.7.12 + 1.1.3 + + + 18.0 + 3.3.2 + + + 1.3 + 4.11 + 1.10.19 + + 4.4 + 4.4 + + 2.4.0 + + + 3.3 + 2.6 + 2.19 + 1.4.16 + + + + \ No newline at end of file diff --git a/spring-zuul/spring-zuul-foos-resource/.classpath b/spring-zuul/spring-zuul-foos-resource/.classpath new file mode 100644 index 0000000000..0cad5db2d0 --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-zuul/spring-zuul-foos-resource/.project b/spring-zuul/spring-zuul-foos-resource/.project new file mode 100644 index 0000000000..de3fc55423 --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/.project @@ -0,0 +1,48 @@ + + + spring-zuul-foos-resource + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/spring-zuul/spring-zuul-foos-resource/pom.xml b/spring-zuul/spring-zuul-foos-resource/pom.xml new file mode 100644 index 0000000000..6d5e0e52cf --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + spring-zuul-foos-resource + spring-zuul-foos-resource + war + + + org.baeldung + spring-zuul + 1.0.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + + + spring-zuul-foos-resource + + + src/main/resources + true + + + + + \ No newline at end of file diff --git a/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java new file mode 100644 index 0000000000..1e35eff551 --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java @@ -0,0 +1,14 @@ +package org.baeldung.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class ResourceServerApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(ResourceServerApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java new file mode 100644 index 0000000000..c040c8ac42 --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java @@ -0,0 +1,13 @@ +package org.baeldung.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@EnableWebMvc +@ComponentScan({ "org.baeldung.web.controller" }) +public class ResourceServerWebConfig extends WebMvcConfigurerAdapter { + +} diff --git a/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/controller/FooController.java b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/controller/FooController.java new file mode 100644 index 0000000000..486f858ab5 --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/controller/FooController.java @@ -0,0 +1,35 @@ +package org.baeldung.web.controller; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.baeldung.web.dto.Foo; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class FooController { + + public FooController() { + super(); + } + + // API - read + @RequestMapping(method = RequestMethod.GET, value = "/foos/{id}") + @ResponseBody + public Foo findById(@PathVariable final long id, HttpServletRequest req, HttpServletResponse res) { + // System.out.println(req.getHeaderNames()); + // System.out.println("------" + req.getHeader("Test")); + if (req.getHeader("Test") != null) { + res.addHeader("Test", req.getHeader("Test")); + } + return new Foo(Long.parseLong(randomNumeric(2)), randomAlphabetic(4)); + } + +} diff --git a/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/dto/Foo.java b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/dto/Foo.java new file mode 100644 index 0000000000..9d26618e7f --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/src/main/java/org/baeldung/web/dto/Foo.java @@ -0,0 +1,36 @@ +package org.baeldung.web.dto; + +public class Foo { + private long id; + private String name; + + public Foo() { + super(); + } + + public Foo(final long id, final String name) { + super(); + + this.id = id; + this.name = name; + } + + // + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + +} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-foos-resource/src/main/resources/application.properties b/spring-zuul/spring-zuul-foos-resource/src/main/resources/application.properties new file mode 100644 index 0000000000..94c0984ac3 --- /dev/null +++ b/spring-zuul/spring-zuul-foos-resource/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.contextPath=/spring-zuul-foos-resource +server.port=8081 \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/.classpath b/spring-zuul/spring-zuul-ui/.classpath new file mode 100644 index 0000000000..1e75b7bbbb --- /dev/null +++ b/spring-zuul/spring-zuul-ui/.classpath @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-zuul/spring-zuul-ui/.project b/spring-zuul/spring-zuul-ui/.project new file mode 100644 index 0000000000..d87aec6bec --- /dev/null +++ b/spring-zuul/spring-zuul-ui/.project @@ -0,0 +1,48 @@ + + + spring-zuul-ui + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/spring-zuul/spring-zuul-ui/pom.xml b/spring-zuul/spring-zuul-ui/pom.xml new file mode 100644 index 0000000000..65a025f849 --- /dev/null +++ b/spring-zuul/spring-zuul-ui/pom.xml @@ -0,0 +1,91 @@ + + 4.0.0 + spring-zuul-ui + + spring-zuul-ui + war + + + org.baeldung + spring-zuul + 1.0.0-SNAPSHOT + + + + + + + org.springframework.cloud + spring-cloud-starter-zuul + 1.0.4.RELEASE + + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + + org.springframework + spring-test + test + + + + junit + junit + test + + + + org.hamcrest + hamcrest-core + test + + + org.hamcrest + hamcrest-library + test + + + + org.mockito + mockito-core + test + + + + com.jayway.restassured + rest-assured + ${rest-assured.version} + test + + + commons-logging + commons-logging + + + + + + + spring-zuul-ui + + + src/main/resources + true + + + + \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/CustomZuulFilter.java b/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/CustomZuulFilter.java new file mode 100644 index 0000000000..826ac64e9f --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/CustomZuulFilter.java @@ -0,0 +1,33 @@ +package org.baeldung.config; + +import org.springframework.stereotype.Component; + +import com.netflix.zuul.ZuulFilter; +import com.netflix.zuul.context.RequestContext; + +@Component +public class CustomZuulFilter extends ZuulFilter { + + @Override + public Object run() { + final RequestContext ctx = RequestContext.getCurrentContext(); + ctx.addZuulRequestHeader("Test", "TestSample"); + return null; + } + + @Override + public boolean shouldFilter() { + return true; + } + + @Override + public int filterOrder() { + return 1110; + } + + @Override + public String filterType() { + return "pre"; + } + +} diff --git a/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiApplication.java b/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiApplication.java new file mode 100644 index 0000000000..625e5439ee --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiApplication.java @@ -0,0 +1,14 @@ +package org.baeldung.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.netflix.zuul.EnableZuulProxy; + +@EnableZuulProxy +@SpringBootApplication +public class UiApplication { + + public static void main(String[] args) { + SpringApplication.run(UiApplication.class, args); + } +} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiWebConfig.java b/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiWebConfig.java new file mode 100644 index 0000000000..0732182354 --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/main/java/org/baeldung/config/UiWebConfig.java @@ -0,0 +1,39 @@ +package org.baeldung.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; +import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@EnableWebMvc +public class UiWebConfig extends WebMvcConfigurerAdapter { + + @Bean + public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { + return new PropertySourcesPlaceholderConfigurer(); + } + + @Override + public void configureDefaultServletHandling(final DefaultServletHandlerConfigurer configurer) { + configurer.enable(); + } + + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + super.addViewControllers(registry); + registry.addViewController("/").setViewName("forward:/index"); + registry.addViewController("/index"); + registry.addViewController("/login"); + } + + @Override + public void addResourceHandlers(final ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + } + +} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/main/resources/application.yml b/spring-zuul/spring-zuul-ui/src/main/resources/application.yml new file mode 100644 index 0000000000..14660c497b --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/main/resources/application.yml @@ -0,0 +1,9 @@ +zuul: + routes: + foos: + path: /foos/** + url: http://localhost:8081/spring-zuul-foos-resource/foos + users: + path: /users/** + url: http://localhost:8081/spring-zuul-users-resource/users + \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html b/spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html new file mode 100755 index 0000000000..07d2b77f7f --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html @@ -0,0 +1,90 @@ + + + + +Spring Zuul + + + + +
+ + + + + + + +
+
+

Foo Details

+
+ + {{foo.id}} +
+ +
+ + {{foo.name}} +
+ +
+ New Foo +
+

+ +

User Details

+
+ + {{user.id}} +
+ +
+ + {{user.username}} +
+ +
+ + {{user.age}} +
+ +
+ New User +
+ +
+ + \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/main/webapp/resources/angular-utf8-base64.min.js b/spring-zuul/spring-zuul-ui/src/main/webapp/resources/angular-utf8-base64.min.js new file mode 100644 index 0000000000..24af57d020 --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/main/webapp/resources/angular-utf8-base64.min.js @@ -0,0 +1 @@ +"use strict";angular.module("ab-base64",[]).constant("base64",function(){var a={alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",lookup:null,ie:/MSIE /.test(navigator.userAgent),ieo:/MSIE [67]/.test(navigator.userAgent),encode:function(b){var c,d,e,f,g=a.toUtf8(b),h=-1,i=g.length,j=[,,,];if(a.ie){for(c=[];++h>2,j[1]=(3&d)<<4|e>>4,isNaN(e)?j[2]=j[3]=64:(f=g[++h],j[2]=(15&e)<<2|f>>6,j[3]=isNaN(f)?64:63&f),c.push(a.alphabet.charAt(j[0]),a.alphabet.charAt(j[1]),a.alphabet.charAt(j[2]),a.alphabet.charAt(j[3]));return c.join("")}for(c="";++h>2,j[1]=(3&d)<<4|e>>4,isNaN(e)?j[2]=j[3]=64:(f=g[++h],j[2]=(15&e)<<2|f>>6,j[3]=isNaN(f)?64:63&f),c+=a.alphabet[j[0]]+a.alphabet[j[1]]+a.alphabet[j[2]]+a.alphabet[j[3]];return c},decode:function(b){if(b=b.replace(/\s/g,""),b.length%4)throw new Error("InvalidLengthError: decode failed: The string to be decoded is not the correct length for a base64 encoded string.");if(/[^A-Za-z0-9+\/=\s]/g.test(b))throw new Error("InvalidCharacterError: decode failed: The string contains characters invalid in a base64 encoded string.");var c,d=a.fromUtf8(b),e=0,f=d.length;if(a.ieo){for(c=[];f>e;)c.push(d[e]<128?String.fromCharCode(d[e++]):d[e]>191&&d[e]<224?String.fromCharCode((31&d[e++])<<6|63&d[e++]):String.fromCharCode((15&d[e++])<<12|(63&d[e++])<<6|63&d[e++]));return c.join("")}for(c="";f>e;)c+=String.fromCharCode(d[e]<128?d[e++]:d[e]>191&&d[e]<224?(31&d[e++])<<6|63&d[e++]:(15&d[e++])<<12|(63&d[e++])<<6|63&d[e++]);return c},toUtf8:function(a){var b,c=-1,d=a.length,e=[];if(/^[\x00-\x7f]*$/.test(a))for(;++cb?e.push(b):2048>b?e.push(b>>6|192,63&b|128):e.push(b>>12|224,b>>6&63|128,63&b|128);return e},fromUtf8:function(b){var c,d=-1,e=[],f=[,,,];if(!a.lookup){for(c=a.alphabet.length,a.lookup={};++d>4),f[2]=a.lookup[b.charAt(++d)],64!==f[2])&&(e.push((15&f[1])<<4|f[2]>>2),f[3]=a.lookup[b.charAt(++d)],64!==f[3]);)e.push((3&f[2])<<6|f[3]);return e}},b={decode:function(b){b=b.replace(/-/g,"+").replace(/_/g,"/");var c=b.length%4;if(c){if(1===c)throw new Error("InvalidLengthError: Input base64url string is the wrong length to determine padding");b+=new Array(5-c).join("=")}return a.decode(b)},encode:function(b){var c=a.encode(b);return c.replace(/\+/g,"-").replace(/\//g,"_").split("=",1)[0]}};return{decode:a.decode,encode:a.encode,urldecode:b.decode,urlencode:b.encode}}()); \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java b/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java new file mode 100644 index 0000000000..094d3250c7 --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java @@ -0,0 +1,30 @@ +package org.baeldung.web; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.jayway.restassured.RestAssured; +import com.jayway.restassured.response.Response; + +public class LiveTest { + + @Test + public void whenSendRequestToFooResource_thenOK() { + final Response response = RestAssured.get("http://localhost:8080/foos/1"); + assertEquals(200, response.getStatusCode()); + } + + @Test + public void whenSendRequestToUserResource_thenHeaderAdded() { + final Response response = RestAssured.get("http://localhost:8080/users/1"); + assertEquals(200, response.getStatusCode()); + } + + @Test + public void whenSendRequest_thenHeaderAdded() { + final Response response = RestAssured.get("http://localhost:8080/foos/1"); + assertEquals(200, response.getStatusCode()); + assertEquals("TestSample", response.getHeader("Test")); + } +} diff --git a/spring-zuul/spring-zuul-ui/src/test/resources/.gitignore b/spring-zuul/spring-zuul-ui/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/test/resources/persistence-mysql.properties b/spring-zuul/spring-zuul-ui/src/test/resources/persistence-mysql.properties new file mode 100644 index 0000000000..8263b0d9ac --- /dev/null +++ b/spring-zuul/spring-zuul-ui/src/test/resources/persistence-mysql.properties @@ -0,0 +1,10 @@ +# jdbc.X +jdbc.driverClassName=com.mysql.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate4_01?createDatabaseIfNotExist=true +jdbc.user=tutorialuser +jdbc.pass=tutorialmy5ql + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop diff --git a/spring-zuul/spring-zuul-users-resource/.classpath b/spring-zuul/spring-zuul-users-resource/.classpath new file mode 100644 index 0000000000..0cad5db2d0 --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-zuul/spring-zuul-users-resource/.project b/spring-zuul/spring-zuul-users-resource/.project new file mode 100644 index 0000000000..2fedf43db4 --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/.project @@ -0,0 +1,48 @@ + + + spring-zuul-users-resource + + + + + + org.eclipse.wst.jsdt.core.javascriptValidator + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.wst.common.project.facet.core.builder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + org.springframework.ide.eclipse.core.springbuilder + + + + + org.eclipse.wst.validation.validationbuilder + + + + + + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature + org.springframework.ide.eclipse.core.springnature + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature + + diff --git a/spring-zuul/spring-zuul-users-resource/pom.xml b/spring-zuul/spring-zuul-users-resource/pom.xml new file mode 100644 index 0000000000..653c6b9d15 --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + spring-zuul-users-resource + spring-zuul-users-resource + war + + + org.baeldung + spring-zuul + 1.0.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + + + + spring-zuul-users-resource + + + src/main/resources + true + + + + + \ No newline at end of file diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java new file mode 100644 index 0000000000..1e35eff551 --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java @@ -0,0 +1,14 @@ +package org.baeldung.config; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.web.SpringBootServletInitializer; + +@SpringBootApplication +public class ResourceServerApplication extends SpringBootServletInitializer { + + public static void main(String[] args) { + SpringApplication.run(ResourceServerApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java new file mode 100644 index 0000000000..c040c8ac42 --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java @@ -0,0 +1,13 @@ +package org.baeldung.config; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@EnableWebMvc +@ComponentScan({ "org.baeldung.web.controller" }) +public class ResourceServerWebConfig extends WebMvcConfigurerAdapter { + +} diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java new file mode 100644 index 0000000000..b1db89179a --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java @@ -0,0 +1,30 @@ +package org.baeldung.web.controller; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.baeldung.web.dto.User; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class UserController { + + public UserController() { + super(); + } + + // API - read + @RequestMapping(method = RequestMethod.GET, value = "/users/{id}") + @ResponseBody + public User findById(@PathVariable final long id, HttpServletRequest req, HttpServletResponse res) { + return new User(Long.parseLong(randomNumeric(2)), randomAlphabetic(4), Integer.parseInt(randomNumeric(2))); + } + +} diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java new file mode 100644 index 0000000000..f5e4124f93 --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java @@ -0,0 +1,46 @@ +package org.baeldung.web.dto; + +public class User { + private long id; + private String username; + private int age; + + public User() { + super(); + } + + public User(final long id, final String name, int age) { + super(); + + this.id = id; + this.username = name; + this.age = age; + } + + // + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(final String username) { + this.username = username; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + +} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties b/spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties new file mode 100644 index 0000000000..81284546ce --- /dev/null +++ b/spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.contextPath=/spring-zuul-users-resource +server.port=8081 \ No newline at end of file From 89651d72f7275ae61ca2642ebd0278c591925539 Mon Sep 17 00:00:00 2001 From: DOHA Date: Fri, 29 Jan 2016 17:44:11 +0200 Subject: [PATCH 2/2] minor fix --- spring-zuul/pom.xml | 1 - .../spring-zuul-foos-resource/.project | 10 ++-- spring-zuul/spring-zuul-ui/.classpath | 10 ++-- spring-zuul/spring-zuul-ui/.project | 10 ++-- .../src/main/resources/application.yml | 4 -- .../src/main/resources/templates/index.html | 32 ------------- .../test/java/org/baeldung/web/LiveTest.java | 6 --- .../spring-zuul-users-resource/.classpath | 32 ------------- .../spring-zuul-users-resource/.project | 48 ------------------- .../spring-zuul-users-resource/pom.xml | 38 --------------- .../config/ResourceServerApplication.java | 14 ------ .../config/ResourceServerWebConfig.java | 13 ----- .../web/controller/UserController.java | 30 ------------ .../main/java/org/baeldung/web/dto/User.java | 46 ------------------ .../src/main/resources/application.properties | 2 - 15 files changed, 15 insertions(+), 281 deletions(-) delete mode 100644 spring-zuul/spring-zuul-users-resource/.classpath delete mode 100644 spring-zuul/spring-zuul-users-resource/.project delete mode 100644 spring-zuul/spring-zuul-users-resource/pom.xml delete mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java delete mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java delete mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java delete mode 100644 spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java delete mode 100644 spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties diff --git a/spring-zuul/pom.xml b/spring-zuul/pom.xml index 57ad3dfd30..6ad1d0be34 100644 --- a/spring-zuul/pom.xml +++ b/spring-zuul/pom.xml @@ -15,7 +15,6 @@ spring-zuul-foos-resource - spring-zuul-users-resource spring-zuul-ui diff --git a/spring-zuul/spring-zuul-foos-resource/.project b/spring-zuul/spring-zuul-foos-resource/.project index de3fc55423..8d04c873fb 100644 --- a/spring-zuul/spring-zuul-foos-resource/.project +++ b/spring-zuul/spring-zuul-foos-resource/.project @@ -20,11 +20,6 @@ - - org.eclipse.m2e.core.maven2Builder - - - org.springframework.ide.eclipse.core.springbuilder @@ -35,6 +30,11 @@ + + org.eclipse.m2e.core.maven2Builder + + + org.eclipse.jem.workbench.JavaEMFNature diff --git a/spring-zuul/spring-zuul-ui/.classpath b/spring-zuul/spring-zuul-ui/.classpath index 1e75b7bbbb..5c3ac53820 100644 --- a/spring-zuul/spring-zuul-ui/.classpath +++ b/spring-zuul/spring-zuul-ui/.classpath @@ -17,6 +17,11 @@ + + + + + @@ -28,10 +33,5 @@ - - - - - diff --git a/spring-zuul/spring-zuul-ui/.project b/spring-zuul/spring-zuul-ui/.project index d87aec6bec..ec0f2cde81 100644 --- a/spring-zuul/spring-zuul-ui/.project +++ b/spring-zuul/spring-zuul-ui/.project @@ -20,6 +20,11 @@ + + org.eclipse.m2e.core.maven2Builder + + + org.springframework.ide.eclipse.core.springbuilder @@ -30,11 +35,6 @@ - - org.eclipse.m2e.core.maven2Builder - - - org.eclipse.jem.workbench.JavaEMFNature diff --git a/spring-zuul/spring-zuul-ui/src/main/resources/application.yml b/spring-zuul/spring-zuul-ui/src/main/resources/application.yml index 14660c497b..855020a40e 100644 --- a/spring-zuul/spring-zuul-ui/src/main/resources/application.yml +++ b/spring-zuul/spring-zuul-ui/src/main/resources/application.yml @@ -3,7 +3,3 @@ zuul: foos: path: /foos/** url: http://localhost:8081/spring-zuul-foos-resource/foos - users: - path: /users/** - url: http://localhost:8081/spring-zuul-users-resource/users - \ No newline at end of file diff --git a/spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html b/spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html index 07d2b77f7f..d279f9eaf9 100755 --- a/spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html +++ b/spring-zuul/spring-zuul-ui/src/main/resources/templates/index.html @@ -33,17 +33,6 @@ app.controller('mainCtrl', function($scope,$resource,$http) { $scope.foo = $scope.foos.get({fooId:$scope.foo.id}); } - $scope.user = {id:0 , username:"john", age:11}; - $scope.users = $resource("/users/:userId",{userId:'@id'}); - - $scope.getUser = function(){ - $scope.user = $scope.users.get({userId:$scope.user.id}); - } - - - - - }); /*]]>*/ @@ -63,27 +52,6 @@ app.controller('mainCtrl', function($scope,$resource,$http) { -

- -

User Details

-
- - {{user.id}} -
- -
- - {{user.username}} -
- -
- - {{user.age}} -
- -
- New User -
diff --git a/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java b/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java index 094d3250c7..7ced527778 100644 --- a/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java +++ b/spring-zuul/spring-zuul-ui/src/test/java/org/baeldung/web/LiveTest.java @@ -15,12 +15,6 @@ public class LiveTest { assertEquals(200, response.getStatusCode()); } - @Test - public void whenSendRequestToUserResource_thenHeaderAdded() { - final Response response = RestAssured.get("http://localhost:8080/users/1"); - assertEquals(200, response.getStatusCode()); - } - @Test public void whenSendRequest_thenHeaderAdded() { final Response response = RestAssured.get("http://localhost:8080/foos/1"); diff --git a/spring-zuul/spring-zuul-users-resource/.classpath b/spring-zuul/spring-zuul-users-resource/.classpath deleted file mode 100644 index 0cad5db2d0..0000000000 --- a/spring-zuul/spring-zuul-users-resource/.classpath +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-zuul/spring-zuul-users-resource/.project b/spring-zuul/spring-zuul-users-resource/.project deleted file mode 100644 index 2fedf43db4..0000000000 --- a/spring-zuul/spring-zuul-users-resource/.project +++ /dev/null @@ -1,48 +0,0 @@ - - - spring-zuul-users-resource - - - - - - org.eclipse.wst.jsdt.core.javascriptValidator - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - org.springframework.ide.eclipse.core.springbuilder - - - - - org.eclipse.wst.validation.validationbuilder - - - - - - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.springframework.ide.eclipse.core.springnature - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - org.eclipse.wst.common.project.facet.core.nature - org.eclipse.wst.jsdt.core.jsNature - - diff --git a/spring-zuul/spring-zuul-users-resource/pom.xml b/spring-zuul/spring-zuul-users-resource/pom.xml deleted file mode 100644 index 653c6b9d15..0000000000 --- a/spring-zuul/spring-zuul-users-resource/pom.xml +++ /dev/null @@ -1,38 +0,0 @@ - - 4.0.0 - spring-zuul-users-resource - spring-zuul-users-resource - war - - - org.baeldung - spring-zuul - 1.0.0-SNAPSHOT - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - - - - spring-zuul-users-resource - - - src/main/resources - true - - - - - \ No newline at end of file diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java deleted file mode 100644 index 1e35eff551..0000000000 --- a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.baeldung.config; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.web.SpringBootServletInitializer; - -@SpringBootApplication -public class ResourceServerApplication extends SpringBootServletInitializer { - - public static void main(String[] args) { - SpringApplication.run(ResourceServerApplication.class, args); - } - -} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java deleted file mode 100644 index c040c8ac42..0000000000 --- a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/config/ResourceServerWebConfig.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.baeldung.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -@Configuration -@EnableWebMvc -@ComponentScan({ "org.baeldung.web.controller" }) -public class ResourceServerWebConfig extends WebMvcConfigurerAdapter { - -} diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java deleted file mode 100644 index b1db89179a..0000000000 --- a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/controller/UserController.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.baeldung.web.controller; - -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; -import static org.apache.commons.lang3.RandomStringUtils.randomNumeric; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.baeldung.web.dto.User; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class UserController { - - public UserController() { - super(); - } - - // API - read - @RequestMapping(method = RequestMethod.GET, value = "/users/{id}") - @ResponseBody - public User findById(@PathVariable final long id, HttpServletRequest req, HttpServletResponse res) { - return new User(Long.parseLong(randomNumeric(2)), randomAlphabetic(4), Integer.parseInt(randomNumeric(2))); - } - -} diff --git a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java b/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java deleted file mode 100644 index f5e4124f93..0000000000 --- a/spring-zuul/spring-zuul-users-resource/src/main/java/org/baeldung/web/dto/User.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.baeldung.web.dto; - -public class User { - private long id; - private String username; - private int age; - - public User() { - super(); - } - - public User(final long id, final String name, int age) { - super(); - - this.id = id; - this.username = name; - this.age = age; - } - - // - - public long getId() { - return id; - } - - public void setId(final long id) { - this.id = id; - } - - public String getUsername() { - return username; - } - - public void setUsername(final String username) { - this.username = username; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - -} \ No newline at end of file diff --git a/spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties b/spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties deleted file mode 100644 index 81284546ce..0000000000 --- a/spring-zuul/spring-zuul-users-resource/src/main/resources/application.properties +++ /dev/null @@ -1,2 +0,0 @@ -server.contextPath=/spring-zuul-users-resource -server.port=8081 \ No newline at end of file