2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.impl;
19 import java.io.IOException;
20 import java.util.HashMap;
22 import org.apache.http.client.ClientProtocolException;
23 import org.apache.http.impl.client.HttpClientBuilder;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.bo.AaiVnfmInfo;
25 import org.onap.vfc.nfvo.driver.vnfm.svnfm.aai.inf.AaiMgmrInf;
26 import org.onap.vfc.nfvo.driver.vnfm.svnfm.common.bo.AdaptorEnv;
27 import org.onap.vfc.nfvo.driver.vnfm.svnfm.constant.CommonConstants;
28 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpClientProcessorInf;
29 import org.onap.vfc.nfvo.driver.vnfm.svnfm.http.client.HttpRequestProcessor;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.http.MediaType;
34 import org.springframework.stereotype.Component;
35 import org.springframework.web.bind.annotation.RequestMethod;
37 import com.google.gson.Gson;
40 public class AaiMgmrInfImpl implements AaiMgmrInf{
41 private static final Logger logger = LoggerFactory.getLogger(AaiMgmrInfImpl.class);
44 private AdaptorEnv adaptorEnv;
47 HttpClientProcessorInf httpClientProcessor;
49 private Gson gson = new Gson();
51 public AaiVnfmInfo queryVnfm(String vnfmId) throws ClientProtocolException, IOException {
52 String httpPath = String.format(CommonConstants.RetrieveVnfmListPath, vnfmId);
53 RequestMethod method = RequestMethod.GET;
55 String responseStr = operateHttpTask(null, httpPath, method);
57 logger.info("AaiMgmrInfImpl->queryVnfm, the vnfmInfo is {}", responseStr);
59 AaiVnfmInfo response = gson.fromJson(responseStr, AaiVnfmInfo.class);
64 private String operateHttpTask(Object httpBodyObj, String httpPath, RequestMethod method) throws ClientProtocolException, IOException {
65 String url=adaptorEnv.getAaiApiUriFront() + httpPath;
67 HashMap<String, String> map = new HashMap<String, String>();
68 map.put(CommonConstants.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE);
70 String responseStr = httpClientProcessor.process(url, method, map, gson.toJson(httpBodyObj)).getContent();
75 public void setAdaptorEnv(AdaptorEnv env) {
76 this.adaptorEnv = env;