From 7bdf9ce04d265b2f891c2b10b44598f78762ed34 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Tue, 4 Jul 2017 14:01:03 +0200 Subject: [PATCH 1/5] bump version to 0.24.1-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 59f73f54..a4c2273b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.github.libgraviton worker-base jar - 0.24.0 + 0.24.1-SNAPSHOT Graviton Worker Base Library https://github.com/libgraviton/graviton-worker-base-java 2015 From 40ad7e1fbdcca4f03a93dcf932b06e14ce5f05e9 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Fri, 7 Jul 2017 14:09:57 +0200 Subject: [PATCH 2/5] bump gdk-core to 0.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a4c2273b..c463bbbf 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ com.github.libgraviton gdk-core - 0.3.4 + 0.4.0 com.github.libgraviton From d554b7759ada0409757f99ab68f4019841f25245 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Fri, 7 Jul 2017 14:10:14 +0200 Subject: [PATCH 3/5] code cleanup --- .../workerbase/logging/TruncatedMessageConverter.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/github/libgraviton/workerbase/logging/TruncatedMessageConverter.java b/src/main/java/com/github/libgraviton/workerbase/logging/TruncatedMessageConverter.java index 96859380..5063a913 100644 --- a/src/main/java/com/github/libgraviton/workerbase/logging/TruncatedMessageConverter.java +++ b/src/main/java/com/github/libgraviton/workerbase/logging/TruncatedMessageConverter.java @@ -33,6 +33,8 @@ public String convert(ILoggingEvent event) { /** * For some reason getOptionList() is protected. With getOptions() it's exposed and testable. + * + * @return options list */ public List getOptions() { return getOptionList(); From fa340eee5165dba969e4565801e6ce789539a396 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Fri, 7 Jul 2017 14:11:03 +0200 Subject: [PATCH 4/5] move GravitonApi and GravitonFileEndpoint initialization to onStartUp --- .../workerbase/FileWorkerAbstract.java | 13 ++++---- .../workerbase/GravitonAuthApi.java | 32 +++++++------------ .../workerbase/WorkerAbstract.java | 9 ++---- .../workerbase/GravitonAuthApiTest.java | 7 ++-- .../workerbase/WorkerBaseTestCase.java | 1 - .../workerbase/lib/TestFileWorker.java | 2 +- .../workerbase/lib/TestWorker.java | 2 +- .../workerbase/lib/TestWorkerException.java | 2 +- .../workerbase/lib/TestWorkerNoAuto.java | 2 +- 9 files changed, 29 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/github/libgraviton/workerbase/FileWorkerAbstract.java b/src/main/java/com/github/libgraviton/workerbase/FileWorkerAbstract.java index 9415d997..ba675665 100644 --- a/src/main/java/com/github/libgraviton/workerbase/FileWorkerAbstract.java +++ b/src/main/java/com/github/libgraviton/workerbase/FileWorkerAbstract.java @@ -1,8 +1,3 @@ -/** - * abstract base class for file workers providing convenience. - * it extends WorkerAbstract but provides more functions for /file api handling - */ - package com.github.libgraviton.workerbase; import com.github.libgraviton.gdk.GravitonFileEndpoint; @@ -33,7 +28,7 @@ public abstract class FileWorkerAbstract extends WorkerAbstract { protected File gravitonFile; - protected GravitonFileEndpoint fileEndpoint = initFileEndpoint(); + protected GravitonFileEndpoint fileEndpoint; public boolean shouldHandleRequest(QueueEvent queueEvent) throws WorkerException, GravitonCommunicationException { // reset gravitonFile, to make sure we have no cached values that will interfere. @@ -51,6 +46,12 @@ public boolean shouldHandleRequest(QueueEvent queueEvent) throws WorkerException return actionOfInterestPresent; } + @Override + public void onStartUp() throws WorkerException { + super.onStartUp(); + fileEndpoint = initFileEndpoint(); + } + /** * Get required action of interest for worker. * diff --git a/src/main/java/com/github/libgraviton/workerbase/GravitonAuthApi.java b/src/main/java/com/github/libgraviton/workerbase/GravitonAuthApi.java index 11dcd574..470d6512 100644 --- a/src/main/java/com/github/libgraviton/workerbase/GravitonAuthApi.java +++ b/src/main/java/com/github/libgraviton/workerbase/GravitonAuthApi.java @@ -2,9 +2,7 @@ import com.github.libgraviton.gdk.GravitonApi; import com.github.libgraviton.gdk.api.header.HeaderBag; -import com.github.libgraviton.gdk.util.PropertiesLoader; -import java.io.IOException; import java.util.Properties; /** @@ -16,30 +14,22 @@ */ public class GravitonAuthApi extends GravitonApi { - protected Properties properties; + protected String authHeaderName; + protected String authHeaderValue; - @Override - protected HeaderBag getDefaultHeaders() { - String authHeaderValue = properties.getProperty("graviton.authentication.prefix.username") + + public GravitonAuthApi(Properties properties) { + super(); + this.authHeaderValue = properties.getProperty("graviton.authentication.prefix.username") .concat(properties.getProperty("graviton.workerId")); - String authHeaderName = properties.getProperty("graviton.authentication.header.name"); + this.authHeaderName = properties.getProperty("graviton.authentication.header.name"); + } + @Override + protected HeaderBag.Builder getDefaultHeaders() { return new HeaderBag.Builder() .set("Content-Type", "application/json") .set("Accept", "application/json") - .set(authHeaderName, authHeaderValue) - .build(); - } - - - // TODO remove the setup override as soon as properties is no longer private in GravitonApi - @Override - protected void setup() { - try { - this.properties = PropertiesLoader.load(); - } catch (IOException e) { - throw new IllegalStateException("Unable to load properties files.", e); - } - super.setup(); + .set(authHeaderName, authHeaderValue); } } diff --git a/src/main/java/com/github/libgraviton/workerbase/WorkerAbstract.java b/src/main/java/com/github/libgraviton/workerbase/WorkerAbstract.java index 9bda70c8..8ba5f870 100644 --- a/src/main/java/com/github/libgraviton/workerbase/WorkerAbstract.java +++ b/src/main/java/com/github/libgraviton/workerbase/WorkerAbstract.java @@ -1,7 +1,3 @@ -/** - * abstract base class for workers providing convenience - */ - package com.github.libgraviton.workerbase; import com.github.libgraviton.gdk.GravitonApi; @@ -50,7 +46,7 @@ public abstract class WorkerAbstract { protected MessageAcknowledger acknowledger; - protected GravitonApi gravitonApi = initGravitonApi(); + protected GravitonApi gravitonApi; public Properties getProperties() { return properties; @@ -94,6 +90,7 @@ public Boolean getRegistered() { */ public final void initialize(Properties properties) throws WorkerException, GravitonCommunicationException { this.properties = properties; + this.gravitonApi = initGravitonApi(); workerId = properties.getProperty("graviton.workerId"); if (shouldAutoRegister()) { @@ -282,6 +279,6 @@ public QueueManager getQueueManager() { } protected GravitonApi initGravitonApi() { - return new GravitonAuthApi(); + return new GravitonAuthApi(properties); } } diff --git a/src/test/java/com/github/libgraviton/workerbase/GravitonAuthApiTest.java b/src/test/java/com/github/libgraviton/workerbase/GravitonAuthApiTest.java index 9e7d4137..a0857390 100644 --- a/src/test/java/com/github/libgraviton/workerbase/GravitonAuthApiTest.java +++ b/src/test/java/com/github/libgraviton/workerbase/GravitonAuthApiTest.java @@ -2,6 +2,7 @@ import com.github.libgraviton.gdk.api.header.Header; import com.github.libgraviton.gdk.api.header.HeaderBag; +import com.github.libgraviton.workerbase.helper.PropertiesLoader; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -9,9 +10,9 @@ public class GravitonAuthApiTest { @Test - public void testGetDefaultHeader() { - GravitonAuthApi gravitonApi = new GravitonAuthApi(); - HeaderBag headers = gravitonApi.getDefaultHeaders(); + public void testGetDefaultHeader() throws Exception { + GravitonAuthApi gravitonApi = new GravitonAuthApi(PropertiesLoader.load()); + HeaderBag headers = gravitonApi.getDefaultHeaders().build(); assertEquals(3, headers.all().size()); Header header = headers.get("x-graviton-authentication"); diff --git a/src/test/java/com/github/libgraviton/workerbase/WorkerBaseTestCase.java b/src/test/java/com/github/libgraviton/workerbase/WorkerBaseTestCase.java index 58584b02..b53307b2 100644 --- a/src/test/java/com/github/libgraviton/workerbase/WorkerBaseTestCase.java +++ b/src/test/java/com/github/libgraviton/workerbase/WorkerBaseTestCase.java @@ -1,7 +1,6 @@ package com.github.libgraviton.workerbase; import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.libgraviton.gdk.GravitonApi; import com.github.libgraviton.gdk.api.Response; import com.github.libgraviton.gdk.data.GravitonBase; import com.github.libgraviton.gdk.serialization.mapper.GravitonObjectMapper; diff --git a/src/test/java/com/github/libgraviton/workerbase/lib/TestFileWorker.java b/src/test/java/com/github/libgraviton/workerbase/lib/TestFileWorker.java index 1e044431..24c6d9f9 100644 --- a/src/test/java/com/github/libgraviton/workerbase/lib/TestFileWorker.java +++ b/src/test/java/com/github/libgraviton/workerbase/lib/TestFileWorker.java @@ -58,6 +58,6 @@ public List getActionsOfInterest(QueueEvent queueEvent) { } protected GravitonApi initGravitonApi() { - return null; + return gravitonApi; } } diff --git a/src/test/java/com/github/libgraviton/workerbase/lib/TestWorker.java b/src/test/java/com/github/libgraviton/workerbase/lib/TestWorker.java index 1ec4235f..4b91d39e 100644 --- a/src/test/java/com/github/libgraviton/workerbase/lib/TestWorker.java +++ b/src/test/java/com/github/libgraviton/workerbase/lib/TestWorker.java @@ -41,6 +41,6 @@ public QueueEvent getHandledQueueEvent() { } protected GravitonApi initGravitonApi() { - return null; + return gravitonApi; } } diff --git a/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerException.java b/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerException.java index 00e9a87d..9c9443d9 100644 --- a/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerException.java +++ b/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerException.java @@ -42,6 +42,6 @@ public Boolean shouldAutoRegister() } protected GravitonApi initGravitonApi() { - return null; + return gravitonApi; } } diff --git a/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerNoAuto.java b/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerNoAuto.java index 5c52a527..125bbece 100644 --- a/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerNoAuto.java +++ b/src/test/java/com/github/libgraviton/workerbase/lib/TestWorkerNoAuto.java @@ -42,7 +42,7 @@ public Boolean shouldAutoRegister() } protected GravitonApi initGravitonApi() { - return null; + return gravitonApi; } } From 8285079aa8974b4e5b3b291a57a2f8a8bb8dbb56 Mon Sep 17 00:00:00 2001 From: Michael Wegener Date: Fri, 7 Jul 2017 14:17:53 +0200 Subject: [PATCH 5/5] bump version to 0.25.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c463bbbf..d63689eb 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.github.libgraviton worker-base jar - 0.24.1-SNAPSHOT + 0.25.0 Graviton Worker Base Library https://github.com/libgraviton/graviton-worker-base-java 2015