mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Implements wupload.com service
This commit is contained in:
@@ -52,6 +52,11 @@
|
||||
<artifactId>htmlparser</artifactId>
|
||||
<version>2.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.googlecode.json-simple</groupId>
|
||||
<artifactId>json-simple</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<name>HttpChannel/Service/Utilities</name>
|
||||
<description>Module providing several utilities to service implementations. Though this module is not required to implement services, it contains several shortcuts that can help implementing services.</description>
|
||||
|
||||
@@ -19,16 +19,21 @@
|
||||
package com.rogiel.httpchannel.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.rogiel.httpchannel.util.HttpClientUtils;
|
||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
|
||||
public abstract class Request {
|
||||
private static final JSONParser jsonParser = new JSONParser();
|
||||
|
||||
protected final HttpContext ctx;
|
||||
protected final String uri;
|
||||
|
||||
@@ -60,6 +65,19 @@ public abstract class Request {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public InputStream asStream() throws ClientProtocolException, IOException {
|
||||
return request().getEntity().getContent();
|
||||
}
|
||||
|
||||
public Future<InputStream> asStreamAsync() throws IOException {
|
||||
return ctx.threadPool.submit(new Callable<InputStream>() {
|
||||
@Override
|
||||
public InputStream call() throws Exception {
|
||||
return asStream();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public HTMLPage asPage() throws ClientProtocolException, IOException {
|
||||
return HTMLPage.parse(asString());
|
||||
@@ -73,6 +91,19 @@ public abstract class Request {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Object asJson() throws ClientProtocolException, IOException, ParseException {
|
||||
return jsonParser.parse(asString());
|
||||
}
|
||||
|
||||
public Future<Object> asJsonAsync() throws IOException {
|
||||
return ctx.threadPool.submit(new Callable<Object>() {
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
return asJson();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public String getURI() {
|
||||
return uri;
|
||||
|
||||
Reference in New Issue
Block a user