|
|
|
@ -6,6 +6,7 @@ import java.io.BufferedReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
import java.util.Base64;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
@ -57,28 +58,41 @@ public class DdasVREService extends HttpServlet {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
_log.error("Error parsing JSON request string", e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
BrokerResponse theResponse = null;
|
|
|
|
|
String requestId = jsonObject.get("request_id").getAsString();
|
|
|
|
|
if (requestId == null || requestId.equals("")) {
|
|
|
|
|
String requestId = null;
|
|
|
|
|
try {
|
|
|
|
|
requestId = jsonObject.get("requestId").getAsString();
|
|
|
|
|
if (requestId == null || requestId.equals("")) {
|
|
|
|
|
theResponse = new BrokerResponse(405, "Method Not Allowed, something is wrong in the JSON, request_id not found", null);
|
|
|
|
|
}
|
|
|
|
|
} catch (NullPointerException ex) {
|
|
|
|
|
_log.error("Error parsing JSON request string, request_id paarm not found");
|
|
|
|
|
theResponse = new BrokerResponse(405, "Method Not Allowed, something is wrong in the JSON, request_id not found", null);
|
|
|
|
|
String toReturn = gson.toJson(theResponse);
|
|
|
|
|
response.setContentType("application/json");
|
|
|
|
|
response.getWriter().write(toReturn);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_log.debug("GOT JSON");
|
|
|
|
|
_log.debug("JSON="+jsonObject.toString());
|
|
|
|
|
boolean result = authorizeRequest(requestId, jsonObject);
|
|
|
|
|
|
|
|
|
|
String otp = UUID.randomUUID().toString();
|
|
|
|
|
boolean result = authorizeRequest(otp, jsonObject);
|
|
|
|
|
if (result) {
|
|
|
|
|
int status = 200;
|
|
|
|
|
Base64.Encoder withoutPaddingEncoder = Base64.getEncoder().withoutPadding();
|
|
|
|
|
String requestIdParam = withoutPaddingEncoder.encodeToString("request_id".getBytes());
|
|
|
|
|
String requestIdParam = withoutPaddingEncoder.encodeToString("otp".getBytes());
|
|
|
|
|
String message = "Started downloading order files to Virtual Research Environment '"+requestId+"'";
|
|
|
|
|
String vreConfirmUrl = "https://blue-cloud.d4science.org/group/bluecloud-gateway/vre-data-pool?"+requestIdParam+"="+requestId; //redirect URL
|
|
|
|
|
String vreConfirmUrl = "https://blue-cloud.d4science.org/group/bluecloud-gateway/vre-data-pool?"+requestIdParam+"="+otp; //redirect URL
|
|
|
|
|
URL theURL = new URL(vreConfirmUrl);
|
|
|
|
|
theResponse = new BrokerResponse(status, message, theURL);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
theResponse = new BrokerResponse(500, "An error occurred in the VRE Service, downlaod not possible", null);
|
|
|
|
|
}
|
|
|
|
|
Gson gson = new Gson();
|
|
|
|
|
|
|
|
|
|
String toReturn = gson.toJson(theResponse);
|
|
|
|
|
response.setContentType("application/json");
|
|
|
|
|
response.getWriter().write(toReturn);
|
|
|
|
@ -90,11 +104,11 @@ public class DdasVREService extends HttpServlet {
|
|
|
|
|
* @param jsonObject
|
|
|
|
|
* @return true if the operations is successful
|
|
|
|
|
*/
|
|
|
|
|
private boolean authorizeRequest(String requestId,JsonObject jsonObject) {
|
|
|
|
|
private boolean authorizeRequest(String expiry_token,JsonObject jsonObject) {
|
|
|
|
|
OperationFuture<Boolean> writeOp = null;
|
|
|
|
|
try {
|
|
|
|
|
MemcachedClient mClient = new DistributedCacheClient().getMemcachedClient();
|
|
|
|
|
writeOp = mClient.set(requestId, CACHE_SECONDS_EXPIRATION, jsonObject.toString());
|
|
|
|
|
writeOp = mClient.set(expiry_token, CACHE_SECONDS_EXPIRATION, jsonObject.toString());
|
|
|
|
|
Thread.sleep(500);
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|