HttpClient или пружина RestTemplate может выполнять эту работу.
Нечто подобное с пружиной RestTemplate
:
public class Foo {
/**
* Production HTTP end point.
*/
private static final String BASE_URL = "http://www.minecraft.net/haspaid.jsp";
/**
* {@link RestTemplate} for HTTP access.
*/
@Autowire
private RestTemplate restTemplate;
/**
* Constructor.
*/
public Foo() {
this.baseUrl = BASE_URL;
}
/**
* Constructor for testing purposes.
*
* @param baseUrl HTTP end-point url to use.
* @param restTemplate {@link RestTemplate} to use (a mock probably).
*/
protected Foo(final String baseUrl, final RestTemplate restTemplate) {
this.baseUrl = baseUrl;
this.restTemplate = restTemplate;
}
/**
* Check if user has paid.
*
* @param userName Name of the user to check.
* @return true if user has paid
*/
public boolean hasPaid(final String userName) {
if (userName == null) {
return false;
}
final String result = restTemplate.getForObject(this.baseUrl +
"?user={user}", String.class, userName);
return Boolean.valueOf(result);
}
}