Package org.wso2.carbon

Examples of org.wso2.carbon.CarbonException


        MessageContext msgContext = MessageContext.getCurrentMessageContext();

        // Getting HttpServletRequest from Message Context
        String username = (String) msgContext.getProperty(RampartMessageData.USERNAME);
        if (username == null) {
            throw new CarbonException("Username not present in the request");
        }
        return username;
    }
View Full Code Here


     */
    public static NativeArray jsFunction_getHeaders(Context cx, Scriptable thisObj,
                                                       Object[] arguments, Function funObj)
            throws CarbonException {
        if (arguments.length != 0) {
            throw new CarbonException(
                    "Invalid number of parameters for request.getHeader() method.");
        }

        MessageContext msgCtx = MessageContext.getCurrentMessageContext();
        HttpServletRequest request =
View Full Code Here

     * @throws CarbonException
     */
    public static String jsFunction_getHeader(Context cx, Scriptable thisObj, Object[] arguments,
                                              Function funObj) throws CarbonException {
        if (arguments.length != 1) {
            throw new CarbonException(
                    "Invalid number of parameters for request.getHeader() method.");
        }
        if (arguments[0] instanceof String) {
            MessageContext msgCtx = MessageContext.getCurrentMessageContext();
            HttpServletRequest request =
                    (HttpServletRequest) msgCtx.getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
            return request.getHeader((String) arguments[0]);
        } else {
            throw new CarbonException(
                    "Invalid parameter for request.getHeader() method. Parameter should be a string");
        }
    }
View Full Code Here

        */
        File parentDir = jsFile.getParentFile();
        File resourcesDir =
                new File(parentDir, shortFileName + JSConstants.MASHUP_RESOURCES_FOLDER);
        if (!resourcesDir.exists() && !resourcesDir.mkdir()) {
            throw new CarbonException("Unable to create directory " + resourcesDir.getName());
        }

        /*
        creating _private folder in the resources folder to keep private stuff
        This folder can be used to keep information that the user does not want to share when
        a mashup is shared
        */
        File privateDir = new File(resourcesDir, JSConstants.MASHUP_PRIVATE_FOLDER_NAME);
        if (!privateDir.exists() && !privateDir.mkdir()) {
            throw new CarbonException("Unable to create directory " + privateDir.getName());
        }
        return resourcesDir;
    }
View Full Code Here

                        nameParts[0];

                // create the directory, if it does not exist
                File directory = new File(jsServiceDirectory);
                if (!directory.exists() && !directory.mkdirs()) {
                    throw new CarbonException("Unable to create directory " + directory.getName());
                }

                if ("js".equals(type)) {
                    contentsFilePath = jsServiceDirectory + File.separator + nameParts[1] +
                                       MashupConstants.JS_SERVICE_EXTENSION;
                } else {
                    File resourcesDirectory =
                            new File(jsServiceDirectory, nameParts[1] + ".resources");
                    File webResourcesDirectory = new File(resourcesDirectory, "www");
                    if (!resourcesDirectory.mkdir()) {
                        throw new CarbonException(
                                "Unable to create directory " + resourcesDirectory.getName());
                    }
                    if (!webResourcesDirectory.mkdir()) {
                        throw new CarbonException(
                                "Unable to create directory " + webResourcesDirectory.getName());
                    }

                    if ("html".equals(type)) {
                        contentsFilePath = webResourcesDirectory + File.separator + "index.html";
                    } else if ("gadget".equals(type)) {
                        contentsFilePath = webResourcesDirectory + File.separator + "gadget.xml";
                    }
                }

                File file = new File(contentsFilePath);
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    throw new CarbonException(
                            "Error while creating the file for the new service " + serviceName, e);
                }

            } else {
                if (!"js".equals(type)) {
                    File resourcesDirectory = (File) axisService.
                            getParameterValue(MashupConstants.RESOURCES_FOLDER);
                    File webResourcesDirectory = new File(resourcesDirectory, "www");
                    if (!resourcesDirectory.exists() && !resourcesDirectory.mkdir()) {
                        throw new CarbonException(
                                "Unable to create directory " + resourcesDirectory.getName());
                    }
                    if (!webResourcesDirectory.exists() && !webResourcesDirectory.mkdir()) {
                        throw new CarbonException(
                                "Unable to create directory " + webResourcesDirectory.getName());
                    }

                    if ("html".equals(type)) {
                        contentsFilePath = webResourcesDirectory + File.separator + "index.html";
                    } else if ("gadget".equals(type)) {
                        contentsFilePath = webResourcesDirectory + File.separator + "gadget.xml";
                    }
                    File file = new File(contentsFilePath);
                    if (!file.exists()) {
                        try {
                            file.createNewFile();
                        } catch (IOException e) {
                            throw new CarbonException(
                                    "Error while creating the file for the new service " +
                                    serviceName, e);
                        }
                    }
                } else {
                    contentsFilePath =
                            (String) axisService.getParameterValue(MashupConstants.SERVICE_JS);
                }
            }

            //Writing the file with the source provided
            BufferedWriter out = new BufferedWriter(new FileWriter(contentsFilePath));
            out.write(contents);
            out.flush();
            out.close();
            success = true;

        } catch (AxisFault axisFault) {
            throw new CarbonException("Cannot save service Source", axisFault);
        } catch (IOException e) {
            throw new CarbonException("Cannot save service Source", e);
        }

        return success;
    }
View Full Code Here

        // Even if there isnt a service with this name we should check whether there is a file with
        // this service name.
        String axis2RepoDirectory = getAxisConfig().getRepository().getPath();
        String[] nameParts = serviceName.split("/");
        if (nameParts.length != 2) {
            throw new CarbonException("Invalid service name : \"" + serviceName +
                                      "\". Service name should be in the format \"username/mashup\"");
        }
        String jsServiceDirectory =
                axis2RepoDirectory + MashupConstants.JS_SERVICE_REPO + File.separator +
                nameParts[0];
View Full Code Here

        String httpPort = null;
        try {
            httpPort =
                    (String) getAxisConfig().getTransportIn("http").getParameter("port").getValue();
        } catch (Exception e) {
            throw new CarbonException(e);
        }

        return httpPort;
    }
View Full Code Here

            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

        } catch (AxisFault axisFault) {
            String msg = "Failed to initiate SampleDeployer service client.";
            log.error(msg, axisFault);
            throw new CarbonException(msg, axisFault);
        }


    }
View Full Code Here

            option.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, cookie);

        } catch (AxisFault axisFault) {
            String msg = "Failed to initiate SampleDeployer service client.";
            log.error(msg, axisFault);
            throw new CarbonException(msg, axisFault);
        }

    }
View Full Code Here

            stub.uploadSample(sampleName);
            return true;
        } catch (Exception e) {
            String msg = "Failed to upload.";
            log.error(msg, e);
            throw new CarbonException(msg, e);
        }
    }
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.