summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluxin <luxin7@huawei.com>2017-09-22 11:40:05 +0800
committerluxin <luxin7@huawei.com>2017-09-22 11:40:05 +0800
commitbd358dd59eaf3c0a0daae5a5b601b97796a6ddf2 (patch)
tree6a293c648e8f54cbcfef2dc8d04fde61ef1a7382
parent489af660118053837474c26d19af27bdfbee676a (diff)
Define constant instead of "https"
Change-Id: Ib70862306f0a02457acfee073a18a83dbdac609f Issue-Id:VFC-375 Signed-off-by: luxin <luxin7@huawei.com>
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java2
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequests.java59
2 files changed, 32 insertions, 29 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java
index 36a2c7dc..efc515c2 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/constant/Constant.java
@@ -47,6 +47,8 @@ public class Constant {
public static final String ASYNCDELETE = "asyncDelete";
+ public static final String HTTPS = "https";
+
public static final String ENCODEING = "utf-8";
public static final String COOKIE = "Cookie";
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequests.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequests.java
index a23b73ac..e26f76f4 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequests.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/service/csm/connect/HttpRequests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Huawei Technologies Co., Ltd.
+ * Copyright 2016-2017 Huawei Technologies Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,7 +45,7 @@ import org.springframework.http.HttpRequest;
* HTTP Request class.</br>
*
* @author
- * @version VFC 1.0 Sep 14, 2016
+ * @version VFC 1.0 Sep 14, 2016
*/
public final class HttpRequests {
@@ -70,7 +70,7 @@ public final class HttpRequests {
* Request builder.</br>
*
* @author
- * @version VFC 1.0 Sep 14, 2016
+ * @version VFC 1.0 Sep 14, 2016
*/
public static class Builder {
@@ -89,11 +89,10 @@ public final class HttpRequests {
private String authenticateMode;
/**
- *
* Constructor<br>
*
* @param authenticateMode
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder(String authenticateMode) {
this.authenticateMode = authenticateMode;
@@ -110,7 +109,7 @@ public final class HttpRequests {
* @param name
* @param value
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder addHeader(String name, String value) {
headers.add(new Header(name, value));
@@ -124,7 +123,7 @@ public final class HttpRequests {
* @param header
* @param headers
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder addHeaders(Header header, Header... headers) {
if(header != null) {
@@ -144,7 +143,7 @@ public final class HttpRequests {
*
* @param headers
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder addHeaders(List<Header> headers) {
if(headers != null && !headers.isEmpty()) {
@@ -161,7 +160,7 @@ public final class HttpRequests {
* @param path
* @return
* @throws VnfmException
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setUrl(String url, String path) throws VnfmException {
if(StringUtils.isEmpty(url)) {
@@ -172,8 +171,8 @@ public final class HttpRequests {
LOG.info("setUrl: url =" + url);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
+ Protocol.registerProtocol(Constant.HTTPS,
+ new Protocol(Constant.HTTPS, SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
return this;
}
@@ -187,7 +186,7 @@ public final class HttpRequests {
* @param defPort
* @return
* @throws VnfmException
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setUrl(String url, String path, int defPort) throws VnfmException {
if(StringUtils.isEmpty(url)) {
@@ -198,8 +197,8 @@ public final class HttpRequests {
LOG.info("setUrl: url =" + url);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), defPort));
+ Protocol.registerProtocol(Constant.HTTPS, new Protocol(Constant.HTTPS,
+ SslProtocolSocketFactory.getInstance().get(authenticateMode), defPort));
return this;
}
@@ -209,7 +208,7 @@ public final class HttpRequests {
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder post() {
this.httpMethod = new PostMethod(url);
@@ -221,7 +220,7 @@ public final class HttpRequests {
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder get() {
this.httpMethod = new GetMethod(url);
@@ -233,7 +232,7 @@ public final class HttpRequests {
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder put() {
this.httpMethod = new PutMethod(url);
@@ -245,7 +244,7 @@ public final class HttpRequests {
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder delete() {
this.httpMethod = new DeleteMethod(url);
@@ -258,7 +257,7 @@ public final class HttpRequests {
*
* @param json
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setParams(String json) {
this.paramsJson = json;
@@ -271,7 +270,7 @@ public final class HttpRequests {
*
* @param encode
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public Builder setEncoding(String encode) {
this.encoding = encode;
@@ -283,7 +282,7 @@ public final class HttpRequests {
* <br>
*
* @return
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public String request() {
String result = null;
@@ -295,18 +294,20 @@ public final class HttpRequests {
LOG.error("function=request, msg=SSLHandshake Fail, start refresh certificate ...");
SslProtocolSocketFactory socketFactory = SslProtocolSocketFactory.getInstance();
socketFactory.refresh(authenticateMode);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
+ Protocol.registerProtocol(Constant.HTTPS, new Protocol(Constant.HTTPS,
+ SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
LOG.error("function=request, msg=SSLHandshake Fail, certificate refresh successful .");
result = executeMethod().getResponseBodyAsString();
} catch(IOException ioe) {
- LOG.error(String.format("function=request, msg=http request url: %s, error: ", url), ioe);
+ LOG.error(String.format("function=request, IOException msg=http request url: %s, error: ", url),
+ ioe);
} catch(VnfmException ose) {
- LOG.error(String.format("function=request, msg=http request url: %s, error: ", url), ose);
+ LOG.error(String.format("function=request, VnfmException msg=http request url: %s, error: ", url),
+ ose);
}
} catch(IOException | VnfmException e) {
- LOG.error(String.format("function=request, msg=http request url: %s, error: ", url), e);
+ LOG.error(String.format("function=request, IOException msg=http request url: %s, error: ", url), e);
} finally {
httpMethod.releaseConnection();
}
@@ -320,7 +321,7 @@ public final class HttpRequests {
* @return
* @throws VnfmException
* @throws IOException
- * @since VFC 1.0
+ * @since VFC 1.0
*/
public HttpMethod execute() throws VnfmException, IOException {
try {
@@ -330,8 +331,8 @@ public final class HttpRequests {
LOG.error("function=execute, SSLHandshake Fail, start refresh certificate ...");
SslProtocolSocketFactory socketFactory = SslProtocolSocketFactory.getInstance();
socketFactory.refresh(authenticateMode);
- Protocol.registerProtocol("https",
- new Protocol("https", SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
+ Protocol.registerProtocol(Constant.HTTPS, new Protocol(Constant.HTTPS,
+ SslProtocolSocketFactory.getInstance().get(authenticateMode), PORT));
LOG.error("function=execute, SSLHandshake Fail, certificate refresh successful .");
executeMethod();