Skip to content

Commit ced8c25

Browse files
author
Hitesh
committedSep 26, 2017
Netflx Eureka Server and Netflix Eureka Client
1 parent 3db8fcf commit ced8c25

File tree

24 files changed

+771
-8
lines changed

24 files changed

+771
-8
lines changed
 

‎challengesWeb/.classpath

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
10+
<attributes>
11+
<attribute name="maven.pomderived" value="true"/>
12+
</attributes>
13+
</classpathentry>
14+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
15+
<attributes>
16+
<attribute name="optional" value="true"/>
17+
<attribute name="maven.pomderived" value="true"/>
18+
</attributes>
19+
</classpathentry>
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
26+
<attributes>
27+
<attribute name="maven.pomderived" value="true"/>
28+
</attributes>
29+
</classpathentry>
30+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
31+
<attributes>
32+
<attribute name="maven.pomderived" value="true"/>
33+
</attributes>
34+
</classpathentry>
35+
<classpathentry kind="output" path="target/classes"/>
36+
</classpath>

‎challengesWeb/.project

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>challengesWeb</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.wst.common.project.facet.core.builder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.jdt.core.javabuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
<buildCommand>
19+
<name>org.eclipse.m2e.core.maven2Builder</name>
20+
<arguments>
21+
</arguments>
22+
</buildCommand>
23+
<buildCommand>
24+
<name>org.springframework.ide.eclipse.core.springbuilder</name>
25+
<arguments>
26+
</arguments>
27+
</buildCommand>
28+
</buildSpec>
29+
<natures>
30+
<nature>org.springframework.ide.eclipse.core.springnature</nature>
31+
<nature>org.eclipse.jdt.core.javanature</nature>
32+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
33+
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
34+
</natures>
35+
</projectDescription>

‎challengesWeb/pom.xml

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<artifactId>challengesWeb</artifactId>
7+
<packaging>war</packaging>
8+
9+
<name>Challenges WebApp</name>
10+
<description>Demo project for Spring Boot</description>
11+
12+
13+
<parent>
14+
<groupId>com.hitesh.boot</groupId>
15+
<artifactId>heroes</artifactId>
16+
<version>${project.version}</version>
17+
</parent>
18+
19+
20+
21+
<dependencies>
22+
<!-- <dependency>
23+
<groupId>com.hitesh.boot</groupId>
24+
<artifactId>heroClient</artifactId>
25+
<version>${project.version}</version>
26+
</dependency> -->
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-actuator</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-data-jpa</artifactId>
34+
</dependency>
35+
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-web</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>com.h2database</groupId>
43+
<artifactId>h2</artifactId>
44+
<scope>runtime</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-starter-test</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
<dependency>
52+
<groupId>com.thoughtworks.xstream</groupId>
53+
<artifactId>xstream</artifactId>
54+
<version>1.4.9</version>
55+
</dependency>
56+
<!-- <dependency>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-starter-security</artifactId>
59+
</dependency> -->
60+
<!-- added dependency management section in parent pom to get version information of cloud starter eureka -->
61+
<dependency>
62+
<groupId>org.springframework.cloud</groupId>
63+
<artifactId>spring-cloud-starter-eureka</artifactId>
64+
</dependency>
65+
</dependencies>
66+
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-maven-plugin</artifactId>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
76+
77+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.hitesh.boot.challenges;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.boot.autoconfigure.web.HttpMessageConverters;
6+
import org.springframework.boot.web.support.SpringBootServletInitializer;
7+
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
8+
import org.springframework.context.annotation.Bean;
9+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
10+
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
11+
12+
13+
/**
14+
* @author hitjoshi
15+
*
16+
*/
17+
@SpringBootApplication(scanBasePackages={"com.hitesh.boot.challenges.*"})
18+
@EnableJpaRepositories(basePackages = "com.hitesh.boot.challenges.repositories")
19+
@EnableDiscoveryClient
20+
public class ChallengesApplication extends SpringBootServletInitializer {
21+
22+
public static void main(String[] args) {
23+
System.setProperty("spring.config.name", "challenges-server");
24+
SpringApplication.run(ChallengesApplication.class, args);
25+
}
26+
@Bean
27+
public HttpMessageConverters customConverters() {
28+
ByteArrayHttpMessageConverter arrayHttpMessageConverter = new ByteArrayHttpMessageConverter();
29+
return new HttpMessageConverters(arrayHttpMessageConverter);
30+
}
31+
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/**
2+
*
3+
*/
4+
package com.hitesh.boot.challenges.controller;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import org.springframework.beans.factory.annotation.Autowired;
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+
import org.springframework.web.bind.annotation.RestController;
14+
15+
import com.hitesh.boot.challenges.entity.Challenges;
16+
import com.hitesh.boot.challenges.repositories.ChallengesRepository;
17+
18+
19+
20+
21+
/**
22+
* @author hitjoshi
23+
*
24+
*/
25+
@RestController
26+
@RequestMapping(value="/api")
27+
public class ChallengesController {
28+
29+
@Autowired
30+
private ChallengesRepository challengesRepository;
31+
32+
33+
@RequestMapping(value="/challenges", method= RequestMethod.GET)
34+
public List<Challenges> getAllChallenges(){
35+
List<Challenges> challenges = new ArrayList<Challenges>();
36+
Iterable<Challenges> results = this.challengesRepository.findAll();
37+
results.forEach(challenge-> {challenges.add(challenge);});
38+
return challenges;
39+
}
40+
41+
@RequestMapping(value="/severity", method= RequestMethod.GET)
42+
public Challenges getChallengeBySeverity(@RequestParam(required=false) int challengeLevel){
43+
System.out.println("Challenge level "+challengeLevel);
44+
Challenges challenge = this.challengesRepository.findByChallengeLevel(challengeLevel);
45+
return challenge;
46+
}
47+
48+
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
/**
2+
*
3+
*/
4+
package com.hitesh.boot.challenges.entity;
5+
6+
import java.io.Serializable;
7+
8+
import javax.persistence.Column;
9+
import javax.persistence.Entity;
10+
import javax.persistence.GeneratedValue;
11+
import javax.persistence.GenerationType;
12+
import javax.persistence.Id;
13+
import javax.persistence.Table;
14+
15+
/**
16+
* @author hitjoshi
17+
*
18+
*/
19+
20+
@Entity
21+
@Table(name = "CHALLENGES")
22+
public class Challenges implements Serializable {
23+
24+
/**
25+
*
26+
*/
27+
private static final long serialVersionUID = -2641209952095853668L;
28+
29+
@Id
30+
@Column(name = "CHALLENGES_ID")
31+
@GeneratedValue(strategy = GenerationType.AUTO)
32+
private long challengesId;
33+
34+
@Column(name = "CHALLENGE_NAME")
35+
private String challengeName;
36+
37+
@Column(name = "CHALLENGE_LEVEL")
38+
private int challengeLevel;
39+
40+
@Column(name = "MAX_HEROES")
41+
private int maxNumOfHeroes;
42+
43+
/**
44+
* @return the challengesId
45+
*/
46+
public long getChallengesId() {
47+
return challengesId;
48+
}
49+
50+
/**
51+
* @param challengesId the challengesId to set
52+
*/
53+
public void setChallengesId(long challengesId) {
54+
this.challengesId = challengesId;
55+
}
56+
57+
/**
58+
* @return the challengeName
59+
*/
60+
public String getChallengeName() {
61+
return challengeName;
62+
}
63+
64+
/**
65+
* @param challengeName the challengeName to set
66+
*/
67+
public void setChallengeName(String challengeName) {
68+
this.challengeName = challengeName;
69+
}
70+
71+
/**
72+
* @return the challengeLevel
73+
*/
74+
public int getChallengeLevel() {
75+
return challengeLevel;
76+
}
77+
78+
/**
79+
* @param challengeLevel the challengeLevel to set
80+
*/
81+
public void setChallengeLevel(int challengeLevel) {
82+
this.challengeLevel = challengeLevel;
83+
}
84+
85+
/**
86+
* @return the maxNumOfHeroes
87+
*/
88+
public int getMaxNumOfHeroes() {
89+
return maxNumOfHeroes;
90+
}
91+
92+
/**
93+
* @param maxNumOfHeroes the maxNumOfHeroes to set
94+
*/
95+
public void setMaxNumOfHeroes(int maxNumOfHeroes) {
96+
this.maxNumOfHeroes = maxNumOfHeroes;
97+
}
98+
99+
/* (non-Javadoc)
100+
* @see java.lang.Object#hashCode()
101+
*/
102+
@Override
103+
public int hashCode() {
104+
final int prime = 31;
105+
int result = 1;
106+
result = prime * result + challengeLevel;
107+
result = prime * result + ((challengeName == null) ? 0 : challengeName.hashCode());
108+
result = prime * result + (int)(challengesId ^ (challengesId >>> 32));
109+
result = prime * result + maxNumOfHeroes;
110+
return result;
111+
}
112+
113+
/* (non-Javadoc)
114+
* @see java.lang.Object#equals(java.lang.Object)
115+
*/
116+
@Override
117+
public boolean equals(Object obj) {
118+
if (this == obj)
119+
return true;
120+
if (obj == null)
121+
return false;
122+
if (getClass() != obj.getClass())
123+
return false;
124+
Challenges other = (Challenges)obj;
125+
if (challengeLevel != other.challengeLevel)
126+
return false;
127+
if (challengeName == null) {
128+
if (other.challengeName != null)
129+
return false;
130+
}
131+
else if (!challengeName.equals(other.challengeName))
132+
return false;
133+
if (challengesId != other.challengesId)
134+
return false;
135+
if (maxNumOfHeroes != other.maxNumOfHeroes)
136+
return false;
137+
return true;
138+
}
139+
140+
/* (non-Javadoc)
141+
* @see java.lang.Object#toString()
142+
*/
143+
@Override
144+
public String toString() {
145+
StringBuilder builder = new StringBuilder();
146+
builder.append("Challenges [challengesId=").append(challengesId).append(", challengeName=")
147+
.append(challengeName).append(", challengeLevel=").append(challengeLevel)
148+
.append(", maxNumOfHeroes=").append(maxNumOfHeroes).append("]");
149+
return builder.toString();
150+
}
151+
152+
153+
}
154+
155+
156+

0 commit comments

Comments
 (0)
Please sign in to comment.