1c0da4ff9990a69915cbf7b925f1f80795cf2fa5
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / main / java / org / openo / nfvo / jujuvnfmadapter / common / servicetoken / HttpRestHelp.java
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openo.nfvo.jujuvnfmadapter.common.servicetoken;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 import org.openo.baseservice.roa.util.restclient.HttpRest;
23 import org.openo.baseservice.roa.util.restclient.Restful;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 /**
28  * 
29  * Http rest help class.<br>
30  * <p>
31  * </p>
32  * 
33  * @author
34  * @version     NFVO 0.5  Sep 12, 2016
35  */
36 public class HttpRestHelp {
37
38     public static final String PROTO_HTTP = "http";
39
40     private static final Logger LOG = LoggerFactory.getLogger(HttpRestHelp.class);
41
42     private static final Map<String, Restful> INSTANCES = new HashMap<>(2);
43
44     private HttpRestHelp() {
45         // constructor
46     }
47
48     private static Restful createHttpsRest(String ssloptionfile, String restoptionfile, boolean isHttps) {
49
50         HttpRest rest = new HttpRest();
51         setHttpsRestOption(rest, restoptionfile);
52         return rest;
53     }
54
55     /**
56      * 
57      * Get rest instance class.<br>
58      * 
59      * @param ssloptionfile
60      * @param restoptionfile
61      * @param isHttps
62      * @return
63      * @since  NFVO 0.5
64      */
65     public static synchronized Restful getRestInstance(String ssloptionfile, String restoptionfile, boolean isHttps) {
66         Restful rest = INSTANCES.get(PROTO_HTTP);
67         if(null != rest) {
68             return rest;
69         }
70         rest = createHttpsRest(ssloptionfile, restoptionfile, isHttps);
71         INSTANCES.put(PROTO_HTTP, rest);
72         return rest;
73     }
74
75     private static void setHttpsRestOption(HttpRest httpRest, String restoptfile) {
76         LOG.info("setHttpsRestOption");
77     }
78
79 }