package org.onap.vfc.nfvo.resmanagement.common.util.restclient;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import org.eclipse.jetty.client.ContentExchange;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.io.ByteArrayBuffer;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
-import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.HttpBaseRest;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestHttpContentExchange;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulAsyncCallback;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulOptions;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
-import org.onap.vfc.nfvo.resmanagement.common.util.restclient.ServiceException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import javax.ws.rs.core.Request;
-import javax.ws.rs.core.UriBuilder;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.util.Map;
-
public class HttpsRest extends HttpBaseRest {
private static final Logger LOG = LoggerFactory.getLogger(HttpsRest.class);
client.setTimeout(30000); // 30 seconds timeout; if no server reply, the request expires
try {
client.start();
- } catch (Exception e) {
+ } catch(Exception e) {
e.printStackTrace();
}
}
}
@Override
- public RestfulResponse head(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse head(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
return null;
}
}
@Override
- public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncGet(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
}
@Override
- public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPut(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
}
@Override
- public RestfulResponse post(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse post(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
return null;
}
@Override
- public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPost(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
}
@Override
- public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncDelete(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
}
@Override
- public RestfulResponse patch(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse patch(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
return null;
}
@Override
- public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulAsyncCallback callback)
+ throws ServiceException {
}
@Override
- public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulOptions options, RestfulAsyncCallback callback) throws ServiceException {
+ public void asyncPatch(String servicePath, RestfulParametes restParametes, RestfulOptions options,
+ RestfulAsyncCallback callback) throws ServiceException {
}
@Override
- public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option) throws ServiceException {
+ public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option)
+ throws ServiceException {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(servicePath);
exchange.setMethod("GET");
- restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+ restParametes.getHeaderMap().entrySet().stream()
+ .forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
try {
client.send(exchange);
- } catch (IOException e) {
+ } catch(IOException e) {
e.printStackTrace();
}
try {
int exchangeState = exchange.waitForDone();
- if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ if(exchangeState == HttpExchange.STATUS_COMPLETED) {
String res = exchange.getResponseContent();
LOG.info(res);
RestfulResponse restfulResponse = new RestfulResponse();
restfulResponse.setResponseJson(exchange.getResponseContent());
- restfulResponse.setStatus(exchange.getStatus());
+ restfulResponse.setStatus(exchange.getResponseStatus());
return restfulResponse;
} else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
throw new ServiceException(
throw new ServiceException(
"request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
}
- } catch (InterruptedException e) {
+ } catch(InterruptedException e) {
e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
+ } catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
@Override
- public RestfulResponse put(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse put(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
ContentExchange exchange = new ContentExchange(true);
exchange.setURL(servicePath);
exchange.setMethod("PUT");
exchange.setRequestContent(new ByteArrayBuffer(restParametes.getRawData()));
- restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+ restParametes.getHeaderMap().entrySet().stream()
+ .forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
try {
client.send(exchange);
- } catch (IOException e) {
+ } catch(IOException e) {
e.printStackTrace();
}
try {
int exchangeState = exchange.waitForDone();
- if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ if(exchangeState == HttpExchange.STATUS_COMPLETED) {
String res = exchange.getResponseContent();
LOG.info(res);
RestfulResponse restfulResponse = new RestfulResponse();
restfulResponse.setResponseJson(exchange.getResponseContent());
- restfulResponse.setStatus(exchange.getStatus());
+ restfulResponse.setStatus(exchange.getResponseStatus());
return restfulResponse;
} else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
throw new ServiceException(
throw new ServiceException(
"request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
}
- } catch (InterruptedException e) {
+ } catch(InterruptedException e) {
e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
+ } catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
@Override
- public RestfulResponse delete(String servicePath, RestfulParametes restParametes, RestfulOptions options) throws ServiceException {
+ public RestfulResponse delete(String servicePath, RestfulParametes restParametes, RestfulOptions options)
+ throws ServiceException {
ContentExchange exchange = new ContentExchange(true);
String encodeParams = RequestUtil.encodeParams(restParametes);
- if (encodeParams.isEmpty()) {
+ if(encodeParams.isEmpty()) {
exchange.setURL(servicePath);
} else {
exchange.setURL(servicePath + "?" + encodeParams);
}
exchange.setMethod("DELETE");
- if (restParametes.getRawData() != null) {
+ if(restParametes.getRawData() != null) {
exchange.setRequestContent(new ByteArrayBuffer(restParametes.getRawData()));
}
- restParametes.getHeaderMap().entrySet().stream().forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
+ restParametes.getHeaderMap().entrySet().stream()
+ .forEach(entry -> exchange.setRequestHeader(entry.getKey(), entry.getValue()));
try {
client.send(exchange);
- } catch (IOException e) {
+ } catch(IOException e) {
e.printStackTrace();
}
try {
int exchangeState = exchange.waitForDone();
- if (exchangeState == HttpExchange.STATUS_COMPLETED) {
+ if(exchangeState == HttpExchange.STATUS_COMPLETED) {
String res = exchange.getResponseContent();
LOG.info(res);
RestfulResponse restfulResponse = new RestfulResponse();
restfulResponse.setResponseJson(exchange.getResponseContent());
- restfulResponse.setStatus(exchange.getStatus());
+ restfulResponse.setStatus(exchange.getResponseStatus());
return restfulResponse;
} else if(exchangeState == HttpExchange.STATUS_EXCEPTED) {
throw new ServiceException(
throw new ServiceException(
"request is expierd: " + RestHttpContentExchange.toState(HttpExchange.STATUS_EXPIRED));
}
- } catch (InterruptedException e) {
+ } catch(InterruptedException e) {
e.printStackTrace();
- } catch (UnsupportedEncodingException e) {
+ } catch(UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
--- /dev/null
+/*
+ * Copyright 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.
+ * 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.resmanagement.service.listener;
+
+import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_CUSTOMER_ID;
+import static org.onap.vfc.nfvo.resmanagement.common.constant.Constant.VFC_SERVICE_SUBSCRIPTION_ID;
+
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulParametes;
+import org.onap.vfc.nfvo.resmanagement.common.util.restclient.RestfulResponse;
+
+public class AaiNamespaceInitializer implements ServletContextListener {
+
+ @Override
+ public void contextDestroyed(ServletContextEvent arg0) {
+ }
+
+ @Override
+ public void contextInitialized(ServletContextEvent arg0) {
+ createCustomer();
+ createServiceSubscription();
+ }
+
+ private int createCustomer() {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData("{\"global-customer-id\": \"" + VFC_CUSTOMER_ID + "\"," + "\"subscriber-name\": \""
+ + VFC_CUSTOMER_ID + "\"," + "\"subscriber-type\": \"" + VFC_CUSTOMER_ID + "\"}");
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID, restfulParametes,
+ "put");
+ return response.getStatus();
+ }
+
+ private int createServiceSubscription() {
+ RestfulParametes restfulParametes = new RestfulParametes();
+ restfulParametes.setHeaderMap(RequestUtil.getAAIHeaderMap());
+ restfulParametes.setRawData("{\"service-type\": \"" + VFC_SERVICE_SUBSCRIPTION_ID + "\"}");
+
+ RestfulResponse response = RestfulUtil.getRestfulResponse(
+ "https://192.168.17.24:8443/aai/v11/business/customers/customer/" + VFC_CUSTOMER_ID
+ + "/service-subscriptions/service-subscription/" + VFC_SERVICE_SUBSCRIPTION_ID,
+ restfulParametes, "put");
+ return response.getStatus();
+ }
+
+}