// Path: dashboard/src/ch/icclab/cyclops/dashboard/util/LoadConfiguration.java
// public class LoadConfiguration extends ClientResource {
// 
//     //Instantiating the Instance variable for saving the config details
//     public static HashMap<String,String> configuration;
// 
//     /**
//      * Loads the configuration file
//      *
//      * Pseudo Code
//      * 1. Create an instance of the ServletContext
//      * 2. Get the relative path of the configuration.txt file
//      * 3. Load the file and save the values into a static HashMap
//      *
//      * @param context
//      * @throws IOException
//      */
//     public void run(Context context) throws IOException {
//         configuration = new HashMap<String,String>();
//         String nextLine;
// 
//         // Extract the ServletContext from the attributes of RestletContext
//         ServletContext servlet = (ServletContext) context.getAttributes().get("org.restlet.ext.servlet.ServletContext");
//         System.out.println("Reading the config file from " + servlet.getRealPath("/WEB-INF/configuration.txt"));
//         // Get the path of the config file relative to the WAR
//         String rootPath = servlet.getRealPath("/WEB-INF/configuration.txt");
// 
//         //Add WEB-INF path to access local images etc.
//         String webInfPath = servlet.getRealPath("/WEB-INF");
//         configuration.put("WEB-INF", webInfPath);
// 
//         Path path = Paths.get(rootPath);
//         File configFile = new File(path.toString());
//         FileRepresentation file = new FileRepresentation(configFile, MediaType.TEXT_PLAIN);
// 
//         // Read the values from the config file
//         try {
//             BufferedReader reader = new BufferedReader(file.getReader());
//             while((nextLine = reader.readLine()) != null ) {
//                 String[] str = nextLine.split("==");
//                 configuration.put(str[0],str[1]);
//             }
//         } catch (IOException e) {
//             System.out.println("Failed to load the Config file");
//             e.printStackTrace();
//         }
//     }
// }


import ch.icclab.cyclops.dashboard.util.LoadConfiguration;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
package ch.icclab.cyclops.dashboard.errorreporting;



/**
 * This class reports exceptions to a RabbitMQ instance. The RabbitMQ endpoint
 * and credentials are configured in /WEB-INF/configuration.txt with the following fields:
 *
 * ERROR_REPORTER_HOST
 * ERROR_REPORTER_PORT
 * ERROR_REPORTER_VIRTUAL_HOST
 * ERROR_REPORTER_USERNAME
 * ERROR_REPORTER_PASSWORD
 * ERROR_REPORTER_ENABLED
 *
 * Errors will only be reported if ERROR_REPORTER_ENABLED is set to "true"
 */
public class ErrorReporter {
    private static final String EXCHANGE_NAME = "cyclops";

    public static void reportException(Exception ex) {
        if(isExceptionReportingEnabled()) {
            try {
                Connection conn = getConnection();
                Channel channel = conn.createChannel();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Path: dashboard/src/ch/icclab/cyclops/dashboard/util/LoadConfiguration.java
// public class LoadConfiguration extends ClientResource {
// 
//     //Instantiating the Instance variable for saving the config details
//     public static HashMap<String,String> configuration;
// 
//     /**
//      * Loads the configuration file
//      *
//      * Pseudo Code
//      * 1. Create an instance of the ServletContext
//      * 2. Get the relative path of the configuration.txt file
//      * 3. Load the file and save the values into a static HashMap
//      *
//      * @param context
//      * @throws IOException
//      */
//     public void run(Context context) throws IOException {
//         configuration = new HashMap<String,String>();
//         String nextLine;
// 
//         // Extract the ServletContext from the attributes of RestletContext
//         ServletContext servlet = (ServletContext) context.getAttributes().get("org.restlet.ext.servlet.ServletContext");
//         System.out.println("Reading the config file from " + servlet.getRealPath("/WEB-INF/configuration.txt"));
//         // Get the path of the config file relative to the WAR
//         String rootPath = servlet.getRealPath("/WEB-INF/configuration.txt");
// 
//         //Add WEB-INF path to access local images etc.
//         String webInfPath = servlet.getRealPath("/WEB-INF");
//         configuration.put("WEB-INF", webInfPath);
// 
//         Path path = Paths.get(rootPath);
//         File configFile = new File(path.toString());
//         FileRepresentation file = new FileRepresentation(configFile, MediaType.TEXT_PLAIN);
// 
//         // Read the values from the config file
//         try {
//             BufferedReader reader = new BufferedReader(file.getReader());
//             while((nextLine = reader.readLine()) != null ) {
//                 String[] str = nextLine.split("==");
//                 configuration.put(str[0],str[1]);
//             }
//         } catch (IOException e) {
//             System.out.println("Failed to load the Config file");
//             e.printStackTrace();
//         }
//     }
// }


// Path: dashboard/src/ch/icclab/cyclops/dashboard/errorreporting/ErrorReporter.java
import ch.icclab.cyclops.dashboard.util.LoadConfiguration;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.*;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;

package ch.icclab.cyclops.dashboard.errorreporting;



/**
 * This class reports exceptions to a RabbitMQ instance. The RabbitMQ endpoint
 * and credentials are configured in /WEB-INF/configuration.txt with the following fields:
 *
 * ERROR_REPORTER_HOST
 * ERROR_REPORTER_PORT
 * ERROR_REPORTER_VIRTUAL_HOST
 * ERROR_REPORTER_USERNAME
 * ERROR_REPORTER_PASSWORD
 * ERROR_REPORTER_ENABLED
 *
 * Errors will only be reported if ERROR_REPORTER_ENABLED is set to "true"
 */
public class ErrorReporter {
    private static final String EXCHANGE_NAME = "cyclops";

    public static void reportException(Exception ex) {
        if(isExceptionReportingEnabled()) {
            try {
                Connection conn = getConnection();
                Channel channel = conn.createChannel();
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ex.printStackTrace(new PrintStream(baos));