2 * Copyright (c) 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 SDNO 0.5 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<>();
38 * Set called service name.<br/>
40 * @param serviceName service name.
44 public boolean setCalledServiceName(final String serviceName) {
45 this.setOption(RestfulClientConst.CALLED_SERVICE_NAME, serviceName);
50 * Get called service name.<br/>
55 public String getCalledServicName() {
56 final Object obj = this.getOption(RestfulClientConst.CALLED_SERVICE_NAME);
69 public int getPort() {
70 final Object obj = this.getOption(RestfulClientConst.PORT_KEY_NAME);
74 return ((Integer)obj).intValue();
80 * @param port port to set.
84 public boolean setPort(final int port) {
85 this.setOption(RestfulClientConst.PORT_KEY_NAME, port);
95 public String getHost() {
96 final Object obj = this.getOption(RestfulClientConst.HOST_KEY_NAME);
106 * @param host host to set.
110 public boolean setHost(final String host) {
111 this.setOption(RestfulClientConst.HOST_KEY_NAME, host);
116 * Set rest time-out.<br/>
118 * @param timeout time-out to set in seconds.
122 public boolean setRestTimeout(final int timeout) {
123 if(0 < timeout && REST_OPTIONS_TIMEOUT_MAXTIMEOUT >= timeout) {
124 this.setOption(REST_OPTIONS_NAME_TIMEOUT, timeout);
133 * @return time-out in seconds.
136 public int getRestTimeout() {
137 final Object obj = this.getOption(REST_OPTIONS_NAME_TIMEOUT);
141 return ((Integer)obj).intValue();
145 * Get specified option.<br/>
147 * @param optionName option name.
151 public Object getOption(final String optionName) {
152 return optionsMap.get(optionName);
156 * Get option value as integer.<br/>
158 * @param optionName option name.
159 * @return option value as int.
162 public int getIntOption(final String optionName) {
163 final Object obj = this.getOption(optionName);
167 return ((Integer)obj).intValue();
171 * Get option value as string.<br/>
173 * @param optionName option name.
174 * @return option value as string.
177 public String getStringOption(final String optionName) {
178 final Object obj = this.getOption(optionName);
188 * @param option option name.
189 * @param optionsValue option value.
193 public Object setOption(final String option, final Object optionsValue) {
194 return optionsMap.put(option, optionsValue);