mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Implements ifile.it upload service
This commit is contained in:
@@ -22,6 +22,7 @@ import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.rogiel.httpchannel.captcha.ImageCaptcha;
|
||||
import com.rogiel.httpchannel.http.HttpContext;
|
||||
import com.rogiel.httpchannel.util.PatternUtils;
|
||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
|
||||
@@ -22,8 +22,13 @@ import java.net.URI;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.apache.http.HttpRequest;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.params.ClientParamBean;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.impl.client.DefaultRedirectStrategy;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
@@ -35,7 +40,29 @@ public class HttpContext {
|
||||
/**
|
||||
* The {@link HttpClient} instance for this service
|
||||
*/
|
||||
protected DefaultHttpClient client = new DefaultHttpClient();
|
||||
protected final DefaultHttpClient client = new DefaultHttpClient();
|
||||
|
||||
protected final ClientParamBean params;
|
||||
|
||||
public HttpContext() {
|
||||
// default configuration
|
||||
params = new ClientParamBean(client.getParams());
|
||||
params.setHandleRedirects(true);
|
||||
params.setAllowCircularRedirects(true);
|
||||
params.setRejectRelativeRedirect(false);
|
||||
params.setMaxRedirects(10);
|
||||
|
||||
// browser behavior
|
||||
client.setRedirectStrategy(new DefaultRedirectStrategy() {
|
||||
@Override
|
||||
public boolean isRedirected(HttpRequest request,
|
||||
HttpResponse response,
|
||||
org.apache.http.protocol.HttpContext context)
|
||||
throws ProtocolException {
|
||||
return response.containsHeader("Location");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public GetRequest get(String uri) {
|
||||
return new GetRequest(this, uri);
|
||||
|
||||
@@ -21,6 +21,7 @@ package com.rogiel.httpchannel.http;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.mime.MultipartEntity;
|
||||
@@ -35,12 +36,20 @@ public class PostMultipartRequest extends PostRequest {
|
||||
|
||||
public PostMultipartRequest(HttpContext ctx, String uri) {
|
||||
super(ctx, uri);
|
||||
this.entity = new MultipartEntity();
|
||||
this.entity = new MultipartEntity() {
|
||||
@Override
|
||||
protected String generateBoundary() {
|
||||
return "---------------------------9849436581144108930470211272";
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpResponse request() throws IOException {
|
||||
final HttpPost post = new HttpPost(uri);
|
||||
for (final Header header : headers) {
|
||||
post.addHeader(header);
|
||||
}
|
||||
post.setEntity(entity);
|
||||
return ctx.client.execute(post);
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
@@ -39,6 +40,9 @@ public class PostRequest extends Request {
|
||||
@Override
|
||||
public HttpResponse request() throws IOException {
|
||||
final HttpPost post = new HttpPost(uri);
|
||||
for(final Header header : headers) {
|
||||
post.addHeader(header);
|
||||
}
|
||||
post.setEntity(new UrlEncodedFormEntity(params));
|
||||
return ctx.client.execute(post);
|
||||
}
|
||||
|
||||
@@ -20,11 +20,15 @@ package com.rogiel.httpchannel.http;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
@@ -34,6 +38,8 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
public abstract class Request {
|
||||
private static final JSONParser jsonParser = new JSONParser();
|
||||
|
||||
protected final List<Header> headers = new ArrayList<>();
|
||||
|
||||
protected final HttpContext ctx;
|
||||
protected final String uri;
|
||||
|
||||
@@ -41,6 +47,11 @@ public abstract class Request {
|
||||
this.ctx = ctx;
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
public Request header(String name, String value) {
|
||||
headers.add(new BasicHeader(name, value));
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract HttpResponse request() throws IOException;
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import com.rogiel.httpchannel.service.AccountDetails;
|
||||
import com.rogiel.httpchannel.service.AuthenticationService;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import com.rogiel.httpchannel.service.Authenticator;
|
||||
import com.rogiel.httpchannel.service.Credential;
|
||||
import com.rogiel.httpchannel.service.Authenticator.AuthenticatorConfiguration;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,6 +22,10 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import com.rogiel.httpchannel.service.DownloadChannel;
|
||||
import com.rogiel.httpchannel.service.DownloadListener;
|
||||
import com.rogiel.httpchannel.service.DownloadService;
|
||||
import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
|
||||
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
|
||||
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
|
||||
|
||||
@@ -29,6 +29,9 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.rogiel.httpchannel.http.Request;
|
||||
import com.rogiel.httpchannel.service.DownloadListener;
|
||||
import com.rogiel.httpchannel.service.DownloadService;
|
||||
import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
|
||||
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
|
||||
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
|
||||
|
||||
@@ -25,6 +25,8 @@ 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.service.AbstractService;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
|
||||
import com.rogiel.httpchannel.service.exception.UploadServiceException;
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
|
||||
|
||||
Reference in New Issue
Block a user