diff options
author | 2017-10-07 04:13:25 +0800 | |
---|---|---|
committer | 2017-10-07 04:13:25 +0800 | |
commit | 6bde25ddca5ae6e8c479de6d55d29b083490ab4a (patch) | |
tree | d43e3303a0caa283aa1947ca764006b6f9d0bde0 /nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java | |
parent | c0134003468a9331c1efb70872d0324bbe89ee88 (diff) |
Remove duplicate parts.
Change-Id: Ia4fdcf5c6879bceb5fd793ac72408992b35f5a64
Issue-ID: VFC-53
Signed-off-by: yufei_zhou <yufei.zhou@nokia-sbell.com>
Diffstat (limited to 'nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java')
9 files changed, 103 insertions, 202 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java index caec85da..00fc0000 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/aai/impl/AaiMgmrInfImpl.java @@ -17,6 +17,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.impl; import java.io.IOException; +import java.util.HashMap; import org.apache.http.client.ClientProtocolException; import org.apache.http.impl.client.HttpClientBuilder; @@ -24,6 +25,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo; import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -41,8 +43,8 @@ public class AaiMgmrInfImpl implements AaiMgmrInf{ @Autowired private AdaptorEnv adaptorEnv; - @Autowired - private HttpClientBuilder httpClientBuilder; + @Autowired + HttpClientProcessorInf httpClientProcessor; private Gson gson = new Gson(); @Override @@ -61,14 +63,17 @@ public class AaiMgmrInfImpl implements AaiMgmrInf{ private String operateHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws ClientProtocolException, IOException { String url=adaptorEnv.getAaiApiUriFront() + httpPath; - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, method); - processor.addHdeader(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - processor.addPostEntity(gson.toJson(httpBodyObj)); + HashMap<String, String> map = new HashMap<String, String>(); + map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE); - String responseStr = processor.process(url); + String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent(); return responseStr; } + public void setAdaptorEnv(AdaptorEnv env) { + this.adaptorEnv = env; + } + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java index b00f61c7..2e4dd999 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/catalog/impl/CatalogMgmrImpl.java @@ -17,6 +17,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.impl; import java.io.IOException; +import java.util.HashMap; import org.apache.http.client.ClientProtocolException; import org.apache.http.impl.client.HttpClientBuilder; @@ -26,9 +27,11 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse; import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.inf.CatalogMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nslcm.bo.entity.VnfPackageInfo; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.RequestMethod; @@ -44,13 +47,16 @@ public class CatalogMgmrImpl implements CatalogMgmrInf{ private AdaptorEnv adaptorEnv; @Autowired - private HttpClientBuilder httpClientBuilder; + HttpClientProcessorInf httpClientProcessor; public VnfPackageInfo queryVnfPackage(String vnfPackageId) throws ClientProtocolException, IOException { + String url=adaptorEnv.getCatalogApiUriFront() + String.format(CommonConstants.RetrieveVnfPackagePath, vnfPackageId); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); + HashMap<String, String> map = new HashMap<String, String>(); + + String bodyPostStr = String.format(CommonConstants.RetrieveCbamTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret()); - String responseStr = processor.process(url); + String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr).getContent(); logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr); @@ -59,5 +65,9 @@ public class CatalogMgmrImpl implements CatalogMgmrInf{ return resp.getPackageInfo(); } + public void setAdaptorEnv(AdaptorEnv env) { + this.adaptorEnv = env; + } + } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/controller/CbamController.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/controller/CbamController.java deleted file mode 100644 index 0e772a4b..00000000 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/controller/CbamController.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2016-2017, Nokia Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.controller; - -import java.io.IOException; - -import org.apache.http.client.ClientProtocolException; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.log4j.Logger; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.catalog.bo.CatalogQueryVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMCreateVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfRequest; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMHealVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfRequest; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMInstantiateVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMOperExecutVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMQueryVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfRequest; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMScaleVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfRequest; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.bo.CBAMTerminateVnfResponse; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.MediaType; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; - -import com.google.gson.Gson; - -@Controller -@RequestMapping(value = "/vnfm/lcm/v3") -public class CbamController { - private static final Logger logger = Logger.getLogger(CbamController.class); - @Autowired - private AdaptorEnv adaptorEnv; - - @Autowired - private HttpClientBuilder httpClientBuilder; - - private Gson gson = new Gson(); - - @RequestMapping(value = "/vnfs", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CBAMCreateVnfResponse createVnf(CBAMInstantiateVnfRequest request) throws ClientProtocolException, IOException - { - CBAMCreateVnfResponse response = new CBAMCreateVnfResponse(); - String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamCreateVnfPath); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); - - String responseStr = processor.process(url); - - logger.info("CbamMgmrImpl -> createVnf, responseStr is " + responseStr); - - CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class); - - - return response; - } - @RequestMapping(value = "/vnfs/{vnfInstanceId}/instantiate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CBAMInstantiateVnfResponse initiateVnf(CBAMInstantiateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException - { - CBAMInstantiateVnfResponse response = new CBAMInstantiateVnfResponse(); - String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamInstantiateVnfPath,vnfInstanceId); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); - - String responseStr = processor.process(url); - - logger.info("CbamMgmrImpl -> initiateVnf, responseStr is " + responseStr); - - CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class); - - - return response; - } - - @RequestMapping(value = "/vnfs/{vnfInstanceId}/terminate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CBAMTerminateVnfResponse terminateVnf(CBAMTerminateVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException - { - CBAMTerminateVnfResponse response = new CBAMTerminateVnfResponse(); - String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamTerminateVnfPath,vnfInstanceId); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); - - String responseStr = processor.process(url); - - logger.info("CbamMgmrImpl -> terminateVnf, responseStr is " + responseStr); - - CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class); - return response; - } - - @RequestMapping(value = "/vnfs/{vnfInstanceId}/scale", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CBAMScaleVnfResponse scaleVnf(CBAMScaleVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException - { - CBAMScaleVnfResponse response = new CBAMScaleVnfResponse(); - String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamScaleVnfPath,vnfInstanceId); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); - - String responseStr = processor.process(url); - - logger.info("CbamMgmrImpl -> scaleVnf, responseStr is " + responseStr); - - CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class); - return response; - } - - @RequestMapping(value = "/vnfs/{vnfInstanceId}/heal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CBAMHealVnfResponse healVnf(CBAMHealVnfRequest request, @PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException - { - CBAMHealVnfResponse response = new CBAMHealVnfResponse(); - String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamHealVnfPath,vnfInstanceId); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); - - String responseStr = processor.process(url); - - logger.info("CbamMgmrImpl -> healVnf, responseStr is " + responseStr); - - CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class); - return response; - } - - - @RequestMapping(value = "/vnfs/{vnfInstanceId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CBAMQueryVnfResponse queryVnf(@PathVariable("vnfInstanceId") String vnfInstanceId) throws ClientProtocolException, IOException - { - CBAMQueryVnfResponse response = new CBAMQueryVnfResponse(); - String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamQueryVnfPath, vnfInstanceId); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); - - String responseStr = processor.process(url); - - logger.info("CbamMgmrImpl -> queryVnfPackage, responseStr is " + responseStr); - - CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class); - - - return response; - } - - - @RequestMapping(value = "/operation_executions/{operationExecutionId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) - @ResponseBody - public CBAMOperExecutVnfResponse operVnf(@PathVariable("operationExecutionId") String operationExecutionId) throws ClientProtocolException, IOException - { - CBAMOperExecutVnfResponse response = new CBAMOperExecutVnfResponse(); - String url=adaptorEnv.getCbamApiUriFront() + String.format(CommonConstants.CbamGetOperStatusPath,operationExecutionId); - HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, RequestMethod.GET); - - String responseStr = processor.process(url); - - logger.info("CbamMgmrImpl -> operVnf, responseStr is " + responseStr); - - CatalogQueryVnfResponse resp = gson.fromJson(responseStr, CatalogQueryVnfResponse.class); - return response; - } - - - - -} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java index 2c88320e..ee6b011a 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/CbamMgmrImpl.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.util.HashMap; import org.apache.http.client.ClientProtocolException; -import org.apache.http.impl.client.HttpClientBuilder; import org.apache.log4j.Logger; import org.json.JSONException; import org.json.JSONObject; @@ -40,7 +39,6 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.cbam.inf.CbamMgmrInf; import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv; import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants; import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import org.springframework.stereotype.Component; @@ -68,7 +66,7 @@ public class CbamMgmrImpl implements CbamMgmrInf { String bodyPostStr = String.format(CommonConstants.RetrieveCbamTokenPostStr, adaptorEnv.getGrantType(), adaptorEnv.getClientId(), adaptorEnv.getClientSecret()); - String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr); + String responseStr = httpClientProcessor.process(url, RequestMethod.GET, map, bodyPostStr).getContent(); logger.info("CbamMgmrImpl -> retrieveToken, responseStr is " + responseStr); @@ -181,7 +179,7 @@ public class CbamMgmrImpl implements CbamMgmrInf { map.put(CommonConstants.AUTHORIZATION, "bearer " + token); map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)); + String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent(); return responseStr; } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java index 9bebb1c9..319b0e32 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorImpl.java @@ -31,7 +31,7 @@ public class HttpClientProcessorImpl implements HttpClientProcessorInf{ @Autowired private HttpClientBuilder httpClientBuilder; - public String process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException + public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException { HttpRequestProcessor processor = new HttpRequestProcessor(httpClientBuilder, methodType); if(headerMap != null && !headerMap.isEmpty()) diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorInf.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorInf.java index 41b84d9b..cbb820b8 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorInf.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpClientProcessorInf.java @@ -23,6 +23,6 @@ import org.apache.http.client.ClientProtocolException; import org.springframework.web.bind.annotation.RequestMethod; public interface HttpClientProcessorInf { - public String process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException; + public HttpResult process(String url, RequestMethod methodType, HashMap<String, String> headerMap, String bodyString) throws ClientProtocolException, IOException; } diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java index b2414a52..bd3e3635 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpRequestProcessor.java @@ -41,20 +41,33 @@ public class HttpRequestProcessor { httpRequest = HttpClientUtils.getHttpRequest(requestMethod); } - public String process(String url) throws ClientProtocolException, IOException + public HttpResult process(String url) throws ClientProtocolException, IOException { httpRequest.setURI(URI.create(url)); HttpResponse response = httpClient.execute(httpRequest); + + HttpResult httpResult = buildHttpResult(response); + httpClient.close(); + + return httpResult; + } + + private HttpResult buildHttpResult(HttpResponse response) throws IOException { HttpEntity resEntity = response.getEntity(); String responseContent = ""; if (resEntity != null) { responseContent = EntityUtils.toString(resEntity, CommonConstants.UTF_8); EntityUtils.consume(resEntity); } - httpClient.close(); - return responseContent; + HttpResult httpResult = new HttpResult(); + httpResult.setStatusCode(response.getStatusLine().getStatusCode()); + httpResult.setStatusCause(response.getStatusLine().getReasonPhrase()); + httpResult.setHeaders(response.getAllHeaders()); + httpResult.setContent(responseContent); + + return httpResult; } public void addHdeader(String key, String value) { diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpResult.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpResult.java new file mode 100644 index 00000000..3c5ace92 --- /dev/null +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/http/client/HttpResult.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client; + +import org.apache.http.Header; + +public class HttpResult { + private int statusCode; + private String statusCause; + private Header[] headers; + private String content; + + public int getStatusCode() { + return statusCode; + } + + public void setStatusCode(int statusCode) { + this.statusCode = statusCode; + } + + public String getStatusCause() { + return statusCause; + } + + public void setStatusCause(String statusCause) { + this.statusCause = statusCause; + } + + public Header[] getHeaders() { + return headers; + } + + public void setHeaders(Header[] headers) { + this.headers = headers; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/impl/NslcmMgmrImpl.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/impl/NslcmMgmrImpl.java index 405c7365..e9c58122 100644 --- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/impl/NslcmMgmrImpl.java +++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nslcm/impl/NslcmMgmrImpl.java @@ -92,7 +92,7 @@ public class NslcmMgmrImpl implements NslcmMgmrInf{ HashMap<String, String> map = new HashMap<String, String>(); map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); - String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)); + String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent(); return responseStr; } |