From e02d336413547e33f6dfa17e10e60da0e6bbb535 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 10 Oct 2017 12:59:47 +0530 Subject: [PATCH] Fixed issue in MT --- .../output/adapter/http/HTTPEventAdapter.java | 42 +++++++------------ 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java index 0fdd7189f..a37f49b71 100644 --- a/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java +++ b/components/extensions/cdmf-transport-adapters/output/org.wso2.carbon.device.mgt.output.adapter.http/src/main/java/org/wso2/carbon/device/mgt/output/adapter/http/HTTPEventAdapter.java @@ -27,10 +27,8 @@ import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpPost; -import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHeader; @@ -70,9 +68,11 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; public class HTTPEventAdapter implements OutputEventAdapter { + private static final Log log = LogFactory.getLog(OutputEventAdapter.class); - private static ExecutorService executorService; - private static HttpConnectionManager connectionManager; + + private ExecutorService executorService; + private HttpConnectionManager connectionManager; private OutputEventAdapterConfiguration eventAdapterConfiguration; private Map globalProperties; private String clientMethod; @@ -81,7 +81,8 @@ public class HTTPEventAdapter implements OutputEventAdapter { private String contentType; private HttpClient httpClient = null; private HostConfiguration hostConfiguration = null; - private String clientId, clientSecret; + private String clientId; + private String clientSecret; public HTTPEventAdapter(OutputEventAdapterConfiguration eventAdapterConfiguration, @@ -166,7 +167,7 @@ public class HTTPEventAdapter implements OutputEventAdapter { @Override public void connect() { - this.checkHTTPClientInit(eventAdapterConfiguration.getStaticProperties()); + this.checkHTTPClientInit(); httpConnectionConfiguration = new HTTPConnectionConfiguration(eventAdapterConfiguration, globalProperties); generateToken(); @@ -185,8 +186,6 @@ public class HTTPEventAdapter implements OutputEventAdapter { } catch (RejectedExecutionException e) { EventAdapterUtil .logAndDrop(eventAdapterConfiguration.getName(), message, "Job queue is full", e, log, tenantId); - } catch (MalformedURLException e) { - log.error("Malformed url: '" + url + "'", e); } } @@ -205,7 +204,7 @@ public class HTTPEventAdapter implements OutputEventAdapter { return false; } - private void checkHTTPClientInit(Map staticProperties) { + private void checkHTTPClientInit() { if (this.httpClient != null) { return; @@ -321,38 +320,27 @@ public class HTTPEventAdapter implements OutputEventAdapter { private HttpClient httpClient; - public HTTPSender(String url, String payload, Map headers, - HttpClient httpClient) throws MalformedURLException { - - if (tenantId == -1234) { - this.url = url; - } else { - URL urlObj = new URL(url); - String protocol = urlObj.getProtocol(); - String host = urlObj.getHost(); - int port = urlObj.getPort(); - String path = "t/" + PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getTenantDomain(true) + "/" + urlObj.getPath(); - this.url = protocol + "://" + host + ":" + port + "/" + path; - } + HTTPSender(String url, String payload, Map headers, + HttpClient httpClient) { + this.url = url; this.payload = payload; this.headers = headers; this.httpClient = httpClient; } - public String getUrl() { + String getUrl() { return url; } - public String getPayload() { + String getPayload() { return payload; } - public Map getHeaders() { + Map getHeaders() { return headers; } - public HttpClient getHttpClient() { + HttpClient getHttpClient() { return httpClient; }