75 | if ($env:MVNW_REPOURL) {
76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
78 | }
79 | $distributionUrlName = $distributionUrl -replace '^.*/',''
80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
82 | if ($env:MAVEN_USER_HOME) {
83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
84 | }
85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
87 |
88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
91 | exit $?
92 | }
93 |
94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
96 | }
97 |
98 | # prepare tmp dir
99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
102 | trap {
103 | if ($TMP_DOWNLOAD_DIR.Exists) {
104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
106 | }
107 | }
108 |
109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
110 |
111 | # Download and Install Apache Maven
112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
113 | Write-Verbose "Downloading from: $distributionUrl"
114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
115 |
116 | $webclient = New-Object System.Net.WebClient
117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
119 | }
120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
122 |
123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
125 | if ($distributionSha256Sum) {
126 | if ($USE_MVND) {
127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
128 | }
129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
132 | }
133 | }
134 |
135 | # unzip and move
136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
138 | try {
139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
140 | } catch {
141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
142 | Write-Error "fail to move MAVEN_HOME"
143 | }
144 | } finally {
145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
147 | }
148 |
149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
150 |
--------------------------------------------------------------------------------
/SpringSoapExample/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | org.springframework.boot
8 | spring-boot-starter-parent
9 | 3.3.4
10 |
11 |
12 | com.mcnz.spring.soap
13 | SpringWithSoap
14 | 1.0
15 | SpringWithSoap
16 | Demo project for Spring Boot
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 | 17
32 |
33 |
34 |
35 | org.springframework.boot
36 | spring-boot-starter-web-services
37 |
38 |
39 |
40 | wsdl4j
41 | wsdl4j
42 |
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-devtools
47 | runtime
48 | true
49 |
50 |
51 | org.springframework.boot
52 | spring-boot-starter-test
53 | test
54 |
55 |
56 |
57 |
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-maven-plugin
62 |
63 |
64 |
65 | org.codehaus.mojo
66 | jaxb2-maven-plugin
67 | 3.2.0
68 |
69 |
70 | xjc
71 |
72 | xjc
73 |
74 |
75 |
76 |
77 |
78 | src/main/resources/score.xsd
79 |
80 | src/main/java
81 | false
82 |
83 |
84 |
85 | org.springframework.boot
86 | spring-boot-maven-plugin
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/SpringSoapExample/readme.md:
--------------------------------------------------------------------------------
1 | Enjoy!
2 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/META-INF/JAXB/episode_xjc.xjb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/jee/soap/GetScoreRequest.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the Eclipse Implementation of JAXB, v3.0.2
3 | // See https://eclipse-ee4j.github.io/jaxb-ri
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2024.10.11 at 08:22:49 PM EDT
6 | //
7 |
8 |
9 | package com.mcnz.jee.soap;
10 |
11 | import jakarta.xml.bind.annotation.XmlAccessType;
12 | import jakarta.xml.bind.annotation.XmlAccessorType;
13 | import jakarta.xml.bind.annotation.XmlElement;
14 | import jakarta.xml.bind.annotation.XmlRootElement;
15 | import jakarta.xml.bind.annotation.XmlType;
16 |
17 |
18 | /**
19 | * Java class for anonymous complex type.
20 | *
21 | *
The following schema fragment specifies the expected content contained within this class.
22 | *
23 | *
24 | * <complexType>
25 | * <complexContent>
26 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
27 | * <sequence>
28 | * <element name="user" type="{http://www.w3.org/2001/XMLSchema}string"/>
29 | * </sequence>
30 | * </restriction>
31 | * </complexContent>
32 | * </complexType>
33 | *
34 | *
35 | *
36 | */
37 | @XmlAccessorType(XmlAccessType.FIELD)
38 | @XmlType(name = "", propOrder = {
39 | "user"
40 | })
41 | @XmlRootElement(name = "getScoreRequest")
42 | public class GetScoreRequest {
43 |
44 | @XmlElement(required = true)
45 | protected String user;
46 |
47 | /**
48 | * Gets the value of the user property.
49 | *
50 | * @return
51 | * possible object is
52 | * {@link String }
53 | *
54 | */
55 | public String getUser() {
56 | return user;
57 | }
58 |
59 | /**
60 | * Sets the value of the user property.
61 | *
62 | * @param value
63 | * allowed object is
64 | * {@link String }
65 | *
66 | */
67 | public void setUser(String value) {
68 | this.user = value;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/jee/soap/GetScoreResponse.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the Eclipse Implementation of JAXB, v3.0.2
3 | // See https://eclipse-ee4j.github.io/jaxb-ri
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2024.10.11 at 08:22:49 PM EDT
6 | //
7 |
8 |
9 | package com.mcnz.jee.soap;
10 |
11 | import jakarta.xml.bind.annotation.XmlAccessType;
12 | import jakarta.xml.bind.annotation.XmlAccessorType;
13 | import jakarta.xml.bind.annotation.XmlElement;
14 | import jakarta.xml.bind.annotation.XmlRootElement;
15 | import jakarta.xml.bind.annotation.XmlType;
16 |
17 |
18 | /**
19 | * Java class for anonymous complex type.
20 | *
21 | *
The following schema fragment specifies the expected content contained within this class.
22 | *
23 | *
24 | * <complexType>
25 | * <complexContent>
26 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
27 | * <sequence>
28 | * <element name="score" type="{http://soap.jee.mcnz.com/}score"/>
29 | * </sequence>
30 | * </restriction>
31 | * </complexContent>
32 | * </complexType>
33 | *
34 | *
35 | *
36 | */
37 | @XmlAccessorType(XmlAccessType.FIELD)
38 | @XmlType(name = "", propOrder = {
39 | "score"
40 | })
41 | @XmlRootElement(name = "getScoreResponse")
42 | public class GetScoreResponse {
43 |
44 | @XmlElement(required = true)
45 | protected Score score;
46 |
47 | /**
48 | * Gets the value of the score property.
49 | *
50 | * @return
51 | * possible object is
52 | * {@link Score }
53 | *
54 | */
55 | public Score getScore() {
56 | return score;
57 | }
58 |
59 | /**
60 | * Sets the value of the score property.
61 | *
62 | * @param value
63 | * allowed object is
64 | * {@link Score }
65 | *
66 | */
67 | public void setScore(Score value) {
68 | this.score = value;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/jee/soap/ObjectFactory.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the Eclipse Implementation of JAXB, v3.0.2
3 | // See https://eclipse-ee4j.github.io/jaxb-ri
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2024.10.11 at 08:22:49 PM EDT
6 | //
7 |
8 |
9 | package com.mcnz.jee.soap;
10 |
11 | import jakarta.xml.bind.annotation.XmlRegistry;
12 |
13 |
14 | /**
15 | * This object contains factory methods for each
16 | * Java content interface and Java element interface
17 | * generated in the com.mcnz.jee.soap package.
18 | * An ObjectFactory allows you to programatically
19 | * construct new instances of the Java representation
20 | * for XML content. The Java representation of XML
21 | * content can consist of schema derived interfaces
22 | * and classes representing the binding of schema
23 | * type definitions, element declarations and model
24 | * groups. Factory methods for each of these are
25 | * provided in this class.
26 | *
27 | */
28 | @XmlRegistry
29 | public class ObjectFactory {
30 |
31 |
32 | /**
33 | * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.mcnz.jee.soap
34 | *
35 | */
36 | public ObjectFactory() {
37 | }
38 |
39 | /**
40 | * Create an instance of {@link GetScoreRequest }
41 | *
42 | */
43 | public GetScoreRequest createGetScoreRequest() {
44 | return new GetScoreRequest();
45 | }
46 |
47 | /**
48 | * Create an instance of {@link GetScoreResponse }
49 | *
50 | */
51 | public GetScoreResponse createGetScoreResponse() {
52 | return new GetScoreResponse();
53 | }
54 |
55 | /**
56 | * Create an instance of {@link Score }
57 | *
58 | */
59 | public Score createScore() {
60 | return new Score();
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/jee/soap/Score.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the Eclipse Implementation of JAXB, v3.0.2
3 | // See https://eclipse-ee4j.github.io/jaxb-ri
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2024.10.11 at 08:22:49 PM EDT
6 | //
7 |
8 |
9 | package com.mcnz.jee.soap;
10 |
11 | import jakarta.xml.bind.annotation.XmlAccessType;
12 | import jakarta.xml.bind.annotation.XmlAccessorType;
13 | import jakarta.xml.bind.annotation.XmlElement;
14 | import jakarta.xml.bind.annotation.XmlType;
15 |
16 |
17 | /**
18 | *
Java class for score complex type.
19 | *
20 | *
The following schema fragment specifies the expected content contained within this class.
21 | *
22 | *
23 | * <complexType name="score">
24 | * <complexContent>
25 | * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
26 | * <sequence>
27 | * <element name="user" type="{http://www.w3.org/2001/XMLSchema}string"/>
28 | * <element name="wins" type="{http://www.w3.org/2001/XMLSchema}int"/>
29 | * <element name="losses" type="{http://www.w3.org/2001/XMLSchema}int"/>
30 | * <element name="ties" type="{http://www.w3.org/2001/XMLSchema}int"/>
31 | * </sequence>
32 | * </restriction>
33 | * </complexContent>
34 | * </complexType>
35 | *
36 | *
37 | *
38 | */
39 | @XmlAccessorType(XmlAccessType.FIELD)
40 | @XmlType(name = "score", propOrder = {
41 | "user",
42 | "wins",
43 | "losses",
44 | "ties"
45 | })
46 | public class Score {
47 |
48 | @XmlElement(required = true)
49 | protected String user;
50 | protected int wins;
51 | protected int losses;
52 | protected int ties;
53 |
54 | /**
55 | * Gets the value of the user property.
56 | *
57 | * @return
58 | * possible object is
59 | * {@link String }
60 | *
61 | */
62 | public String getUser() {
63 | return user;
64 | }
65 |
66 | /**
67 | * Sets the value of the user property.
68 | *
69 | * @param value
70 | * allowed object is
71 | * {@link String }
72 | *
73 | */
74 | public void setUser(String value) {
75 | this.user = value;
76 | }
77 |
78 | /**
79 | * Gets the value of the wins property.
80 | *
81 | */
82 | public int getWins() {
83 | return wins;
84 | }
85 |
86 | /**
87 | * Sets the value of the wins property.
88 | *
89 | */
90 | public void setWins(int value) {
91 | this.wins = value;
92 | }
93 |
94 | /**
95 | * Gets the value of the losses property.
96 | *
97 | */
98 | public int getLosses() {
99 | return losses;
100 | }
101 |
102 | /**
103 | * Sets the value of the losses property.
104 | *
105 | */
106 | public void setLosses(int value) {
107 | this.losses = value;
108 | }
109 |
110 | /**
111 | * Gets the value of the ties property.
112 | *
113 | */
114 | public int getTies() {
115 | return ties;
116 | }
117 |
118 | /**
119 | * Sets the value of the ties property.
120 | *
121 | */
122 | public void setTies(int value) {
123 | this.ties = value;
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/jee/soap/package-info.java:
--------------------------------------------------------------------------------
1 | //
2 | // This file was generated by the Eclipse Implementation of JAXB, v3.0.2
3 | // See https://eclipse-ee4j.github.io/jaxb-ri
4 | // Any modifications to this file will be lost upon recompilation of the source schema.
5 | // Generated on: 2024.10.11 at 08:22:49 PM EDT
6 | //
7 |
8 | @jakarta.xml.bind.annotation.XmlSchema(namespace = "http://soap.jee.mcnz.com/", elementFormDefault = jakarta.xml.bind.annotation.XmlNsForm.QUALIFIED)
9 | package com.mcnz.jee.soap;
10 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/spring/soap/ScoreEndpoint.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.spring.soap;
2 |
3 | import org.springframework.ws.server.endpoint.annotation.Endpoint;
4 | import org.springframework.ws.server.endpoint.annotation.PayloadRoot;
5 | import org.springframework.ws.server.endpoint.annotation.RequestPayload;
6 | import org.springframework.ws.server.endpoint.annotation.ResponsePayload;
7 |
8 | import com.mcnz.jee.soap.GetScoreRequest;
9 | import com.mcnz.jee.soap.GetScoreResponse;
10 | import com.mcnz.jee.soap.Score;
11 |
12 | @Endpoint
13 | public class ScoreEndpoint {
14 |
15 | @PayloadRoot(namespace = "http://soap.jee.mcnz.com/", localPart = "getScoreRequest")
16 | @ResponsePayload
17 | public GetScoreResponse getScore(@RequestPayload GetScoreRequest request) {
18 | Score score = new Score();
19 | if (request.getUser().equalsIgnoreCase("Scrumtuous")) {
20 | score.setWins(100);
21 | } else {
22 | score.setWins(99);
23 | score.setLosses(66);
24 | score.setTies(7);
25 | }
26 | GetScoreResponse response = new GetScoreResponse();
27 | response.setScore(score);
28 | return response;
29 | }
30 |
31 | }
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/spring/soap/SpringWithSoapApplication.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.spring.soap;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SpringWithSoapApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SpringWithSoapApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/java/com/mcnz/spring/soap/WebServiceConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.spring.soap;
2 |
3 | import org.springframework.boot.web.servlet.ServletRegistrationBean;
4 | import org.springframework.context.ApplicationContext;
5 | import org.springframework.context.annotation.Bean;
6 | import org.springframework.context.annotation.Configuration;
7 | import org.springframework.core.io.ClassPathResource;
8 | import org.springframework.ws.config.annotation.EnableWs;
9 | import org.springframework.ws.config.annotation.WsConfigurerAdapter;
10 | import org.springframework.ws.transport.http.MessageDispatcherServlet;
11 | import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition;
12 | import org.springframework.xml.xsd.SimpleXsdSchema;
13 | import org.springframework.xml.xsd.XsdSchema;
14 |
15 | @Configuration
16 | @EnableWs
17 | public class WebServiceConfiguration extends WsConfigurerAdapter {
18 |
19 | @Bean
20 | public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
21 | MessageDispatcherServlet servlet = new MessageDispatcherServlet();
22 | servlet.setApplicationContext(applicationContext);
23 | servlet.setTransformWsdlLocations(true);
24 | return new ServletRegistrationBean<>(servlet, "/ws/*");
25 | }
26 |
27 | @Bean
28 | public XsdSchema scoreSchema() {
29 | return new SimpleXsdSchema(new ClassPathResource("score.xsd"));
30 | }
31 |
32 | @Bean(name = "score")
33 | public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema scoreSchema) {
34 | DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
35 | wsdl11Definition.setPortTypeName("ScorePort");
36 | wsdl11Definition.setLocationUri("/ws");
37 | wsdl11Definition.setTargetNamespace("http://soap.jee.mcnz.com/");
38 | wsdl11Definition.setSchema(scoreSchema());
39 | return wsdl11Definition;
40 | }
41 | }
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=SpringWithSoap
2 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/main/resources/score.xsd:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/SpringSoapExample/src/test/java/com/mcnz/spring/soap/SpringWithSoapApplicationTests.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.spring.soap;
2 |
3 | import org.junit.jupiter.api.Test;
4 | import org.springframework.boot.test.context.SpringBootTest;
5 |
6 | @SpringBootTest
7 | class SpringWithSoapApplicationTests {
8 |
9 | @Test
10 | void contextLoads() {
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/WA3104-REL_1_1-LabGuide.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/WA3104-REL_1_1-LabGuide.pdf
--------------------------------------------------------------------------------
/commands.txt:
--------------------------------------------------------------------------------
1 | package com.example.demo;
2 |
3 | import org.springframework.data.repository.CrudRepository;
4 | import org.springframework.stereotype.Repository;
5 |
6 | @Repository
7 | public interface ScoreRepository extends CrudRepository {
8 |
9 |
10 | }
11 | @Component
12 | public class Score {
13 |
14 |
15 | @Id
16 | Long id;
17 | int wins, losses, ties;
18 |
19 | public Score() {
20 | super();
21 | }
22 |
23 |
24 | package com.example.demo;
25 |
26 | import java.util.Scanner;
27 |
28 | import org.springframework.beans.factory.annotation.Autowired;
29 | import org.springframework.boot.CommandLineRunner;
30 | import org.springframework.boot.SpringApplication;
31 | import org.springframework.boot.autoconfigure.SpringBootApplication;
32 |
33 | @SpringBootApplication
34 | public class ConsoleAppApplication implements CommandLineRunner {
35 |
36 | //@Autowired
37 | //Score score;
38 |
39 | @Autowired
40 | ScoreRepository scoreRepo;
41 |
42 | public static void main(String[] args) {
43 | SpringApplication.run(ConsoleAppApplication.class, args);
44 | }
45 |
46 | @Override
47 | public void run(String... args) throws Exception {
48 |
49 | Scanner scanner = new Scanner(System.in);
50 | Score score = scoreRepo.findById(Long.valueOf(1)).get();
51 | String result = "";
52 | String gesture = "";
53 | do {
54 | gesture = scanner.next();
55 | if (gesture.equalsIgnoreCase("rock")) {
56 | score.wins++;
57 | result = "tie";
58 | }
59 | if (gesture.equalsIgnoreCase("paper")) {
60 | score.ties++;
61 | result = "win";
62 | }
63 | if (gesture.equalsIgnoreCase("scissors")) {
64 | score.losses++;
65 | result = "loss";
66 | }
67 | System.out.println("You chose rock. The result is a: " + result);
68 | System.out.println("The score is: " + score);
69 | } while (!gesture.equalsIgnoreCase("q"));
70 | scanner.close();
71 |
72 |
73 | }
74 |
75 | }
76 |
77 |
78 |
79 |
80 | @Operation(summary = "Non-idempotent update the score by a single unit.")
81 |
82 | @Parameter(description = "New value for the number of wins.")
83 |
84 | @ApiResponse(responseCode = "200", description = "Wins updated, score returned.",
85 | content = { @Content(mediaType = "application/json",
86 | schema = @Schema(implementation = Score.class)) })
87 |
88 |
89 | @OpenAPIDefinition(info = @Info(title = "Score API - Definition", version = "1.2", description = "Operations to Help Settle Scores"))
90 |
91 |
92 |
93 | @Id
94 | @NotNull(message = "Id cannot be null")
95 | private Integer id;
96 |
97 | @NotBlank
98 | @PositiveOrZero
99 | @Size(min = 0, max = 20)
100 | int wins, losses, ties;
101 |
102 |
103 | @GetMapping("/search")
104 | public Page searchForScores(@ParameterObject Pageable pageable) {
105 | return null;
106 | }
107 |
108 | @RestControllerAdvice
109 | public class GlobalExceptionHandler {
110 |
111 | @ExceptionHandler(HttpMessageNotReadableException.class)
112 | @ResponseStatus(HttpStatus.I_AM_A_TEAPOT)
113 | public ResponseEntity handleTeapotError(RuntimeException exception) {
114 | return new ResponseEntity<>(exception.getMessage(), HttpStatus.I_AM_A_TEAPOT);
115 | }
116 |
117 | }
118 |
--------------------------------------------------------------------------------
/comprehensive-rps/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 4.0.0
6 |
7 | com.example
8 | demo
9 | 0.0.1-SNAPSHOT
10 | jar
11 |
12 | demo
13 | Demo project for Spring Boot
14 |
15 |
16 | org.springframework.boot
17 | spring-boot-starter-parent
18 | 2.0.2.RELEASE
19 |
20 |
21 |
22 |
23 | UTF-8
24 | UTF-8
25 | 1.8
26 |
27 |
28 |
29 |
30 |
31 | org.apache.tomcat.embed
32 | tomcat-embed-jasper
33 |
34 |
35 |
36 |
37 | org.springframework.boot
38 | spring-boot-starter-data-jpa
39 |
40 |
41 | org.springframework.boot
42 | spring-boot-starter-web
43 |
44 |
45 |
46 | org.springframework.boot
47 | spring-boot-starter-test
48 | test
49 |
50 |
51 | org.apache.derby
52 | derby
53 |
54 |
55 | org.apache.derby
56 | derbyclient
57 | 10.12.1.1
58 |
59 |
60 | org.springframework.boot
61 | spring-boot-configuration-processor
62 | true
63 |
64 |
65 |
66 | org.springframework.boot
67 | spring-boot-starter-thymeleaf
68 |
69 |
70 | org.springframework.boot
71 | spring-boot-devtools
72 | true
73 |
74 |
75 |
76 | org.hibernate
77 | hibernate-entitymanager
78 | 5.2.10.Final
79 | runtime
80 |
81 |
82 |
83 | org.apache.derby
84 | derby
85 |
86 |
87 | org.springframework.boot
88 | spring-boot-configuration-processor
89 | true
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 | org.springframework.boot
99 | spring-boot-maven-plugin
100 |
101 |
102 |
103 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/GameSummary.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.EnumType;
5 | import javax.persistence.Enumerated;
6 | import javax.persistence.GeneratedValue;
7 | import javax.persistence.GenerationType;
8 | import javax.persistence.Id;
9 | import javax.persistence.NamedQuery;
10 | import javax.persistence.Table;
11 |
12 |
13 |
14 | @Entity
15 | @Table(name = "GAMESUMMARY")
16 | @NamedQuery(query = "select gs from GameSummary gs", name = "query_find_all_summaries")
17 | public class GameSummary {
18 |
19 |
20 | @Id
21 | @GeneratedValue(strategy=GenerationType.IDENTITY)
22 | private Long id;
23 | @Enumerated(EnumType.STRING)
24 | Gesture clientGesture;
25 | @Enumerated(EnumType.STRING)
26 | Gesture serverGesture;
27 | String result;
28 | java.util.Date date = new java.util.Date();
29 |
30 | public GameSummary(){}
31 |
32 | public GameSummary(Gesture clientGesture, Gesture serverGesture) {
33 | super();
34 | this.clientGesture = clientGesture;
35 | this.serverGesture = serverGesture;
36 | }
37 |
38 | public Long getId() {
39 | return id;
40 | }
41 | public void setId(Long id) {
42 | this.id = id;
43 | }
44 |
45 | public Gesture getClientGesture() {
46 | return clientGesture;
47 | }
48 | public void setClientGesture(Gesture clientGesture) {
49 | this.clientGesture = clientGesture;
50 | }
51 | public Gesture getServerGesture() {
52 | return serverGesture;
53 | }
54 | public void setServerGesture(Gesture serverGesture) {
55 | this.serverGesture = serverGesture;
56 | }
57 | public String getResult() {
58 | return result;
59 | }
60 | public void setResult(String result) {
61 | this.result = result;
62 | }
63 | public java.util.Date getDate() {
64 | return date;
65 | }
66 | public void setDate(java.util.Date date) {
67 | this.date = date;
68 | }
69 |
70 | }
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/GameSummaryRepository.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import java.util.List;
4 |
5 | import javax.persistence.EntityManager;
6 | import javax.persistence.PersistenceContext;
7 | import javax.persistence.Query;
8 | import javax.transaction.Transactional;
9 |
10 | import org.springframework.stereotype.Repository;
11 |
12 | @Repository
13 | @Transactional
14 | public class GameSummaryRepository {
15 |
16 | @PersistenceContext
17 | private EntityManager entityManager;
18 |
19 | public GameSummary find(long id) {
20 | return entityManager.find(GameSummary.class, id);
21 | }
22 |
23 | public List findAll() {
24 | Query query = entityManager.createNamedQuery("query_find_all_summaries", GameSummary.class);
25 | return query.getResultList();
26 | }
27 |
28 | public long insert(GameSummary gs) {
29 | entityManager.persist(gs);
30 | ;
31 | return gs.getId();
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/GameSummaryService.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RestController;
8 |
9 | @RestController
10 | public class GameSummaryService {
11 |
12 | @Autowired
13 | private GameSummaryRepository gameSummaryRepository;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/Gesture.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | public enum Gesture {
4 |
5 | ROCK, PAPER, SCISSORS;
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/RoshamboApplication.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5 | import org.springframework.boot.autoconfigure.SpringBootApplication;
6 | import org.springframework.boot.web.client.RestTemplateBuilder;
7 | import org.springframework.context.annotation.Bean;
8 | import org.springframework.context.annotation.ComponentScan;
9 | import org.springframework.web.client.RestTemplate;
10 | import org.springframework.web.servlet.config.annotation.EnableWebMvc;
11 |
12 | @ComponentScan
13 | @EnableWebMvc
14 | @EnableAutoConfiguration
15 | @SpringBootApplication
16 | public class RoshamboApplication {
17 |
18 |
19 |
20 | public static void main(String[] args) {
21 | SpringApplication.run(RoshamboApplication.class, args);
22 | }
23 |
24 | @Bean
25 | public RestTemplate restTemplate(RestTemplateBuilder builder) {
26 | return builder.build();
27 | }
28 |
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/Score.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import javax.persistence.Entity;
4 | import javax.persistence.GeneratedValue;
5 | import javax.persistence.GenerationType;
6 | import javax.persistence.Id;
7 | import javax.persistence.NamedQuery;
8 | import javax.persistence.Table;
9 |
10 | @Entity
11 | @Table(name = "Score")
12 | @NamedQuery(query = "select s from Score s", name = "query_find_all_scores")
13 | public class Score {
14 |
15 | @Id
16 | @GeneratedValue(strategy=GenerationType.IDENTITY)
17 | long id;
18 |
19 | public long getId() {
20 | return id;
21 | }
22 | public void setId(long id) {
23 | this.id = id;
24 | }
25 | private int wins, losses, ties;
26 |
27 | public void increaseWins(){
28 | System.out.println("Increasing wins in the bean");;
29 | wins++;
30 | }
31 | public void increaseLosses(){
32 | losses++;
33 | }
34 | public void increaseTies(){
35 | ties++;
36 | }
37 |
38 | public String toString(){
39 | String output = "Wins: " + wins + " Ties: " + ties + " Losses: " + losses;
40 | return output;
41 | }
42 |
43 | public int getWins() {return wins;}
44 | public int getLosses() {return losses;}
45 | public int getTies() {return ties;}
46 |
47 | }
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/ScoreRepository.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import java.util.List;
4 |
5 | import javax.persistence.EntityManager;
6 | import javax.persistence.PersistenceContext;
7 | import javax.persistence.Query;
8 | import javax.transaction.Transactional;
9 |
10 | import org.springframework.stereotype.Repository;
11 |
12 | @Repository
13 | @Transactional
14 | public class ScoreRepository {
15 |
16 | @PersistenceContext
17 | private EntityManager entityManager;
18 |
19 | public Score find(long id) {
20 | return entityManager.find(Score.class, id);
21 | }
22 |
23 | public List findAll() {
24 | Query query = entityManager.createNamedQuery("query_find_all_scores", Score.class);
25 | return query.getResultList();
26 | }
27 |
28 | public long save(Score score) {
29 | entityManager.persist(score);
30 | System.out.println("Persisted score: " + score.getId() + " wins " + score.getWins() +" ties " + score.getTies());
31 | return score.getId();
32 | }
33 |
34 | public Score findScore() {
35 | Score score=null;
36 | Query query = entityManager.createNamedQuery("query_find_all_scores", Score.class);
37 | List scores = query.getResultList();
38 | System.out.println("Number of scores: " + scores.size());
39 | if (scores.size()>0) {
40 | //score = (Score)scores.get(0);
41 | score = entityManager.find(Score.class, new Long(1));
42 | } else {
43 | score = new Score();
44 | entityManager.persist(score);
45 | System.out.println("New score created with id of: " + score.getId());
46 | }
47 |
48 | return score;
49 |
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/ScoreService.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import java.util.List;
4 |
5 | import org.springframework.beans.factory.annotation.Autowired;
6 | import org.springframework.web.bind.annotation.RequestMapping;
7 | import org.springframework.web.bind.annotation.RequestMethod;
8 | import org.springframework.web.bind.annotation.RestController;
9 |
10 | @RestController
11 | public class ScoreService {
12 |
13 |
14 | @Autowired
15 | private ScoreRepository scoreRepository;
16 |
17 | @RequestMapping(value = "/score", method=RequestMethod.GET)
18 | public Score getScore() {
19 | System.out.println("Finding Score");
20 | return scoreRepository.findScore();
21 | }
22 |
23 | @RequestMapping(value = "/score/wins", method=RequestMethod.GET)
24 | public int getWins() {
25 | Score score = scoreRepository.findScore();
26 | return score.getWins();
27 | }
28 |
29 | @RequestMapping(value = "/score/losses", method=RequestMethod.GET)
30 | public int getLosses() {
31 | Score score = scoreRepository.findScore();
32 | return score.getLosses();
33 | }
34 |
35 | @RequestMapping(value = "/score/ties", method=RequestMethod.GET)
36 | public int getTies() {
37 | Score score = scoreRepository.findScore();
38 | return score.getTies();
39 | }
40 |
41 | @RequestMapping(value = "/score/wins", method=RequestMethod.POST)
42 | public boolean increaseWins() {
43 | System.out.println("POST wins");
44 | Score score = scoreRepository.findScore();
45 | score.increaseWins();
46 | System.out.println(score.getId());;
47 | scoreRepository.save(score);
48 | return true;
49 | }
50 |
51 | @RequestMapping(value = "/score/losses", method=RequestMethod.POST)
52 | public boolean increaseLosses() {
53 | System.out.println("POST losses");
54 | Score score = scoreRepository.findScore();
55 | score.increaseLosses();
56 | System.out.println(score.getId());;
57 | scoreRepository.save(score);
58 | return true;
59 | }
60 |
61 | @RequestMapping(value = "/score/ties", method=RequestMethod.POST)
62 | public boolean increaseTies() {
63 | System.out.println("POST ties");
64 | Score score = scoreRepository.findScore();
65 | score.increaseTies();
66 | System.out.println(score.getId());;
67 | scoreRepository.save(score);
68 | return true;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/java/com/mcnz/rps/spring/WebController.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps.spring;
2 |
3 | import org.springframework.stereotype.Controller;
4 | import org.springframework.ui.Model;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.RequestParam;
7 | import org.springframework.web.client.RestTemplate;
8 |
9 | @Controller
10 | public class WebController {
11 |
12 | @GetMapping("/playagame")
13 | public String playRoshambo(@RequestParam(name = "choice", required=false) String choice, Model model) {
14 | System.out.println("In play");
15 | if (choice == null) {
16 | return "index";
17 | }
18 | System.out.println("Choice: " + choice);
19 |
20 | GameSummary gameSummary = new GameSummary();
21 | gameSummary.clientGesture = Gesture.valueOf(choice.toUpperCase());
22 | gameSummary.serverGesture = Gesture.ROCK;
23 |
24 | String result = "tie";
25 | if (gameSummary.clientGesture.equals(Gesture.PAPER)) {
26 | result = "win";
27 | RestTemplate restTemplate = new RestTemplate();
28 | restTemplate.postForObject("http://localhost:8080/score/wins", "", Object.class);
29 | }
30 | if (gameSummary.clientGesture.equals(Gesture.SCISSORS)) {
31 | result = "lose";
32 | RestTemplate restTemplate = new RestTemplate();
33 | restTemplate.postForObject("http://localhost:8080/score/losses", "", Object.class);
34 | }
35 | if (result == "tie") {
36 | RestTemplate restTemplate = new RestTemplate();
37 | restTemplate.postForObject("http://localhost:8080/score/ties", "", Object.class);
38 | }
39 | gameSummary.setResult(result);
40 |
41 | RestTemplate restTemplate = new RestTemplate();
42 | Score score = restTemplate.getForObject("http://localhost:8080/score", Score.class);
43 |
44 | model.addAttribute("gameSummary", gameSummary);
45 | model.addAttribute("score", score);
46 | // request.getRequestDispatcher("index.jsp").forward(request, response);
47 |
48 | return "results";
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/resources/META-INF/xxxpersistence.xmlxxx:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 | org.hibernate.ejb.HibernatePersistence
9 |
10 | com.mcnz.rps.GameSummary
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.datasource.url=jdbc:derby://localhost:1527/OEDB
2 | spring.datasource.driver-class-name=org.apache.derby.jdbc.ClientDriver
3 | spring.datasource.username=rps
4 | spring.datasource.jdbc-url=jdbc:derby://localhost:1527/OEDB
5 | app.datasource.jdbc-url=jdbc:derby://localhost:1527/OEDB
6 | spring.thymeleaf.enabled=true
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/resources/templates/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Roshambo!
4 |
5 |
6 |
7 | Which one will it be?
8 |
9 | rock
10 | paper
11 | scissors
12 |
13 |
14 |
--------------------------------------------------------------------------------
/comprehensive-rps/src/main/resources/templates/results.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Getting Started: Serving Web Content
5 |
6 |
7 |
8 |
9 | rock
10 | paper
11 | scissors
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/labs/Lab 06 - Utilizing Runners, Arguments, and Environment.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Lab 06 - Utilizing Runners, Arguments, and Environment.zip
--------------------------------------------------------------------------------
/labs/Lab 07 - Using Multiple ViewResolver.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Lab 07 - Using Multiple ViewResolver.zip
--------------------------------------------------------------------------------
/labs/Lab 08 - Implementing Spring Data REST.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Lab 08 - Implementing Spring Data REST.zip
--------------------------------------------------------------------------------
/labs/Lab 09 - Implementing OAuth2 using Spring Boot.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Lab 09 - Implementing OAuth2 using Spring Boot.zip
--------------------------------------------------------------------------------
/labs/Lab 11 - Authentication with JWT.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Lab 11 - Authentication with JWT.zip
--------------------------------------------------------------------------------
/labs/Lab 12 - Spring Boot Actuator.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Lab 12 - Spring Boot Actuator.zip
--------------------------------------------------------------------------------
/labs/LabGuide-Protected.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/LabGuide-Protected.pdf
--------------------------------------------------------------------------------
/labs/Restaurant-Microservice.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Restaurant-Microservice.zip
--------------------------------------------------------------------------------
/labs/Spring-Boot-AMQP-Starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Spring-Boot-AMQP-Starter.zip
--------------------------------------------------------------------------------
/labs/Spring-Boot-Basic-Security-Starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Spring-Boot-Basic-Security-Starter.zip
--------------------------------------------------------------------------------
/labs/Spring-Boot-JDBC-Starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Spring-Boot-JDBC-Starter.zip
--------------------------------------------------------------------------------
/labs/Spring-Boot-MVC-Starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Spring-Boot-MVC-Starter.zip
--------------------------------------------------------------------------------
/labs/Spring-Boot-REST-Client-Starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Spring-Boot-REST-Client-Starter.zip
--------------------------------------------------------------------------------
/labs/Spring-Boot-REST-Starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/Spring-Boot-REST-Starter.zip
--------------------------------------------------------------------------------
/labs/WA3104-REL_1_1-LabGuide.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/WA3104-REL_1_1-LabGuide.pdf
--------------------------------------------------------------------------------
/labs/files.txt:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/labs/labs 1-5.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/labs 1-5.zip
--------------------------------------------------------------------------------
/labs/spring-controllers-starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/spring-controllers-starter.zip
--------------------------------------------------------------------------------
/labs/spring-data-rest-starter.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cameronmcnz/spring-boot-examples/5d48cc368965539c57acc89e967e4ae413e2895c/labs/spring-data-rest-starter.zip
--------------------------------------------------------------------------------
/settling-scores/.gitignore:
--------------------------------------------------------------------------------
1 | HELP.md
2 | target/
3 | !.mvn/wrapper/maven-wrapper.jar
4 | !**/src/main/**/target/
5 | !**/src/test/**/target/
6 |
7 | ### STS ###
8 | .apt_generated
9 | .classpath
10 | .factorypath
11 | .project
12 | .settings
13 | .springBeans
14 | .sts4-cache
15 |
16 | ### IntelliJ IDEA ###
17 | .idea
18 | *.iws
19 | *.iml
20 | *.ipr
21 |
22 | ### NetBeans ###
23 | /nbproject/private/
24 | /nbbuild/
25 | /dist/
26 | /nbdist/
27 | /.nb-gradle/
28 | build/
29 | !**/src/main/**/build/
30 | !**/src/test/**/build/
31 |
32 | ### VS Code ###
33 | .vscode/
34 |
--------------------------------------------------------------------------------
/settling-scores/.mvn/wrapper/maven-wrapper.properties:
--------------------------------------------------------------------------------
1 | # Licensed to the Apache Software Foundation (ASF) under one
2 | # or more contributor license agreements. See the NOTICE file
3 | # distributed with this work for additional information
4 | # regarding copyright ownership. The ASF licenses this file
5 | # to you under the Apache License, Version 2.0 (the
6 | # "License"); you may not use this file except in compliance
7 | # with the License. You may obtain a copy of the License at
8 | #
9 | # https://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing,
12 | # software distributed under the License is distributed on an
13 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 | # KIND, either express or implied. See the License for the
15 | # specific language governing permissions and limitations
16 | # under the License.
17 | wrapperVersion=3.3.2
18 | distributionType=only-script
19 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.7/apache-maven-3.9.7-bin.zip
20 |
--------------------------------------------------------------------------------
/settling-scores/mvnw.cmd:
--------------------------------------------------------------------------------
1 | <# : batch portion
2 | @REM ----------------------------------------------------------------------------
3 | @REM Licensed to the Apache Software Foundation (ASF) under one
4 | @REM or more contributor license agreements. See the NOTICE file
5 | @REM distributed with this work for additional information
6 | @REM regarding copyright ownership. The ASF licenses this file
7 | @REM to you under the Apache License, Version 2.0 (the
8 | @REM "License"); you may not use this file except in compliance
9 | @REM with the License. You may obtain a copy of the License at
10 | @REM
11 | @REM https://www.apache.org/licenses/LICENSE-2.0
12 | @REM
13 | @REM Unless required by applicable law or agreed to in writing,
14 | @REM software distributed under the License is distributed on an
15 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | @REM KIND, either express or implied. See the License for the
17 | @REM specific language governing permissions and limitations
18 | @REM under the License.
19 | @REM ----------------------------------------------------------------------------
20 |
21 | @REM ----------------------------------------------------------------------------
22 | @REM Apache Maven Wrapper startup batch script, version 3.3.2
23 | @REM
24 | @REM Optional ENV vars
25 | @REM MVNW_REPOURL - repo url base for downloading maven distribution
26 | @REM MVNW_USERNAME/MVNW_PASSWORD - user and password for downloading maven
27 | @REM MVNW_VERBOSE - true: enable verbose log; others: silence the output
28 | @REM ----------------------------------------------------------------------------
29 |
30 | @IF "%__MVNW_ARG0_NAME__%"=="" (SET __MVNW_ARG0_NAME__=%~nx0)
31 | @SET __MVNW_CMD__=
32 | @SET __MVNW_ERROR__=
33 | @SET __MVNW_PSMODULEP_SAVE=%PSModulePath%
34 | @SET PSModulePath=
35 | @FOR /F "usebackq tokens=1* delims==" %%A IN (`powershell -noprofile "& {$scriptDir='%~dp0'; $script='%__MVNW_ARG0_NAME__%'; icm -ScriptBlock ([Scriptblock]::Create((Get-Content -Raw '%~f0'))) -NoNewScope}"`) DO @(
36 | IF "%%A"=="MVN_CMD" (set __MVNW_CMD__=%%B) ELSE IF "%%B"=="" (echo %%A) ELSE (echo %%A=%%B)
37 | )
38 | @SET PSModulePath=%__MVNW_PSMODULEP_SAVE%
39 | @SET __MVNW_PSMODULEP_SAVE=
40 | @SET __MVNW_ARG0_NAME__=
41 | @SET MVNW_USERNAME=
42 | @SET MVNW_PASSWORD=
43 | @IF NOT "%__MVNW_CMD__%"=="" (%__MVNW_CMD__% %*)
44 | @echo Cannot start maven from wrapper >&2 && exit /b 1
45 | @GOTO :EOF
46 | : end batch / begin powershell #>
47 |
48 | $ErrorActionPreference = "Stop"
49 | if ($env:MVNW_VERBOSE -eq "true") {
50 | $VerbosePreference = "Continue"
51 | }
52 |
53 | # calculate distributionUrl, requires .mvn/wrapper/maven-wrapper.properties
54 | $distributionUrl = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionUrl
55 | if (!$distributionUrl) {
56 | Write-Error "cannot read distributionUrl property in $scriptDir/.mvn/wrapper/maven-wrapper.properties"
57 | }
58 |
59 | switch -wildcard -casesensitive ( $($distributionUrl -replace '^.*/','') ) {
60 | "maven-mvnd-*" {
61 | $USE_MVND = $true
62 | $distributionUrl = $distributionUrl -replace '-bin\.[^.]*$',"-windows-amd64.zip"
63 | $MVN_CMD = "mvnd.cmd"
64 | break
65 | }
66 | default {
67 | $USE_MVND = $false
68 | $MVN_CMD = $script -replace '^mvnw','mvn'
69 | break
70 | }
71 | }
72 |
73 | # apply MVNW_REPOURL and calculate MAVEN_HOME
74 | # maven home pattern: ~/.m2/wrapper/dists/{apache-maven-,maven-mvnd--}/
75 | if ($env:MVNW_REPOURL) {
76 | $MVNW_REPO_PATTERN = if ($USE_MVND) { "/org/apache/maven/" } else { "/maven/mvnd/" }
77 | $distributionUrl = "$env:MVNW_REPOURL$MVNW_REPO_PATTERN$($distributionUrl -replace '^.*'+$MVNW_REPO_PATTERN,'')"
78 | }
79 | $distributionUrlName = $distributionUrl -replace '^.*/',''
80 | $distributionUrlNameMain = $distributionUrlName -replace '\.[^.]*$','' -replace '-bin$',''
81 | $MAVEN_HOME_PARENT = "$HOME/.m2/wrapper/dists/$distributionUrlNameMain"
82 | if ($env:MAVEN_USER_HOME) {
83 | $MAVEN_HOME_PARENT = "$env:MAVEN_USER_HOME/wrapper/dists/$distributionUrlNameMain"
84 | }
85 | $MAVEN_HOME_NAME = ([System.Security.Cryptography.MD5]::Create().ComputeHash([byte[]][char[]]$distributionUrl) | ForEach-Object {$_.ToString("x2")}) -join ''
86 | $MAVEN_HOME = "$MAVEN_HOME_PARENT/$MAVEN_HOME_NAME"
87 |
88 | if (Test-Path -Path "$MAVEN_HOME" -PathType Container) {
89 | Write-Verbose "found existing MAVEN_HOME at $MAVEN_HOME"
90 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
91 | exit $?
92 | }
93 |
94 | if (! $distributionUrlNameMain -or ($distributionUrlName -eq $distributionUrlNameMain)) {
95 | Write-Error "distributionUrl is not valid, must end with *-bin.zip, but found $distributionUrl"
96 | }
97 |
98 | # prepare tmp dir
99 | $TMP_DOWNLOAD_DIR_HOLDER = New-TemporaryFile
100 | $TMP_DOWNLOAD_DIR = New-Item -Itemtype Directory -Path "$TMP_DOWNLOAD_DIR_HOLDER.dir"
101 | $TMP_DOWNLOAD_DIR_HOLDER.Delete() | Out-Null
102 | trap {
103 | if ($TMP_DOWNLOAD_DIR.Exists) {
104 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
105 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
106 | }
107 | }
108 |
109 | New-Item -Itemtype Directory -Path "$MAVEN_HOME_PARENT" -Force | Out-Null
110 |
111 | # Download and Install Apache Maven
112 | Write-Verbose "Couldn't find MAVEN_HOME, downloading and installing it ..."
113 | Write-Verbose "Downloading from: $distributionUrl"
114 | Write-Verbose "Downloading to: $TMP_DOWNLOAD_DIR/$distributionUrlName"
115 |
116 | $webclient = New-Object System.Net.WebClient
117 | if ($env:MVNW_USERNAME -and $env:MVNW_PASSWORD) {
118 | $webclient.Credentials = New-Object System.Net.NetworkCredential($env:MVNW_USERNAME, $env:MVNW_PASSWORD)
119 | }
120 | [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
121 | $webclient.DownloadFile($distributionUrl, "$TMP_DOWNLOAD_DIR/$distributionUrlName") | Out-Null
122 |
123 | # If specified, validate the SHA-256 sum of the Maven distribution zip file
124 | $distributionSha256Sum = (Get-Content -Raw "$scriptDir/.mvn/wrapper/maven-wrapper.properties" | ConvertFrom-StringData).distributionSha256Sum
125 | if ($distributionSha256Sum) {
126 | if ($USE_MVND) {
127 | Write-Error "Checksum validation is not supported for maven-mvnd. `nPlease disable validation by removing 'distributionSha256Sum' from your maven-wrapper.properties."
128 | }
129 | Import-Module $PSHOME\Modules\Microsoft.PowerShell.Utility -Function Get-FileHash
130 | if ((Get-FileHash "$TMP_DOWNLOAD_DIR/$distributionUrlName" -Algorithm SHA256).Hash.ToLower() -ne $distributionSha256Sum) {
131 | Write-Error "Error: Failed to validate Maven distribution SHA-256, your Maven distribution might be compromised. If you updated your Maven version, you need to update the specified distributionSha256Sum property."
132 | }
133 | }
134 |
135 | # unzip and move
136 | Expand-Archive "$TMP_DOWNLOAD_DIR/$distributionUrlName" -DestinationPath "$TMP_DOWNLOAD_DIR" | Out-Null
137 | Rename-Item -Path "$TMP_DOWNLOAD_DIR/$distributionUrlNameMain" -NewName $MAVEN_HOME_NAME | Out-Null
138 | try {
139 | Move-Item -Path "$TMP_DOWNLOAD_DIR/$MAVEN_HOME_NAME" -Destination $MAVEN_HOME_PARENT | Out-Null
140 | } catch {
141 | if (! (Test-Path -Path "$MAVEN_HOME" -PathType Container)) {
142 | Write-Error "fail to move MAVEN_HOME"
143 | }
144 | } finally {
145 | try { Remove-Item $TMP_DOWNLOAD_DIR -Recurse -Force | Out-Null }
146 | catch { Write-Warning "Cannot remove $TMP_DOWNLOAD_DIR" }
147 | }
148 |
149 | Write-Output "MVN_CMD=$MAVEN_HOME/bin/$MVN_CMD"
150 |
--------------------------------------------------------------------------------
/settling-scores/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 | org.springframework.boot
7 | spring-boot-starter-parent
8 | 3.3.1
9 |
10 |
11 | com.mcnz.rps
12 | settling-scores
13 | 0.0.1-SNAPSHOT
14 | settling-scores
15 | Demo project for Spring Boot and RESTful APIs
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | 17
31 |
32 |
33 |
34 | org.springframework.boot
35 | spring-boot-starter-web
36 |
37 |
38 |
39 | org.springframework.boot
40 | spring-boot-devtools
41 | runtime
42 | true
43 |
44 |
45 | org.springframework.boot
46 | spring-boot-starter-test
47 | test
48 |
49 |
50 |
51 |
52 |
53 |
54 | org.springframework.boot
55 | spring-boot-maven-plugin
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/settling-scores/src/main/java/com/mcnz/rps/Score.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps;
2 |
3 | public class Score {
4 |
5 | int wins;
6 | int losses;
7 | int ties;
8 |
9 |
10 | public Score() {}
11 |
12 | public Score(int wins, int losses, int ties) {
13 | super();
14 | this.wins = wins;
15 | this.losses = losses;
16 | this.ties = ties;
17 | }
18 |
19 | public int getWins() {
20 | return wins;
21 | }
22 | public void setWins(int wins) {
23 | this.wins = wins;
24 | }
25 | public int getLosses() {
26 | return losses;
27 | }
28 | public void setLosses(int losses) {
29 | this.losses = losses;
30 | }
31 | public int getTies() {
32 | return ties;
33 | }
34 | public void setTies(int ties) {
35 | this.ties = ties;
36 | }
37 |
38 |
39 |
40 | }
41 |
--------------------------------------------------------------------------------
/settling-scores/src/main/java/com/mcnz/rps/ScoreController.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps;
2 |
3 | import org.springframework.web.bind.annotation.CrossOrigin;
4 | import org.springframework.web.bind.annotation.DeleteMapping;
5 | import org.springframework.web.bind.annotation.GetMapping;
6 | import org.springframework.web.bind.annotation.PatchMapping;
7 | import org.springframework.web.bind.annotation.PathVariable;
8 | import org.springframework.web.bind.annotation.PostMapping;
9 | import org.springframework.web.bind.annotation.PutMapping;
10 | import org.springframework.web.bind.annotation.RequestBody;
11 | import org.springframework.web.bind.annotation.RequestParam;
12 | import org.springframework.web.bind.annotation.RestController;
13 |
14 | @CrossOrigin
15 | @RestController
16 | public class ScoreController {
17 |
18 | static Score score = new Score(30, 20, 10);
19 |
20 | @PatchMapping("/score/wins")
21 | public Score setWins(@RequestParam(name="new-value") int newValue) {
22 | score.wins = newValue;
23 | return score;
24 | }
25 |
26 | @GetMapping("/score/health-check")
27 | public String healthCheck() {
28 | return "Situation normal everything fine";
29 | }
30 |
31 | @GetMapping("/score")
32 | public Score getScore() {
33 | if (score == null) {
34 | score = new Score();
35 | }
36 | return score;
37 | }
38 |
39 | @PostMapping("/score/wins")
40 | public Score increaseWins() {
41 | score.wins++;
42 | return score;
43 | }
44 |
45 | @PostMapping("/score/losses")
46 | public Score increaseLosses() {
47 | score.losses++;
48 | return score;
49 | }
50 |
51 | @PostMapping("/score/ties")
52 | public Score increaseTies() {
53 | score.ties++;
54 | return score;
55 | }
56 |
57 | @PutMapping("/score")
58 | public Score setScore(@RequestBody Score newScore) {
59 | score = newScore;
60 | return score;
61 | }
62 |
63 |
64 | @DeleteMapping("/score")
65 | public void deleteScore() {
66 | score = null;
67 | }
68 |
69 | @GetMapping("/score/{winsLossesOrTies}")
70 | public int getWinsLossesOrTies(@PathVariable String winsLossesOrTies) {
71 | int valueToReturn;
72 | if (winsLossesOrTies.equalsIgnoreCase("wins")) {
73 | valueToReturn = score.wins;
74 | } else if (winsLossesOrTies.equalsIgnoreCase("losses")){
75 | valueToReturn = score.losses;
76 | } else {
77 | valueToReturn = score.ties;
78 | }
79 | return valueToReturn;
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/settling-scores/src/main/java/com/mcnz/rps/SettlingScoresApplication.java:
--------------------------------------------------------------------------------
1 | package com.mcnz.rps;
2 |
3 | import org.springframework.boot.SpringApplication;
4 | import org.springframework.boot.autoconfigure.SpringBootApplication;
5 |
6 | @SpringBootApplication
7 | public class SettlingScoresApplication {
8 |
9 | public static void main(String[] args) {
10 | SpringApplication.run(SettlingScoresApplication.class, args);
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/settling-scores/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | spring.application.name=settling-scores
2 |
--------------------------------------------------------------------------------
/settling-scores/src/main/resources/static/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Rock Paper Scissor App
4 |
5 |
6 |
7 | Which one will it be?
8 | rock
9 | paper
10 | scissors
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |