Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,16 @@ proguard/
build/
bin/
gradle.properties
/.vs/VSWorkspaceState.json
/.vs/socketlabs-java/v17/TestStore/0/testlog.manifest
/.vs/socketlabs-java/v17/TestStore/0/000.testlog
/.vs/socketlabs-java/v17/TestStore/0
/.vs/socketlabs-java/v17/.suo
/.vs/socketlabs-java/v17
/.vs/socketlabs-java/FileContentIndex/read.lock
/.vs/socketlabs-java/FileContentIndex/ef65df61-58c3-4809-877e-1a74a50b04c7.vsidx
/.vs/socketlabs-java/FileContentIndex/48b5b17b-b96e-40bb-b2b8-c0ea41589ac7.vsidx
/.vs/socketlabs-java/FileContentIndex/269ac744-ce5b-47d6-93ab-6719ed06796b.vsidx
/.vs/socketlabs-java/FileContentIndex/1393436c-32a5-4a38-a2bb-d05cfa884457.vsidx
/.vs/socketlabs-java/FileContentIndex
/.vs/slnx.sqlite
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ repositories {
<dependency>
<groupId>com.socketlabs</groupId>
<artifactId>injectionApi</artifactId>
<version>1.4.0</version>
<version>1.4.4</version>
</dependency>
```

### via jar file

You can just drop the jar file in.

[injectionApi-1.4.0.jar](https://github.com/socketlabs/socketlabs-java/releases/download/1.4.0/injectionApi-1.4.0.jar)
[injectionApi-1.4.4.jar](https://github.com/socketlabs/socketlabs-java/releases/download/1.4.4/injectionApi-1.4.4.jar)

[injectionApi-1.4.0-sources.jar](https://github.com/socketlabs/socketlabs-java/releases/download/1.4.0/injectionApi-1.4.0-sources.jar)
[injectionApi-1.4.4-sources.jar](https://github.com/socketlabs/socketlabs-java/releases/download/1.4.4/injectionApi-1.4.4-sources.jar)

[injectionApi-1.4.0-javadoc.jar](https://github.com/socketlabs/socketlabs-java/releases/download/1.4.0/injectionApi-1.4.0-javadoc.jar)
[injectionApi-1.4.4-javadoc.jar](https://github.com/socketlabs/socketlabs-java/releases/download/1.4.4/injectionApi-1.4.4-javadoc.jar)

Alternately, you can simply [clone this repository](https://github.com/socketlabs/socketlabs-java.git) directly to include the source code in your project.

Expand Down Expand Up @@ -232,6 +232,7 @@ For more information about AMP please see [AMP Project](https://amp.dev/document

<a name="version"></a>
# Version
* 1.4.4 - Added MetadataOrTagsAreTooLarge error messsage
* 1.4.0 - Adding Metadata and Tags
* 1.2.1 - Adding optional retry logic for Http requests. If configured, the request will retry when certain 500 errors occur (500, 502, 503, 504)
* 1.1.1 - Adding request timeout value on the client for Http requests
Expand Down
2 changes: 1 addition & 1 deletion examples/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ dependencies {
testCompile group: 'junit', name: 'junit', version: '4.9.2'
compile 'com.fasterxml.jackson.core:jackson-core:2.14.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.14.0'
compile group: 'com.socketlabs', name: 'injectionApi', version: '1.4.0-SNAPSHOT'
compile group: 'com.socketlabs', name: 'injectionApi', version: '1.4.2'
}
20 changes: 16 additions & 4 deletions injectionApi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
def baseGroupId = "com.socketlabs"
def baseArtifactId = 'injectionApi'
def computeVersion() {
def baseVersion = "1.4.0"
def baseVersion = "1.4.4"
def release = true
if (release)
return "${baseVersion}"
Expand All @@ -28,8 +28,9 @@ compileJava {
dependencies {
compile 'com.fasterxml.jackson.core:jackson-core:2.14.0'
compile 'com.fasterxml.jackson.core:jackson-databind:2.14.0'
compile group: 'com.google.guava', name: 'guava', version: '31.1-jre'
compile group: 'com.google.guava', name: 'guava', version: '32.1.3-jre'
compile 'com.squareup.okhttp3:okhttp:4.10.0'

}
jar {
manifest {
Expand Down Expand Up @@ -65,7 +66,7 @@ uploadArchives {
MavenDeployment deployment -> signing.signPom(deployment)
}

repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: sonatypeUsername, password: sonatypePassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
Expand Down Expand Up @@ -123,6 +124,17 @@ uploadArchives {
role 'Developer'
}
}
developer {
id 'mike.boshuyzen'
name 'Mike Boshuyzen'
organization {
name 'socketlabs'
url 'https://github.com/socketlabs'
}
roles {
role 'Developer'
}
}
}
contributors {
contributor {
Expand All @@ -139,4 +151,4 @@ uploadArchives {
}.writeTo("$projectDir/pom.xml")
}
}
}
}
16 changes: 12 additions & 4 deletions injectionApi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.socketlabs</groupId>
<artifactId>injectionApi</artifactId>
<version>1.4.0</version>
<version>1.4.2</version>
<name>socketlabs-java</name>
<description>SocketLabs Email Delivery Java library</description>
<url>https://github.com/socketlabs/socketlabs-java/</url>
Expand All @@ -23,15 +23,23 @@
<id>david-schrenker</id>
<name>David Schrenker</name>
<email>[email protected]</email>
<organization>org.apache.maven.model.Organization@5245fb42</organization>
<organization>org.apache.maven.model.Organization@f125de5</organization>
<roles>
<role>Developer</role>
</roles>
</developer>
<developer>
<id>rbrazuk</id>
<name>Ross Brazuk</name>
<organization>org.apache.maven.model.Organization@560210f5</organization>
<organization>org.apache.maven.model.Organization@19eaf41b</organization>
<roles>
<role>Developer</role>
</roles>
</developer>
<developer>
<id>mike.boshuyzen</id>
<name>Mike Boshuyzen</name>
<organization>org.apache.maven.model.Organization@6c023990</organization>
<roles>
<role>Developer</role>
</roles>
Expand All @@ -40,7 +48,7 @@
<contributors>
<contributor>
<name>Ryan Lydzinski</name>
<organization>org.apache.maven.model.Organization@166a59d1</organization>
<organization>org.apache.maven.model.Organization@399b8af0</organization>
<roles>
<role>Intern</role>
</roles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public SendResponse send(BasicMessage message) throws Exception {
return result;

HttpRequest request = buildHttpRequest(this.proxy);

ApiKeyParser keyParser = new ApiKeyParser();
ApiKeyParseResult parseResult = keyParser.Parse(this.apiKey);

if (parseResult != null && parseResult == ApiKeyParseResult.Success)
{
request.setHeader("Authorization", "Bearer " + this.apiKey);
}

request.setBody(new InjectionRequestFactory(this.serverId, this.apiKey).GenerateRequest(message));
RetryHandler retryHandler = new RetryHandler(request, this.endPointUrl, new RetrySettings(this.numberOfRetries));
Response response = retryHandler.send();
Expand All @@ -105,6 +114,15 @@ public SendResponse send(BulkMessage message) throws Exception {
return result;

HttpRequest request = buildHttpRequest(this.proxy);

ApiKeyParser keyParser = new ApiKeyParser();
ApiKeyParseResult parseResult = keyParser.Parse(this.apiKey);

if (parseResult != null && parseResult == ApiKeyParseResult.Success)
{
request.setHeader("Authorization", "Bearer " + this.apiKey);
}

request.setBody(new InjectionRequestFactory(this.serverId, this.apiKey).GenerateRequest(message));

RetryHandler retryHandler = new RetryHandler(request, this.endPointUrl, new RetrySettings(this.numberOfRetries));
Expand All @@ -131,6 +149,15 @@ public void sendAsync(BasicMessage message, final SendAsyncCallback callback) th
}

HttpRequest request = buildHttpRequest(this.proxy);

ApiKeyParser keyParser = new ApiKeyParser();
ApiKeyParseResult parseResult = keyParser.Parse(this.apiKey);

if (parseResult != null && parseResult == ApiKeyParseResult.Success)
{
request.setHeader("Authorization", "Bearer " + this.apiKey);
}

request.setBody(new InjectionRequestFactory(this.serverId, this.apiKey).GenerateRequest(message));

RetryHandler retryHandler = new RetryHandler(request, this.endPointUrl, new RetrySettings(this.numberOfRetries));
Expand Down Expand Up @@ -164,6 +191,15 @@ public void sendAsync(BulkMessage message, final SendAsyncCallback callback) thr
}

HttpRequest request = buildHttpRequest(this.proxy);

ApiKeyParser keyParser = new ApiKeyParser();
ApiKeyParseResult parseResult = keyParser.Parse(this.apiKey);

if (parseResult != null && parseResult == ApiKeyParseResult.Success)
{
request.setHeader("Authorization", "Bearer " + this.apiKey);
}

request.setBody(new InjectionRequestFactory(this.serverId, this.apiKey).GenerateRequest(message));

RetryHandler retryHandler = new RetryHandler(request, this.endPointUrl, new RetrySettings(this.numberOfRetries));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.socketLabs.injectionApi.core;

public enum ApiKeyParseResult {
/// <summary>
/// No result could be produced.
/// </summary>

None,
/// <summary>
/// The key length was found.
/// </summary>
InvalidKeyLength,

/// <summary>
/// The key format was found.
/// </summary>
InvalidKeyFormat,

/// <summary>
/// The key was found to be blank or invalid.
/// </summary>
InvalidEmptyOrWhitespace,

/// <summary>
/// The public portion of the key was unable to be parsed.
/// </summary>
InvalidUnableToExtractPublicPart,

/// <summary>
/// The secret portion of the key was unable to be parsed.
/// </summary>
InvalidUnableToExtractSecretPart,

/// <summary>
/// The public portion of the key is the incorrect length.
/// </summary>
InvalidPublicPartLength,

/// <summary>
/// The secret portion of the key is the incorrect length.
/// </summary>
InvalidSecretPartLength,

/// <summary>
/// Key was successfully parsed.
/// </summary>

Success
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.socketLabs.injectionApi.core;

/**
* Contains the method for parsing the Api Key.
*/
public class ApiKeyParser {

/**
* Parse the API key to determine what kind of key was provided.
* @param wholeApiKey String
* @return A ApiKeyParseResult with the parsing results
*/
public ApiKeyParseResult Parse(String wholeApiKey)
{
if (wholeApiKey == null || wholeApiKey.length() == 0)
return ApiKeyParseResult.InvalidEmptyOrWhitespace;

if (wholeApiKey.length() != 61)
return ApiKeyParseResult.InvalidKeyLength;

if (wholeApiKey.indexOf('.') == -1)
return ApiKeyParseResult.InvalidKeyFormat;

//extract public part
int publicPartEnd = wholeApiKey.substring(0, 50).indexOf('.'); //don't check more than 50 chars
if (publicPartEnd == -1)
return ApiKeyParseResult.InvalidUnableToExtractPublicPart;

String publicPart = wholeApiKey.substring(0, publicPartEnd);
if (publicPart.length() != 20)
return ApiKeyParseResult.InvalidPublicPartLength;

//now extract the private part
if (wholeApiKey.length() <= publicPartEnd + 1)
return ApiKeyParseResult.InvalidUnableToExtractSecretPart;

String privatePart = wholeApiKey.substring(publicPartEnd + 1);
if (privatePart.length() != 40)
return ApiKeyParseResult.InvalidSecretPartLength;

//success
return ApiKeyParseResult.Success;
}

}