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.3.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Wegener committed May 10, 2017
2 parents 6d8e8df + 81df785 commit a42d4c9
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 26 deletions.
12 changes: 6 additions & 6 deletions gdk-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.3.3</version>
<version>0.3.4</version>
</parent>
<artifactId>gdk-core</artifactId>
<name>gdk-core</name>
Expand All @@ -32,12 +32,12 @@
<dependency>
<groupId>com.fasterxml.jackson.jr</groupId>
<artifactId>jackson-jr-objects</artifactId>
<version>2.8.1</version>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.4.1</version>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
Expand All @@ -62,12 +62,12 @@
<dependency>
<groupId>com.flipkart.zjsonpatch</groupId>
<artifactId>zjsonpatch</artifactId>
<version>0.2.4</version>
<version>0.3.1</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.7</version>
<version>1.2.3</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand All @@ -78,7 +78,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.2.9</version>
<version>2.7.22</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,28 @@ public Response execute(Request request) throws CommunicationException {
}

protected void logBody(Request request) {
int maxBodySize = 1000;
String truncatePostfix = "... [body too big to display in its complete beauty]";

if (request.getBody() != null) {
logStandardRequest(request, maxBodySize, truncatePostfix);
logStandardRequest(request);
}

if (request.getParts() != null && request.getParts().size() > 0) {
logMultipartRequest(request, maxBodySize, truncatePostfix);
logMultipartRequest(request);
}
}

private void logStandardRequest(Request request, int maxBodySize, String truncatePostfix) {
private void logStandardRequest(Request request) {
String body = request.getBody();
body = body.length() <= maxBodySize
? body
: body.substring(0, maxBodySize) + truncatePostfix;
LOG.debug("with request body '" + body + "'");
}

private void logMultipartRequest(Request request, int maxBodySize, String truncatePostfix) {
private void logMultipartRequest(Request request) {
StringBuilder builder = new StringBuilder();
for (Part part: request.getParts()) {
byte[] body = part.getBody();
String loggablePart = "Part{" +
"formName='" + part.getFormName() + '\'' +
", body='" +
(body.length <= maxBodySize
? new String(body)
: new String(Arrays.copyOfRange(body, 0, maxBodySize)) + truncatePostfix) +
new String(body) +
'\'' +
"}";
builder.append(loggablePart).append("\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
import com.github.libgraviton.gdk.api.endpoint.exception.UnableToLoadEndpointAssociationsException;
import com.github.libgraviton.gdk.api.endpoint.exception.UnableToPersistEndpointAssociationsException;
import com.github.libgraviton.gdk.util.PropertiesLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.Iterator;
import java.util.Map;

/**
Expand All @@ -13,6 +16,8 @@
*/
public class GeneratedEndpointManager extends EndpointManager {

private static final Logger LOG = LoggerFactory.getLogger(GeneratedEndpointManager.class);

public enum Mode {
LOAD, CREATE
}
Expand Down Expand Up @@ -81,6 +86,7 @@ public int load() throws UnableToLoadEndpointAssociationsException {
ObjectInputStream objectinputstream = new ObjectInputStream(loadInputStream());
endpoints = (Map<String, Endpoint>) objectinputstream.readObject();
objectinputstream.close();
LOG.debug(endpoints.size() + " endpoints loaded");
} catch (IOException e) {
throw new UnableToLoadEndpointAssociationsException(
"Unable to deserialize '" + assocFilePath + "'.",
Expand All @@ -104,9 +110,11 @@ public int load() throws UnableToLoadEndpointAssociationsException {

protected InputStream loadInputStream() throws UnableToLoadEndpointAssociationsException {
// try to load as resource first
LOG.debug("Load resource as stream from '" + assocFilePath + "'.");
InputStream inputStream = GeneratedEndpointManager.class.getClassLoader().getResourceAsStream(assocFilePath);

if(inputStream == null && serializationFile.exists()) {
LOG.debug("Resource not found. Fallback to serialization file '" + serializationFile.getAbsolutePath() + "'.");
try {
// resource not found? Try to load as file
inputStream = new FileInputStream(serializationFile);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
package com.github.libgraviton.gdk.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
* Loading properties (default as fallback, with the ability to overwrite values).
* Loading properties (with the ability to overwrite values).
*/
public class PropertiesLoader {

private static final String DEFAULT_PROPERTIES_PATH = "default-gdk.properties";

private static final String OVERWRITE_PROPERTIES_PATH = "app.properties";

private static final String SYSTEM_PROPERTY = "propFile";

/**
* Loads the Properties in the following order (if a property entry ia already loaded, it will be overridden with the new value).
* 1.) Default Properties
* 1.) Default Properties (resource path)
* Minimal needed properties for the gdk
*
* 2.) Overwrite Properties
* 2.) Overwrite Properties (resource path)
* Usually projects that make use of the gdk library will define these properties.
*
* 3.) System Properties
* 3.) Overwrite Properties (system property path)
* Whenever the project needs to run as a jar file with an external properties file,
* it's required to pass the SYSTEM_PROPERTY key with the path to the properties file as value. (e.g. -DpropFile=/app.properties)
*
* 4.) System Properties
* Projects that use the gdk library could be deployed to several environments that require different property values.
* The easiest way at this point is to just redefine those properties as system properties.
*
Expand All @@ -41,6 +48,13 @@ public static Properties load() throws IOException {
}
}

String systemPropertiesPath = System.getProperty(SYSTEM_PROPERTY);
if (systemPropertiesPath != null) {
try (InputStream overwriteProperties = new FileInputStream(systemPropertiesPath)) {
properties.load(overwriteProperties);
}
}

properties.putAll(System.getProperties());

return properties;
Expand Down
4 changes: 2 additions & 2 deletions gdk-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.3.3</version>
<version>0.3.4</version>
</parent>
<artifactId>gdk-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
Expand Down Expand Up @@ -34,7 +34,7 @@
<dependency>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk-core</artifactId>
<version>0.3.3</version>
<version>0.3.4</version>
</dependency>
<dependency>
<groupId>org.jsonschema2pojo</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.libgraviton</groupId>
<artifactId>gdk</artifactId>
<version>0.3.3</version>
<version>0.3.4</version>
<packaging>pom</packaging>
<name>gdk</name>
<description>Graviton Development Kit</description>
Expand Down

0 comments on commit a42d4c9

Please sign in to comment.