X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Freactor%2Fqueries%2FHttpQuery.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Freactor%2Fqueries%2FHttpQuery.java;h=0000000000000000000000000000000000000000;hb=6f69aff66ba5617d0bb27874014b4274bc551ab8;hp=2cec1187ca9153a935f76e8b8db0ed8a5ba64963;hpb=13a4fe6bece23b3dd561de657cf9bb7ea307e2b6;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/reactor/queries/HttpQuery.java b/src/main/java/net/pterodactylus/reactor/queries/HttpQuery.java deleted file mode 100644 index 2cec118..0000000 --- a/src/main/java/net/pterodactylus/reactor/queries/HttpQuery.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Reactor - HttpQuery.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.reactor.queries; - -import java.io.IOException; -import java.io.InputStreamReader; - -import net.pterodactylus.reactor.Query; -import net.pterodactylus.reactor.State; -import net.pterodactylus.reactor.states.FailedState; -import net.pterodactylus.reactor.states.HttpState; - -import org.apache.http.HttpEntity; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.protocol.ResponseContentEncoding; -import org.apache.http.impl.client.DefaultHttpClient; -import org.apache.http.util.EntityUtils; - -import com.google.common.io.Closeables; - -/** - * {@link Query} that performs an HTTP GET request to a fixed uri. - * - * @author David ‘Bombe’ Roden - */ -public class HttpQuery implements Query { - - /** The uri to request. */ - private final String uri; - - /** - * Creates a new HTTP query. - * - * @param uri - * The uri to request - */ - public HttpQuery(String uri) { - this.uri = uri; - } - - // - // QUERY METHODS - // - - /** - * {@inheritDoc} - */ - @Override - @SuppressWarnings("deprecation") - public State state() { - DefaultHttpClient httpClient = new DefaultHttpClient(); - httpClient.addResponseInterceptor(new ResponseContentEncoding()); - HttpGet get = new HttpGet(uri); - - InputStreamReader inputStreamReader = null; - try { - /* make request. */ - get.addHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/536.11 (KHTML, like Gecko) Ubuntu/12.04 Chromium/20.0.1132.47 Chrome/20.0.1132.47 Safari/536.11"); - HttpResponse response = httpClient.execute(get); - if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { - return new FailedState(); - } - HttpEntity entity = response.getEntity(); - - /* yay, done! */ - return new HttpState(uri, response.getStatusLine().getStatusCode(), entity.getContentType().getValue(), EntityUtils.toByteArray(entity)); - - } catch (IOException ioe1) { - return new FailedState(ioe1); - } finally { - Closeables.closeQuietly(inputStreamReader); - } - } - -}