Commit 4b908432 by Adi Amir

support binary content

parent 0d8514fa
...@@ -4,7 +4,7 @@ apply plugin: 'maven-publish' ...@@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
def gitLog() { return "git log --pretty=format:'%h' -n 1".execute().text.trim().replaceAll("'", "") } def gitLog() { return "git log --pretty=format:'%h' -n 1".execute().text.trim().replaceAll("'", "") }
group = 'com.ipgallery' group = 'com.ipgallery'
version = '1.0.1' + gitLog() version = '1.0.2' + gitLog()
sourceCompatibility = 1.8 sourceCompatibility = 1.8
repositories { repositories {
...@@ -16,7 +16,7 @@ repositories { ...@@ -16,7 +16,7 @@ repositories {
dependencies { dependencies {
// compile 'com.flipkart.zjsonpatch:zjsonpatch:0.2.1' // compile 'com.flipkart.zjsonpatch:zjsonpatch:0.2.1'
// compile group:'com.ipgallery.common', name:'microservice', version:'1.2.0' // compile group:'com.ipgallery.common', name:'microservice', version:'1.2.0'
compile group:'com.ipgallery.common', name:'microservice', version:'1.4.0-local' compile group:'com.ipgallery.common', name:'microservice', version:'1.4.1'
compile group:'com.ipgallery.common', name:'itc', version:'1.0.0' compile group:'com.ipgallery.common', name:'itc', version:'1.0.0'
// compile 'com.ipgallery.common:utils:1.1.0' // compile 'com.ipgallery.common:utils:1.1.0'
compile 'io.swagger:swagger-annotations:1.5.7' compile 'io.swagger:swagger-annotations:1.5.7'
......
...@@ -8,6 +8,7 @@ import http.simpleHttpClient.SimpleHttpClient; ...@@ -8,6 +8,7 @@ import http.simpleHttpClient.SimpleHttpClient;
import http.simpleHttpClient.SimpleHttpRequest; import http.simpleHttpClient.SimpleHttpRequest;
import http.simpleHttpClient.SimpleHttpResponse; import http.simpleHttpClient.SimpleHttpResponse;
import microservice.RequestContext; import microservice.RequestContext;
import microservice.io.iface.ILogger;
import microservice.types.BaseRestResponse; import microservice.types.BaseRestResponse;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
...@@ -45,8 +46,10 @@ public class GEManager { ...@@ -45,8 +46,10 @@ public class GEManager {
public static String TOKEN = "NOT_VALID"; public static String TOKEN = "NOT_VALID";
private SimpleHttpClient httpClient = null; private SimpleHttpClient httpClient = null;
private ILogger logger;
public GEManager() throws Exception { public GEManager(ILogger logger) throws Exception {
this.logger = logger;
httpClient = new SimpleHttpClient(); httpClient = new SimpleHttpClient();
httpClient.Initialize(100); httpClient.Initialize(100);
} }
...@@ -77,6 +80,7 @@ public class GEManager { ...@@ -77,6 +80,7 @@ public class GEManager {
req = buildCameraHttpRequest(requestContext,content,apiIdAsParams); req = buildCameraHttpRequest(requestContext,content,apiIdAsParams);
try { try {
resp = httpClient.processRequest(req); resp = httpClient.processRequest(req);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -88,6 +92,9 @@ public class GEManager { ...@@ -88,6 +92,9 @@ public class GEManager {
else else
brr.setError("failed to retrieve a valid token"); brr.setError("failed to retrieve a valid token");
} }
else {
brr.setError("processRequest() failed. path: " + req.getPath() + " resp: " + resp.toString());
}
return brr; return brr;
} }
...@@ -145,13 +152,25 @@ public class GEManager { ...@@ -145,13 +152,25 @@ public class GEManager {
ObjectNode objectNode = mapper.createObjectNode(); ObjectNode objectNode = mapper.createObjectNode();
JsonNode contentObj = mapper.readTree(content); JsonNode contentObj = mapper.readTree(content);
JsonNode arrNode = contentObj.get("content"); JsonNode arrNode = contentObj.get("content");
if (arrNode.isArray()) { String url = arrNode.get(0).get("url").asText();
req = buildOpenCameraLinkRequest(arrNode.get(0).get("url").asText()); req = buildOpenCameraLinkRequest(url);
resp = httpClient.processRequest(req); resp = httpClient.processRequest(req);
if (resp.getStatusCode() == 200) {
ObjectNode dataObj = mapper.createObjectNode();
// file name
String filename = getImageFileName(url);
String[] fileNameTokens = filename.split("\\.");
filename = fileNameTokens[0] + ".latest" + "." + fileNameTokens[1];
dataObj.put("fileName", filename);
// data
dataObj.put("data", resp.getContent());
brr.objectNode = dataObj;
} }
// brr.objectNode = resp.getContent(); } catch (Exception e) {
} catch (IOException e) { String err = "buildCameraResp() failed. e: " + e.toString();
logger.error(err);
e.printStackTrace(); e.printStackTrace();
return new BaseRestResponse(false, err);
} }
return brr; return brr;
} }
...@@ -275,6 +294,15 @@ public class GEManager { ...@@ -275,6 +294,15 @@ public class GEManager {
return newArray; return newArray;
} }
private String getImageFileName(String link) {
String[] linkTokens = link.split("/");
if(linkTokens.length > 1) {
return linkTokens[linkTokens.length-1];
}
else
return null;
}
private BaseRestResponse testGetImage(RequestContext requestContext, String[] apiIds) { private BaseRestResponse testGetImage(RequestContext requestContext, String[] apiIds) {
try { try {
......
...@@ -35,7 +35,7 @@ public class MdeManager { ...@@ -35,7 +35,7 @@ public class MdeManager {
private AdaptersRepository adaptersRepository; private AdaptersRepository adaptersRepository;
private ServicesRepository servicesRepository; private ServicesRepository servicesRepository;
private GEManager geManager = new GEManager(); private GEManager geManager = null;
public MdeManager(ILogger logger) throws Exception { public MdeManager(ILogger logger) throws Exception {
...@@ -44,6 +44,7 @@ public class MdeManager { ...@@ -44,6 +44,7 @@ public class MdeManager {
jsonPatchAddAppKey = Utils.readJsonNodeFromFile(Constants.CONFIG_LOCATION+"jsonPatchAddAppKey.json"); jsonPatchAddAppKey = Utils.readJsonNodeFromFile(Constants.CONFIG_LOCATION+"jsonPatchAddAppKey.json");
this.logger = logger; this.logger = logger;
geManager = new GEManager(logger);
LoadServices(logger); LoadServices(logger);
loadAdapters(logger); loadAdapters(logger);
ValidityCheck(); ValidityCheck();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment