Java tutorial
/* Copyright 2013 Terso Solutions Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package com.TersoSolutions.Jetstream.SDK.Application.User; import java.io.File; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import com.TersoSolutions.Jetstream.SDK.Application.JetstreamClient; import com.TersoSolutions.Jetstream.SDK.Application.JetstreamResponseException; /** * Client proxy object for the Jetstream Web Service * * @author Johnathon Ender * @since 1.0 */ public class JetstreamServiceClient extends JetstreamClient { private String _baseUri; private String _accessKey; private Configuration config; /* * ////////////////////////////////////////////////////////////////////////// * * Constructor */// /////////////////////////////////////////////////////////////////////// /** * Constructor for the JetstreamServiceClient. This client is the base * service for accessing the Jetstream REST endpoints. Reads information * from the service.properties file located at the root of the project * * @throws IllegalArgumentException */ public JetstreamServiceClient() { try { config = new PropertiesConfiguration("service.properties"); String jetstreamAPIUrl = config.getString("jetstream.baseuri"); String accessKey = config.getString("jetstream.accesskey"); init(jetstreamAPIUrl, accessKey); } catch (ConfigurationException e) { e.printStackTrace(); } } /** * Constructor for the JetstreamServiceClient. This client is the base * service for accessing the Jetstream REST endpoints. Reads information * from the provided file * * @param properties * The properties file * @throws IllegalArgumentException */ public JetstreamServiceClient(File properties) { try { config = new PropertiesConfiguration(properties); String jetstreamAPIUrl = config.getString("jetstream.baseuri"); String accessKey = config.getString("jetstream.accesskey"); init(jetstreamAPIUrl, accessKey); } catch (ConfigurationException e) { e.printStackTrace(); } } /** * Constructor for the JetstreamServiceClient. This client is the base * service for accessing the Jetstream REST endpoints. * * @param jetstreamAPIUrl * The root https url for the Jetstream web service. * <p> * https://jetstream.tersosolutions.com * </p> * <p> * https://jetstreambeta.tersosolutions.com * </p> * @param accessKey * Your accesskey for Jetstream * @throws IllegalArgumentException */ public JetstreamServiceClient(String jetstreamAPIUrl, String accessKey) { init(jetstreamAPIUrl, accessKey); } /* * A initialization helper method that checks for null or invalid values * * An IllegalArgumentException is thrown if any values are invalid */ private void init(String jetstreamAPIUrl, String accessKey) { if (jetstreamAPIUrl == null || jetstreamAPIUrl.isEmpty()) { throw new IllegalArgumentException("Invalid Url: " + "Url is null or empty"); } if (accessKey == null || accessKey.isEmpty()) { throw new IllegalArgumentException("Invalid Access Key: " + "Access Key is null or empty"); } jetstreamAPIUrl = jetstreamAPIUrl.trim(); if (!jetstreamAPIUrl.endsWith("/")) { jetstreamAPIUrl += "/"; } _baseUri = jetstreamAPIUrl; _accessKey = accessKey; } /** * Returns the root https url for the Jetstream web service. * * @return a String representing the root https url for the Jetstream web * service. */ public String getBaseUri() { return _baseUri; } /** * Returns the root https url for the Jetstream web service. * * @return a String representing the root https url for the Jetstream web * service. */ public String getAccessKey() { return _accessKey; } /** * Calls the Jetstream v1.5 AddLogicalDevice REST endpoint and adds a device * to your application. * https://jetstreamrfid.com/Docs/Application/1.5/AddLogicalDevice.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public AddLogicalDeviceResponse AddLogicalDevice(AddLogicalDeviceRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, AddLogicalDeviceResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 GetDeviceDefinitions REST endpoint * https://jetstreamrfid.com/Docs/Application/1.5/GetDeviceDefinitions.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public GetDeviceDefinitionsResponse GetDeviceDefinitions(GetDeviceDefinitionsRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, GetDeviceDefinitionsResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 RemoveLogicalDevice REST endpoint and removes a * device from your application. * https://jetstreamrfid.com/Docs/Application/1.5/RemoveLogicalDevice.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public RemoveLogicalDeviceResponse RemoveLogicalDevice(RemoveLogicalDeviceRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, RemoveLogicalDeviceResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 GetEPCListCommand REST endpoint to queue a * command * https://jetstreamrfid.com/Docs/Application/1.5/GetEPCListCommand.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public GetEPCListCommandResponse GetEPCListCommand(GetEPCListCommandRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, GetEPCListCommandResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 DeviceSpecificCommand REST endpoint to queue a * command specific to an individual device type * https://jetstreamrfid.com/Docs/Application/1.5/DeviceSpecificCommand.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public DeviceSpecificCommandResponse DeviceSpecificCommand(DeviceSpecificCommandRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, DeviceSpecificCommandResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 ResetCommand REST endpoint to queue a command * https://jetstreamrfid.com/Docs/Application/1.5/ResetCommand.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public ResetCommandResponse ResetCommand(ResetCommandRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, ResetCommandResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 GetConfigValuesCommand REST endpoint to queue a * command * https://jetstreamrfid.com/Docs/Application/1.5/GetConfigValuesCommand * .aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public GetConfigValuesCommandResponse GetConfigValuesCommand(GetConfigValuesCommandRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, GetConfigValuesCommandResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 SetConfigValuesCommand REST endpoint to queue a * command * https://jetstreamrfid.com/Docs/Application/1.5/SetConfigValuesCommand * .aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public SetConfigValuesCommandResponse SetConfigValuesCommand(SetConfigValuesCommandRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, SetConfigValuesCommandResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 UpdateFirmwareCommand REST endpoint to queue a * command * https://jetstreamrfid.com/Docs/Application/1.5/UpdateFirmwareCommand.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public UpdateFirmwareCommandResponse UpdateFirmwareCommand(UpdateFirmwareCommandRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, UpdateFirmwareCommandResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 GetConfiguration REST endpoint * https://jetstreamrfid.com/Docs/Application/1.5/GetConfiguration.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public GetConfigurationResponse GetConfiguration(GetConfigurationRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, GetConfigurationResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 AddDeviceToPolicy REST endpoint and adds a * device to one of your application's policies. * https://jetstreamrfid.com/Docs/Application/1.5/AddDeviceToPolicy.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public AddDeviceToPolicyResponse AddDeviceToPolicy(AddDeviceToPolicyRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, AddDeviceToPolicyResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 AddPolicy REST endpoint and adds a new policy to * your application. * https://jetstreamrfid.com/Docs/Application/1.5/AddPolicy.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public AddPolicyResponse AddPolicy(AddPolicyRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, AddPolicyResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 GetPolicies REST endpoint and adds a new policy * to your application. * https://jetstreamrfid.com/Docs/Application/1.5/GetPolicies.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public GetPoliciesResponse GetPolicies(GetPoliciesRequest request) throws JetstreamResponseException { return execute(request, GetPoliciesResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 RemovePolicy REST endpoint and removes an * existing policy from your application. * https://jetstreamrfid.com/Docs/Application/1.5/RemovePolicy.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public RemovePolicyResponse RemovePolicy(RemovePolicyRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, RemovePolicyResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 RemoveDeviceFromPolicy REST endpoint and removes * an existing device from a policy * https://jetstreamrfid.com/Docs/Application * /1.1/RemoveDeviceFromPolicy.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public RemoveDeviceFromPolicyResponse RemoveDeviceFromPolicy(RemoveDeviceFromPolicyRequest request) throws JetstreamResponseException { return execute(request, RemoveDeviceFromPolicyResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 GetEvents REST endpoint * https://jetstreamrfid.com/Docs/Application/1.5/GetEvents.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public GetEventsResponse GetEvents(GetEventsRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, GetEventsResponse.class, _baseUri, _accessKey); } /** * Calls the Jetstream v1.5 RemoveEvents REST endpoint * https://jetstreamrfid.com/Docs/Application/1.5/RemoveEvents.aspx * * @param request * Object that represents the HTTP Jetstream request * @return Object that represents the HTTP Jetstream response * @throws JetstreamResponseException * @throws IllegalArgumentException */ public RemoveEventsResponse RemoveEvents(RemoveEventsRequest request) throws JetstreamResponseException, IllegalArgumentException { return execute(request, RemoveEventsResponse.class, _baseUri, _accessKey); } }