update the pom version for the security issue fix
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / main / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / common / restclient / RestfulOptions.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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
18
19 import java.util.HashMap;
20 import java.util.Map;
21
22 /**
23  * Options for Rest communication.<br/>
24  * <p>
25  * </p>
26  * 
27  * @author
28  * @version 28-May-2016
29  */
30 public class RestfulOptions {
31
32     public static final String REST_OPTIONS_NAME_TIMEOUT = "timeout";
33
34     public static final int REST_OPTIONS_TIMEOUT_MAXTIMEOUT = 1800000;
35
36     private final Map<String, Object> optionsMap = new HashMap<>();
37
38     /**
39      * Get port.<br/>
40      * 
41      * @return port.
42      * @since
43      */
44     public int getPort() {
45         final Object obj = this.getOption(RestfulClientConst.PORT_KEY_NAME);
46         if(null == obj) {
47             return 0;
48         }
49         return ((Integer)obj).intValue();
50     }
51
52     /**
53      * Set port.<br/>
54      * 
55      * @param port port to set.
56      * @return
57      * @since
58      */
59     public boolean setPort(final int port) {
60         this.setOption(RestfulClientConst.PORT_KEY_NAME, port);
61         return true;
62     }
63
64     /**
65      * Get host.<br/>
66      * 
67      * @return the host.
68      * @since
69      */
70     public String getHost() {
71         final Object obj = this.getOption(RestfulClientConst.HOST_KEY_NAME);
72         if(null == obj) {
73             return "";
74         }
75         return (String)obj;
76     }
77
78     /**
79      * Set host.<br/>
80      * 
81      * @param host host to set.
82      * @return
83      * @since
84      */
85     public boolean setHost(final String host) {
86         this.setOption(RestfulClientConst.HOST_KEY_NAME, host);
87         return true;
88     }
89
90     /**
91      * Set rest time-out.<br/>
92      * 
93      * @param timeout time-out to set in seconds.
94      * @return
95      * @since
96      */
97     public boolean setRestTimeout(final int timeout) {
98         if(0 < timeout && REST_OPTIONS_TIMEOUT_MAXTIMEOUT >= timeout) {
99             this.setOption(REST_OPTIONS_NAME_TIMEOUT, timeout);
100             return true;
101         }
102         return false;
103     }
104
105     /**
106      * Get time-out.<br/>
107      * 
108      * @return time-out in seconds.
109      * @since
110      */
111     public int getRestTimeout() {
112         final Object obj = this.getOption(REST_OPTIONS_NAME_TIMEOUT);
113         if(null == obj) {
114             return 0;
115         }
116         return ((Integer)obj).intValue();
117     }
118
119     /**
120      * Get specified option.<br/>
121      * 
122      * @param optionName option name.
123      * @return option
124      * @since
125      */
126     public Object getOption(final String optionName) {
127         return optionsMap.get(optionName);
128     }
129
130     /**
131      * Get option value as integer.<br/>
132      * 
133      * @param optionName option name.
134      * @return option value as int.
135      * @since
136      */
137     public int getIntOption(final String optionName) {
138         final Object obj = this.getOption(optionName);
139         if(null == obj) {
140             return 0;
141         }
142         return ((Integer)obj).intValue();
143     }
144
145     /**
146      * Get option value as string.<br/>
147      * 
148      * @param optionName option name.
149      * @return option value as string.
150      * @since
151      */
152     public String getStringOption(final String optionName) {
153         final Object obj = this.getOption(optionName);
154         if(null == obj) {
155             return "";
156         }
157         return (String)obj;
158     }
159
160     /**
161      * Set option.<br/>
162      * 
163      * @param option option name.
164      * @param optionsValue option value.
165      * @return
166      * @since
167      */
168     public Object setOption(final String option, final Object optionsValue) {
169         return optionsMap.put(option, optionsValue);
170     }
171 }