public class MRBaseClient extends HttpClient implements MRClient {
+ private final static String HEADER_TRANSACTION_ID = "transactionid";
+
+ private final static String JSON_RESULT = "result";
+ private final static String JSON_STATUS = "status";
+
+ private final static String AUTH_FAILED = "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.";
+ private final static String LOG_TRANSACTION_ID = "TransactionId : ";
+
private ClientConfig clientConfig = null;
protected MRBaseClient(Collection<String> hosts) throws MalformedURLException {
- super(ConnectionType.HTTP, hosts, MRConstants.kStdMRServicePort);
+ super(ConnectionType.HTTP, hosts, MRConstants.STD_MR_SERVICE_PORT);
fLog = LoggerFactory.getLogger(this.getClass().getName());
}
}
protected MRBaseClient(Collection<String> hosts, String clientSignature) throws MalformedURLException {
- super(ConnectionType.HTTP, hosts, MRConstants.kStdMRServicePort, clientSignature, CacheUse.NONE, 1, 1L,
+ super(ConnectionType.HTTP, hosts, MRConstants.STD_MR_SERVICE_PORT, clientSignature, CacheUse.NONE, 1, 1L,
TimeUnit.MILLISECONDS, 32, 32, 600000);
fLog = LoggerFactory.getLogger(this.getClass().getName());
@Override
public void close() {
+ // nothing to close
}
protected Set<String> jsonArrayToSet(JSONArray a) {
return getResponseDataInJson(response);
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
responseData = (String) response.readEntity(String.class);
return responseData;
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
postAuthDO.getAuthDate(), postAuthDO.getData(), postAuthDO.getContentType());
return getResponseDataInJson(response);
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
return responseData;
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/AuthDate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
}
return getResponseDataInJson(response);
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/Authdate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
String encoding = Base64.encodeAsString(username + ":" + password);
response = DmaapClientUtil.getResponsewtBasicAuth(target, encoding);
}
- MRClientFactory.HTTPHeadersMap = response.getHeaders();
+ MRClientFactory.setHTTPHeadersMap(response.getHeaders());
- String transactionid = response.getHeaderString("transactionid");
+ String transactionid = response.getHeaderString(HEADER_TRANSACTION_ID);
if (transactionid != null && !transactionid.equalsIgnoreCase("")) {
- fLog.info("TransactionId : " + transactionid);
+ fLog.info(LOG_TRANSACTION_ID + transactionid);
}
responseData = (String) response.readEntity(String.class);
return responseData;
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/Authdate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
return getResponseDataInJson(response);
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/Authdate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
target = DmaapClientUtil.getTarget(clientConfig,path, username, password);
response = DmaapClientUtil.getResponsewtCambriaAuth(target, authKey, authDate);
- MRClientFactory.HTTPHeadersMap = response.getHeaders();
+ MRClientFactory.setHTTPHeadersMap(response.getHeaders());
- String transactionid = response.getHeaderString("transactionid");
+ String transactionid = response.getHeaderString(HEADER_TRANSACTION_ID);
if (transactionid != null && !transactionid.equalsIgnoreCase("")) {
- fLog.info("TransactionId : " + transactionid);
+ fLog.info(LOG_TRANSACTION_ID + transactionid);
}
responseData = (String) response.readEntity(String.class);
return responseData;
} else {
- throw new HttpException(
- "Authentication Failed: Username/password/AuthKey/Authdate parameter(s) cannot be null or empty.");
+ throw new HttpException(AUTH_FAILED);
}
}
target = DmaapClientUtil.getTarget(clientConfig,path, username, password);
response = DmaapClientUtil.getResponsewtNoAuth(target);
- MRClientFactory.HTTPHeadersMap = response.getHeaders();
+ MRClientFactory.setHTTPHeadersMap(response.getHeaders());
- String transactionid = response.getHeaderString("transactionid");
+ String transactionid = response.getHeaderString(HEADER_TRANSACTION_ID);
if (transactionid != null && !transactionid.equalsIgnoreCase("")) {
- fLog.info("TransactionId : " + transactionid);
+ fLog.info(LOG_TRANSACTION_ID + transactionid);
}
responseData = (String) response.readEntity(String.class);
private JSONObject getResponseDataInJson(Response response) throws JSONException {
try {
- MRClientFactory.HTTPHeadersMap = response.getHeaders();
+ MRClientFactory.setHTTPHeadersMap(response.getHeaders());
// MultivaluedMap<String, Object> headersMap =
// for(String key : headersMap.keySet()) {
- String transactionid = response.getHeaderString("transactionid");
+ String transactionid = response.getHeaderString(HEADER_TRANSACTION_ID);
if (transactionid != null && !transactionid.equalsIgnoreCase("")) {
- fLog.info("TransactionId : " + transactionid);
+ fLog.info(LOG_TRANSACTION_ID + transactionid);
}
if (response.getStatus() == 403) {
jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
jsonArray.put(response.getEntity());
- jsonObject.put("result", jsonArray);
- jsonObject.put("status", response.getStatus());
+ jsonObject.put(JSON_RESULT, jsonArray);
+ jsonObject.put(JSON_STATUS, response.getStatus());
return jsonObject;
}
String responseData = (String) response.readEntity(String.class);
if ('[' == firstChar) {
JSONArray jsonArray = new JSONArray(jsonTokener);
jsonObject = new JSONObject();
- jsonObject.put("result", jsonArray);
- jsonObject.put("status", response.getStatus());
+ jsonObject.put(JSON_RESULT, jsonArray);
+ jsonObject.put(JSON_STATUS, response.getStatus());
} else {
jsonObject = new JSONObject(jsonTokener);
- jsonObject.put("status", response.getStatus());
+ jsonObject.put(JSON_STATUS, response.getStatus());
}
return jsonObject;