All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.iotf.client.IoTFCReSTException Maven / Gradle / Ivy

Go to download

IBM Watson IoT client library to simplify device/gateway/application interactions with the IoT Platform

There is a newer version: 0.2.6
Show newest version
/**
 *****************************************************************************
 Copyright (c) 2015-16 IBM Corporation and other Contributors.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
 http://www.eclipse.org/legal/epl-v10.html
 Contributors:
 Sathiskumar Palaniappan - Initial Contribution
 *****************************************************************************
 *
 */
package com.ibm.iotf.client;

import com.google.gson.JsonElement;

public class IoTFCReSTException extends Exception {
	
	public static final String HTTP_ERR_UNEXPECTED = "Unexpected error code";
	public static final String HTTP_ERR_500 = "Unexpected error";
	public static final String HTTP_ADD_DEVICE_ERR_400 = 
			"Invalid request (No body, invalid JSON, unexpected key, bad value)";
	public static final String HTTP_ADD_DEVICE_ERR_401 = 
			"The authentication token is empty or invalid";
	public static final String HTTP_ADD_DEVICE_ERR_403 = 
			"The authentication method is invalid or the API key used does not exist";
	public static final String HTTP_ADD_DEVICE_ERR_409 =
			"The device already exists";
	public static final String HTTP_ADD_DEVICE_ERR_500 = HTTP_ERR_500;
	
	public static final String HTTP_ADD_DM_EXTENSION_ERR_400 =
			"Invalid request";
	public static final String HTTP_ADD_DM_EXTENSION_ERR_401 =
			"Unauthorized";
	public static final String HTTP_ADD_DM_EXTENSION_ERR_403 =
			"Forbidden";
	public static final String HTTP_ADD_DM_EXTENSION_ERR_409 =
			"Conflict";
	public static final String HTTP_ADD_DM_EXTENSION_ERR_500 =
			"Internal server error";
	public static final String HTTP_INITIATE_DM_REQUEST_ERR_500 = HTTP_ERR_500;
	
	private String method = null;
	private String url = null;
	private int httpCode;
	private JsonElement response = null;
	private String request = null;
	
	/**
	 * 
	 * @param method One of the HTTP methods ("get","post", "put", "delete")
	 * @param url URL of the ReST call
	 * @param request Requested parameters or NULL
	 * @param httpCode Returned code from Watson IoT Platform
	 * @param reason Reason for the exception
	 * @param response Response from Watson IoT Platform or NULL
	 */
	public IoTFCReSTException(String method, String url, String request, 
			int httpCode, String reason, JsonElement response) {
		super(reason);
		this.method = method;
		this.url = url;
		this.request = request;
		this.httpCode = httpCode;
		this.response = response;
	}
	
	public IoTFCReSTException(int httpCode, String reason, JsonElement response) {
		super(reason);
		this.httpCode = httpCode;
		this.response = response;
	}
	
	public IoTFCReSTException(int httpCode, String reason) {
		super(reason);
		this.httpCode = httpCode;
	}
	
	public IoTFCReSTException(String reason, JsonElement response) {
		super(reason);
		this.response = response;
	}
	
	public IoTFCReSTException(String reason) {
		super(reason);
	}
	
	public String getMethodL() {
		return method;
	}
	
	public String getURL() {
		return url;
	}
	
	public String getRequest() {
		return request;
	}

	public int getHttpCode() {
		return httpCode;
	}

	/**
	 * Return the response from Watson IoT or null.
	 * @return JsonElement or null
	 */
	public JsonElement getResponse() {
		return response;
	}
	
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy