/**
* ============LICENSE_START=======================================================
- * DataRouter
+ * org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
* Copyright © 2017 Amdocs
- * All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* limitations under the License.
* ============LICENSE_END=========================================================
*
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.openecomp.datarouter.util;
import com.fasterxml.jackson.databind.JsonNode;
+import org.apache.camel.Exchange;
+import org.apache.camel.component.cxf.common.message.CxfConstants;
+import org.apache.cxf.message.Message;
import org.json.JSONObject;
+import org.onap.aai.cl.mdc.MdcContext;
+import org.onap.aai.restclient.client.Headers;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
+
+import javax.servlet.ServletRequest;
public class RouterServiceUtil {
+
+ public static void setMdcContext(Exchange exchange){
+ String txnID = exchange.getIn().getHeader(Headers.TRANSACTION_ID,
+ Arrays.asList(UUID.randomUUID())).toString();
+ String remote = exchange.getIn().getHeader(Headers.FROM_APP_ID, "").toString();
+ String remoteAddress = "";
+ Message cxfMessage = exchange.getIn().getHeader(CxfConstants.CAMEL_CXF_MESSAGE, Message.class);
+ if (cxfMessage != null) {
+ ServletRequest request = (ServletRequest) cxfMessage.get("HTTP.REQUEST");
+ if ( request != null)
+ remoteAddress = request.getRemoteAddr();
+ }
+
+ MdcContext.initialize(txnID, "Synapse", "", remote, remoteAddress);
+ }
public static Map<String, String> parseJsonPayloadIntoMap(String jsonPayload) {
String json = jsonObject.toString();
return json;
}
+
+ /**
+ * Helper utility to concatenate substrings of a URI together to form a proper URI.
+ *
+ * @param suburis the list of substrings to concatenate together
+ * @return the concatenated list of substrings
+ */
+ public static String concatSubUri(String... suburis) {
+ String finalUri = "";
+
+ for (String suburi : suburis) {
+
+ if (suburi != null) {
+ // Remove any leading / since we only want to append /
+ suburi = suburi.replaceFirst("^/*", "");
+
+ // Add a trailing / if one isn't already there
+ finalUri += suburi.endsWith("/") ? suburi : suburi + "/";
+ }
+ }
+
+ return finalUri;
+ }
}