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.
16 package org.openo.baseservice.roa.util.restclient;
18 import java.util.HashMap;
22 * Options for Rest communication.<br/>
27 * @version 28-May-2016
29 public class RestfulOptions {
31 public static final String REST_OPTIONS_NAME_TIMEOUT = "timeout";
33 public static final int REST_OPTIONS_TIMEOUT_MAXTIMEOUT = 1800000;
35 private final Map<String, Object> optionsMap = new HashMap<>();
43 public int getPort() {
44 final Object obj = this.getOption(RestfulClientConst.PORT_KEY_NAME);
48 return ((Integer)obj).intValue();
54 * @param port port to set.
58 public boolean setPort(final int port) {
59 this.setOption(RestfulClientConst.PORT_KEY_NAME, port);
69 public String getHost() {
70 final Object obj = this.getOption(RestfulClientConst.HOST_KEY_NAME);
80 * @param host host to set.
84 public boolean setHost(final String host) {
85 this.setOption(RestfulClientConst.HOST_KEY_NAME, host);
90 * Set rest time-out.<br/>
92 * @param timeout time-out to set in seconds.
96 public boolean setRestTimeout(final int timeout) {
97 if(0 < timeout && REST_OPTIONS_TIMEOUT_MAXTIMEOUT >= timeout) {
98 this.setOption(REST_OPTIONS_NAME_TIMEOUT, timeout);
107 * @return time-out in seconds.
110 public int getRestTimeout() {
111 final Object obj = this.getOption(REST_OPTIONS_NAME_TIMEOUT);
115 return ((Integer)obj).intValue();
119 * Get specified option.<br/>
121 * @param optionName option name.
125 public Object getOption(final String optionName) {
126 return optionsMap.get(optionName);
130 * Get option value as integer.<br/>
132 * @param optionName option name.
133 * @return option value as int.
136 public int getIntOption(final String optionName) {
137 final Object obj = this.getOption(optionName);
141 return ((Integer)obj).intValue();
145 * Get option value as string.<br/>
147 * @param optionName option name.
148 * @return option value as string.
151 public String getStringOption(final String optionName) {
152 final Object obj = this.getOption(optionName);
162 * @param option option name.
163 * @param optionsValue option value.
167 public Object setOption(final String option, final Object optionsValue) {
168 return optionsMap.put(option, optionsValue);