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

Commit

Permalink
TSE Feature Support
Browse files Browse the repository at this point in the history
- Added support for TSE
- Removed Security Token in URL
  • Loading branch information
sfdrogojan authored and manivinesh committed Nov 19, 2018
1 parent 91b78ff commit e76eaa6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 28 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,7 +44,7 @@ The easiest way to install the Java SDK is via Maven—simply add the follow
<dependency>
<groupId>com.github.salesforce-marketingcloud</groupId>
<artifactId>fuelsdk</artifactId>
<version>1.2.2</version>
<version>1.3.2</version>
</dependency>

Maven will automatically resolve, download, and install all dependencies for you.
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.salesforce-marketingcloud</groupId>
<artifactId>fuelsdk</artifactId>
<version>1.2.2</version>
<version>1.3.2</version>
<name>Salesforce Marketing Cloud Java SDK</name>
<description>Salesforce Marketing Cloud Java SDK</description>
<url>https://github.com/salesforce-marketingcloud/FuelSDK-Java</url>
Expand Down
55 changes: 37 additions & 18 deletions src/main/java/com/exacttarget/fuelsdk/ETClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/exacttarget/fuelsdk/ETSoapConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/exacttarget/fuelsdk/ETClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

package com.exacttarget.fuelsdk;

import java.lang.reflect.Field;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit e76eaa6

Please sign in to comment.