private static final Logger LOG = LoggerFactory.getLogger(ResultRequestUtil.class);
+ private static final String CONNECT_FAIL = "connect fail.";
+
+ private static final String RESPONSE_STATUS = "function=call, msg=response status is {}. result is {}";
+
+ private static final String IOEXCEPTION = "function=call, msg=IOException, e is {}";
+
+ private static final String REFLECTIVEOPERATIONEXCEPTION =
+ "function=call, msg=ReflectiveOperationException, e is {}";
+
+ private static final String THROWABLE = "function=call, msg=Throwable, e is {}";
+
+ private static final String CONNECTION_ERROR = "get connection error";
+
private ResultRequestUtil() throws VnfmException {
throw new VnfmException("can't be instanced.");
}
if(Constant.HTTP_OK != mgrVcmm.connect(vnfmObject)) {
resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
- resultJson.put("data", "connect fail.");
+ resultJson.put("data", CONNECT_FAIL);
return resultJson;
}
builder = (HttpRequests.Builder)mt.invoke();
httpMethod = builder.execute();
result = httpMethod.getResponseBodyAsString();
- LOG.warn("function=call, msg=response status is {}. result is {}", httpMethod.getStatusCode(), result);
+ LOG.warn(RESPONSE_STATUS, httpMethod.getStatusCode(), result);
resultJson.put(Constant.RETCODE, httpMethod.getStatusCode());
resultJson.put("data", result);
} catch(IOException e) {
- LOG.info("function=call, msg=IOException, e is {}", e);
+ LOG.info(IOEXCEPTION, e);
} catch(ReflectiveOperationException e) {
- LOG.info("function=call, msg=ReflectiveOperationException, e is {}", e);
+ LOG.info(REFLECTIVEOPERATIONEXCEPTION, e);
} catch(Throwable e) {
- LOG.info("function=call, msg=Throwable, e is {}", e);
+ LOG.info(THROWABLE, e);
} finally {
if(httpMethod != null) {
httpMethod.releaseConnection();
if(httpMethod == null) {
resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
- resultJson.put("data", "get connection error");
+ resultJson.put("data", CONNECTION_ERROR);
}
return resultJson;
if(Constant.HTTP_OK != mgrVcmm.connect(vnfmObject, authModel)) {
resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
- resultJson.put("data", "connect fail.");
+ resultJson.put("data", CONNECT_FAIL);
return resultJson;
}
builder = (HttpRequests.Builder)mt.invoke();
httpMethod = builder.execute();
result = httpMethod.getResponseBodyAsString();
- LOG.warn("function=call, msg=response status is {}. result is {}", httpMethod.getStatusCode(), result);
+ LOG.warn(RESPONSE_STATUS, httpMethod.getStatusCode(), result);
resultJson.put(Constant.RETCODE, httpMethod.getStatusCode());
resultJson.put("data", result);
String user = vnfmObject.getString(Constant.USERNAME);
removeTokens(vnfmUrl, token, roaRand, user);
} catch(IOException e) {
- LOG.info("function=call, msg=IOException, e is {}", e);
+ LOG.info(IOEXCEPTION, e);
} catch(ReflectiveOperationException e) {
- LOG.info("function=call, msg=ReflectiveOperationException, e is {}", e);
+ LOG.info(REFLECTIVEOPERATIONEXCEPTION, e);
} catch(Throwable e) {
- LOG.info("function=call, msg=Throwable, e is {}", e);
+ LOG.info(THROWABLE, e);
} finally {
if(httpMethod != null) {
httpMethod.releaseConnection();
if(httpMethod == null) {
resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
- resultJson.put("data", "get connection error");
+ resultJson.put("data", CONNECTION_ERROR);
}
return resultJson;
LOG.info("removeTokens tokenUrl=" + tokenUrl);
try {
httpMethodToken = new HttpRequests.Builder(Constant.CERTIFICATE).setUrl(vnfmUrl.trim(), tokenUrl)
- .setParams("").addHeader("X-Auth-Token", token).delete().execute();
+ .setParams("").addHeader(Constant.X_AUTH_TOKEN, token).delete().execute();
int statusCode = httpMethodToken.getStatusCode();
String result = httpMethodToken.getResponseBodyAsString();
LOG.info("removeTokens int=" + statusCode + ", result=" + result);
} catch(IOException e) {
- LOG.info("function=call, msg=IOException, e is {}", e);
+ LOG.info(IOEXCEPTION, e);
} catch(Throwable e) {
- LOG.info("function=call, msg=Throwable, e is {}", e);
+ LOG.info(THROWABLE, e);
} finally {
if(httpMethodToken != null) {
httpMethodToken.releaseConnection();
if(Constant.HTTP_OK != mgrVcmm.connectSouth(vnfmObject, authModel)) {
resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
- resultJson.put("data", "connect fail.");
+ resultJson.put("data", CONNECT_FAIL);
return resultJson;
}
LOG.info("function=callSouth, paramsJson is {}", paramsJson);
HttpRequests.Builder builder =
- new HttpRequests.Builder(authModel).addHeader("X-Auth-Token", mgrVcmm.getAccessSession())
+ new HttpRequests.Builder(authModel).addHeader(Constant.X_AUTH_TOKEN, mgrVcmm.getAccessSession())
.setUrl(newUrl, vnfPath).setParams(paramsJson);
MethodType methodType = MethodType.methodType(HttpRequests.Builder.class, new Class[0]);
MethodHandle mt =
builder = (HttpRequests.Builder)mt.invoke();
httpMethod = builder.execute();
result = httpMethod.getResponseBodyAsString();
- LOG.warn("function=call, msg=response status is {}. result is {}", httpMethod.getStatusCode(), result);
+ LOG.warn(RESPONSE_STATUS, httpMethod.getStatusCode(), result);
resultJson.put(Constant.RETCODE, httpMethod.getStatusCode());
resultJson.put("data", result);
String user = vnfmObject.getString(Constant.USERNAME);
removeV3Tokens(newUrl, token, user);
} catch(IOException e) {
- LOG.info("function=call, msg=IOException, e is {}", e);
+ LOG.info(IOEXCEPTION, e);
} catch(ReflectiveOperationException e) {
- LOG.info("function=call, msg=ReflectiveOperationException, e is {}", e);
+ LOG.info(REFLECTIVEOPERATIONEXCEPTION, e);
} catch(Throwable e) {
- LOG.info("function=call, msg=Throwable, e is {}", e);
+ LOG.info(THROWABLE, e);
} finally {
if(httpMethod != null) {
httpMethod.releaseConnection();
if(httpMethod == null) {
resultJson.put(Constant.RETCODE, Constant.HTTP_INNERERROR);
- resultJson.put("data", "get connection error");
+ resultJson.put("data", CONNECTION_ERROR);
}
return resultJson;
LOG.info("removeTokens tokenUrl=" + tokenUrl);
try {
httpMethodToken = new HttpRequests.Builder(Constant.CERTIFICATE).setUrl(vnfmUrl.trim(), tokenUrl)
- .setParams("").addHeader("X-Auth-Token", token).delete().execute();
+ .setParams("").addHeader(Constant.X_AUTH_TOKEN, token).delete().execute();
int statusCode = httpMethodToken.getStatusCode();
String result = httpMethodToken.getResponseBodyAsString();
LOG.info("removeTokens int=" + statusCode + ", result=" + result);
} catch(IOException e) {
- LOG.info("function=call, msg=IOException, e is {}", e);
+ LOG.info(IOEXCEPTION, e);
} catch(Throwable e) {
- LOG.info("function=call, msg=Throwable, e is {}", e);
+ LOG.info(THROWABLE, e);
} finally {
if(httpMethodToken != null) {
httpMethodToken.releaseConnection();
public static final String APPLICATION = "application/json";
+ public static final String METHODTYPE = "methodType";
+
+ public static final String AUTHMODE = "authMode";
+
private static final Logger LOG = LoggerFactory.getLogger(VNFRestfulUtil.class);
private VNFRestfulUtil() {
public static RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens,
boolean isNfvoApp) {
String utilUrl = paramsMap.get("url");
- String utilMethodType = paramsMap.get("methodType");
+ String utilMethodType = paramsMap.get(METHODTYPE);
String utilPath = paramsMap.get("path");
- String authMode = paramsMap.get("authMode");
+ String authMode = paramsMap.get(AUTHMODE);
RestfulResponse rsp = null;
Restful rest = null;
return null;
}
String url = paramsMap.get("url");
- String methodType = paramsMap.get("methodType");
+ String methodType = paramsMap.get(METHODTYPE);
RestfulResponse rsp = null;
Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP);
public static Map<String, String> generateParamsMap(String url, String methodType, String path, String authMode) {
Map<String, String> utilParamsMap = new HashMap<>(6);
utilParamsMap.put("url", url);
- utilParamsMap.put("methodType", methodType);
+ utilParamsMap.put(METHODTYPE, methodType);
utilParamsMap.put("path", path);
- utilParamsMap.put("authMode", authMode);
+ utilParamsMap.put(AUTHMODE, authMode);
return utilParamsMap;
}
public static Map<String, String> generateParamsMap(String url, String methodType, String path) {
Map<String, String> paramsMap = new HashMap<>(6);
paramsMap.put("url", url);
- paramsMap.put("methodType", methodType);
+ paramsMap.put(METHODTYPE, methodType);
paramsMap.put("path", path);
- paramsMap.put("authMode", "Certificate");
+ paramsMap.put(AUTHMODE, "Certificate");
return paramsMap;
}