Java Code Examples for org.jboss.resteasy.client.ClientRequest#accept()

The following examples show how to use org.jboss.resteasy.client.ClientRequest#accept() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecaptchaUtil.java    From oxTrust with MIT License 6 votes vote down vote up
public boolean verifyGoogleRecaptcha(String gRecaptchaResponse, String secretKey) {
	boolean result = false;
	try {
		ClientRequest request = new ClientRequest("https://www.google.com/recaptcha/api/siteverify");
		request.formParameter("secret", secretKey);
		request.formParameter("response", gRecaptchaResponse);
		request.accept("application/json");

		ClientResponse<String> response = request.post(String.class);

		ObjectMapper mapper = new ObjectMapper();
		Map<String, String> map = mapper.readValue(new ByteArrayInputStream(response.getEntity().getBytes()),
				new TypeReference<Map<String, String>>() {
				});

		return Boolean.parseBoolean(map.get("success"));
	} catch (Exception e) {
		log.warn("Exception happened while verifying recaptcha, check your internet connection", e);
		return result;
	}
}
 
Example 2
Source File: HttpUtils.java    From pnc with Apache License 2.0 5 votes vote down vote up
/**
 * Process HTTP requests and tests if server responds with expected HTTP code. Request is implicitly set to accept
 * MIME type application/json.
 *
 * @param ecode Expected HTTP error code
 * @param url Request URL
 * @throws Exception Thrown if some error occurs in communication with server
 */
public static void testResponseHttpCode(int ecode, String url) throws Exception {
    ClientRequest request = new ClientRequest(url);
    request.accept(MediaType.APPLICATION_JSON);

    ClientResponse<String> response = request.get(String.class);
    if (response.getStatus() != ecode)
        throw new Exception("Server returned unexpected HTTP code! Returned code:" + response.getStatus());
}
 
Example 3
Source File: HttpUtils.java    From pnc with Apache License 2.0 4 votes vote down vote up
public static String processGetRequest(String url) throws Exception {
    ClientRequest request = new ClientRequest(url);
    request.accept(MediaType.APPLICATION_JSON);
    ClientResponse<String> response = request.get(String.class);
    return response.getEntity();
}
 
Example 4
Source File: HttpUtils.java    From pnc with Apache License 2.0 3 votes vote down vote up
/**
 * Process HTTP GET request and get the data as type specified as parameter. Client accepts application/json MIME
 * type.
 *
 * @param clazz Class to which the data are unmarshalled
 * @param <T> module config
 * @param url Request URL
 * @throws Exception Thrown if some error occurs in communication with server
 * @return Unmarshalled entity data
 */
public static <T> T processGetRequest(Class<T> clazz, String url) throws Exception {
    ClientRequest request = new ClientRequest(url);
    request.accept(MediaType.APPLICATION_JSON);

    ClientResponse<T> response = request.get(clazz);
    return response.getEntity();
}