2 * Copyright 2017 Huawei Technologies Co., Ltd.
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.resmanagement.service.listener;
19 import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_CUSTOMER_ID;
20 import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_SERVICE_SUBSCRIPTION_ID;
22 import javax.servlet.ServletContextEvent;
23 import javax.servlet.ServletContextListener;
25 import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
26 import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
27 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
28 import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
30 public class AaiNamespaceInitializer implements ServletContextListener {
33 public void contextDestroyed(ServletContextEvent arg0) {
37 public void contextInitialized(ServletContextEvent arg0) {
39 createServiceSubscription();
42 private int createCustomer() {
43 RestfulParametes restfulParametes = new RestfulParametes();
44 restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
45 restfulParametes.setRawData("{\"global-customer-id\": \"" + VFC_CUSTOMER_ID + "\"," + "\"subscriber-name\": \""
46 + VFC_CUSTOMER_ID + "\"," + "\"subscriber-type\": \"" + VFC_CUSTOMER_ID + "\"}");
48 RestfulResponse response = RestfulUtil.getRestfulResponse(
49 "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID, restfulParametes,
51 return response.getStatus();
54 private int createServiceSubscription() {
55 RestfulParametes restfulParametes = new RestfulParametes();
56 restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
57 restfulParametes.setRawData("{\"service-type\": \"" + VFC_SERVICE_SUBSCRIPTION_ID + "\"}");
59 RestfulResponse response = RestfulUtil.getRestfulResponse(
60 "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID
61 + "/service-subscriptions/service-subscription/" + VFC_SERVICE_SUBSCRIPTION_ID,
62 restfulParametes, "put");
63 return response.getStatus();