2 * Copyright 2015 Samsung Electronics All Rights Reserved.
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.oic.simulator.clientcontroller;
19 import java.util.LinkedList;
22 import org.oic.simulator.InvalidArgsException;
23 import org.oic.simulator.NoSupportException;
24 import org.oic.simulator.OperationInProgressException;
25 import org.oic.simulator.SimulatorException;
26 import org.oic.simulator.SimulatorResourceModel;
27 import org.oic.simulator.SimulatorResult;
30 * SimulatorRemoteResource represents a Resource running in the remote Simulator
31 * Server. It comes with a well-defined contract or interface onto which you can
32 * perform different operations or subscribe for event notifications.
34 public class SimulatorRemoteResource {
36 private SimulatorRemoteResource(long nativeHandle) {
37 this.nativeHandle = nativeHandle;
41 * API to get the URI for this resource.
43 * @return Resource URI
45 public String getUri() {
50 * API to get the observe policy of this resource.
52 * @return True if the resource is observable, otherwise false.
54 public boolean getIsObservable() {
59 * API to get the connectivity type for this resource.
61 * @return Connectivity type.
63 public SimulatorConnectivityType getConnectivityType() {
64 return SimulatorConnectivityType.getConnectivityType(mConnType);
68 * API to get the list of resource types.
70 * @return List of resource types.
72 public LinkedList<String> getResourceTypes() {
77 * API to get the list of resource interfaces.
79 * @return List of resource interfaces.
81 public LinkedList<String> getResourceInterfaces() {
82 return mResInterfaces;
86 * API to get host address and port information of the resource.
88 * @return Host address.
90 public String getHost() {
95 * API to get a unique Id of the resource .
99 public String getId() {
104 * API to start observing the resource.
107 * Allows the client to specify how it wants to observe.
108 * @param queryParamsMap
109 * Map which can have the query parameter names and values.
110 * @param onObserveListener
111 * The handler method which will be invoked with a map of
112 * attribute names and values whenever there is a change in
113 * resource model of the remote resource.
115 * @throws InvalidArgsException
116 * This exception will be thrown if any parameter has invalid
118 * @throws SimulatorException
119 * This exception will be thrown for other errors.
121 public native void startObserve(SimulatorObserveType observeType,
122 Map<String, String> queryParamsMap,
123 IObserveListener onObserveListener) throws InvalidArgsException,
127 * API to stop observing the resource.
129 * @throws InvalidArgsException
130 * This exception will be thrown if the native remote resource
131 * object is unavailable.
132 * @throws SimulatorException
133 * This exception will be thrown for other errors.
135 public native void stopObserve() throws InvalidArgsException,
139 * API to send GET request to the resource. Response will be notified
140 * asynchronously via callback set for {@link IGetListener}.
142 * @param queryParamsMap
143 * Map which can have the query parameter name and value.
144 * @param onGetListener
145 * Event handler which will be invoked with the response for GET
146 * request with a map of attribute name and values.
148 * @throws InvalidArgsException
149 * This exception will be thrown if any parameter has invalid
151 * @throws NoSupportException
152 * This exception will be thrown if we cannot send GET request
153 * to the remote resource.
154 * @throws SimulatorException
155 * This exception will be thrown for other errors.
157 public void get(Map<String, String> queryParamsMap,
158 IGetListener onGetListener) throws InvalidArgsException,
159 NoSupportException, SimulatorException {
160 if (null == onGetListener)
161 throw new InvalidArgsException(
162 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
163 "Parameter passed in invalid");
164 this.nativeGet(null, queryParamsMap, onGetListener);
168 * API to send GET request to the resource. Response will be notified
169 * asynchronously via callback set for {@link IGetListener}.
171 * @param resourceInterface
172 * Interface type of the resource to operate on.
173 * @param queryParamsMap
174 * Map which can have the query parameter name and value.
175 * @param onGetListener
176 * Event handler which will be invoked with the response for GET
177 * request with a map of attribute name and values.
179 * @throws InvalidArgsException
180 * This exception will be thrown if any parameter has invalid
182 * @throws NoSupportException
183 * This exception will be thrown if we cannot send GET request
184 * to the remote resource.
185 * @throws SimulatorException
186 * This exception will be thrown for other errors.
188 public void get(String resourceInterface,
189 Map<String, String> queryParamsMap, IGetListener onGetListener)
190 throws InvalidArgsException, NoSupportException, SimulatorException {
191 if (null == resourceInterface || resourceInterface.isEmpty() || null == onGetListener)
192 throw new InvalidArgsException(
193 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
194 "Parameter passed in invalid");
195 this.nativeGet(resourceInterface, queryParamsMap, onGetListener);
198 private native void nativeGet(String resourceInterface,
199 Map<String, String> queryParamsMap, IGetListener onGetListener)
200 throws InvalidArgsException, NoSupportException, SimulatorException;
203 * API to send PUT request to the resource. Response will be notified
204 * asynchronously via callback set for {@link IPutListener}.
206 * @param representation
207 * {@link SimulatorResourceModel} holding the representation of
209 * @param queryParamsMap
210 * Map which can have the query parameter name and value.
211 * @param onPutListener
212 * Event handler which will be invoked with the response for PUT
213 * request with a map of attribute name and values.
215 * @throws InvalidArgsException
216 * This exception will be thrown if any parameter has invalid
218 * @throws NoSupportException
219 * This exception will be thrown if we cannot send PUT request
220 * to the remote resource.
221 * @throws SimulatorException
222 * This exception will be thrown for other errors.
224 public void put(SimulatorResourceModel representation,
225 Map<String, String> queryParamsMap, IPutListener onPutListener)
226 throws InvalidArgsException, NoSupportException, SimulatorException {
227 if (null == representation || null == onPutListener)
228 throw new InvalidArgsException(
229 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
230 "Parameter passed in invalid");
231 this.nativePut(null, representation, queryParamsMap, onPutListener);
235 * API to send PUT request to the resource. Response will be notified
236 * asynchronously via callback set for {@link IPutListener}.
238 * @param resourceInterface
239 * Interface type of the resource to operate on.
240 * @param representation
241 * {@link SimulatorResourceModel} holding the representation of
243 * @param queryParamsMap
244 * Map which can have the query parameter name and value.
245 * @param onPutListener
246 * Event handler which will be invoked with the response for PUT
247 * request with a map of attribute name and values.
249 * @throws InvalidArgsException
250 * This exception will be thrown if any parameter has invalid
252 * @throws NoSupportException
253 * This exception will be thrown if we cannot send PUT request
254 * to the remote resource.
255 * @throws SimulatorException
256 * This exception will be thrown for other errors.
258 public void put(String resourceInterface,
259 SimulatorResourceModel representation,
260 Map<String, String> queryParamsMap, IPutListener onPutListener)
261 throws InvalidArgsException, NoSupportException, SimulatorException {
262 if (null == resourceInterface || resourceInterface.isEmpty() ||
263 null == representation || null == onPutListener)
264 throw new InvalidArgsException(
265 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
266 "Parameter passed in invalid");
267 this.nativePut(resourceInterface, representation, queryParamsMap, onPutListener);
270 private native void nativePut(String resourceInterface,
271 SimulatorResourceModel representation,
272 Map<String, String> queryParamsMap, IPutListener onPutListener)
273 throws InvalidArgsException, NoSupportException, SimulatorException;
276 * API to send POST request to the resource. Response will be notified
277 * asynchronously via callback set for {@link IPostListener}.
279 * @param representation
280 * {@link SimulatorResourceModel} holding the representation of
282 * @param queryParamsMap
283 * Map which can have the query parameter name and value
284 * @param onPostListener
285 * Event handler which will be invoked with the response for POST
286 * request with a map of attribute name and values.
288 * @throws InvalidArgsException
289 * This exception will be thrown if any parameter has invalid
291 * @throws NoSupportException
292 * This exception will be thrown if we cannot send POST request
293 * on the remote resource.
294 * @throws SimulatorException
295 * This exception will be thrown for other errors.
297 public void post(SimulatorResourceModel representation,
298 Map<String, String> queryParamsMap, IPostListener onPostListener)
299 throws InvalidArgsException, NoSupportException, SimulatorException {
300 if (null == representation || null == onPostListener)
301 throw new InvalidArgsException(
302 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
303 "Parameter passed in invalid");
304 this.nativePost(null, representation, queryParamsMap, onPostListener);
308 * API to send POST request to the resource. Response will be notified
309 * asynchronously via callback set for {@link IPostListener}.
311 * @param resourceInterface
312 * Interface type of the resource to operate on.
313 * @param representation
314 * {@link SimulatorResourceModel} holding the representation of
316 * @param queryParamsMap
317 * Map which can have the query parameter name and value.
318 * @param onPostListener
319 * Event handler which will be invoked with the response for POST
320 * request with a map of attribute name and values.
322 * @throws InvalidArgsException
323 * This exception will be thrown if any parameter has invalid
325 * @throws NoSupportException
326 * This exception will be thrown if we cannot send POST request
327 * on the remote resource.
328 * @throws SimulatorException
329 * This exception will be thrown for other errors.
331 public void post(String resourceInterface,
332 SimulatorResourceModel representation,
333 Map<String, String> queryParamsMap, IPostListener onPostListener)
334 throws InvalidArgsException, NoSupportException, SimulatorException {
335 if (null == resourceInterface || resourceInterface.isEmpty() ||
336 null == representation || null == onPostListener)
337 throw new InvalidArgsException(
338 SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
339 "Parameter passed in invalid");
340 this.nativePost(resourceInterface, representation, queryParamsMap, onPostListener);
343 private native void nativePost(String resourceInterface,
344 SimulatorResourceModel representation,
345 Map<String, String> queryParamsMap, IPostListener onPostListener)
346 throws InvalidArgsException, NoSupportException, SimulatorException;
349 * API to provide remote resource configure information,
350 * which is required for using automation feature.
355 * @throws InvalidArgsException
356 * Thrown if the RAML configuration file path is invalid.
357 * @throws SimulatorException
358 * Thrown for other errors.
360 public native void setConfigInfo(String path)
361 throws InvalidArgsException, SimulatorException;
364 * API to send multiple requests for the resource, based on
365 * the configure file provided from {@link setConfigInfo}.
366 * This verifies response received as well.
369 * Request type to verify.
370 * @param onVerifyListener
371 * This event handler will be invoked with the current status of
374 * @return Automation ID.
376 * @throws InvalidArgsException
377 * This exception will be thrown if any parameter has invalid
379 * @throws NoSupportException
380 * Thrown either if the resource does not support the request
381 * type or the resource is not configured with RAML.
382 * @throws OperationInProgressException
383 * Thrown if another request generation session is already in
385 * @throws SimulatorException
386 * This exception will be thrown for other errors.
388 public int startVerification(SimulatorVerificationType requestType,
389 IVerificationListener onVerifyListener)
390 throws InvalidArgsException, NoSupportException,
391 OperationInProgressException, SimulatorException {
392 return startVerification(requestType.ordinal(), onVerifyListener);
396 * API to stop sending requests which has been started using {@link setConfigInfo}.
401 * @throws InvalidArgsException
402 * Thrown if the automation ID is invalid.
403 * @throws NoSupportException
404 * Thrown if the resource is not configured with RAML.
405 * @throws SimulatorException
406 * Thrown for other errors.
408 public native void stopVerification(int id) throws InvalidArgsException,
409 NoSupportException, SimulatorException;
411 private native int startVerification(int requestType,
412 IVerificationListener onVerifyListener)
413 throws InvalidArgsException, NoSupportException,
414 OperationInProgressException, SimulatorException;
417 protected void finalize() throws Throwable {
425 private native void dispose();
427 private long nativeHandle;
429 private int mConnType;
430 private String mHost;
432 private LinkedList<String> mResTypes;
433 private LinkedList<String> mResInterfaces;
434 private boolean mIsObservable;