Java SDK Samples - Attachment Operations
package com.zoho.crm.sample.attachments;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.zoho.crm.api.ParameterMap;
import com.zoho.crm.api.attachments.APIException;
import com.zoho.crm.api.attachments.ActionHandler;
import com.zoho.crm.api.attachments.ActionResponse;
import com.zoho.crm.api.attachments.ActionWrapper;
import com.zoho.crm.api.attachments.AttachmentsOperations;
import com.zoho.crm.api.attachments.AttachmentsOperations.DeleteAttachmentsParam;
import com.zoho.crm.api.attachments.AttachmentsOperations.UploadLinkAttachmentParam;
import com.zoho.crm.api.attachments.FileBodyWrapper;
import com.zoho.crm.api.attachments.ResponseHandler;
import com.zoho.crm.api.attachments.ResponseWrapper;
import com.zoho.crm.api.attachments.SuccessResponse;
import com.zoho.crm.api.record.Record;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;
import com.zoho.crm.api.util.StreamWrapper;
@SuppressWarnings("unused")
public class Attachment
{
/**
* Upload Attachments
* This method is used to upload an attachment to a single record of a module with ID and print the response.
* @throws Exception
* @param moduleAPIName The API Name of the record's module
* @param recordId The ID of the record to upload attachment
* @param absoluteFilePath The absolute file path of the file to be attached
*/
public static void uploadAttachments(String moduleAPIName, Long recordId, String absoluteFilePath) throws Exception
{
//example
// String moduleAPIName = "Leads";
// Long recordId = 3477061000005177002L;
// String absoluteFilePath = "/Users/use_name/Desktop/image.png";
//Get instance of AttachmentsOperations Class that takes moduleAPIName and recordId as parameter
AttachmentsOperations attachmentsOperations = new AttachmentsOperations(moduleAPIName, recordId);
//Get instance of FileBodyWrapper class that will contain the request file
com.zoho.crm.api.attachments.FileBodyWrapper fileBodyWrapper = new com.zoho.crm.api.attachments.FileBodyWrapper();
//Get instance of StreamWrapper class that takes absolute path of the file to be attached as parameter
StreamWrapper streamWrapper = new StreamWrapper(absoluteFilePath);
//Set file to the FileBodyWrapper instance
fileBodyWrapper.setFile(streamWrapper);
//Call uploadAttachment method that takes FileBodyWrapper instance as parameter
APIResponse<ActionHandler> response = attachmentsOperations.uploadAttachment(fileBodyWrapper);
if(response != null)
{
//Get the status code from response
System.out.println("Status Code: " + response.getStatusCode());
//Check if expected response is received
if(response.isExpected())
{
//Get object from response
ActionHandler actionHandler = response.getObject();
if(actionHandler instanceof ActionWrapper)
{
//Get the received ActionWrapper instance
ActionWrapper actionWrapper = (ActionWrapper) actionHandler;
//Get the list of obtained action responses
List<ActionResponse> actionResponses = actionWrapper.getData();
for(ActionResponse actionResponse : actionResponses)
{
//Check if the request is successful
if(actionResponse instanceof SuccessResponse)
{
//Get the received SuccessResponse instance
SuccessResponse successResponse = (SuccessResponse)actionResponse;
//Get the Status
System.out.println("Status: " + successResponse.getStatus().getValue());
//Get the Code
System.out.println("Code: " + successResponse.getCode().getValue());
System.out.println("Details: " );
if(successResponse.getDetails() != null)
{
//Get the details map
for(Map.Entry<String, Object> entry : successResponse.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
//Get the Message
System.out.println("Message: " + successResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionResponse;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
if(exception.getDetails() != null)
{
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
}
//Check if the request returned an exception
else if(actionHandler instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionHandler;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
if(exception.getDetails() != null)
{
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
else
{//If response is not as expected
//Get model object from response
Model responseObject = response.getModel();
//Get the response object's class
Class<? extends Model> clas = responseObject.getClass();
//Get all declared fields of the response class
java.lang.reflect.Field[] fields = clas.getDeclaredFields();
for(java.lang.reflect.Field field : fields)
{
//Get each value
System.out.println(field.getName() + ":" + field.get(responseObject));
}
}
}
}
}
package com.zoho.crm.sample.attachments;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.zoho.crm.api.ParameterMap;
import com.zoho.crm.api.attachments.APIException;
import com.zoho.crm.api.attachments.ActionHandler;
import com.zoho.crm.api.attachments.ActionResponse;
import com.zoho.crm.api.attachments.ActionWrapper;
import com.zoho.crm.api.attachments.AttachmentsOperations;
import com.zoho.crm.api.attachments.AttachmentsOperations.DeleteAttachmentsParam;
import com.zoho.crm.api.attachments.AttachmentsOperations.UploadLinkAttachmentParam;
import com.zoho.crm.api.attachments.FileBodyWrapper;
import com.zoho.crm.api.attachments.ResponseHandler;
import com.zoho.crm.api.attachments.ResponseWrapper;
import com.zoho.crm.api.attachments.SuccessResponse;
import com.zoho.crm.api.record.Record;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;
import com.zoho.crm.api.util.StreamWrapper;
@SuppressWarnings("unused")
public class Attachment
{
/**
* Delete Attachments
* This method is used to Delete attachments to a single record of a module with ID and print the response.
* @param moduleAPIName The API Name of the record's module
* @param recordId The ID of the record to upload attachment
* @param attachmentIds The ID of the attachment to be downloaded
*/
public static void deleteAttachments(String moduleAPIName, Long recordId, List<Long> attachmentIds) throws Exception
{
//example
// String moduleAPIName = "Leads";
// Long recordId = 3477061000005177002L;;
// List<Long> attachmentIds = new ArrayList<Long>(Arrays.asList("3477061000005979001", "3477061000005968003", "3477061000005961010"));
//Get instance of AttachmentsOperations Class that takes moduleAPIName and recordId as parameter
AttachmentsOperations attachmentsOperations = new AttachmentsOperations(moduleAPIName, recordId);
//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();
for(Long attachmentId : attachmentIds)
{
paramInstance.add(DeleteAttachmentsParam.IDS, attachmentId);
}
//Call deleteAttachments method that takes paramInstance as parameter
APIResponse<ActionHandler>response = attachmentOperations.deleteAttachments(paramInstance);
if(response != null)
{
//Get the status code from response
System.out.println("Status Code: " + response.getStatusCode());
//Check if expected response is received
if(response.isExpected())
{
//Get object from response
ActionHandler actionHandler = response.getObject();
if(actionHandler instanceof ActionWrapper)
{
//Get the received ActionWrapper instance
ActionWrapper actionWrapper = (ActionWrapper) actionHandler;
//Get the list of obtained Attachment Record instances
List<ActionResponse> actionResponses = actionWrapper.getData();
for(ActionResponse actionResponse : actionResponses)
{
//Check if the request is successful
if(actionResponse instanceof SuccessResponse)
{
//Get the received SuccessResponse instance
SuccessResponse successResponse = (SuccessResponse)actionResponse;
//Get the Status
System.out.println("Status: " + successResponse.getStatus().getValue());
//Get the Code
System.out.println("Code: " + successResponse.getCode().getValue());
System.out.println("Details: " );
if(successResponse.getDetails() != null)
{
//Get the details map
for(Map.Entry<String, Object> entry : successResponse.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
}
//Get the Message
System.out.println("Message: " + successResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionResponse;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
}
//Check if the request returned an exception
else if(actionHandler instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionHandler;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
else
{//If response is not as expected
//Get model object from response
Model responseObject = response.getModel();
//Get the response object's class
Class<? extends Model> clas = responseObject.getClass();
//Get all declared fields of the response class
java.lang.reflect.Field[] fields = clas.getDeclaredFields();
for(java.lang.reflect.Field field : fields)
{
//Get each value
System.out.println(field.getName() + ":" + field.get(responseObject));
}
}
}
}
}
package com.zoho.crm.sample.attachments;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.zoho.crm.api.ParameterMap;
import com.zoho.crm.api.attachments.APIException;
import com.zoho.crm.api.attachments.ActionHandler;
import com.zoho.crm.api.attachments.ActionResponse;
import com.zoho.crm.api.attachments.ActionWrapper;
import com.zoho.crm.api.attachments.AttachmentsOperations;
import com.zoho.crm.api.attachments.AttachmentsOperations.DeleteAttachmentsParam;
import com.zoho.crm.api.attachments.AttachmentsOperations.UploadLinkAttachmentParam;
import com.zoho.crm.api.attachments.FileBodyWrapper;
import com.zoho.crm.api.attachments.ResponseHandler;
import com.zoho.crm.api.attachments.ResponseWrapper;
import com.zoho.crm.api.attachments.SuccessResponse;
import com.zoho.crm.api.record.Record;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;
import com.zoho.crm.api.util.StreamWrapper;
@SuppressWarnings("unused")
public class Attachment
{
/**
* Download an Attachment
* This method is used to download an attachment of a single record of a module with ID and attachment ID and write the file in the specified destination.
* @throws Exception
* @param moduleAPIName The API Name of the record's module
* @param recordId The ID of the record to download attachment
* @param attachmentId The ID of the attachment to be downloaded
* @param destinationFolder The absolute path of the destination folder to store the attachment
*/
public static void downloadAttachment(String moduleAPIName, Long recordId, Long attachmentId, String destinationFolder) throws Exception
{
//example
// String moduleAPIName = "Leads";
// Long recordId = 3477061000005177002L;
// Long attachmentId = 3477061000005177023L;
// String destinationFolder = "/Users/user_name/Desktop";
//Get instance of AttachmentsOperations Class that takes moduleAPIName and recordId as parameter
AttachmentsOperations attachmentsOperations = new AttachmentsOperations(moduleAPIName, recordId);
//Call downloadAttachment method that takes attachmentId as parameters
APIResponse<ResponseHandler> response = attachmentOperations.downloadAttachment(attachmentId);
if(response != null)
{
//Get the status code from response
System.out.println("Status Code : " + response.getStatusCode());
if(response.getStatusCode() == 204)
{
System.out.println("No Content");
return;
}
//Check if expected response is received
if(response.isExpected())
{
//Get object from response
ResponseHandler responseHandler = response.getObject();
if(responseHandler instanceof FileBodyWrapper)
{
//Get the received FileBodyWrapper instance
FileBodyWrapper fileBodyWrapper = (FileBodyWrapper)responseHandler;
//Get StreamWrapper instance from the returned FileBodyWrapper instance
StreamWrapper streamWrapper = fileBodyWrapper.getFile();
//Create a file instance with the absolute_file_path
File file = new File(destinationFolder + File.separatorChar + streamWrapper.getName());
//Get InputStream from the response
InputStream is = streamWrapper.getStream();
//Create an OutputStream for the destination file
OutputStream os = new FileOutputStream(file);
byte[] buffer = new byte[1024];
int bytesRead;
//read the InputStream till the end
while((bytesRead = is.read(buffer)) != -1)
{
//write data to OutputStream
os.write(buffer, 0, bytesRead);
}
//Close the InputStream
is.close();
//Flush and close the OutputStream
os.flush();
os.close();
}
//Check if the request returned an exception
else if(responseHandler instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) responseHandler;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
else
{//If response is not as expected
//Get model object from response
Model responseObject = response.getModel();
//Get the response object's class
Class<? extends Model> clas = responseObject.getClass();
//Get all declared fields of the response class
java.lang.reflect.Field[] fields = clas.getDeclaredFields();
for(java.lang.reflect.Field field : fields)
{
//Get each value
System.out.println(field.getName() + ":" + field.get(responseObject));
}
}
}
}
}
package com.zoho.crm.sample.attachments;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.zoho.crm.api.ParameterMap;
import com.zoho.crm.api.attachments.APIException;
import com.zoho.crm.api.attachments.ActionHandler;
import com.zoho.crm.api.attachments.ActionResponse;
import com.zoho.crm.api.attachments.ActionWrapper;
import com.zoho.crm.api.attachments.AttachmentsOperations;
import com.zoho.crm.api.attachments.AttachmentsOperations.DeleteAttachmentsParam;
import com.zoho.crm.api.attachments.AttachmentsOperations.UploadLinkAttachmentParam;
import com.zoho.crm.api.attachments.FileBodyWrapper;
import com.zoho.crm.api.attachments.ResponseHandler;
import com.zoho.crm.api.attachments.ResponseWrapper;
import com.zoho.crm.api.attachments.SuccessResponse;
import com.zoho.crm.api.record.Record;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;
import com.zoho.crm.api.util.StreamWrapper;
@SuppressWarnings("unused")
public class Attachment
{
/**
* Delete an Attachment
* This method is used to delete an attachment to a single record of a module with ID and print the response.
* @param moduleAPIName The API Name of the record's module
* @param recordId The ID of the record to download attachment
* @param attachmentId The ID of the attachment to be downloaded
*/
public static void deleteAttachment(String moduleAPIName, Long recordId, Long attachmentId) throws Exception
{
//example
// String moduleAPIName = "Leads";
// Long recordId = 3477061000005177002L;
// Long attachmentId = 3477061000005177002L;
//Get instance of AttachmentsOperations Class that takes moduleAPIName and recordId as parameter
AttachmentsOperations attachmentsOperations = new AttachmentsOperations(moduleAPIName, recordId);
//Call getAttachments method that takes recordId as parameter
APIResponse<ActionHandler> response = attachmentsOperations.deleteAttachment(attachmentId);
if(response != null)
{
//Get the status code from response
System.out.println("Status Code: " + response.getStatusCode());
//Check if expected response is received
if(response.isExpected())
{
//Get object from response
ActionHandler actionHandler = response.getObject();
if(actionHandler instanceof ActionWrapper)
{
//Get the received ActionWrapper instance
ActionWrapper actionWrapper = (ActionWrapper) actionHandler;
//Get the list of obtained Attachment Record instances
List<ActionResponse> actionResponses = actionWrapper.getData();
for(ActionResponse actionResponse : actionResponses)
{
//Check if the request is successful
if(actionResponse instanceof SuccessResponse)
{
//Get the received SuccessResponse instance
SuccessResponse successResponse = (SuccessResponse)actionResponse;
//Get the Status
System.out.println("Status: " + successResponse.getStatus().getValue());
//Get the Code
System.out.println("Code: " + successResponse.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : successResponse.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + successResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionResponse;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
}
//Check if the request returned an exception
else if(actionHandler instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionHandler;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
else
{//If response is not as expected
//Get model object from response
Model responseObject = response.getModel();
//Get the response object's class
Class<? extends Model> clas = responseObject.getClass();
//Get all declared fields of the response class
java.lang.reflect.Field[] fields = clas.getDeclaredFields();
for(java.lang.reflect.Field field : fields)
{
//Get each value
System.out.println(field.getName() + ":" + field.get(responseObject));
}
}
}
}
}
package com.zoho.crm.sample.attachments;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import com.zoho.crm.api.ParameterMap;
import com.zoho.crm.api.attachments.APIException;
import com.zoho.crm.api.attachments.ActionHandler;
import com.zoho.crm.api.attachments.ActionResponse;
import com.zoho.crm.api.attachments.ActionWrapper;
import com.zoho.crm.api.attachments.AttachmentsOperations;
import com.zoho.crm.api.attachments.AttachmentsOperations.DeleteAttachmentsParam;
import com.zoho.crm.api.attachments.AttachmentsOperations.UploadLinkAttachmentParam;
import com.zoho.crm.api.attachments.FileBodyWrapper;
import com.zoho.crm.api.attachments.ResponseHandler;
import com.zoho.crm.api.attachments.ResponseWrapper;
import com.zoho.crm.api.attachments.SuccessResponse;
import com.zoho.crm.api.record.Record;
import com.zoho.crm.api.util.APIResponse;
import com.zoho.crm.api.util.Model;
import com.zoho.crm.api.util.StreamWrapper;
@SuppressWarnings("unused")
public class Attachment
{
/**
* Upload Link as an Attachment
* This method is used to upload a link as an attachment to a single record of a module with ID and print the response.
* @param moduleAPIName The API Name of the record's module
* @param recordId The ID of the record to download attachment
* @param attachmentURL The attachmentURL of the doc or image link to be attached
*/
public static void uploadLinkAttachments(String moduleAPIName, Long recordId, String attachmentURL) throws Exception
{
//example
// String moduleAPIName = "Leads";
// Long recordId = 3477061000005177002L;
// String attachmentURL = "https://5.imimg.com/data5/KJ/UP/MY-8655440/zoho-crm-500x500.png";
//Get instance of AttachmentsOperations Class that takes moduleAPIName and recordId as parameter
AttachmentsOperations attachmentsOperations = new AttachmentsOperations(moduleAPIName, recordId);
//Get instance of ParameterMap Class
ParameterMap paramInstance = new ParameterMap();
paramInstance.add(UploadLinkAttachmentParam.ATTACHMENTURL, attachmentURL);
//Call uploadLinkAttachment method that takes paramInstance as parameter
APIResponse<ActionHandler> response = attachmentsOperations.uploadLinkAttachment(paramInstance);
if(response != null)
{
//Get the status code from response
System.out.println("Status Code: " + response.getStatusCode());
//Check if expected response is received
if(response.isExpected())
{
//Get object from response
ActionHandler actionHandler = response.getObject();
if(actionHandler instanceof ActionWrapper)
{
//Get the received ActionWrapper instance
ActionWrapper actionWrapper = (ActionWrapper) actionHandler;
//Get the list of obtained Attachment Record instances
List<ActionResponse> actionResponses = actionWrapper.getData();
for(ActionResponse actionResponse : actionResponses)
{
//Check if the request is successful
if(actionResponse instanceof SuccessResponse)
{
//Get the received SuccessResponse instance
SuccessResponse successResponse = (SuccessResponse)actionResponse;
//Get the Status
System.out.println("Status: " + successResponse.getStatus().getValue());
//Get the Code
System.out.println("Code: " + successResponse.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : successResponse.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + successResponse.getMessage().getValue());
}
//Check if the request returned an exception
else if(actionResponse instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionResponse;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
}
//Check if the request returned an exception
else if(actionHandler instanceof APIException)
{
//Get the received APIException instance
APIException exception = (APIException) actionHandler;
//Get the Status
System.out.println("Status: " + exception.getStatus().getValue());
//Get the Code
System.out.println("Code: " + exception.getCode().getValue());
System.out.println("Details: " );
//Get the details map
for(Map.Entry<String, Object> entry : exception.getDetails().entrySet())
{
//Get each value in the map
System.out.println(entry.getKey() + ": " + entry.getValue());
}
//Get the Message
System.out.println("Message: " + exception.getMessage().getValue());
}
}
else
{//If response is not as expected
//Get model object from response
Model responseObject = response.getModel();
//Get the response object's class
Class<? extends Model> clas = responseObject.getClass();
//Get all declared fields of the response class
java.lang.reflect.Field[] fields = clas.getDeclaredFields();
for(java.lang.reflect.Field field : fields)
{
//Get each value
System.out.println(field.getName() + ":" + field.get(responseObject));
}
}
}
}
}