/** * Send a delete request * @param url Url as string * @param headers Optional map with headers * @return response Response as string * @throws IOException */ public static String delete(String url, Map<String, String> headers) throws IOException { return fetch("DELETE", url, null, headers); }
/** * Send a delete request * @param url Url as string * @return response Response as string * @throws IOException */ public static String delete(String url) throws IOException { return delete(url, null); }
/** * Send a get request * @param url * @return response * @throws IOException */ public static String get(String url) throws IOException { return get(url, null); }
@Override @JsonIgnore public <T> T get(final String key, final Class<T> type) { return TypeUtil.inject(get(key), type); }
/** * Test whether a method has named parameters. * * @param method * the method * @param requestParams * the request params * @return hasNamedParams */ private static boolean hasNamedParams(final AnnotatedMethod method, final RequestParams requestParams) { for (final AnnotatedParam param : method.getParams()) { boolean found = false; for (final Annotation a : param.getAnnotations()) { if (requestParams != null && requestParams.has(a)) { found = true; break; } else if (a instanceof Name) { found = true; break; } } if (!found) { return false; } } return true; }
@Override public <T> T callSync(final URI url, final String method, final ObjectNode params, final Class<T> clazz) throws IOException { return (T) callSync(url, method, params, TypeUtil.get(clazz)); }
/** * Send a post request * @param url Url as string * @param body Request body as string * @return response Response as string * @throws IOException */ public static String post(String url, String body) throws IOException { return post(url, body, null); }
/** * Send a put request * @param url Url as string * @return response Response as string * @throws IOException */ public static String put(String url, String body) throws IOException { return put(url, body, null); }
/** * Post a form with parameters * @param url Url as string * @param params map with parameters/values * @return response Response as string * @throws IOException */ public static String postForm(String url, Map<String, String> params) throws IOException { return postForm(url, params, null); }
private String createAuthorizationUrl() throws IOException { Map<String, String> params = new HashMap<String, String>(); params.put("scope", SCOPE); params.put("redirect_uri", REDIRECT_URI); params.put("response_type", "code"); params.put("access_type", "offline"); params.put("client_id", CLIENT_ID); params.put("approval_prompt", "force"); String url = HttpUtil.appendQueryParams(OAUTH_URI + "/auth", params); return url; }
/** * Get the name of a parameter Reads the parameter annotation @Name. Returns * null if the annotation is not provided. * * @param param * the param * @return name */ static String getName(final AnnotatedParam param) { String name = null; final Name nameAnnotation = param.getAnnotation(Name.class); if (nameAnnotation != null) { name = nameAnnotation.value(); } return name; }
@Override @JsonIgnore public <T> T get(final String key, final JavaType type) { return TypeUtil.inject(get(key), type); }
/** * Send a post request * @param url Url as string * @param body Request body as string * @param headers Optional map with headers * @return response Response as string * @throws IOException */ public static String post(String url, String body, Map<String, String> headers) throws IOException { return fetch("POST", url, body, headers); }
@SuppressWarnings("unchecked") @Override public <T> T callSync(final URI url, final String method, final ObjectNode params, final JavaType type) throws IOException { return (T) callSync(url, method, params, TypeUtil.get(type)); }
private void sendAuthorizationToAgent(String agentUrl, String agentMethod, ObjectNode auth) throws IOException { JSONRequest rpcRequest = new JSONRequest(agentMethod, auth); HttpUtil.post(agentUrl, rpcRequest.toString()); }
@Override @JsonIgnore public <T> T get(final String key, final TypeUtil<T> type) { return type.inject(get(key)); }
/** * Send a put request * @param url Url as string * @param body Request body as string * @param headers Optional map with headers * @return response Response as string * @throws IOException */ public static String put(String url, String body, Map<String, String> headers) throws IOException { return fetch("PUT", url, body, headers); }
@SuppressWarnings("unchecked") @Override public <T> T callSync(final URI url, final String method, final ObjectNode params, final Type type) throws IOException { return (T) callSync(url, method, params, TypeUtil.get(type)); }
@Override @JsonIgnore public <T> T get(final String key, final Type type) { return TypeUtil.inject(get(key), type); }
/** * Send a get request * @param url Url as string * @param headers Optional map with headers * @return response Response as string * @throws IOException */ public static String get(String url, Map<String, String> headers) throws IOException { return fetch("GET", url, null, headers); }