summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java202
-rw-r--r--src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java490
-rw-r--r--src/main/java/org/onap/dcae/restapi/endpoints/Ui.java13
3 files changed, 336 insertions, 369 deletions
diff --git a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
index bd9a223e..babb184b 100644
--- a/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
+++ b/src/main/java/org/onap/dcae/restapi/RestfulCollectorServlet.java
@@ -21,17 +21,6 @@
package org.onap.dcae.restapi;
-import java.io.IOException;
-import java.net.URL;
-
-import javax.servlet.ServletException;
-
-import org.apache.tomcat.util.codec.binary.Base64;
-import org.onap.dcae.commonFunction.CommonStartup;
-import org.onap.dcae.commonFunction.VESLogger;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import com.att.nsa.apiServer.CommonServlet;
import com.att.nsa.configs.ConfigDbException;
import com.att.nsa.drumlin.service.framework.DrumlinErrorHandler;
@@ -43,108 +32,97 @@ import com.att.nsa.drumlin.till.nv.rrNvReadable;
import com.att.nsa.drumlin.till.nv.rrNvReadable.loadException;
import com.att.nsa.drumlin.till.nv.rrNvReadable.missingReqdSetting;
import com.att.nsa.security.NsaAuthenticator;
-
import com.att.nsa.security.authenticators.SimpleAuthenticator;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
+import org.apache.tomcat.util.codec.binary.Base64;
+import org.onap.dcae.commonFunction.CommonStartup;
+import org.onap.dcae.commonFunction.VESLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URL;
+import javax.servlet.ServletException;
-public class RestfulCollectorServlet extends CommonServlet
-{
- String authid = null;
- String authpwd = null;
- String authlist = null;
-
- public RestfulCollectorServlet ( rrNvReadable settings ) throws loadException, missingReqdSetting
- {
- super ( settings, "collector", false );
- authid = settings.getString(CommonStartup.kSetting_authid,null);
- if (authid != null)
- {
- String authpwdtemp = settings.getString(CommonStartup.kSetting_authpwd,null);
- authpwd = new String(Base64.decodeBase64(authpwdtemp));
- }
- authlist = settings.getString(CommonStartup.kSetting_authlist,null);
- }
-
-
- /**
- * This is called once at server start. Use it to init any shared objects and setup the route mapping.
- */
- @Override
- protected void servletSetup () throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, ServletException
- {
- super.servletSetup ();
-
- try
- {
- // the base class provides a bunch of things like API authentication and ECOMP compliant
- // logging. The Restful Collector likely doesn't need API authentication, so for now,
- // we init the base class services with an in-memory (and empty!) config DB.
- commonServletSetup ( ConfigDbType.MEMORY );
-
- VESLogger.setUpEcompLogging();
-
- // setup the servlet routing and error handling
- final DrumlinRequestRouter drr = getRequestRouter ();
-
- // you can tell the request router what to do when a particular kind of exception is thrown.
- drr.setHandlerForException( IllegalArgumentException.class, new DrumlinErrorHandler()
- {
- @Override
- public void handle ( DrumlinRequestContext ctx, Throwable cause )
- {
- sendJsonReply ( ctx, HttpStatusCodes.k400_badRequest, cause.getMessage() );
- }
- });
-
- // load the routes from the config file
- final URL routes = findStream ( "routes.conf" );
- if ( routes == null ) throw new rrNvReadable.missingReqdSetting ( "No routing configuration." );
- final DrumlinPlayishRoutingFileSource drs = new DrumlinPlayishRoutingFileSource ( routes );
- drr.addRouteSource ( drs );
-
- if (CommonStartup.authflag > 0) {
- NsaAuthenticator<NsaSimpleApiKey> NsaAuth = new SimpleAuthenticator ();
- if (authlist != null)
- {
- String authpair[] = authlist.split("\\|");
- for (String pair: authpair) {
- String lineid[] = pair.split(",");
- String listauthid = lineid[0];
- String listauthpwd = new String(Base64.decodeBase64(lineid[1]));
- ((SimpleAuthenticator) NsaAuth).add(listauthid,listauthpwd);
- }
-
- }
- else if (authid != null)
- {
- ((SimpleAuthenticator) NsaAuth).add(authid,authpwd);
- }
- else
- {
- //add a default test account
- ((SimpleAuthenticator) NsaAuth).add("admin","collectorpasscode");
- }
- this.getSecurityManager().addAuthenticator(NsaAuth);
- }
-
- log.info ( "Restful Collector Servlet is up." );
- }
- catch ( SecurityException e )
- {
- throw new ServletException ( e );
- }
- catch ( IOException e )
- {
- throw new ServletException ( e );
- }
- catch ( ConfigDbException e )
- {
- throw new ServletException ( e );
- }
- }
-
-
-
- private static final long serialVersionUID = 1L;
- private static final Logger log = LoggerFactory.getLogger ( RestfulCollectorServlet.class );
+public class RestfulCollectorServlet extends CommonServlet {
+
+ String authid;
+ String authpwd;
+ String authlist;
+
+ public RestfulCollectorServlet(rrNvReadable settings) throws loadException, missingReqdSetting {
+ super(settings, "collector", false);
+ authid = settings.getString(CommonStartup.kSetting_authid, null);
+ if (authid != null) {
+ String authpwdtemp = settings.getString(CommonStartup.kSetting_authpwd, null);
+ authpwd = new String(Base64.decodeBase64(authpwdtemp));
+ }
+ authlist = settings.getString(CommonStartup.kSetting_authlist, null);
+ }
+
+
+ /**
+ * This is called once at server start. Use it to init any shared objects and setup the route mapping.
+ */
+ @Override
+ protected void servletSetup()
+ throws rrNvReadable.missingReqdSetting, rrNvReadable.invalidSettingValue, ServletException {
+ super.servletSetup();
+
+ try {
+ // the base class provides a bunch of things like API authentication and ECOMP compliant
+ // logging. The Restful Collector likely doesn't need API authentication, so for now,
+ // we init the base class services with an in-memory (and empty!) config DB.
+ commonServletSetup(ConfigDbType.MEMORY);
+
+ VESLogger.setUpEcompLogging();
+
+ // setup the servlet routing and error handling
+ final DrumlinRequestRouter drr = getRequestRouter();
+
+ // you can tell the request router what to do when a particular kind of exception is thrown.
+ drr.setHandlerForException(IllegalArgumentException.class, new DrumlinErrorHandler() {
+ @Override
+ public void handle(DrumlinRequestContext ctx, Throwable cause) {
+ sendJsonReply(ctx, HttpStatusCodes.k400_badRequest, cause.getMessage());
+ }
+ });
+
+ // load the routes from the config file
+ final URL routes = findStream("routes.conf");
+ if (routes == null) {
+ throw new rrNvReadable.missingReqdSetting("No routing configuration.");
+ }
+ final DrumlinPlayishRoutingFileSource drs = new DrumlinPlayishRoutingFileSource(routes);
+ drr.addRouteSource(drs);
+
+ if (CommonStartup.authflag > 0) {
+ NsaAuthenticator<NsaSimpleApiKey> nsaAuth = new SimpleAuthenticator();
+ if (authlist != null) {
+ String[] authpair = authlist.split("\\|");
+ for (String pair : authpair) {
+ String[] lineid = pair.split(",");
+ String listauthid = lineid[0];
+ String listauthpwd = new String(Base64.decodeBase64(lineid[1]));
+ ((SimpleAuthenticator) nsaAuth).add(listauthid, listauthpwd);
+ }
+
+ } else if (authid != null) {
+ ((SimpleAuthenticator) nsaAuth).add(authid, authpwd);
+ } else {
+ //add a default test account
+ ((SimpleAuthenticator) nsaAuth).add("admin", "collectorpasscode");
+ }
+ this.getSecurityManager().addAuthenticator(nsaAuth);
+ }
+
+ log.info("Restful Collector Servlet is up.");
+ } catch (SecurityException | IOException | ConfigDbException e) {
+ throw new ServletException(e);
+ }
+ }
+
+
+ private static final long serialVersionUID = 1L;
+ private static final Logger log = LoggerFactory.getLogger(RestfulCollectorServlet.class);
}
diff --git a/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java b/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java
index 159d483a..e6b7d20c 100644
--- a/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java
+++ b/src/main/java/org/onap/dcae/restapi/endpoints/EventReceipt.java
@@ -20,267 +20,259 @@
package org.onap.dcae.restapi.endpoints;
-import java.io.FileReader;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.UUID;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.json.JSONTokener;
-import org.onap.dcae.commonFunction.CommonStartup;
-import org.onap.dcae.commonFunction.CustomExceptionLoader;
-import org.onap.dcae.commonFunction.VESLogger;
-import org.onap.dcae.commonFunction.CommonStartup.QueueFullException;
-
import com.att.nsa.apiServer.endpoints.NsaBaseEndpoint;
import com.att.nsa.clock.SaClock;
import com.att.nsa.drumlin.service.framework.context.DrumlinRequestContext;
import com.att.nsa.drumlin.service.standards.HttpStatusCodes;
import com.att.nsa.drumlin.service.standards.MimeTypes;
import com.att.nsa.logging.LoggingContext;
-
import com.att.nsa.logging.log4j.EcompFields;
import com.att.nsa.security.db.simple.NsaSimpleApiKey;
-
import com.google.gson.JsonParser;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+import org.json.JSONTokener;
+import org.onap.dcae.commonFunction.CommonStartup;
+import org.onap.dcae.commonFunction.CommonStartup.QueueFullException;
+import org.onap.dcae.commonFunction.CustomExceptionLoader;
+import org.onap.dcae.commonFunction.VESLogger;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EventReceipt extends NsaBaseEndpoint {
- static String valresult = null;
- static JSONObject customerror = null;
-
- private static final Logger log = LoggerFactory.getLogger(EventReceipt.class);
-
-
- public static void receiveVESEvent(DrumlinRequestContext ctx) throws IOException {
- // the request body carries events. assume for now it's an array
- // of json objects that fits in memory. (See cambria's parsing for
- // handling large messages)
-
- NsaSimpleApiKey retkey = null;
-
- JSONArray jsonArray = null;
- JSONArray jsonArrayMod = new JSONArray();
- JSONObject event = null;
- JSONObject jsonObject = null;
- FileReader fr = null;
- InputStream istr = null;
- int arrayflag = 0;
- String vesversion = null;
-
-
-
- try {
- //System.out.print("Version string:" + version);
-
- // String br = new BufferedReader(new InputStreamReader(ctx.request().getBodyStream())).readLine();
- // JsonElement msg = new JsonParser().parse(new BufferedReader(new InputStreamReader(ctx.request().getBodyStream())).readLine());
- // jsonArray = new JSONArray ( new JSONTokener ( ctx.request().getBodyStream () ) );
-
-
- log.debug ("Request recieved :" + ctx.request().getRemoteAddress());
- istr = ctx.request().getBodyStream();
- jsonObject = new JSONObject(new JSONTokener(istr));
-
- log.info("ctx getPathInContext: " + ctx.request().getPathInContext());
- Pattern p = Pattern.compile("(v\\d+)");
- Matcher m = p.matcher(ctx.request().getPathInContext());
-
- if (m.find()) {
- log.info("VES version:" + m.group());
- vesversion = m.group();
- }
- if (ctx.request().getPathInContext().contains("eventBatch"))
- {
- CommonStartup.inlog.info(ctx.request().getRemoteAddress() + "VES Batch Input Messsage: " + jsonObject);
- log.info(ctx.request().getRemoteAddress() + "VES Batch Input Messsage: " + jsonObject);
- arrayflag = 1;
- }
- else
- {
- CommonStartup.inlog.info(ctx.request().getRemoteAddress() + "Input Messsage: " + jsonObject);
- log.info(ctx.request().getRemoteAddress() + "Input Messsage: " + jsonObject);
-
- }
-
-
- final UUID uuid = java.util.UUID.randomUUID();
- LoggingContext localLC = VESLogger.getLoggingContextForThread(uuid);
- localLC .put ( EcompFields.kBeginTimestampMs, SaClock.now () );
-
-
-
- try {
- if (CommonStartup.authflag == 1) {
- retkey = NsaBaseEndpoint.getAuthenticatedUser(ctx);
- }
- } catch (NullPointerException x) {
- log.info(
- "Invalid user request " + ctx.request().getContentType() + " Message:" + jsonObject.toString());
- CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Unauthorized user" + x.toString());
- respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized, "Invalid user");
- return;
- }
-
- if (retkey != null || CommonStartup.authflag == 0) {
- if (CommonStartup.schema_Validatorflag > 0) {
-
- //fr = new FileReader(CommonStartup.schemaFile);
- fr = new FileReader(schemaFileVersion(vesversion));
- String schema = new JsonParser().parse(fr).toString();
-
- valresult = CommonStartup.schemavalidate(jsonObject.toString(), schema);
- if (valresult.equals("true")) {
- log.info("Validation successful");
- } else if (valresult.equals("false")) {
- log.info("Validation failed");
- respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest, "Schema validation failed");
-
- return;
- } else {
- log.error("Validation errored" + valresult);
- respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest, "Couldn't parse JSON object");
- return;
-
- }
-
-
- if (arrayflag ==1) {
- jsonArray = jsonObject.getJSONArray("eventList");
- log.info("Validation successful for all events in batch");
- for (int i = 0; i < jsonArray.length(); i++) {
- event = new JSONObject().put("event", jsonArray.getJSONObject(i));
- event.put("VESuniqueId", uuid + "-"+i);
- event.put("VESversion", vesversion);
- jsonArrayMod.put(event);
- }
-
- log.info("Modified jsonarray:" + jsonArrayMod.toString());
-
- }
- else
- {
-
- jsonObject.put("VESuniqueId", uuid);
- jsonObject.put("VESversion", vesversion);
- jsonArrayMod = new JSONArray().put(jsonObject);
- }
-
- }
- // reject anything that's not JSON
- if (!ctx.request().getContentType().equalsIgnoreCase("application/json")) {
- log.info("Rejecting request with content type " + ctx.request().getContentType() + " Message:"
- + jsonObject);
- respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
- "Incorrect message content-type; only accepts application/json messages");
- return;
- }
-
- CommonStartup.handleEvents(jsonArrayMod);
- } else {
- log.info(
- "Unauthorized request " + ctx.request().getContentType() + " Message:" + jsonObject.toString());
- respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized, "Unauthorized user");
- return;
- }
- } catch (JSONException | NullPointerException | IOException x) {
- log.error("Couldn't parse JSON Array - HttpStatusCodes.k400_badRequest" + HttpStatusCodes.k400_badRequest
- + " Message:" + x.getMessage());
- CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Invalid user request " + x.toString());
- respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest, "Couldn't parse JSON object");
- return;
- } catch (QueueFullException e) {
- e.printStackTrace();
- log.error("Collector internal queue full :" + e.getMessage());
- CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: QueueFull" + e.toString());
- respondWithCustomMsginJson(ctx, HttpStatusCodes.k503_serviceUnavailable, "Queue full");
- return;
- } finally {
- if (fr != null) {
- safeClose(fr);
- }
-
- if (istr != null) {
- safeClose(istr);
- }
- }
- log.info("MessageAccepted and k200_ok to be sent");
- ctx.response().sendErrorAndBody(HttpStatusCodes.k200_ok, "Message Accepted", MimeTypes.kAppJson);
- }
-
-
- public static void respondWithCustomMsginJson(DrumlinRequestContext ctx, int sc, String msg) {
- String[] str = null;
- String ExceptionType = "GeneralException";
-
- str = CustomExceptionLoader.LookupMap(String.valueOf(sc), msg);
- System.out.println("Post CustomExceptionLoader.LookupMap" + str);
-
- if (str != null) {
-
- if (str[0].matches("SVC")) {
- ExceptionType = "ServiceException";
- } else if (str[1].matches("POL")) {
- ExceptionType = "PolicyException";
- }
-
- JSONObject jb = new JSONObject().put("requestError",
- new JSONObject().put(ExceptionType, new JSONObject().put("MessagID", str[0]).put("text", str[1])));
-
- log.debug("Constructed json error : " + jb.toString());
- ctx.response().sendErrorAndBody(sc, jb.toString(), MimeTypes.kAppJson);
- } else {
- JSONObject jb = new JSONObject().put("requestError",
- new JSONObject().put(ExceptionType, new JSONObject().put("Status", sc).put("Error", msg)));
- ctx.response().sendErrorAndBody(sc, jb.toString(), MimeTypes.kAppJson);
- }
-
- }
-
- public static void safeClose(FileReader fr) {
- if (fr != null) {
- try {
- fr.close();
- } catch (IOException e) {
- log.error("Error closing file reader stream : " + e.toString());
- }
- }
-
- }
-
- public static void safeClose(InputStream is) {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {
- log.error("Error closing Input stream : " + e.toString());
- }
- }
-
- }
-
- public static String schemaFileVersion(String version)
- {
- String filename = null;
-
- if (CommonStartup.schemaFileJson.has(version))
- {
- filename = CommonStartup.schemaFileJson.getString(version);
- }
- else
- {
- filename = CommonStartup.schemaFile;
- }
- log.info("VESversion: " + version + " Schema File:" + filename);
- return filename;
-
- }
-
+
+ private static final Logger log = LoggerFactory.getLogger(EventReceipt.class);
+ private static final String MESSAGE = " Message:";
+ static String valresult;
+ static JSONObject customerror;
+
+
+ public static void receiveVESEvent(DrumlinRequestContext ctx) {
+ // the request body carries events. assume for now it's an array
+ // of json objects that fits in memory. (See cambria's parsing for
+ // handling large messages)
+
+ NsaSimpleApiKey retkey = null;
+
+ JSONArray jsonArray;
+ JSONArray jsonArrayMod = new JSONArray();
+ JSONObject event;
+ JSONObject jsonObject;
+ FileReader fr = null;
+ InputStream istr = null;
+ int arrayFlag = 0;
+ String vesVersion = null;
+
+ try {
+ //System.out.print("Version string:" + version);
+
+ // String br = new BufferedReader(new InputStreamReader(ctx.request().getBodyStream())).readLine();
+ // JsonElement msg = new JsonParser().parse(new BufferedReader(new InputStreamReader(ctx.request().getBodyStream())).readLine());
+ // jsonArray = new JSONArray ( new JSONTokener ( ctx.request().getBodyStream () ) );
+
+ log.debug("Request recieved :" + ctx.request().getRemoteAddress());
+ istr = ctx.request().getBodyStream();
+ jsonObject = new JSONObject(new JSONTokener(istr));
+
+ log.info("ctx getPathInContext: " + ctx.request().getPathInContext());
+ Pattern p = Pattern.compile("(v\\d+)");
+ Matcher m = p.matcher(ctx.request().getPathInContext());
+
+ if (m.find()) {
+ log.info("VES version:" + m.group());
+ vesVersion = m.group();
+ }
+ if (ctx.request().getPathInContext().contains("eventBatch")) {
+ CommonStartup.inlog.info(
+ ctx.request().getRemoteAddress() + "VES Batch Input Messsage: " + jsonObject);
+ log.info(
+ ctx.request().getRemoteAddress() + "VES Batch Input Messsage: " + jsonObject);
+ arrayFlag = 1;
+ } else {
+ CommonStartup.inlog
+ .info(ctx.request().getRemoteAddress() + "Input Messsage: " + jsonObject);
+ log.info(ctx.request().getRemoteAddress() + "Input Messsage: " + jsonObject);
+
+ }
+
+ UUID uuid = UUID.randomUUID();
+ LoggingContext localLC = VESLogger.getLoggingContextForThread(uuid);
+ localLC.put(EcompFields.kBeginTimestampMs, SaClock.now());
+
+ try {
+ if (CommonStartup.authflag == 1) {
+ retkey = NsaBaseEndpoint.getAuthenticatedUser(ctx);
+ }
+ } catch (NullPointerException x) {
+ log.info(
+ "Invalid user request " + ctx.request().getContentType() + MESSAGE
+ + jsonObject);
+ CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Unauthorized user" + x);
+ respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized, "Invalid user");
+ return;
+ }
+
+ if (retkey != null || CommonStartup.authflag == 0) {
+ if (CommonStartup.schema_Validatorflag > 0) {
+
+ //fr = new FileReader(CommonStartup.schemaFile);
+ fr = new FileReader(schemaFileVersion(vesVersion));
+ String schema = new JsonParser().parse(fr).toString();
+
+ valresult = CommonStartup.schemavalidate(jsonObject.toString(), schema);
+ if ("true".equals(valresult)) {
+ log.info("Validation successful");
+ } else if ("false".equals(valresult)) {
+ log.info("Validation failed");
+ respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
+ "Schema validation failed");
+
+ return;
+ } else {
+ log.error("Validation errored" + valresult);
+ respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
+ "Couldn't parse JSON object");
+ return;
+
+ }
+
+ if (arrayFlag == 1) {
+ jsonArray = jsonObject.getJSONArray("eventList");
+ log.info("Validation successful for all events in batch");
+ for (int i = 0; i < jsonArray.length(); i++) {
+ event = new JSONObject().put("event", jsonArray.getJSONObject(i));
+ event.put("VESuniqueId", uuid + "-" + i);
+ event.put("VESversion", vesVersion);
+ jsonArrayMod.put(event);
+ }
+
+ log.info("Modified jsonarray:" + jsonArrayMod);
+
+ } else {
+
+ jsonObject.put("VESuniqueId", uuid);
+ jsonObject.put("VESversion", vesVersion);
+ jsonArrayMod = new JSONArray().put(jsonObject);
+ }
+
+ }
+ // reject anything that's not JSON
+ if (!ctx.request().getContentType().equalsIgnoreCase("application/json")) {
+ log.info(String.format("Rejecting request with content type %s Message:%s",
+ ctx.request().getContentType(), jsonObject));
+ respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
+ "Incorrect message content-type; only accepts application/json messages");
+ return;
+ }
+
+ CommonStartup.handleEvents(jsonArrayMod);
+ } else {
+ log.info(
+ String.format("Unauthorized request %s%s%s", ctx.request().getContentType(),
+ MESSAGE, jsonObject));
+ respondWithCustomMsginJson(ctx, HttpStatusCodes.k401_unauthorized,
+ "Unauthorized user");
+ return;
+ }
+ } catch (JSONException | NullPointerException | IOException x) {
+ log.error(String
+ .format("Couldn't parse JSON Array - HttpStatusCodes.k400_badRequest%d%s%s",
+ HttpStatusCodes.k400_badRequest, MESSAGE, x.getMessage()));
+ CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: Invalid user request " + x);
+ respondWithCustomMsginJson(ctx, HttpStatusCodes.k400_badRequest,
+ "Couldn't parse JSON object");
+ return;
+ } catch (QueueFullException e) {
+ log.error("Collector internal queue full :" + e.getMessage(), e);
+ CommonStartup.eplog.info("EVENT_RECEIPT_FAILURE: QueueFull" + e);
+ respondWithCustomMsginJson(ctx, HttpStatusCodes.k503_serviceUnavailable, "Queue full");
+ return;
+ } finally {
+ if (fr != null) {
+ safeClose(fr);
+ }
+
+ if (istr != null) {
+ safeClose(istr);
+ }
+ }
+ log.info("MessageAccepted and k200_ok to be sent");
+ ctx.response()
+ .sendErrorAndBody(HttpStatusCodes.k200_ok, "Message Accepted", MimeTypes.kAppJson);
+ }
+
+
+ public static void respondWithCustomMsginJson(DrumlinRequestContext ctx, int sc, String msg) {
+ String[] str;
+ String exceptionType = "GeneralException";
+
+ str = CustomExceptionLoader.LookupMap(String.valueOf(sc), msg);
+ log.info("Post CustomExceptionLoader.LookupMap" + str);
+
+ if (str != null) {
+
+ if (str[0].matches("SVC")) {
+ exceptionType = "ServiceException";
+ } else if (str[1].matches("POL")) {
+ exceptionType = "PolicyException";
+ }
+
+ JSONObject jb = new JSONObject().put("requestError",
+ new JSONObject().put(exceptionType,
+ new JSONObject().put("MessagID", str[0]).put("text", str[1])));
+
+ log.debug("Constructed json error : " + jb);
+ ctx.response().sendErrorAndBody(sc, jb.toString(), MimeTypes.kAppJson);
+ } else {
+ JSONObject jb = new JSONObject().put("requestError",
+ new JSONObject()
+ .put(exceptionType, new JSONObject().put("Status", sc).put("Error", msg)));
+ ctx.response().sendErrorAndBody(sc, jb.toString(), MimeTypes.kAppJson);
+ }
+
+ }
+
+ public static void safeClose(FileReader fr) {
+ if (fr != null) {
+ try {
+ fr.close();
+ } catch (IOException e) {
+ log.error("Error closing file reader stream : " + e);
+ }
+ }
+
+ }
+
+ public static void safeClose(InputStream is) {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ log.error("Error closing Input stream : " + e);
+ }
+ }
+
+ }
+
+ public static String schemaFileVersion(String version) {
+ String filename = null;
+
+ if (CommonStartup.schemaFileJson.has(version)) {
+ filename = CommonStartup.schemaFileJson.getString(version);
+ } else {
+ filename = CommonStartup.schemaFile;
+ }
+ log.info(String.format("VESversion: %s Schema File:%s", version, filename));
+ return filename;
+
+ }
}
diff --git a/src/main/java/org/onap/dcae/restapi/endpoints/Ui.java b/src/main/java/org/onap/dcae/restapi/endpoints/Ui.java
index 36747660..ae593b44 100644
--- a/src/main/java/org/onap/dcae/restapi/endpoints/Ui.java
+++ b/src/main/java/org/onap/dcae/restapi/endpoints/Ui.java
@@ -20,15 +20,12 @@
package org.onap.dcae.restapi.endpoints;
-import java.io.IOException;
-
import com.att.nsa.apiServer.endpoints.NsaBaseEndpoint;
import com.att.nsa.drumlin.service.framework.context.DrumlinRequestContext;
-public class Ui extends NsaBaseEndpoint
-{
- public static void hello ( DrumlinRequestContext ctx ) throws IOException
- {
- ctx.renderer ().renderTemplate ( "templates/hello.html" );
- }
+public class Ui extends NsaBaseEndpoint {
+
+ public static void hello(DrumlinRequestContext ctx) {
+ ctx.renderer().renderTemplate("templates/hello.html");
+ }
}