-
- String targetUrl = "http://" + host + ":" + port + "/" + this.targetUri;
- auditLogger.info(DataRouterMsgs.ROUTING_FROM_TO, this.getOriginUrl(), targetUrl);
- long startTimeInMs = System.currentTimeMillis();
-
- result = this.getResults(targetUrl, targetPayload);
-
- long targetMsOpTime = (System.currentTimeMillis() - startTimeInMs);
- auditLogger.info(DataRouterMsgs.OP_TIME, "Target service at "+ targetUrl, String.valueOf(targetMsOpTime));
-
- int rc = result.getResultCode();
- String resultStr = "";
- if (HttpUtil.isHttpResponseClassSuccess(rc)) {
- resultStr = result.getResult();
- } else {
- resultStr = result.getFailureCause();
+
+ public final void handleRequest(String host, String port, Exchange exchange) throws Exception {
+ RouterServiceUtil.setMdcContext(exchange);
+ Message message = exchange.getIn();
+ String body = message.getBody(String.class);
+ OperationResult result = new OperationResult();
+
+ this.setHost(host);
+ this.setPort(port);
+
+ this.setOriginUrl(message.getHeader(Exchange.HTTP_URL).toString());
+ if (body != null && body.length() != 0) {
+ JsonNode node = NodeUtils.convertJsonStrToJsonNode(body);
+ this.setTargetPayload(AaiUiSvcPolicyUtil.getOriginPayload(node));
+ this.setTargetUri(AaiUiSvcPolicyUtil.getTargetUri(node));
+ }
+
+ if (this.getTargetPayload() == null || this.getTargetUri() == null) {
+ logger.error(DataRouterMsgs.INVALID_ORIGIN_PAYLOAD, body);
+ result.setResultCode(HttpStatus.BAD_REQUEST.value());
+ result.setFailureCause("Invalid payload");
+ }
+
+ String targetUrl = "http://" + host + ":" + port + "/" + this.targetUri;
+ auditLogger.info(DataRouterMsgs.ROUTING_FROM_TO, this.getOriginUrl(), targetUrl);
+ long startTimeInMs = System.currentTimeMillis();
+
+ result = this.getResults(targetUrl, targetPayload);
+
+ long targetMsOpTime = System.currentTimeMillis() - startTimeInMs;
+ auditLogger.info(DataRouterMsgs.OP_TIME, "Target service at " + targetUrl, String.valueOf(targetMsOpTime));
+
+ int rc = result.getResultCode();
+ String resultStr;
+ if (HttpUtil.isHttpResponseClassSuccess(rc)) {
+ resultStr = result.getResult();
+ } else {
+ resultStr = result.getFailureCause();
+ }
+
+ logger.debug(DataRouterMsgs.ROUTING_RESPONSE, targetUrl, result.toString());
+ exchange.getOut().setHeader(Exchange.HTTP_RESPONSE_CODE, rc);
+ exchange.getOut().setBody(resultStr);
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#getHost()
+ */
+ @Override
+ public String getHost() {
+ return host;
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#setHost(java.lang.String)
+ */
+ @Override
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#getPort()
+ */
+ @Override
+ public String getPort() {
+ return port;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#setPort(java.lang.String)
+ */
+ @Override
+ public void setPort(String port) {
+ this.port = port;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#getTargetUri()
+ */
+ @Override
+ public String getTargetUri() {
+ return targetUri;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#setTargetUri(java.lang.String)
+ */
+ @Override
+ public void setTargetUri(String targetUri) {
+ this.targetUri = targetUri;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#getTargetPayload()
+ */
+ @Override
+ public JsonNode getTargetPayload() {
+ return targetPayload;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client
+ * .SvcRoutingRestClient#setTargetPayload(com.fasterxml.jackson.databind.JsonNode)
+ */
+ @Override
+ public void setTargetPayload(JsonNode targetPayload) {
+ this.targetPayload = targetPayload;
+ }
+
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#getRestClient()
+ */
+ @Override
+ public RestClient getRestClient() {
+ return restClient;
+ }
+
+ /* (non-Javadoc)
+ * @see org.openecomp.datarouter.util.client.SvcRoutingRestClient#setRestClient()
+ */
+ @Override
+ public void setRestClient(RestClient client) {
+ this.restClient = client;
+ }
+
+
+ public String getOriginUrl() {
+ return originUrl;
+ }
+
+
+ public void setOriginUrl(String originUrl) {
+ this.originUrl = originUrl;