From 460fcd0b7411c48ec84e0653c91dd0b0377fe0d7 Mon Sep 17 00:00:00 2001 From: Hecheng Li Date: Wed, 29 Aug 2018 19:39:56 +0800 Subject: [PATCH 1/8] Renamed project --- app/pom.xml | 83 +++++++++++++++++++ .../TianMiao/TianMiaoApplicatapp/ion.java | 21 +++++ .../contapp/roller/UserController.java | 61 ++++++++++++++ .../ion/ResourceNotFoundException.java | 30 +++++++ .../java/com/example/TianMiao/model/User.java | 72 ++++++++++++++++ .../repositapp/ory/UserRepository.java | 11 +++ .../main/resources/applicatapp/ion.properties | 12 +++ .../TianMeow/TianMeowApplicationTests.java | 16 ++++ 8 files changed, 306 insertions(+) create mode 100644 app/pom.xml create mode 100644 app/src/main/java/com/example/TianMiao/TianMiaoApplicatapp/ion.java create mode 100644 app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java create mode 100644 app/src/main/java/com/example/TianMiao/exceptapp/ion/ResourceNotFoundException.java create mode 100644 app/src/main/java/com/example/TianMiao/model/User.java create mode 100644 app/src/main/java/com/example/TianMiao/repositapp/ory/UserRepository.java create mode 100644 app/src/main/resources/applicatapp/ion.properties create mode 100644 app/src/tapp/est/java/com/example/TianMeow/TianMeowApplicationTests.java diff --git a/app/pom.xml b/app/pom.xml new file mode 100644 index 0000000..76a0038 --- /dev/null +++ b/app/pom.xml @@ -0,0 +1,83 @@ + + + 4.0.0 + + com.example + TianMiao + 0.0.1-SNAPSHOT + war + + TianMeow + Demo project for Online Shopping + + + org.springframework.boot + spring-boot-starter-parent + 2.0.4.RELEASE + + + + + UTF-8 + UTF-8 + 10 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.springframework.boot + spring-boot-devtools + runtime + + + mysql + mysql-connector-java + runtime + + + org.springframework.boot + spring-boot-starter-test + test + + + javax.xml.bind + jaxb-api + + + javax.servlet + javax.servlet-api + + + + + ${artifactId} + + + + + + + diff --git a/app/src/main/java/com/example/TianMiao/TianMiaoApplicatapp/ion.java b/app/src/main/java/com/example/TianMiao/TianMiaoApplicatapp/ion.java new file mode 100644 index 0000000..ba3dcc9 --- /dev/null +++ b/app/src/main/java/com/example/TianMiao/TianMiaoApplicatapp/ion.java @@ -0,0 +1,21 @@ +package com.example.TianMiao; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; +import org.springframework.data.jpa.repository.config.EnableJpaAuditing; + +@SpringBootApplication +@EnableJpaAuditing +public class TianMiaoApplication extends SpringBootServletInitializer { + + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { + return application.sources(TianMiaoApplication.class); + } + + public static void main(String[] args) { + SpringApplication.run(TianMiaoApplication.class, args); + } +} diff --git a/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java b/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java new file mode 100644 index 0000000..527bb4b --- /dev/null +++ b/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java @@ -0,0 +1,61 @@ +package com.example.TianMiao.controller; + +import java.util.List; + +import javax.validation.Valid; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.example.TianMiao.exception.ResourceNotFoundException; +import com.example.TianMiao.model.User; +import com.example.TianMiao.repository.UserRepository; + +@RestController +@RequestMapping("/api") +public class UserController { + @Autowired + UserRepository userRepository; + + @GetMapping("/users") + public List getAllUsers() { + return userRepository.findAll(); + } + + @PostMapping("/users") + public User createUser(@Valid @RequestBody User user) { + return userRepository.save(user); + } + + @GetMapping("/users/{id}") + public User getUserById(@PathVariable(value = "id") Long userId) { + return userRepository.findById(userId) + .orElseThrow(() -> new ResourceNotFoundException("User", "id", userId)); + } + + @PutMapping("/notes/{id}") + public User updateUser(@PathVariable(value = "id") Long userId, @Valid @RequestBody User userDetails) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new ResourceNotFoundException("User", "id", userId)); + + user.setUsername(userDetails.getUsername()); + User updatedUser = userRepository.save(user); + return updatedUser; + } + + @DeleteMapping("/notes/{id}") + public ResponseEntity deleteUser(@PathVariable(value = "id") Long userId) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new ResourceNotFoundException("User", "id", userId)); + userRepository.delete(user); + return ResponseEntity.ok().build(); + } +} diff --git a/app/src/main/java/com/example/TianMiao/exceptapp/ion/ResourceNotFoundException.java b/app/src/main/java/com/example/TianMiao/exceptapp/ion/ResourceNotFoundException.java new file mode 100644 index 0000000..0d2837d --- /dev/null +++ b/app/src/main/java/com/example/TianMiao/exceptapp/ion/ResourceNotFoundException.java @@ -0,0 +1,30 @@ +package com.example.TianMiao.exception; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(value = HttpStatus.NOT_FOUND) +public class ResourceNotFoundException extends RuntimeException { + private String resourceName; + private String fieldName; + private Object fieldValue; + + public ResourceNotFoundException( String resourceName, String fieldName, Object fieldValue) { + super(String.format("%s not found with %s : '%s'", resourceName, fieldName, fieldValue)); + this.resourceName = resourceName; + this.fieldName = fieldName; + this.fieldValue = fieldValue; + } + + public String getResourceName() { + return resourceName; + } + + public String getFieldName() { + return fieldName; + } + + public Object getFieldValue() { + return fieldValue; + } +} diff --git a/app/src/main/java/com/example/TianMiao/model/User.java b/app/src/main/java/com/example/TianMiao/model/User.java new file mode 100644 index 0000000..24360f1 --- /dev/null +++ b/app/src/main/java/com/example/TianMiao/model/User.java @@ -0,0 +1,72 @@ +package com.example.TianMiao.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.annotation.LastModifiedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; +import javax.persistence.*; +import javax.validation.constraints.NotBlank; + +import java.io.Serializable; +import java.util.Date; + +@Entity +@Table(name = "user") +@EntityListeners(AuditingEntityListener.class) +@JsonIgnoreProperties(value = {"createdAt", "updatedAt"}, allowGetters = true) +public class User implements Serializable { + /** + * + */ + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @NotBlank + private String username; + + @Column(nullable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) + @CreatedDate + private Date createdAt; + + @Column(nullable = false) + @Temporal(TemporalType.TIMESTAMP) + @LastModifiedDate + private Date updatedAt; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public Date getUpdatedAt() { + return updatedAt; + } + + public void setUpdatedAt(Date updatedAt) { + this.updatedAt = updatedAt; + } + +} diff --git a/app/src/main/java/com/example/TianMiao/repositapp/ory/UserRepository.java b/app/src/main/java/com/example/TianMiao/repositapp/ory/UserRepository.java new file mode 100644 index 0000000..cf4385d --- /dev/null +++ b/app/src/main/java/com/example/TianMiao/repositapp/ory/UserRepository.java @@ -0,0 +1,11 @@ +package com.example.TianMiao.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import com.example.TianMiao.model.User; + +@Repository +public interface UserRepository extends JpaRepository { + +} diff --git a/app/src/main/resources/applicatapp/ion.properties b/app/src/main/resources/applicatapp/ion.properties new file mode 100644 index 0000000..52c2f98 --- /dev/null +++ b/app/src/main/resources/applicatapp/ion.properties @@ -0,0 +1,12 @@ +## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties) +spring.datasource.url = jdbc:mysql://mysql/TianMiao?allowPublicKeyRetrieval=true&useSSL=false +spring.datasource.username = root +spring.datasource.password = password + + +## Hibernate Properties +# The SQL dialect makes Hibernate generate better SQL for the chosen database +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect + +# Hibernate ddl auto (create, create-drop, validate, update) +spring.jpa.hibernate.ddl-auto = update \ No newline at end of file diff --git a/app/src/tapp/est/java/com/example/TianMeow/TianMeowApplicationTests.java b/app/src/tapp/est/java/com/example/TianMeow/TianMeowApplicationTests.java new file mode 100644 index 0000000..63faafa --- /dev/null +++ b/app/src/tapp/est/java/com/example/TianMeow/TianMeowApplicationTests.java @@ -0,0 +1,16 @@ +package com.example.TianMeow; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class TianMeowApplicationTests { + + @Test + public void contextLoads() { + } + +} From 1ae0075a5cc77e961cb4e855d779b10f03a22fa4 Mon Sep 17 00:00:00 2001 From: "Hecheng(Chris) Li" Date: Thu, 30 Aug 2018 17:11:26 +0800 Subject: [PATCH 2/8] modified: TianMiao/pom.xml index.html --- app/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/pom.xml b/app/pom.xml index 76a0038..6c4677c 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -8,7 +8,7 @@ 0.0.1-SNAPSHOT war - TianMeow + TianMiao Demo project for Online Shopping From 278ad8d4a55ae86e0e2eb1d98c8e1a44cdcd0acf Mon Sep 17 00:00:00 2001 From: Joe Elliott Date: Wed, 2 Sep 2020 09:13:20 -0400 Subject: [PATCH 3/8] things work Signed-off-by: Joe Elliott --- app/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index 6c4677c..2301056 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -72,10 +72,10 @@ ${artifactId} - + From 348722f75a07e92a6ca8a0dc0ccdd14878e845c7 Mon Sep 17 00:00:00 2001 From: Joe Elliott Date: Wed, 2 Sep 2020 09:44:23 -0400 Subject: [PATCH 4/8] tracing works! Signed-off-by: Joe Elliott --- app/pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/pom.xml b/app/pom.xml index 2301056..45269cd 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -66,6 +66,12 @@ javax.servlet javax.servlet-api + + + + io.opentracing.contrib + opentracing-spring-jaeger-cloud-starter + 3.1.2 From 3ee3f05e6b54898e60a4b580e2302d9d50a92daf Mon Sep 17 00:00:00 2001 From: Joe Elliott Date: Wed, 2 Sep 2020 10:04:18 -0400 Subject: [PATCH 5/8] Added sibling and parent/child traces Signed-off-by: Joe Elliott --- .../contapp/roller/UserController.java | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java b/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java index 527bb4b..640ccff 100644 --- a/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java +++ b/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java @@ -1,6 +1,7 @@ package com.example.TianMiao.controller; import java.util.List; +import java.util.Map; import javax.validation.Valid; @@ -19,6 +20,11 @@ import com.example.TianMiao.model.User; import com.example.TianMiao.repository.UserRepository; +import io.opentracing.Scope; +import io.opentracing.Span; +import io.opentracing.Tracer; +import io.opentracing.util.GlobalTracer; + @RestController @RequestMapping("/api") public class UserController { @@ -27,7 +33,18 @@ public class UserController { @GetMapping("/users") public List getAllUsers() { - return userRepository.findAll(); + List users; + int value = this.SiblingHelperMethod(); + + Tracer tracer = GlobalTracer.get(); + Span span = tracer.buildSpan("parent-child").start(); + try (Scope scope = tracer.scopeManager().activate(span)) { + users = userRepository.findAll(); + } finally { + span.finish(); + } + + return users; } @PostMapping("/users") @@ -58,4 +75,16 @@ public ResponseEntity deleteUser(@PathVariable(value = "id") Long userId) { userRepository.delete(user); return ResponseEntity.ok().build(); } + + private int SiblingHelperMethod() { + Tracer tracer = GlobalTracer.get(); + Span span = tracer.buildSpan("sibling-span").start(); + try (Scope scope = tracer.scopeManager().activate(span)) { + span.setTag("tag", "value"); + } finally { + span.finish(); + } + + return 3; + } } From aefce69bd5c0207d158ae62834aa0b89f379a6db Mon Sep 17 00:00:00 2001 From: Joe Elliott Date: Wed, 20 Jan 2021 10:47:53 -0500 Subject: [PATCH 6/8] got otel working Signed-off-by: Joe Elliott --- app/pom.xml | 32 +++++++++++++++---- .../contapp/roller/UserController.java | 30 +---------------- 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index 45269cd..406d99d 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -67,12 +67,32 @@ javax.servlet javax.servlet-api - - - io.opentracing.contrib - opentracing-spring-jaeger-cloud-starter - 3.1.2 - + + + org.javassist + javassist + 3.25.0-GA + + diff --git a/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java b/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java index 640ccff..12d0f4c 100644 --- a/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java +++ b/app/src/main/java/com/example/TianMiao/contapp/roller/UserController.java @@ -20,11 +20,6 @@ import com.example.TianMiao.model.User; import com.example.TianMiao.repository.UserRepository; -import io.opentracing.Scope; -import io.opentracing.Span; -import io.opentracing.Tracer; -import io.opentracing.util.GlobalTracer; - @RestController @RequestMapping("/api") public class UserController { @@ -33,18 +28,7 @@ public class UserController { @GetMapping("/users") public List getAllUsers() { - List users; - int value = this.SiblingHelperMethod(); - - Tracer tracer = GlobalTracer.get(); - Span span = tracer.buildSpan("parent-child").start(); - try (Scope scope = tracer.scopeManager().activate(span)) { - users = userRepository.findAll(); - } finally { - span.finish(); - } - - return users; + return userRepository.findAll(); } @PostMapping("/users") @@ -75,16 +59,4 @@ public ResponseEntity deleteUser(@PathVariable(value = "id") Long userId) { userRepository.delete(user); return ResponseEntity.ok().build(); } - - private int SiblingHelperMethod() { - Tracer tracer = GlobalTracer.get(); - Span span = tracer.buildSpan("sibling-span").start(); - try (Scope scope = tracer.scopeManager().activate(span)) { - span.setTag("tag", "value"); - } finally { - span.finish(); - } - - return 3; - } } From cd27f37df87418625c625df26112ab448c4375a8 Mon Sep 17 00:00:00 2001 From: Joe Elliott Date: Wed, 20 Jan 2021 16:03:25 -0500 Subject: [PATCH 7/8] trace id logging Signed-off-by: Joe Elliott --- .../Requestapp/LoggingFilterConfig.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 app/src/main/java/com/example/TianMiao/Requestapp/LoggingFilterConfig.java diff --git a/app/src/main/java/com/example/TianMiao/Requestapp/LoggingFilterConfig.java b/app/src/main/java/com/example/TianMiao/Requestapp/LoggingFilterConfig.java new file mode 100644 index 0000000..d07aeb1 --- /dev/null +++ b/app/src/main/java/com/example/TianMiao/Requestapp/LoggingFilterConfig.java @@ -0,0 +1,19 @@ +package com.example.TianMiao; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.filter.CommonsRequestLoggingFilter; + +@Configuration +public class RequestLoggingFilterConfig { + + @Bean + public CommonsRequestLoggingFilter logFilter() { + CommonsRequestLoggingFilter filter + = new CommonsRequestLoggingFilter(); + filter.setIncludeQueryString(true); + filter.setIncludeHeaders(true); + filter.setIncludeClientInfo(true); + return filter; + } +} \ No newline at end of file From 8b778ba0fa2fdb16c4971d54b5c370a0c1d5364a Mon Sep 17 00:00:00 2001 From: Joe Elliott Date: Thu, 21 Jan 2021 17:13:50 -0500 Subject: [PATCH 8/8] cleanup of pom.xml Signed-off-by: Joe Elliott --- app/pom.xml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/app/pom.xml b/app/pom.xml index 406d99d..0ae7679 100644 --- a/app/pom.xml +++ b/app/pom.xml @@ -67,32 +67,11 @@ javax.servlet javax.servlet-api - org.javassist javassist 3.25.0-GA -