diff --git a/README.md b/README.md
index 735d6477..92a83507 100755
--- a/README.md
+++ b/README.md
@@ -25,12 +25,15 @@ Java platform. Among other things, the SDK:
For more information about the Java SDK and how to use it, please see
the Javadocs at http://salesforce-marketingcloud.github.io/FuelSDK-Java/.
-New Features in Version 1.2.2
+New Features in Version 1.3.2
------------
-* Content Area
-* Data Extract
-* Result Message
-* Triggered Send Summary
+* Added support for your tenant’s endpoints - [More Details](https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/your-subdomain-tenant-specific-endpoints.htm)
+* REST, Auth endpoints are configurable. If not specified in the fuelsdk.properties file,
+they are defaulted to "https://www.exacttargetapis.com" for REST and
+"https://auth.exacttargetapis.com" for Auth.
+* SOAP endpoint is also configurable. If not specified in the fuelsdk.properties file,
+it is defaulted to "https://webservice.exacttarget.com/service.asmx"
+* Removed the legacyToken query string parameter support.
Installation
@@ -41,7 +44,7 @@ The easiest way to install the Java SDK is via Maven—simply add the follow
com.github.salesforce-marketingcloud
fuelsdk
- 1.2.2
+ 1.3.2
Maven will automatically resolve, download, and install all dependencies for you.
diff --git a/pom.xml b/pom.xml
index 2beb6ea2..50e9fc05 100755
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
com.github.salesforce-marketingcloud
fuelsdk
- 1.2.2
+ 1.3.2
Salesforce Marketing Cloud Java SDK
Salesforce Marketing Cloud Java SDK
https://github.com/salesforce-marketingcloud/FuelSDK-Java
diff --git a/src/main/java/com/exacttarget/fuelsdk/ETClient.java b/src/main/java/com/exacttarget/fuelsdk/ETClient.java
index 1f4c8785..bde330fa 100755
--- a/src/main/java/com/exacttarget/fuelsdk/ETClient.java
+++ b/src/main/java/com/exacttarget/fuelsdk/ETClient.java
@@ -66,10 +66,10 @@ public class ETClient {
"https://auth.exacttargetapis.com";
private static final String PATH_REQUESTTOKEN =
"/v1/requestToken";
- private static final String PATH_REQUESTTOKEN_LEGACY =
- "/v1/requestToken?legacy=1";
private static final String PATH_ENDPOINTS_SOAP =
"/platform/v1/endpoints/soap";
+ private static final String DEFAULT_SOAP_ENDPOINT =
+ "https://webservice.exacttarget.com/Service.asmx";
private ETConfiguration configuration = null;
@@ -97,6 +97,9 @@ public class ETClient {
private String refreshToken = null;
private long tokenExpirationTime = 0;
+ private static long soapEndpointExpiration = 0;
+ private static String fetchedSoapEndpoint = null;
+ private static final long cacheDurationInMillis = 1000 * 60 * 10; // 10 minutes
/**
* Class constructor, Initializes a new instance of the class.
@@ -155,17 +158,7 @@ public ETClient(ETConfiguration configuration)
authConnection = new ETRestConnection(this, authEndpoint, true);
requestToken();
restConnection = new ETRestConnection(this, endpoint);
- if (soapEndpoint == null) {
- //
- // If a SOAP endpoint isn't specified automatically determine it:
- //
-
- ETRestConnection.Response response = restConnection.get(PATH_ENDPOINTS_SOAP);
- String responsePayload = response.getResponsePayload();
- JsonParser jsonParser = new JsonParser();
- JsonObject jsonObject = jsonParser.parse(responsePayload).getAsJsonObject();
- soapEndpoint = jsonObject.get("url").getAsString();
- }
+ FetchSoapEndpoint();
soapConnection = new ETSoapConnection(this, soapEndpoint, accessToken);
} else {
if (username == null || password == null) {
@@ -198,6 +191,35 @@ public ETClient(ETConfiguration configuration)
}
}
+ private void FetchSoapEndpoint() {
+ if (soapEndpoint == null || soapEndpoint.equals("")) {
+ //
+ // If a SOAP endpoint isn't specified automatically determine it:
+ //
+ try {
+ if(System.currentTimeMillis() > soapEndpointExpiration || fetchedSoapEndpoint == null) {
+ ETRestConnection.Response response = restConnection.get(PATH_ENDPOINTS_SOAP);
+ if (response.getResponseCode() == 200) {
+ String responsePayload = response.getResponsePayload();
+ JsonParser jsonParser = new JsonParser();
+ JsonObject jsonObject = jsonParser.parse(responsePayload).getAsJsonObject();
+ soapEndpoint = jsonObject.get("url").getAsString();
+ fetchedSoapEndpoint = soapEndpoint;
+ soapEndpointExpiration = System.currentTimeMillis() + cacheDurationInMillis;
+ } else {
+ soapEndpoint = DEFAULT_SOAP_ENDPOINT;
+ }
+ }
+ else {
+ soapEndpoint = fetchedSoapEndpoint;
+ }
+ }
+ catch(ETSdkException ex) {
+ soapEndpoint = DEFAULT_SOAP_ENDPOINT;
+ }
+ }
+ }
+
/**
*
* @return The client ID
@@ -323,11 +345,8 @@ public synchronized String requestToken(String refreshToken)
String requestPayload = gson.toJson(jsonObject);
ETRestConnection.Response response = null;
- if (configuration.isTrue("requestLegacyToken")) {
- response = authConnection.post(PATH_REQUESTTOKEN_LEGACY, requestPayload);
- } else {
- response = authConnection.post(PATH_REQUESTTOKEN, requestPayload);
- }
+
+ response = authConnection.post(PATH_REQUESTTOKEN, requestPayload);
if (response.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new ETSdkException("error obtaining access token "
diff --git a/src/main/java/com/exacttarget/fuelsdk/ETRestConnection.java b/src/main/java/com/exacttarget/fuelsdk/ETRestConnection.java
index 7d2ca499..484c8b09 100755
--- a/src/main/java/com/exacttarget/fuelsdk/ETRestConnection.java
+++ b/src/main/java/com/exacttarget/fuelsdk/ETRestConnection.java
@@ -240,7 +240,7 @@ private HttpURLConnection sendRequest(URL url, Method method, String payload)
try {
connection = (HttpURLConnection) url.openConnection();
- connection.setRequestProperty("User-Agent", "FuelSDK-Java-v1.2.2-REST-"+method+"-"+object);
+ connection.setRequestProperty("User-Agent", "FuelSDK-Java-v1.3.2-REST-"+method+"-"+object);
connection.setRequestMethod(method.toString());
} catch (ProtocolException ex) {
throw new ETSdkException("error setting request method: " + method.toString(), ex);
diff --git a/src/main/java/com/exacttarget/fuelsdk/ETSoapConnection.java b/src/main/java/com/exacttarget/fuelsdk/ETSoapConnection.java
index 061b0754..e8578de7 100755
--- a/src/main/java/com/exacttarget/fuelsdk/ETSoapConnection.java
+++ b/src/main/java/com/exacttarget/fuelsdk/ETSoapConnection.java
@@ -234,12 +234,12 @@ public Soap getSoap() {
}
public Soap getSoap(String m) {
- soapClient.getRequestContext().put("HTTP_HEADER_USER_AGENT", "FuelSDK-Java-v1.2.2-SOAP-"+m);
+ soapClient.getRequestContext().put("HTTP_HEADER_USER_AGENT", "FuelSDK-Java-v1.3.2-SOAP-"+m);
return soap;
}
public Soap getSoap(String m, String o) {
- soapClient.getRequestContext().put("HTTP_HEADER_USER_AGENT", "FuelSDK-Java-v1.2.2-SOAP-"+m+"-"+o);
+ soapClient.getRequestContext().put("HTTP_HEADER_USER_AGENT", "FuelSDK-Java-v1.3.2-SOAP-"+m+"-"+o);
return soap;
}
diff --git a/src/test/java/com/exacttarget/fuelsdk/ETClientTest.java b/src/test/java/com/exacttarget/fuelsdk/ETClientTest.java
index 19920a42..3ccb62d4 100755
--- a/src/test/java/com/exacttarget/fuelsdk/ETClientTest.java
+++ b/src/test/java/com/exacttarget/fuelsdk/ETClientTest.java
@@ -34,6 +34,7 @@
package com.exacttarget.fuelsdk;
+import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -198,6 +199,43 @@ public void testBackwardCompatibility4()
assertNull(folder.getAllowChildren());
}
+ @Test
+ public void testSoapEndpointCaching()
+ throws ETSdkException, NoSuchFieldException, IllegalAccessException {
+ ETClient client1 = new ETClient("fuelsdk.properties");
+ ETClient client2 = new ETClient("fuelsdk.properties");
+
+ long instance1SoapEndpointExpiration = getInstanceSoapEndpointExpiration(client1);
+ String instance1FetchedSoapEndpoint = getFetchedSoapEndpoint(client1);
+
+ long instance2SoapEndpointExpiration = getInstanceSoapEndpointExpiration(client2);
+ String instance2FetchedSoapEndpoint = getFetchedSoapEndpoint(client2);
+
+ // check if cache was used
+ if(instance1FetchedSoapEndpoint != null && instance2FetchedSoapEndpoint != null) {
+ assertTrue(instance1SoapEndpointExpiration > 0);
+ assertTrue(instance2SoapEndpointExpiration > 0);
+ assertEquals(instance1SoapEndpointExpiration, instance2SoapEndpointExpiration);
+ }
+ else
+ {
+ assertTrue(instance1SoapEndpointExpiration == 0);
+ assertTrue(instance2SoapEndpointExpiration == 0);
+ }
+ }
+
+ private String getFetchedSoapEndpoint(ETClient client) throws NoSuchFieldException, IllegalAccessException {
+ Field field = client.getClass().getDeclaredField("fetchedSoapEndpoint");
+ field.setAccessible(true);
+ return (String) field.get(null);
+ }
+
+ private long getInstanceSoapEndpointExpiration(ETClient client) throws NoSuchFieldException, IllegalAccessException {
+ Field field = client.getClass().getDeclaredField("soapEndpointExpiration");
+ field.setAccessible(true);
+ return field.getLong(null);
+ }
+
//
// XXX make these available to all tests
//