Commit 4b908432 by Adi Amir

support binary content

parent 0d8514fa
......@@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
def gitLog() { return "git log --pretty=format:'%h' -n 1".execute().text.trim().replaceAll("'", "") }
group = 'com.ipgallery'
version = '1.0.1' + gitLog()
version = '1.0.2' + gitLog()
sourceCompatibility = 1.8
repositories {
......@@ -16,7 +16,7 @@ repositories {
dependencies {
// 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.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 'com.ipgallery.common:utils:1.1.0'
compile 'io.swagger:swagger-annotations:1.5.7'
......
......@@ -8,6 +8,7 @@ import http.simpleHttpClient.SimpleHttpClient;
import http.simpleHttpClient.SimpleHttpRequest;
import http.simpleHttpClient.SimpleHttpResponse;
import microservice.RequestContext;
import microservice.io.iface.ILogger;
import microservice.types.BaseRestResponse;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
......@@ -45,8 +46,10 @@ public class GEManager {
public static String TOKEN = "NOT_VALID";
private SimpleHttpClient httpClient = null;
private ILogger logger;
public GEManager() throws Exception {
public GEManager(ILogger logger) throws Exception {
this.logger = logger;
httpClient = new SimpleHttpClient();
httpClient.Initialize(100);
}
......@@ -77,6 +80,7 @@ public class GEManager {
req = buildCameraHttpRequest(requestContext,content,apiIdAsParams);
try {
resp = httpClient.processRequest(req);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
......@@ -88,6 +92,9 @@ public class GEManager {
else
brr.setError("failed to retrieve a valid token");
}
else {
brr.setError("processRequest() failed. path: " + req.getPath() + " resp: " + resp.toString());
}
return brr;
}
......@@ -145,13 +152,25 @@ public class GEManager {
ObjectNode objectNode = mapper.createObjectNode();
JsonNode contentObj = mapper.readTree(content);
JsonNode arrNode = contentObj.get("content");
if (arrNode.isArray()) {
req = buildOpenCameraLinkRequest(arrNode.get(0).get("url").asText());
resp = httpClient.processRequest(req);
String url = arrNode.get(0).get("url").asText();
req = buildOpenCameraLinkRequest(url);
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 (IOException e) {
} catch (Exception e) {
String err = "buildCameraResp() failed. e: " + e.toString();
logger.error(err);
e.printStackTrace();
return new BaseRestResponse(false, err);
}
return brr;
}
......@@ -275,6 +294,15 @@ public class GEManager {
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) {
try {
......
......@@ -35,7 +35,7 @@ public class MdeManager {
private AdaptersRepository adaptersRepository;
private ServicesRepository servicesRepository;
private GEManager geManager = new GEManager();
private GEManager geManager = null;
public MdeManager(ILogger logger) throws Exception {
......@@ -44,6 +44,7 @@ public class MdeManager {
jsonPatchAddAppKey = Utils.readJsonNodeFromFile(Constants.CONFIG_LOCATION+"jsonPatchAddAppKey.json");
this.logger = logger;
geManager = new GEManager(logger);
LoadServices(logger);
loadAdapters(logger);
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