Package org.wso2.carbon

Examples of org.wso2.carbon.CarbonException


    public TransportParameter[] getServiceLevelTransportParameters(
            String service, boolean listener, AxisConfiguration axisConfig) throws Exception {

        if (axisConfig.getService(service) == null) {
            throw new CarbonException("No service exists by the name : " + service);
        }

        return getGlobalTransportParameters(listener, axisConfig);
    }
View Full Code Here


    public void updateServiceLevelTransportParameters(String service, TransportParameter[] params,
                                                      boolean listener, ConfigurationContext cfgCtx) throws Exception {

        AxisConfiguration axisConfig = cfgCtx.getAxisConfiguration();
        if (axisConfig.getService(service) == null) {
            throw new CarbonException("No service exists by the name : " + service);
        }

        updateGlobalTransportParameters(params, listener, cfgCtx);
    }
View Full Code Here

                            new TransportParameter[newParams.size()]), listener, cfgCtx);
                    return;
                }
            }

            throw new CarbonException("The transport parameter : " + param + " does not exist");
        }
    }
View Full Code Here

            } catch (Exception e) {
                String msg = "Protocol " + protocolParam.getName() + ":" +
                             protocolParam.getValue() + " is invalid. " +
                             "Please set the proper protocol in the mgt-transports.xml file.";
                log.error(msg);
                throw new CarbonException(msg, e);
            }
            int port = getPort(portParam);
            connector = TomcatUtil.getConnector(protocol, address, port);
            if(clientAuthParam != null){
                TomcatUtil.getTomcat().setClientAuth(connector, clientAuthParam.getValue());
            }
            log.info("Created Connector [" + protocol + "://" + (address != null ? address : "*") +
                         ":" + port + "]");
            for (Map.Entry<String, TransportParameter> entry : parameters.entrySet()) {
                String paramName = entry.getKey();
                if (!paramName.equals("port") && !paramName.equals("proxyPort") &&
                    !paramName.equals("protocol") && !paramName.equals("clientAuth")) {
                    connector.setAttribute(paramName, entry.getValue().getValue());
                }
            }
            connector.setEnableLookups(true);
        } catch (Exception e) {
            String msg = "Exception occurred while starting the Tomcat HTTP connector";
            log.error(msg, e);
            throw new CarbonException(msg, e);
        }
    }
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

     */
    public static void jsFunction_wait(Context cx, Scriptable thisObj, Object[] arguments,
                                       Function funObj) throws CarbonException {
        try {
            if (arguments.length > 1) {
                throw new CarbonException("Invalid number of arguments.");
            }
            if (arguments.length == 0) {
                Thread.sleep(10);
            } else if (arguments[0] instanceof String) {
                String timePeriod = (String) arguments[0];
                Thread.sleep(Long.parseLong(timePeriod));
            } else if (arguments[0] instanceof Integer) {
                Integer timePeriod = (Integer) arguments[0];
                Thread.sleep(timePeriod.longValue());
            } else {
                throw new CarbonException("Unsupported parameter.");
            }
        } catch (Throwable e) {
            throw new CarbonException(e);
        }
    }
View Full Code Here

     */
    public String jsGet_localHostName() throws CarbonException {
        try {
            return NetworkUtils.getLocalHostname();
        } catch (SocketException e) {
            throw new CarbonException(e);
        }
    }
View Full Code Here

        // retrieves the AxisService object from the Rhino context
        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");
        }

        // Retrieves the service.resources directory corresponding to this
        // mashup service
        Parameter parameter = axisService.getParameter(MashupConstants.RESOURCES_FOLDER);
        Object resourceFileObject = parameter.getValue();
        File resourceFolder;
        if (resourceFileObject != null && resourceFileObject instanceof File) {
            resourceFolder = (File) resourceFileObject;
        } else {
            throw new CarbonException("Mashup Resources folder not found.");
        }

        // Creates the base URI for URI resolving. URI's are resolved relative
        // to the serviceContextRoot of the Mashup server.
        // (eg:http://localhost:7762/services/)
        URI baseURI;
        //todo need to handle this scenario
        /*try {
            String contextPath = AdminUIServletContextListener.contextPath;
            if (!contextPath.endsWith(MashupConstants.FORWARD_SLASH)) {
                contextPath += MashupConstants.FORWARD_SLASH;
            }
            baseURI = new URI("http", null, NetworkUtils.getLocalHostname(),
                              ServerManager.getInstance().getHttpPort(),
                              contextPath +
                                      configurationContext.getServicePath() + "/",
                              null, null);
        } catch (Exception e) {
            throw new CarbonException("Cannot create the server base URI.", e);
        }*/

        for (int i = 0; i < arguments.length; i++) {
            Reader reader;
            String path = arguments[i].toString();
            File f = new File(resourceFolder, path);
            // We change the scriptName in the engine so that when warnings are displayed they use the  name of the
            // included scripr rather than the calling script name.
            String parentScriptName = engine.getScriptName();

            try {
                // Check whether this is a file in the service.resources directory
                if (f.exists() && !f.isDirectory()) {
                    reader = new FileReader(f);
                    engine.setScriptName(path);
                    engine.evaluate(reader);
                } else {
                    // This is not a file.. So we check whether this is a URL
                    //todo need to check this
                    //                    readFromURI(engine, baseURI, path);
                }
            } catch (IOException e) {
                throw new CarbonException(e);
            } finally {
                engine.setScriptName(parentScriptName);
            }
        }
    }
View Full Code Here

        Reader reader;
        // Not a file in the service.resources Dir.. Then check whether this is
        // a URI.
        if (path.startsWith("file://")) {
            // we do not allow file: schema due to security restrictions
            throw new CarbonException(
                    "Unsupported URI schema 'file'. 'file://' is not allowed due to security policies.");
        }

        // If this is a relative URL, then we resolves this relative to the
        // baseURI, if the URL is absolute we leave it as it is
        URI uri = baseURI.resolve(path);
        HttpMethod method = new GetMethod(uri.toString());
        try {
            URL url = uri.toURL();
            int statusCode = MashupUtils.executeHTTPMethod(method, url, null, null);
            if (statusCode != HttpStatus.SC_OK) {
                throw new CarbonException(
                        "An error occured while getting the resource at " + url + ". Reason :" +
                        method.getStatusLine());
            }
            reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
            engine.setScriptName(path);
            engine.evaluate(reader);
        } catch (MalformedURLException e) {
            throw new CarbonException(e);
        } catch (IOException e) {
            throw new CarbonException(e);
        } 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 frequency = 0;
        Date startTime = null;
        Date endTime = null;
        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 execution frequency 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) {
                    frequency = ((Number) arguments[1]).longValue();
                } else {
                    throw new CarbonException("Invalid parameter. The second parameter " +
                                              "must be the execution frequency in milliseconds.");
                }

                //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(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                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) {
                    frequency = ((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 NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);

                    } else if (arguments[2] instanceof String) {
                        taskName = (String) arguments[2];
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array " +
                                "of parameters to the argument, a string value for the task name or null.");
                    }
                }

                //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(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                break;

            case 4:// A javascript function, its execution frequnecy, function parameters and a start time is 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) {
                    frequency = ((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 NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array of " +
                                "parameters to the argument or null.");
                    }
                }

                if (arguments[3] != null) {
                    if (arguments[3] instanceof String) {
                        taskName = (String) arguments[3];
                    } else {
                        try {
                            startTime = (Date) Context.jsToJava(arguments[3], Date.class);
                        } catch (EvaluatorException e) {
                            throw new CarbonException(
                                    "Invalid parameter. The fourth parameter must be " +
                                    "the start time in date format or a string value " +
                                    "for the task name.", e);
                        }
                    }
                }

                //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);

                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                taskDescription.setStartTime(startTime);

                break;

            case 5: // A javascript function, its execution frequnecy, function parameters, start time and an end time is 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) {
                    frequency = ((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 NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array of " +
                                "parameters to the argument or null.");
                    }
                }

                //Extracting the start time from the arguments
                if (arguments[3] != null) {
                    if (arguments[3] instanceof String) {
                        taskName = (String) arguments[3];
                    } else {
                        try {
                            startTime = (Date) Context.jsToJava(arguments[3], Date.class);
                        } catch (EvaluatorException e) {
                            throw new CarbonException(
                                    "Invalid parameter. The fourth parameter must be " +
                                    "the start time in date format.", e);
                        }
                    }
                }

                //Extracting the end time from the arguments
                if (arguments[4] != null) {
                    if (arguments[4] instanceof String) {
                        taskName = (String) arguments[4];
                    } else {
                        try {
                            endTime = (Date) Context.jsToJava(arguments[4], Date.class);
                        } catch (EvaluatorException e) {
                            throw new CarbonException(
                                    "Invalid parameter. The fifth parameter must be " +
                                    "the end time in date format or a string value " +
                                    "for the task name.", e);
                        }
                    }
                }

                //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);

                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                taskDescription.setStartTime(startTime);
                taskDescription.setEndTime(endTime);

                break;

            case 6: // A javascript function, its execution frequnecy, function parameters, start time and an end time is 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) {
                    frequency = ((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 NativeArray) {
                        NativeArray nativeArray = (NativeArray) arguments[2];
                        Object[] objects = nativeArray.getIds();
                        ArrayList tempParamHolder = new ArrayList();
                        for (int i = 0; i < objects.length; i++) {
                            Object currObject = objects[i];
                            if (currObject instanceof String) {
                                String property = (String) currObject;
                                if ("length".equals(property)) {
                                    continue;
                                }
                                tempParamHolder.add(nativeArray.get(property, nativeArray));
                            } else {
                                Integer property = (Integer) currObject;
                                tempParamHolder
                                        .add(nativeArray.get(property.intValue(), nativeArray));
                            }
                        }
                        //Convert the arraylist to an object array
                        functionParams = new Object[tempParamHolder.size()];
                        tempParamHolder.toArray(functionParams);
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The third parameter must be an Array of " +
                                "parameters to the argument or null.");
                    }
                }

                //Extracting the start time from the arguments
                if (arguments[3] != null) {
                    try {
                        startTime = (Date) Context.jsToJava(arguments[3], Date.class);
                    } catch (EvaluatorException e) {
                        throw new CarbonException(
                                "Invalid parameter. The fourth parameter must be " +
                                "the start time in date format.", e);
                    }
                }

                if (arguments[4] != null) {
                    try {
                        endTime = (Date) Context.jsToJava(arguments[4], Date.class);
                    } catch (EvaluatorException e) {
                        throw new CarbonException(
                                "Invalid parameter. The fifth parameter must be " +
                                "the end time in date format.", e);
                    }
                }

                if (arguments[5] != null) {
                    if (arguments[5] instanceof String) {
                        taskName = (String) arguments[5];
                    } else {
                        throw new CarbonException(
                                "Invalid parameter. The sixth parameter must be a string value " +
                                "for 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);

                taskDescription.setName(taskName);
                taskDescription.setCount(SimpleTrigger.REPEAT_INDEFINITELY);
                taskDescription.setInterval(frequency);
                taskDescription.setStartTime(startTime);
                taskDescription.setEndTime(endTime);

                break;

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

        functionSchedulingManager = FunctionSchedulingManager.getInstance();

        functionSchedulingManager.scheduleTask(taskDescription, resources, configurationContext);
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.