2 * Copyright 2016 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.common.util.restclient;
19 import java.util.HashMap;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
26 * RestFul instance factory. <br/>
31 * @version 28-May-2016
33 public class RestfulFactory {
38 public static final String PROTO_HTTPS = "https";
43 public static final String PROTO_HTTP = "http";
45 private static final Logger LOG = LoggerFactory.getLogger(RestfulFactory.class);
47 private static final Map<String, Restful> INSTANCES = new HashMap<>(2);
49 private RestfulFactory() {
54 * Get RESTful instance. This method returns a singleton instance.
57 * @param protocol protocol. currently only support 'http'.
58 * @return restful instance.
61 public static synchronized Restful getRestInstance(final String protocol) {
62 Restful rest = INSTANCES.get(protocol);
66 if(PROTO_HTTP.equals(protocol)) {
67 rest = createHttpRest();
68 INSTANCES.put(protocol, rest);
73 private static Restful createHttpRest() {
74 final HttpRest rest = new HttpRest();
75 setRestOption(rest, null);
79 private static void setRestOption(final HttpRest rest, final String restoptionfile) {
81 RestfulConfigure config;
82 if(restoptionfile == null || restoptionfile.isEmpty()) {
83 config = new RestfulConfigure();
85 config = new RestfulConfigure(restoptionfile);
88 final RestfulOptions option = config.getOptions();
89 rest.initHttpRest(option);
90 } catch(final ServiceException e) {
91 LOG.error("init http client exception: ", e);