Package org.wso2.carbon

Examples of org.wso2.carbon.CarbonException


                cx.getThreadLocal(MashupConstants.AXIS2_CONFIGURATION_CONTEXT);
        if (configurationContextObject != null &&
            configurationContextObject instanceof ConfigurationContext) {
            configurationContext = (ConfigurationContext) configurationContextObject;
        } else {
            throw new CarbonException(
                    "Error obtaining the Service Meta Data : Axis2 ConfigurationContext");
        }

        if (arguments[0] instanceof String) {
            deleteJob(arguments, configurationContext);
        } else {
            throw new CarbonException("Invalid parameter");
        }

    }
View Full Code Here


                    cx.getThreadLocal(MashupConstants.AXIS2_CONFIGURATION_CONTEXT);
            if (configurationContextObject != null &&
                configurationContextObject instanceof ConfigurationContext) {
                configurationContext = (ConfigurationContext) configurationContextObject;
            } else {
                throw new CarbonException(
                        "Error obtaining the Service Meta Data : Axis2 ConfigurationContext");
            }
            return FunctionSchedulingManager.getInstance().isTaskActive((String) arguments[0], configurationContext);
        } else {
            return false;
View Full Code Here

     * @throws CarbonException Thrown in case any exceptions occur
     */
    public static Object jsFunction_getXML(Context context, Scriptable thisObj, Object[] arguments,
                                           Function funObj) throws CarbonException {
        if (arguments[0] == null || !(arguments[0] instanceof String)) {
            throw new CarbonException(
                    "The getXML function should be called with either a single parameter which is " +
                    "the url to fetch XML from or three parameters, which are the url to fetch XML " +
                    "from, the User Name and a Password for basic authentication.");
        }

        String urlString;
        String username = null;
        String password = null;

        if ((arguments.length > 1) && (arguments.length < 4)) {
            urlString = (String) arguments[0];

            // We have a username password combo as well
            if ((arguments[1] == null) || (!(arguments[1] instanceof String))) {
                throw new CarbonException(
                        "The second argument for getXML function should be a string containing the username ");
            } else {
                username = (String) arguments[1];
            }
            if ((arguments[2] == null) || (!(arguments[2] instanceof String))) {
                throw new CarbonException(
                        "The third argument for getXML function should be a string containing the password ");
            } else {
                password = (String) arguments[2];
            }
        } else if (arguments.length == 1) {
            // We have only a URL
            urlString = (String) arguments[0];
        } else {
            throw new CarbonException(
                    "The getXML function should be called with either a single parameter which is " +
                    "the url to fetch XML from or three parameters, which are the url to fetch XML " +
                    "from, the User Name and a Password for basic authentication.");
        }
        HttpMethod method = new GetMethod(urlString);
        try {
            URL url = new URL(urlString);
            int statusCode = MashupUtils.executeHTTPMethod(method, url, username, password);
            if (statusCode != HttpStatus.SC_OK) {
                throw new CarbonException(
                        "An error occured while getting the resource at " + url + ". Reason :" +
                        method.getStatusLine());
            }
            StAXOMBuilder staxOMBuilder =
                    new StAXOMBuilder(new ByteArrayInputStream(method.getResponseBody()));
            OMElement omElement = staxOMBuilder.getDocumentElement();
            Object[] objects = {omElement};
            return context.newObject(thisObj, "XML", objects);
        } catch (MalformedURLException e) {
            throw new CarbonException(e);
        } catch (IOException e) {
            throw new CarbonException(e);
        } catch (XMLStreamException e) {
            throw new CarbonException("Could not get the convert the content of " + urlString +
                                      " to XML. You may have " +
                                      "to use the scraper object to get this url and tidy it");
        } finally {
            // Release the connection.
            method.releaseConnection();
View Full Code Here

        Object axisServiceObject = cx.getThreadLocal(MashupConstants.AXIS2_SERVICE);

        if (axisServiceObject != null && axisServiceObject instanceof AxisService) {
            axisService = (AxisService) axisServiceObject;
        } else {
            throw new CarbonException("Error obtaining the Service Meta Data: Axis2 Service");
        }
        ConfigurationContext configurationContext;
        // retrieves the ConfigurationContext object from the Rhino Engine
        Object configurationContextObject =
                cx.getThreadLocal(MashupConstants.AXIS2_CONFIGURATION_CONTEXT);
        if (configurationContextObject != null &&
            configurationContextObject instanceof ConfigurationContext) {
            configurationContext = (ConfigurationContext) configurationContextObject;
        } else {
            throw new CarbonException(
                    "Error obtaining the Service Meta Data : Axis2 ConfigurationContext");
        }

        //Generating UUID + current time for the taskName
        String taskName =
                system.getFormattedCurrentDateTime() + "-" + UUIDGenerator.getUUID().substring(9);

        int argCount = arguments.length;
        Object jsFunction = null;
        Object[] functionParams = null;
        long timeout = 0;
        Date currentTime = new Date();
        final Map<String, Object> resources = new HashMap<String, Object>();
        final TaskDescription taskDescription = new TaskDescription();
        final FunctionSchedulingManager functionSchedulingManager;

        taskDescription.setGroup(FunctionSchedulingJob.MASHUP_GROUP);
        taskDescription.setTaskClass(FunctionExecutionTask.class.getName());

        OMElement propElem = FACTORY.createOMElement("property", TASK_OM_NAMESPACE);
        OMNamespace nullNS = FACTORY.createOMNamespace("", "");
        propElem.addAttribute("name", "axisService", nullNS);
        propElem.addAttribute("value", axisService.getName(), nullNS);
        taskDescription.addProperty(propElem);

        resources.put(MashupConstants.AXIS2_CONFIGURATION_CONTEXT, configurationContext);

        switch (argCount) {

            case 2://A javascript function and its timeout were passed

                //Extracting the javascript function from the arguments
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must be " +
                                              "a JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    timeout = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException("Invalid parameter. The second parameter " +
                                              "must be function starting timeout.");
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                //Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
                taskDescription.setName(taskName);
                taskDescription.setCount(1);
                taskDescription.setStartTime(new Date(currentTime.getTime() + timeout));
                break;

            case 3://A javascript function its execution frequency and parameters were passed

                //Extracting the javascript function from the arguments=
                if ((arguments[0] instanceof Function) || ((arguments[0] instanceof String))) {
                    jsFunction = arguments[0];
                } else {
                    throw new CarbonException("Invalid parameter. The first parameter must " +
                                              "be a JavaScript function.");
                }

                //Extracting the frequency from the arguments
                if (arguments[1] != null && arguments[1] instanceof Number) {
                    timeout = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException(
                            "Invalid parameter. The second parameter must be the " +
                            "execution frequency in milliseconds.");
                }

                //Extracting function parameters from the arguments
                if (arguments[2] != null) {

                    if (arguments[2] instanceof String) {
                        taskName = (String) arguments[2];
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be a string " +
                                "value for the  the task name");
                    }
                }

                //Storing the function meta-data to be used by the job at execution time
                resources.put(FunctionSchedulingJob.JAVASCRIPT_FUNCTION, jsFunction);
                resources.put(FunctionSchedulingJob.FUNCTION_PARAMETERS, functionParams);
                resources.put(FunctionSchedulingJob.AXIS_SERVICE, axisService);
                resources.put(FunctionSchedulingJob.TASK_NAME, taskName);

                //Creating the trigger. There will be a one-to-one mapping between jobs and triggers in this implementation
                taskDescription.setName(taskName);
                taskDescription.setCount(1);
                taskDescription.setStartTime(new Date(currentTime.getTime() + timeout));
                break;

            default:
                throw new CarbonException("Invalid number of parameters.");
        }

        functionSchedulingManager = FunctionSchedulingManager.getInstance();

        functionSchedulingManager.scheduleTask(taskDescription, resources, configurationContext);
View Full Code Here

                cx.getThreadLocal(MashupConstants.AXIS2_CONFIGURATION_CONTEXT);
        if (configurationContextObject != null &&
            configurationContextObject instanceof ConfigurationContext) {
            configurationContext = (ConfigurationContext) configurationContextObject;
        } else {
            throw new CarbonException(
                    "Error obtaining the Service Meta Data : Axis2 ConfigurationContext");
        }

        if (arguments[0] instanceof String) {
            deleteJob(arguments, configurationContext);
        } else {
            throw new CarbonException("Invalid parameter");
        }
    }
View Full Code Here

        Object argument = arguments[0];
        if (argument != null && !(argument instanceof Undefined || argument instanceof UniqueTag)) {
            logMessage = argument.toString();
        } else {
            throw new CarbonException("The first argument should contain a message to log");
        }

        if (arguments.length > 1) {
            if (arguments[1] instanceof String) {
                logLevel = (String) arguments[1];

                if (logLevel.equalsIgnoreCase("info")) {
                    log.info(logMessage);
                } else if (logLevel.equalsIgnoreCase("warn")) {
                    log.warn(logMessage);
                } else if (logLevel.equalsIgnoreCase("debug")) {
                    log.debug(logMessage);
                } else if (logLevel.equalsIgnoreCase("error")) {
                    log.error(logMessage);
                } else if (logLevel.equalsIgnoreCase("fatal")) {
                    log.fatal(logMessage);
                } else {
                    throw new CarbonException(
                            "Unsupported log level. Please refer documentation for this function.");
                }

            } else {
                throw new CarbonException(
                        "The second argument should contain a String indicating the log level");
            }
        } else {
            log.info(logMessage);
        }
View Full Code Here

     * @throws CarbonException Thrown in case any exceptions occur
     */
    public static Scriptable jsFunction_getJSON(Context cx, Scriptable thisObj, Object[] arguments,
                                                 Function funObj) throws CarbonException {
        if (arguments[0] == null || !(arguments[0] instanceof String)) {
            throw new CarbonException(
                    "The getJSON function should be called with either a single parameter which is " +
                    "the url to fetch JSON from or three parameters, which are the url to fetch JSON " +
                    "from, the User Name and a Password for basic authentication.");
        }

        String urlString;
        String username = null;
        String password = null;

        if ((arguments.length > 1) && (arguments.length < 4)) {
            urlString = (String) arguments[0];

            // We have a username password combo as well
            if ((arguments[1] == null) || (!(arguments[1] instanceof String))) {
                throw new CarbonException(
                        "The second argument for getJSON function should be a string containing the username ");
            } else {
                username = (String) arguments[1];
            }
            if ((arguments[2] == null) || (!(arguments[2] instanceof String))) {
                throw new CarbonException(
                        "The third argument for getJSON function should be a string containing the password ");
            } else {
                password = (String) arguments[2];
            }
        } else if (arguments.length == 1) {
            // We have only a URL
            urlString = (String) arguments[0];
        } else {
            throw new CarbonException(
                    "The getJSON function should be called with either a single parameter which is " +
                    "the url to fetch JSON from or three parameters, which are the url to fetch JSON " +
                    "from, the User Name and a Password for basic authentication.");
        }
        HttpMethod method = new GetMethod(urlString);
        BufferedReader bufferedReader = null;
        try {
            URL url = new URL(urlString);
            int statusCode = MashupUtils.executeHTTPMethod(method, url, username, password);
            if (statusCode != HttpStatus.SC_OK) {
                throw new CarbonException(
                        "An error occured while getting the resource at " + url + ". Reason :" +
                        method.getStatusLine());
            }
            bufferedReader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
            StringBuilder sb = new StringBuilder();
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                sb.append(line + "\n");
            }
            String json = "var x = " + sb.toString() + ";";
            cx.evaluateString(thisObj, json, "Get JSON", 0, null);
            return (Scriptable) thisObj.get("x", thisObj);
        } catch (MalformedURLException e) {
            String msg = "Malformed URL supplied for the system.getJSON()";
            log.error(msg, e);
            throw new CarbonException(msg, e);
        } catch (IOException e) {
            String msg = "Error while reading content from the URL in system.getJSON()";
            log.error(msg, e);
            throw new CarbonException(msg, e);
        } finally {
            method.releaseConnection();
            if (bufferedReader != null) {
                try {
                    bufferedReader.close();
View Full Code Here

                checkServiceFileExtensionValidity(fileName, ALLOWED_FILE_EXTENSIONS);

                if (fileName.endsWith(".aar") || fileName.endsWith(".rsl")) {
                    serviceUploaderClient.uploadService(fileName, fileItemData.getDataHandler());
                } else {
                    throw new CarbonException("File with extension " + fileName
                            + " is not supported!. Supported extensions are : .aar and .rsl");
                }
            }
            response.setContentType("text/html; charset=utf-8");
            msg = "Rule Service archive file uploaded successfully.";
View Full Code Here

            }

            Map mjdm = jobExecutionContext.getMergedJobDataMap();
            String jobClassName = (String) mjdm.get(CLASSNAME);
            if (jobClassName == null) {
                throw new CarbonException("No " + CLASSNAME + " in JobDetails");
            }

            try {
                task = (Task) getClass().getClassLoader().loadClass(jobClassName).newInstance();
            } catch (Exception e) {
                throw new CarbonException("Cannot instantiate Function scheduling task : " + jobClassName, e);
            }

            /*Set properties = (Set) mjdm.get(PROPERTIES);
            for (Object property : properties) {
                OMElement prop = (OMElement) property;
View Full Code Here

        AppDeployerUtils.createDir(destinationDir);

        try {
            extract(garPath, destinationDir);
        } catch (IOException e) {
            throw new CarbonException("Error while extracting cApp artifact : " + fileName, e);
        }

        return destinationDir;
    }
View Full Code Here

TOP

Related Classes of org.wso2.carbon.CarbonException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.