Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.25.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wegener committed Jul 7, 2017
2 parents eb34d12 + 8285079 commit 35610fa
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 43 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.github.libgraviton</groupId>
<artifactId>worker-base</artifactId>
<packaging>jar</packaging>
<version>0.24.0</version>
<version>0.25.0</version>
<name>Graviton Worker Base Library</name>
<url>https://github.com/libgraviton/graviton-worker-base-java</url>
<inceptionYear>2015</inceptionYear>
Expand Down Expand Up @@ -62,7 +62,7 @@
<dependency>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk-core</artifactId>
<version>0.3.4</version>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>com.github.libgraviton</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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.
Expand All @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/**
* abstract base class for workers providing convenience
*/

package com.github.libgraviton.workerbase;

import com.github.libgraviton.gdk.GravitonApi;
Expand Down Expand Up @@ -50,7 +46,7 @@ public abstract class WorkerAbstract {

protected MessageAcknowledger acknowledger;

protected GravitonApi gravitonApi = initGravitonApi();
protected GravitonApi gravitonApi;

public Properties getProperties() {
return properties;
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -282,6 +279,6 @@ public QueueManager getQueueManager() {
}

protected GravitonApi initGravitonApi() {
return new GravitonAuthApi();
return new GravitonAuthApi(properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> getOptions() {
return getOptionList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

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;

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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ public List<String> getActionsOfInterest(QueueEvent queueEvent) {
}

protected GravitonApi initGravitonApi() {
return null;
return gravitonApi;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ public QueueEvent getHandledQueueEvent() {
}

protected GravitonApi initGravitonApi() {
return null;
return gravitonApi;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public Boolean shouldAutoRegister()
}

protected GravitonApi initGravitonApi() {
return null;
return gravitonApi;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Boolean shouldAutoRegister()
}

protected GravitonApi initGravitonApi() {
return null;
return gravitonApi;
}

}

0 comments on commit 35610fa

Please sign in to comment.