Revert "Shrink Cloud Foundry Connector Footprint"
This commit is contained in:
@@ -13,20 +13,21 @@ apply plugin: 'com.github.johnrengelman.shadow'
|
||||
apply from: "publish-maven.gradle"
|
||||
|
||||
ext {
|
||||
jsonVersion = "20171018"
|
||||
jacksonVersion = "2.3.3"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':spring-cloud-connectors-core')
|
||||
compile("org.json:json:$jsonVersion")
|
||||
compile("com.fasterxml.jackson.core:jackson-core:$jacksonVersion")
|
||||
compile("com.fasterxml.jackson.core:jackson-databind:$jacksonVersion")
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
classifier = null
|
||||
dependencies {
|
||||
include dependency('org.json:json')
|
||||
include dependency('com.fasterxml.jackson.core:jackson-.*')
|
||||
}
|
||||
relocate 'org.json', 'org.springframework.cloud.cloudfoundry.org.json'
|
||||
relocate 'com.fasterxml.jackson', 'org.springframework.cloud.cloudfoundry.com.fasterxml.jackson'
|
||||
}
|
||||
|
||||
assemble.dependsOn shadowJar
|
||||
|
||||
@@ -4,10 +4,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.cloud.AbstractCloudConnector;
|
||||
import org.springframework.cloud.CloudException;
|
||||
import org.springframework.cloud.FallbackServiceInfoCreator;
|
||||
@@ -15,6 +12,8 @@ import org.springframework.cloud.app.ApplicationInstanceInfo;
|
||||
import org.springframework.cloud.service.BaseServiceInfo;
|
||||
import org.springframework.cloud.util.EnvironmentAccessor;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Ramnivas Laddad
|
||||
@@ -22,6 +21,7 @@ import org.springframework.cloud.util.EnvironmentAccessor;
|
||||
*/
|
||||
public class CloudFoundryConnector extends AbstractCloudConnector<Map<String,Object>> {
|
||||
|
||||
private ObjectMapper objectMapper = new ObjectMapper();
|
||||
private EnvironmentAccessor environment = new EnvironmentAccessor();
|
||||
|
||||
private ApplicationInstanceInfoCreator applicationInstanceInfoCreator = new ApplicationInstanceInfoCreator();
|
||||
@@ -43,8 +43,8 @@ public class CloudFoundryConnector extends AbstractCloudConnector<Map<String,Obj
|
||||
public ApplicationInstanceInfo getApplicationInstanceInfo() {
|
||||
try {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> rawApplicationInstanceInfo
|
||||
= new JSONObject(environment.getEnvValue("VCAP_APPLICATION")).toMap();
|
||||
Map<String, Object> rawApplicationInstanceInfo
|
||||
= objectMapper.readValue(environment.getEnvValue("VCAP_APPLICATION"), Map.class);
|
||||
return applicationInstanceInfoCreator.createApplicationInstanceInfo(rawApplicationInstanceInfo);
|
||||
} catch (Exception e) {
|
||||
throw new CloudException(e);
|
||||
@@ -71,8 +71,7 @@ public class CloudFoundryConnector extends AbstractCloudConnector<Map<String,Obj
|
||||
|
||||
if (servicesString != null && servicesString.length() > 0) {
|
||||
try {
|
||||
rawServices = new CloudFoundryRawServiceData(new JSONObject(servicesString).toMap().entrySet().stream()
|
||||
.collect(Collectors.toMap(Map.Entry::getKey, entry -> (List<Map<String, Object>>) entry.getValue())));
|
||||
rawServices = objectMapper.readValue(servicesString, CloudFoundryRawServiceData.class);
|
||||
} catch (Exception e) {
|
||||
throw new CloudException(e);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
@@ -16,6 +15,8 @@ import org.springframework.cloud.service.ServiceInfo;
|
||||
import org.springframework.cloud.service.UriBasedServiceInfo;
|
||||
import org.springframework.cloud.util.EnvironmentAccessor;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -35,6 +36,8 @@ public abstract class AbstractCloudFoundryConnectorTest {
|
||||
protected static final int port = 1234;
|
||||
protected static String username = "myuser";
|
||||
protected static final String password = "mypass";
|
||||
|
||||
private static ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
@@ -113,7 +116,7 @@ public abstract class AbstractCloudFoundryConnectorTest {
|
||||
@SuppressWarnings("unchecked")
|
||||
private static String getServiceLabel(String servicePayload) {
|
||||
try {
|
||||
Map<String, Object> serviceMap = new JSONObject(servicePayload).toMap();
|
||||
Map<String, Object> serviceMap = objectMapper.readValue(servicePayload, Map.class);
|
||||
return serviceMap.get("label").toString();
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
|
||||
@@ -22,10 +22,11 @@ import static org.junit.Assert.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.service.common.CassandraServiceInfo;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* Unit tests for link {@link CassandraServiceInfoCreator}.
|
||||
*
|
||||
@@ -33,6 +34,8 @@ import org.springframework.cloud.service.common.CassandraServiceInfo;
|
||||
*/
|
||||
public class CassandraServiceInfoCreatorTests extends AbstractCloudFoundryConnectorTest {
|
||||
|
||||
private ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
public void shouldCreateServiceInfo() throws Exception {
|
||||
|
||||
@@ -88,7 +91,7 @@ public class CassandraServiceInfoCreatorTests extends AbstractCloudFoundryConnec
|
||||
}
|
||||
|
||||
private Map readServiceData(String resource) throws java.io.IOException {
|
||||
return new JSONObject(readTestDataFile(resource)).toMap();
|
||||
return mapper.readValue(readTestDataFile(resource), Map.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
Reference in New Issue
Block a user