Skip to content

Commit a72f364

Browse files
authored
Merge pull request #40 from CyberSource/dec19-dev
Adding code for auditing
2 parents 630ed0f + 0918ae2 commit a72f364

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

generator/cybersource-java-template/libraries/okhttp-gson/ApiClient.mustache

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,21 @@ import java.security.KeyStore;
2525
import java.security.SecureRandom;
2626
import java.security.cert.Certificate;
2727
import java.security.cert.CertificateException;
28+
import java.security.cert.CertificateFactory;
29+
import java.security.cert.X509Certificate;
30+
import java.text.DateFormat;
31+
import java.text.ParseException;
32+
import java.text.SimpleDateFormat;
33+
import java.util.ArrayList;
34+
import java.util.Collection;
35+
import java.util.Collections;
36+
import java.util.Date;
37+
import java.util.HashMap;
38+
import java.util.List;
39+
import java.util.Map;
40+
import java.util.Map.Entry;
41+
import java.util.Properties;
42+
import java.util.TimeZone;
2843
import java.util.concurrent.TimeUnit;
2944
import java.util.regex.Matcher;
3045
import java.util.regex.Pattern;
@@ -127,6 +142,7 @@ public class ApiClient {
127142

128143
private OkHttpClient httpClient;
129144
private JSON json;
145+
private String versionInfo;
130146

131147
private HttpLoggingInterceptor loggingInterceptor;
132148

@@ -136,6 +152,8 @@ public class ApiClient {
136152
public ApiClient() {
137153
httpClient = new OkHttpClient();
138154
155+
versionInfo = getClientID();
156+
139157
httpClient = new OkHttpClient.Builder()
140158
.connectTimeout(1, TimeUnit.SECONDS)
141159
.writeTimeout(60, TimeUnit.SECONDS)
@@ -170,6 +188,19 @@ public class ApiClient {
170188
authentications = Collections.unmodifiableMap(authentications);
171189
}
172190

191+
private String getClientID() {
192+
String propertyVersionInfo = null;
193+
final Properties properties = new Properties();
194+
try {
195+
properties.load(this.getClass().getClassLoader().getResourceAsStream("cybersource-rest-client-java.properties"));
196+
propertyVersionInfo = properties.getProperty("sdk.version");
197+
} catch (IOException e) {
198+
199+
}
200+
201+
return propertyVersionInfo;
202+
}
203+
173204
public ApiClient(MerchantConfig merchantConfig) {
174205
this();
175206
final boolean useProxy = merchantConfig.isUseProxyEnabled();
@@ -921,7 +952,7 @@ public class ApiClient {
921952
if ((returnType == null && response != null) || ("byte[]".equals(returnType.toString()))) {
922953
try {
923954
T respBody = (T) response.body().byteStream();
924-
955+
925956
return respBody;
926957
} catch (IOException e) {
927958
throw new ApiException(e);
@@ -1173,7 +1204,7 @@ public class ApiClient {
11731204
if (response.isSuccessful()) {
11741205
if (response.code() == 204) {
11751206
if (response.body() != null) {
1176-
response.body().close();
1207+
response.body().close();
11771208
}
11781209
return null;
11791210
} else {
@@ -1294,6 +1325,14 @@ public class ApiClient {
12941325
token = "Bearer " + token;
12951326
addDefaultHeader("Authorization", token);
12961327
}
1328+
1329+
if (merchantConfig.getSolutionId() != null && !merchantConfig.getSolutionId().isEmpty()) {
1330+
addDefaultHeader("v-c-solution-id", merchantConfig.getSolutionId());
1331+
}
1332+
}
1333+
1334+
if (versionInfo != null && !versionInfo.isEmpty()) {
1335+
addDefaultHeader("v-c-client-id", "cybs-rest-sdk-java-" + versionInfo);
12971336
}
12981337

12991338
} catch (ConfigException e) {

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@
3838
</developers>
3939

4040
<build>
41+
<resources>
42+
<resource>
43+
<directory>src/main/resources</directory>
44+
<filtering>true</filtering>
45+
</resource>
46+
</resources>
4147
<plugins>
4248
<plugin>
4349
<groupId>org.apache.maven.plugins</groupId>
@@ -258,7 +264,7 @@
258264
<dependency>
259265
<groupId>com.cybersource</groupId>
260266
<artifactId>AuthenticationSdk</artifactId>
261-
<version>0.0.7</version>
267+
<version>0.0.8</version>
262268
</dependency>
263269

264270
<!-- Added dependencies -->
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sdk.version=${project.version}

0 commit comments

Comments
 (0)