use of com.microsoft.azure.sdk.iot.service.ProxyOptions in project azure-iot-sdk-java by Azure.
the class DeviceTwin method queryTwinCollection.
/**
* Create a {@link QueryCollection} object that can be used to query whole pages of results at a time.
* QueryCollection objects also allow you to provide a continuation token for the query to pick up from.
*
* @param sqlQuery The SQL-style query to run.
* @param pageSize the number of results to return at a time.
* @return The created QueryCollection object that can be used to query the service.
* @throws MalformedURLException If twin query URL is not correct.
*/
public synchronized QueryCollection queryTwinCollection(String sqlQuery, Integer pageSize) throws MalformedURLException {
ProxyOptions proxyOptions = options.getProxyOptions();
Proxy proxy = proxyOptions != null ? proxyOptions.getProxy() : null;
if (this.credentialCache != null) {
return new QueryCollection(sqlQuery, pageSize, QueryType.TWIN, this.credentialCache, IotHubConnectionString.getUrlTwinQuery(this.hostName), HttpMethod.POST, options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
} else if (this.azureSasCredential != null) {
return new QueryCollection(sqlQuery, pageSize, QueryType.TWIN, this.azureSasCredential, IotHubConnectionString.getUrlTwinQuery(this.hostName), HttpMethod.POST, options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
} else {
return new QueryCollection(sqlQuery, pageSize, QueryType.TWIN, this.iotHubConnectionString, IotHubConnectionString.getUrlTwinQuery(this.hostName), HttpMethod.POST, options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
}
}
use of com.microsoft.azure.sdk.iot.service.ProxyOptions in project azure-iot-sdk-java by Azure.
the class DeviceTwin method queryTwin.
/**
* SQL-style query for twin.
*
* @param sqlQuery SQL-style query string to query Iot hub for Twin.
* @param pageSize Size to limit query response by.
* @return {@link Query} Object to be used for looking up responses for this query.
* @throws IotHubException If query request was not successful at the Iot hub.
* @throws IOException If input parameters are invalid.
*/
public synchronized Query queryTwin(String sqlQuery, Integer pageSize) throws IotHubException, IOException {
if (sqlQuery == null || sqlQuery.length() == 0) {
throw new IllegalArgumentException("Query cannot be null or empty.");
}
if (pageSize <= 0) {
throw new IllegalArgumentException("pageSize cannot be negative or zero.");
}
Query deviceTwinQuery = new Query(sqlQuery, pageSize, QueryType.TWIN);
ProxyOptions proxyOptions = options.getProxyOptions();
Proxy proxy = proxyOptions != null ? proxyOptions.getProxy() : null;
deviceTwinQuery.sendQueryRequest(this.credentialCache, this.azureSasCredential, this.iotHubConnectionString, IotHubConnectionString.getUrlTwinQuery(this.hostName), HttpMethod.POST, options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
return deviceTwinQuery;
}
use of com.microsoft.azure.sdk.iot.service.ProxyOptions in project azure-iot-sdk-java by Azure.
the class JobClient method queryDeviceJob.
/**
* Query for device Job
*
* @param sqlQuery sql style query over device.jobs
* @param pageSize the value per which to limit the size of query response by.
* @return Query object for this query
* @throws IotHubException When IotHub fails to respond
* @throws IOException When any of the parameters are incorrect
*/
public synchronized Query queryDeviceJob(String sqlQuery, Integer pageSize) throws IotHubException, IOException {
if (sqlQuery == null || sqlQuery.length() == 0) {
throw new IllegalArgumentException("Query cannot be null or empty");
}
if (pageSize <= 0) {
throw new IllegalArgumentException("pagesize cannot be negative or zero");
}
Query deviceJobQuery = new Query(sqlQuery, pageSize, QueryType.DEVICE_JOB);
ProxyOptions proxyOptions = options.getProxyOptions();
Proxy proxy = proxyOptions != null ? proxyOptions.getProxy() : null;
deviceJobQuery.sendQueryRequest(this.credentialCache, this.azureSasCredential, this.iotHubConnectionString, IotHubConnectionString.getUrlTwinQuery(this.hostName), HttpMethod.POST, options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
return deviceJobQuery;
}
use of com.microsoft.azure.sdk.iot.service.ProxyOptions in project azure-iot-sdk-java by Azure.
the class JobClient method cancelJob.
/**
* Cancel a current jod on the IoTHub
*
* @param jobId Unique Job Id for this job
* @return a jobResult object
* @throws IllegalArgumentException if the jobId is invalid
* @throws IOException if the function cannot create a URL for the job, or the IO failed on request
* @throws IotHubException if the http request failed
*/
public synchronized JobResult cancelJob(String jobId) throws IllegalArgumentException, IOException, IotHubException {
URL url;
if (Tools.isNullOrEmpty(jobId)) {
throw new IllegalArgumentException("jobId cannot be null or empty");
}
try {
url = IotHubConnectionString.getUrlJobsCancel(this.hostName, jobId);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid JobId to create url");
}
ProxyOptions proxyOptions = options.getProxyOptions();
Proxy proxy = proxyOptions != null ? proxyOptions.getProxy() : null;
HttpResponse response = DeviceOperations.request(this.getAuthenticationToken(), url, HttpMethod.POST, EMPTY_JSON, null, options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
return new JobResult(response.getBody());
}
use of com.microsoft.azure.sdk.iot.service.ProxyOptions in project azure-iot-sdk-java by Azure.
the class JobClient method scheduleUpdateTwin.
/**
* Creates a new Job to update twin tags and desired properties on one or multiple devices
*
* @param jobId Unique Job Id for this job
* @param queryCondition Query condition to evaluate which devices to run the job on. It can be {@code null} or empty
* @param updateTwin Twin object to use for the update
* @param startTimeUtc Date time in Utc to start the job
* @param maxExecutionTimeInSeconds Max execution time in seconds, i.e., ttl duration the job can run
* @return a jobResult object
* @throws IllegalArgumentException if one of the provided parameters is invalid
* @throws IOException if the function cannot create a URL for the job
* @throws IotHubException if the http request failed
*/
public synchronized JobResult scheduleUpdateTwin(String jobId, String queryCondition, DeviceTwinDevice updateTwin, Date startTimeUtc, long maxExecutionTimeInSeconds) throws IllegalArgumentException, IOException, IotHubException {
URL url;
if (Tools.isNullOrEmpty(jobId)) {
throw new IllegalArgumentException("jobId cannot be null or empty");
}
if (updateTwin == null) {
throw new IllegalArgumentException("updateTwin cannot be null");
}
if (startTimeUtc == null) {
throw new IllegalArgumentException("startTimeUtc cannot be null");
}
if (maxExecutionTimeInSeconds < 0) {
throw new IllegalArgumentException("maxExecutionTimeInSeconds cannot be negative");
}
JobsParser jobsParser = new JobsParser(jobId, getParserFromDevice(updateTwin), queryCondition, startTimeUtc, maxExecutionTimeInSeconds);
String json = jobsParser.toJson();
try {
url = IotHubConnectionString.getUrlJobs(this.hostName, jobId);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Invalid JobId to create url");
}
ProxyOptions proxyOptions = options.getProxyOptions();
Proxy proxy = proxyOptions != null ? proxyOptions.getProxy() : null;
HttpResponse response = DeviceOperations.request(this.getAuthenticationToken(), url, HttpMethod.PUT, json.getBytes(StandardCharsets.UTF_8), null, options.getHttpConnectTimeout(), options.getHttpReadTimeout(), proxy);
return new JobResult(response.getBody());
}
Aggregations