} 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() + "]");
}
}
}
}