diff --git a/pom.xml b/pom.xml
index 59f73f54..d63689eb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.github.libgraviton
worker-base
jar
- 0.24.0
+ 0.25.0
Graviton Worker Base Library
https://github.com/libgraviton/graviton-worker-base-java
2015
@@ -62,7 +62,7 @@
com.github.libgraviton
gdk-core
- 0.3.4
+ 0.4.0
com.github.libgraviton
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/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();
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;
}
}