import org.onap.usecaseui.server.bean.sotn.NetWorkResource;
import org.onap.usecaseui.server.bean.sotn.Pinterface;
import org.onap.usecaseui.server.bean.sotn.Pnf;
+import org.onap.usecaseui.server.constant.Constant;
import org.onap.usecaseui.server.service.sotn.SOTNService;
+import org.onap.usecaseui.server.util.HttpUtil;
import org.onap.usecaseui.server.util.UuiCommonUtil;
-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 org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
-@Controller
+@RestController
@RequestMapping("/uui-sotn")
public class SotnController {
this.sotnService = sotnService;
}
- @ResponseBody
- @RequestMapping(value = {"/getNetWorkResources"}, method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/getNetWorkResources"}, method = RequestMethod.GET)
public List<NetWorkResource> getNetWorkResources(){
List<NetWorkResource> result = new ArrayList<NetWorkResource>();
String json = sotnService.getNetWorkResources();
return result;
}
- @ResponseBody
- @RequestMapping(value = {"/getPinterfaceByPnfName/{pnfName}"}, method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/getPinterfaceByPnfName/{pnfName}"}, method = RequestMethod.GET)
public List<Pinterface> getPinterfaceByPnfName(@PathVariable(value="pnfName") String pnfName){
return sotnService.getPinterfaceByPnfName(pnfName);
}
- @ResponseBody
- @RequestMapping(value = {"/getLogicalLinks"}, method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/getLogicalLinks"}, method = RequestMethod.GET)
public String getLogicalLinks(){
return sotnService.getLogicalLinks();
}
- @ResponseBody
- @RequestMapping(value = {"/getSpecificLogicalLink/{linkName}"}, method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/getSpecificLogicalLink/{linkName}"}, method = RequestMethod.GET)
public String getSpecificLogicalLink(@PathVariable(value="linkName") String linkName){
return sotnService.getSpecificLogicalLink(linkName);
}
- @ResponseBody
- @RequestMapping(value = {"/getHostUrl/{aaiId}"}, method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/getHostUrl/{aaiId}"}, method = RequestMethod.GET)
public String getHostUrl(@PathVariable(value="aaiId") String aaiId){
return sotnService.getHostUrl(aaiId);
}
- @ResponseBody
- @RequestMapping(value = {"/createHostUrl/{aaiId}"}, method = RequestMethod.PUT , produces = "application/json")
+ @RequestMapping(value = {"/createHostUrl/{aaiId}"}, method = RequestMethod.PUT)
public String createHostUrl(HttpServletRequest request,@PathVariable(value="aaiId") String aaiId){
return sotnService.createTopoNetwork(request,aaiId);
}
- @ResponseBody
- @RequestMapping(value = {"/createTopoNetwork/{networkId}"}, method = RequestMethod.PUT , produces = "application/json")
+ @RequestMapping(value = {"/createTopoNetwork/{networkId}"}, method = RequestMethod.PUT)
public String createTopoNetwork(HttpServletRequest request,@PathVariable(value="networkId") String networkId){
return sotnService.createTopoNetwork(request,networkId);
}
- @ResponseBody
- @RequestMapping(value = {"/pnf/{pnfName}/p-interfaces/p-interface/{tp-id}/createTerminationPoint"}, method = RequestMethod.PUT , produces = "application/json")
+ @RequestMapping(value = {"/pnf/{pnfName}/p-interfaces/p-interface/{tp-id}/createTerminationPoint"}, method = RequestMethod.PUT)
public String createTerminationPoint(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName,@PathVariable(value="tp-id") String tpId){
return sotnService.createTerminationPoint(request,pnfName,tpId);
}
- @ResponseBody
- @RequestMapping(value = {"/createLink/{linkName}"}, method = RequestMethod.PUT , produces = "application/json")
+ @RequestMapping(value = {"/createLink/{linkName}"}, method = RequestMethod.PUT)
public String createLink(HttpServletRequest request,@PathVariable(value="linkName") String linkName){
return sotnService.createLink(request, linkName);
}
- @ResponseBody
- @RequestMapping(value = {"/createPnf/{pnfName}"}, method = RequestMethod.PUT , produces = "application/json")
+ @RequestMapping(value = {"/createPnf/{pnfName}"}, method = RequestMethod.PUT)
public String createPnf(HttpServletRequest request,@PathVariable(value="pnfName") String pnfName){
return sotnService.createPnf(request, pnfName);
}
- @ResponseBody
- @RequestMapping(value = {"/deleteLink/{linkName}/{resourceVersion}"}, method = RequestMethod.DELETE , produces = "application/json")
+ @RequestMapping(value = {"/deleteLink/{linkName}/{resourceVersion}"}, method = RequestMethod.DELETE)
public String deleteLink(@PathVariable(value="linkName") String linkName,@PathVariable(value="resourceVersion") String resourceVersion){
return sotnService.deleteLink(linkName,resourceVersion);
}
- @ResponseBody
- @RequestMapping(value = {"/getServiceInstanceInfo"}, method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/getServiceInstanceInfo"}, method = RequestMethod.GET)
public String getServiceInstanceInfo(HttpServletRequest request){
String customerId = request.getParameter("customerId");
String serviceType = request.getParameter("serviceType");
return sotnService.serviceInstanceInfo(customerId, serviceType, serviceId);
}
- @ResponseBody
- @RequestMapping(value = {"/getServiceInstanceList"}, method = RequestMethod.GET , produces = "application/json")
+ @RequestMapping(value = {"/getServiceInstanceList"}, method = RequestMethod.GET)
public String getServiceInstanceList(HttpServletRequest request){
String customerId = request.getParameter("customerId");
String serviceType = request.getParameter("serviceType");
return sotnService.getServiceInstances(customerId, serviceType);
}
+ @RequestMapping(value = {"/getOssInvenory"}, method = RequestMethod.GET)
+ public String getData(){
+ String result = HttpUtil.sendGet("http://10.73.242.244:8082/uui-sotn/getLogicalLinks", "");
+ return result;
+ }
private void createJson(String json,List<NetWorkResource> list){
ObjectMapper mapper = new ObjectMapper();
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createHostUrl[code=%s, message=%s]", response.code(), response.message()));
- throw new SOException("aai createHostUrl failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("createHostUrl occur exception:"+e);
- throw new SOException("aai createHostUrl is not available!", e);
}
return result;
}
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createTopoNetwork[code=%s, message=%s]", response.code(), response.message()));
- throw new SOException("aai createTopoNetwork failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("createTopoNetwork occur exception:"+e);
- throw new SOException("aai createTopoNetwork is not available!", e);
}
return result;
}
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createTerminationPoint[code=%s, message=%s]", response.code(), response.message()));
- throw new SOException("aai createTerminationPoint failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("createTerminationPoint occur exception:"+e);
- throw new SOException("aai createTerminationPoint is not available!", e);
}
return result;
}
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createLink[code=%s, message=%s]", response.code(), response.message()));
- throw new SOException("aai createLink failed!");
}
} catch (Exception e) {
result="FAILED";
logger.error("createLink occur exception:"+e);
- throw new SOException("aai createLink is not available!", e);
}
return result;
}
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not createPnf[code=%s, message=%s]", response.code(), response.message()));
- throw new SOException("aai createPnf failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
} else {
result=Constant.CONSTANT_FAILED;
logger.error(String.format("Can not deleteLink[code=%s, message=%s]", response.code(), response.message()));
- throw new SOException("aai deleteLink failed!");
}
} catch (Exception e) {
result=Constant.CONSTANT_FAILED;
logger.error("deleteLink occur exception:"+e);
- throw new SOException("aai deleteLink is not available!", e);
}
return result;
}
--- /dev/null
+/*
+ * Copyright (C) 2018 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.usecaseui.server.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.List;
+import java.util.Map;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HttpUtil {
+
+ private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
+ /**
+ * 向指定URL发送GET方法的请求
+ *
+ * @param url
+ * 发送请求的URL
+ * @param param
+ * 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+ * @return URL 所代表远程资源的响应结果
+ */
+ public static String sendGet(String url, String param) {
+ String result = "";
+ BufferedReader in = null;
+ try {
+ String urlNameString = url + "?" + param;
+ URL realUrl = new URL(urlNameString);
+ // 打开和URL之间的连接
+ URLConnection connection = realUrl.openConnection();
+ // 设置通用的请求属性
+ connection.setRequestProperty("accept", "*/*");
+ connection.setRequestProperty("connection", "Keep-Alive");
+ connection.setRequestProperty("user-agent",
+ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+ // 建立实际的连接
+ connection.connect();
+ // 获取所有响应头字段
+ Map<String, List<String>> map = connection.getHeaderFields();
+ // 遍历所有的响应头字段
+ for (String key : map.keySet()) {
+ logger.error(key + "--->" + map.get(key));
+ }
+ // 定义 BufferedReader输入流来读取URL的响应
+ in = new BufferedReader(new InputStreamReader(
+ connection.getInputStream()));
+ String line;
+ while ((line = in.readLine()) != null) {
+ result += line;
+ }
+ } catch (Exception e) {
+ logger.error("发送GET请求出现异常!" + e);
+ e.printStackTrace();
+ }
+ // 使用finally块来关闭输入流
+ finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ }
+ return result;
+ }
+
+ /**
+ * 向指定 URL 发送POST方法的请求
+ *
+ * @param url
+ * 发送请求的 URL
+ * @param param
+ * 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
+ * @return 所代表远程资源的响应结果
+ */
+ public static String sendPost(String url, String param) {
+ PrintWriter out = null;
+ BufferedReader in = null;
+ String result = "";
+ try {
+ URL realUrl = new URL(url);
+ // 打开和URL之间的连接
+ URLConnection conn = realUrl.openConnection();
+ // 设置通用的请求属性
+ conn.setRequestProperty("accept", "*/*");
+ conn.setRequestProperty("connection", "Keep-Alive");
+ conn.setRequestProperty("user-agent",
+ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
+ // 发送POST请求必须设置如下两行
+ conn.setDoOutput(true);
+ conn.setDoInput(true);
+ // 获取URLConnection对象对应的输出流
+ out = new PrintWriter(conn.getOutputStream());
+ // 发送请求参数
+ out.print(param);
+ // flush输出流的缓冲
+ out.flush();
+ // 定义BufferedReader输入流来读取URL的响应
+ in = new BufferedReader(
+ new InputStreamReader(conn.getInputStream()));
+ String line;
+ while ((line = in.readLine()) != null) {
+ result += line;
+ }
+ } catch (Exception e) {
+ logger.error("发送 POST 请求出现异常!"+e);
+ e.printStackTrace();
+ }
+ //使用finally块来关闭输出流、输入流
+ finally{
+ try{
+ if(out!=null){
+ out.close();
+ }
+ if(in!=null){
+ in.close();
+ }
+ }
+ catch(IOException ex){
+ ex.printStackTrace();
+ }
+ }
+ return result;
+ }
+}