diff --git a/checkup.sh b/checkup.sh new file mode 100755 index 0000000..374bb68 --- /dev/null +++ b/checkup.sh @@ -0,0 +1,7 @@ +echo +echo "************** BUILDING FOR LATEST SPRING BOOT 2.x ************** " +mvn clean install +echo +echo +echo "************** BUILDING FOR SPRING BOOT 1.x ************** " +mvn clean install -Dspring-boot.version=1.5.8.RELEASE diff --git a/pom.xml b/pom.xml index bbaab1a..c3a54ee 100644 --- a/pom.xml +++ b/pom.xml @@ -1,26 +1,42 @@ + 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.0.3.RELEASE - - - com.clearlydecoded rest-messenger-demo war - 2.0.1 - + 2.1.0 - 1.8 + 1.8 + 1.8 + UTF-8 + 2.0.3.RELEASE + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + org.springframework.boot @@ -36,7 +52,7 @@ com.clearlydecoded rest-messenger - 2.0.1 + 2.1.0 @@ -57,6 +73,12 @@ org.springframework.boot spring-boot-maven-plugin + ${spring-boot.version} + + + org.apache.maven.plugins + maven-war-plugin + 3.2.2 diff --git a/src/main/java/com/clearlydecoded/messenger/demo/message/GingerCookieOrder.java b/src/main/java/com/clearlydecoded/messenger/demo/message/GingerCookieOrder.java index 10bc7a4..3d3b2f2 100644 --- a/src/main/java/com/clearlydecoded/messenger/demo/message/GingerCookieOrder.java +++ b/src/main/java/com/clearlydecoded/messenger/demo/message/GingerCookieOrder.java @@ -18,9 +18,7 @@ */ public class GingerCookieOrder implements Message { - public static final String TYPE = "FirstAvailableGingerCookieOrder"; - - private final String type = TYPE; + private final String type = "FirstAvailableGingerCookieOrder"; public GingerCookieOrder() { } diff --git a/src/main/java/com/clearlydecoded/messenger/demo/message/GreetMeMessage.java b/src/main/java/com/clearlydecoded/messenger/demo/message/GreetMeMessage.java index 0623f98..5a2619e 100644 --- a/src/main/java/com/clearlydecoded/messenger/demo/message/GreetMeMessage.java +++ b/src/main/java/com/clearlydecoded/messenger/demo/message/GreetMeMessage.java @@ -10,6 +10,8 @@ import com.clearlydecoded.messenger.Message; import java.util.Objects; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; /** * Demo class that requests a greeting with a supplied name. @@ -19,15 +21,15 @@ public class GreetMeMessage implements Message { /** - * Set up the required message type identifier like so. - * There are other ways to define it, but this approach is nice. + * String-based type identifier of this message that is unique system-wide. */ - public static final String TYPE = "GreetMe"; - private final String type = TYPE; + private final String type = "GreetMe"; /** * The actual data we want to pass to the processor. */ + @NotNull(message = "'myName' can't be null") + @Size(min = 2, message = "'myName' has to be at least 2 characters long") private String myName; /** diff --git a/src/main/java/com/clearlydecoded/messenger/demo/message/MaxSugarOrder.java b/src/main/java/com/clearlydecoded/messenger/demo/message/MaxSugarOrder.java index f504d81..2811aac 100644 --- a/src/main/java/com/clearlydecoded/messenger/demo/message/MaxSugarOrder.java +++ b/src/main/java/com/clearlydecoded/messenger/demo/message/MaxSugarOrder.java @@ -9,6 +9,8 @@ package com.clearlydecoded.messenger.demo.message; import com.clearlydecoded.messenger.Message; +import javax.validation.constraints.Max; +import javax.validation.constraints.Min; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @@ -28,10 +30,10 @@ @NoArgsConstructor public class MaxSugarOrder implements Message { - public static final String TYPE = "MaxSugarOrder"; - - private final String type = TYPE; + private final String type = "MaxSugarOrder"; + @Min(value = 10, message = "'maxSugarInGrams' must be between 10 and 2000.") + @Max(value = 2000, message = "'maxSugarInGrams' must be between 10 and 2000.") private int maxSugarInGrams; @Override diff --git a/src/main/java/com/clearlydecoded/messenger/demo/message/SugarComaCookieOrder.java b/src/main/java/com/clearlydecoded/messenger/demo/message/SugarComaCookieOrder.java index 30863e5..5788291 100644 --- a/src/main/java/com/clearlydecoded/messenger/demo/message/SugarComaCookieOrder.java +++ b/src/main/java/com/clearlydecoded/messenger/demo/message/SugarComaCookieOrder.java @@ -18,6 +18,12 @@ */ public class SugarComaCookieOrder implements Message { + /** + * Set up the required message type identifier like so. + * There are other ways to define it, but this approach is useful because this message will get + * processed by a processor that implements the MessageProcessor interface and this public static + * type makes it easy to use for a return type of getCompatibleMessageType method. + */ public static final String TYPE = "SugarComaCookieOrder"; private final String type = TYPE; diff --git a/src/main/java/com/clearlydecoded/messenger/demo/processor/GreetMeMessageProcessor.java b/src/main/java/com/clearlydecoded/messenger/demo/processor/GreetMeMessageProcessor.java index 6c9467a..91b0007 100644 --- a/src/main/java/com/clearlydecoded/messenger/demo/processor/GreetMeMessageProcessor.java +++ b/src/main/java/com/clearlydecoded/messenger/demo/processor/GreetMeMessageProcessor.java @@ -11,6 +11,7 @@ import com.clearlydecoded.messenger.AbstractMessageProcessor; import com.clearlydecoded.messenger.demo.message.GreetMeMessage; import com.clearlydecoded.messenger.demo.message.GreetMeMessageResponse; +import javax.validation.Valid; import org.springframework.stereotype.Service; /** @@ -23,7 +24,7 @@ public class GreetMeMessageProcessor extends AbstractMessageProcessor { @Override - public GreetMeMessageResponse process(GreetMeMessage message) { + public GreetMeMessageResponse process(@Valid GreetMeMessage message) { // This is where you write the actual business logic return new GreetMeMessageResponse("Hello " + message.getMyName()); diff --git a/src/main/java/com/clearlydecoded/messenger/demo/processor/MaxSugarOrderProcessor.java b/src/main/java/com/clearlydecoded/messenger/demo/processor/MaxSugarOrderProcessor.java index dfa4c77..399745b 100644 --- a/src/main/java/com/clearlydecoded/messenger/demo/processor/MaxSugarOrderProcessor.java +++ b/src/main/java/com/clearlydecoded/messenger/demo/processor/MaxSugarOrderProcessor.java @@ -14,6 +14,7 @@ import com.clearlydecoded.messenger.demo.model.Cookie; import com.clearlydecoded.messenger.demo.service.CookieStoreService; import java.util.List; +import javax.validation.Valid; import lombok.Setter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -33,7 +34,7 @@ public class MaxSugarOrderProcessor extends private CookieStoreService cookieStoreService; @Override - public MaxSugarOrderResponse process(MaxSugarOrder message) { + public MaxSugarOrderResponse process(@Valid MaxSugarOrder message) { List cookies = cookieStoreService .giveMeCookiesUpToMaxSugar(message.getMaxSugarInGrams());