1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-05 23:22:51 +00:00

Implements uploadhere.com service

This commit is contained in:
2012-01-15 20:23:01 -02:00
parent 23f80b50e6
commit 1719e54b77
34 changed files with 790 additions and 429 deletions

View File

@@ -0,0 +1,26 @@
/**
*
*/
package com.rogiel.httpchannel.captcha;
import java.io.IOException;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*
*/
public abstract class AbstractHTMLImageCaptchaService<C extends AbstractImageCaptcha>
extends AbstractImageCaptchaService<C> {
@Override
public final C create(String html) {
try {
return create(HTMLPage.parse(html));
} catch (IOException e) {
return null;
}
}
public abstract C create(HTMLPage page) throws IOException;
}

View File

@@ -3,14 +3,12 @@
*/
package com.rogiel.httpchannel.captcha;
import java.io.IOException;
import java.net.URL;
import com.rogiel.httpchannel.http.GetRequest;
import com.rogiel.httpchannel.http.HttpContext;
import com.rogiel.httpchannel.http.PostMultipartRequest;
import com.rogiel.httpchannel.http.PostRequest;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -20,17 +18,6 @@ public abstract class AbstractImageCaptchaService<C extends AbstractImageCaptcha
implements ImageCaptchaService<C> {
protected final HttpContext http = new HttpContext();
@Override
public final C create(String html) {
try {
return create(HTMLPage.parse(html));
} catch (IOException e) {
return null;
}
}
public abstract C create(HTMLPage page) throws IOException;
@Override
public boolean resolve(C captcha) {
return false;

View File

@@ -22,10 +22,12 @@ import java.net.URL;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import com.rogiel.httpchannel.http.Request;
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.util.ThreadUtils;
/**
@@ -58,6 +60,11 @@ public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration>
protected InputStreamDownloadChannel download(Request request)
throws IOException {
final HttpResponse response = request.request();
if (!(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK
|| response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED || response
.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT))
throw new DownloadLinkNotFoundException();
final String filename = FilenameUtils.getName(request.getURL());
final long contentLength = getContentLength(response);
return createInputStreamChannel(response.getEntity().getContent(),

View File

@@ -56,6 +56,10 @@ public abstract class AbstractHttpService extends AbstractService implements
return http.post(url);
}
public PostRequest post(URL url) {
return post(url.toString());
}
public PostMultipartRequest multipartPost(String url) {
return http.multipartPost(url);
}