Package com.google.jplurk.exception

Examples of com.google.jplurk.exception.PlurkException


            result = (T) client.execute(method, clazz.newInstance(), ctx);
        } catch (SocketTimeoutException e) {
            isTimeOut = true;
            logger.debug("need timeout retry.");
        } catch (Exception e) {
            throw new PlurkException(e);
        } finally {
            monitor.cleanIdleConnections(client.getConnectionManager());
        }
        return (T) (isTimeOut ? execute(method) : result);
View Full Code Here


        this.client = client;
        try {
            cometQueryUrl.setLength(0);
            cometQueryUrl.append(userChannel.getString("comet_server"));
        } catch (Exception e) {
            throw new PlurkException(
                    "Something is wrong when creating the plurk notifier.", e);
        }
    }
View Full Code Here

      Object v = null;
      try {
        Constructor<?> ctor = validatorClazz.getConstructor(new Class<?>[0]);
        v = ctor.newInstance(new Object[0]);
      } catch (Exception e) {
        throw new PlurkException(
          "cannot create validator from [" + validatorClazz + "], please check validator has the default constructor.", e);
      }

      Boolean passValidation = false;
      try {
        Method method = validatorClazz.getMethod("validate", new Class<?>[]{String.class});
        passValidation = (Boolean) method.invoke(v, value);
      } catch (Exception e) {
        throw new PlurkException(
          "cannot invoke method from [" + validatorClazz + "]", e);
      }

      if (!passValidation) {
        logger.warn("value[" + value + "] cannot pass the validator[" + validatorClazz + "]");
View Full Code Here

    public JSONObject update(String currentPassword, String fullName,
            String newPassword, String email, String displayName,
            PrivacyPolicy privacyPolicy, DateTime birth) throws PlurkException {
        if (StringUtils.isBlank(currentPassword)) {
            logger.warn("current password can not be null.");
            throw new PlurkException("current password can not be null");
        }

        Args args = config.args();
        args.name("current_password").value(currentPassword);
        if (StringUtils.isNotBlank(fullName)) {
View Full Code Here

     * @throws PlurkException
     */
    public JSONObject updatePicture(File file) throws PlurkException {
        if (file == null || !file.exists() || !file.isFile()) {
            logger.warn("not a valid file: " + file);
            throw new PlurkException("not a valid file: " + file);
        }

        HttpPost method = new HttpPost("http://www.plurk.com/API/Users/updatePicture");
        try {
            ThinMultipartEntity entity = new ThinMultipartEntity();
View Full Code Here

    }

    private Properties getSettings(File settingFile) throws PlurkException {
        Properties prop = new Properties();
        if (!settingFile.exists()) {
            throw new PlurkException("settings file is not found: " + settingFile.getAbsolutePath());
        }

        FileInputStream fin = null;
        try {
            fin = new FileInputStream(settingFile);
            prop.load(fin);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (fin != null) {
                try {
                    fin.close();
                } catch (IOException e) {
                }
            }
        }

        if (StringUtils.isBlank(prop.getProperty("api_key"))) {
            throw new PlurkException("settings has no api_key.");
        }

        return prop;
    }
View Full Code Here

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }

        if (method == null) {
            throw new PlurkException("can not find the method: " + methodName);
        }

        // get metadata to validate the user supplied data
        Meta meta = method.getAnnotation(Meta.class);
        if (meta == null) {
            throw new PlurkException("can not find the meta annotation");
        }

        // assemble the query string (the param-value will be url-encoded)
        final StringBuffer buf = new StringBuffer();
        for (String key : params.keySet()) {
            try {
                buf.append(key).append("=").append(URLEncoder.encode(params.get(key), "utf-8")).append("&");
            } catch (UnsupportedEncodingException e) {
                logger.error(e.getMessage(), e);
            }
        }
        buf.deleteCharAt(buf.length() - 1);

        // make the request url
        final String queryString = meta.uri() + "?" + buf.toString();
        final String uri = meta.isHttps() ? getSecuredApiUri(queryString) : getApiUri(queryString);
        final HttpRequestBase httpMethod = meta.type().equals(Type.GET) ? new HttpGet(uri) : new HttpPost(uri);

        for (String key : meta.require()) {
            if (!params.containsKey(key)) {
                throw new PlurkException("require param [" + key + "] is not found");
            }
        }

        Headers headers = method.getAnnotation(Headers.class);
        if (headers != null) {
            logger.debug("found @Headers");
            for (Header header : headers.headers()) {
                logger.debug("add header => name[" + header.key() + "] value[" + header.value() + "]");
                httpMethod.addHeader(header.key(), header.value());
            }
        }

        Validation validation = method.getAnnotation(Validation.class);
        if (validation != null) {
            logger.debug("found @Validation");
            for (Validator v : validation.value()) {
                if (params.containsKey(v.field())) {
                    logger.debug("validate field[" + v.field() + "]");
                    boolean isPass = IValidator.ValidatorUtils.validate(v.validator(), params.get(v.field()));
                    if (!isPass) {
                        throw new PlurkException(
                                "validation failure. the field [" + v.field() + "] can not pass validation [" + v.validator() + "]");
                    }
                }
            }
        }
View Full Code Here

TOP

Related Classes of com.google.jplurk.exception.PlurkException

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.