1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-06 07:32:50 +00:00

Adds -SNAPSHOT to Maven version parameter and few modifications to API

This commit is contained in:
2012-01-17 17:07:48 -02:00
parent 08d22a12fe
commit 673bfc6639
56 changed files with 536 additions and 399 deletions

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-api</artifactId>

View File

@@ -3,7 +3,7 @@
*/
package com.rogiel.httpchannel.captcha;
import java.net.URL;
import java.net.URI;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -15,9 +15,9 @@ public class ImageCaptcha implements Captcha {
*/
private final String ID;
/**
* The CAPTCHA Image {@link URL}
* The CAPTCHA Image {@link URI}
*/
private final URL imageURL;
private final URI imageURI;
/**
* The CAPTCHA answer
*/
@@ -27,9 +27,9 @@ public class ImageCaptcha implements Captcha {
*/
private Object attachment;
public ImageCaptcha(String id, URL imageURL) {
public ImageCaptcha(String id, URI imageURI) {
this.ID = id;
this.imageURL = imageURL;
this.imageURI = imageURI;
}
@Override
@@ -37,8 +37,8 @@ public class ImageCaptcha implements Captcha {
return ID;
}
public URL getImageURL() {
return imageURL;
public URI getImageURI() {
return imageURI;
}
@Override
@@ -68,7 +68,7 @@ public class ImageCaptcha implements Captcha {
@Override
public String toString() {
return "ImageCaptcha [ID=" + ID + ", imageURL=" + imageURL
return "ImageCaptcha [ID=" + ID + ", imageURI=" + imageURI
+ ", answer=" + answer + ", attachment=" + attachment + "]";
}
}

View File

@@ -16,7 +16,7 @@
*/
package com.rogiel.httpchannel.service;
import java.net.URL;
import java.net.URI;
import javax.tools.FileObject;
@@ -33,27 +33,27 @@ public interface DownloadService<C extends DownloaderConfiguration> extends
Service {
/**
* Creates a new instance of the {@link Downloader}. This instance will be
* attached to the {@link URL}, {@link FileObject} provided through the the
* attached to the {@link URI}, {@link FileObject} provided through the the
* arguments and the parent {@link Service} instance.
*
* @param url
* the url to be downloaded
* @param uri
* the uri to be downloaded
* @param configuration
* the downloader configurationf
* the downloader configuration
* @return an new instance of {@link Downloader}
*/
Downloader<C> getDownloader(URL url, C configuration);
Downloader<C> getDownloader(URI uri, C configuration);
/**
* Creates a new instance of the {@link Downloader}. This instance will be
* attached to the {@link URL}, {@link FileObject} provided through the the
* attached to the {@link URI}, {@link FileObject} provided through the the
* arguments and the parent {@link Service} instance.
*
* @param url
* the url to be downloaded
* @param uri
* the uri to be downloaded
* @return an new instance of {@link Downloader}
*/
Downloader<C> getDownloader(URL url);
Downloader<C> getDownloader(URI uri);
/**
* Creates a new configuration object. If a service does not support or
@@ -65,17 +65,17 @@ public interface DownloadService<C extends DownloaderConfiguration> extends
C newDownloaderConfiguration();
/**
* Check if this {@link Service} can download from this URL. Implementations
* Check if this {@link Service} can download from this URI. Implementations
* might or might not perform network activity.
* <p>
* <b>Please note</b> that the value returned by this method may vary based
* on it's state (i.e. premium or not).
*
* @param url
* the {@link URL} to be tested.
* @param uri
* the {@link URI} to be tested.
* @return true if supported, false otherwise.
*/
boolean matchURL(URL url);
boolean matchURI(URI uri);
/**
* Return the matrix of capabilities for this {@link Downloader}.

View File

@@ -37,7 +37,7 @@ public interface Service extends Cloneable {
*
* @return the id of the service
*/
ServiceID getID();
ServiceID getServiceID();
/**
* Get Major version of this service

View File

@@ -17,7 +17,7 @@
package com.rogiel.httpchannel.service;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.channels.Channel;
import java.nio.channels.WritableByteChannel;
@@ -43,7 +43,7 @@ public interface UploadChannel extends HttpChannel, WritableByteChannel {
*
* @return the download link for this upload
*/
URL getDownloadLink();
URI getDownloadLink();
/**
* @throws UploadLinkNotFoundException

View File

@@ -17,7 +17,7 @@
package com.rogiel.httpchannel.service.helper;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import com.rogiel.httpchannel.service.DownloadService;
@@ -25,8 +25,8 @@ import com.rogiel.httpchannel.service.DownloadService;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class DownloadServices {
public static boolean canDownload(DownloadService<?> service, URL url)
public static boolean canDownload(DownloadService<?> service, URI uri)
throws IOException {
return service.matchURL(url);
return service.matchURI(uri);
}
}

View File

@@ -16,7 +16,7 @@
*/
package com.rogiel.httpchannel.service.helper;
import java.net.URL;
import java.net.URI;
import java.util.Iterator;
import java.util.ServiceLoader;
@@ -41,17 +41,17 @@ public class Services {
}
/**
* Tries to detect which service should be used to download the given URL
* Tries to detect which service should be used to download the given URI
*
* @param url
* the URL
* @param uri
* the URI
* @return the matched service
*/
public static DownloadService<?> matchURL(URL url) {
public static DownloadService<?> matchURI(URI uri) {
for (final Service service : iterate()) {
if (!(service instanceof DownloadService))
continue;
if (((DownloadService<?>) service).matchURL(url))
if (((DownloadService<?>) service).matchURI(uri))
return (DownloadService<?>) service;
}
return null;
@@ -66,7 +66,7 @@ public class Services {
*/
public static Service getService(ServiceID id) {
for (final Service service : iterate()) {
if (service.getID().equals(id))
if (service.getServiceID().equals(id))
return service;
}
return null;
@@ -106,7 +106,7 @@ public class Services {
@Override
public ServiceID next() {
return iterator.next().getID();
return iterator.next().getServiceID();
}
@Override

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel-captcha</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<groupId>com.rogiel.httpchannel.captcha</groupId>

View File

@@ -5,9 +5,7 @@ package com.captchatrader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import java.util.List;
import org.apache.http.HttpResponse;
@@ -50,7 +48,7 @@ public class CaptchaTrader {
private final HttpClient client = new DefaultHttpClient();
private final JSONParser json = new JSONParser();
private final URI apiURL;
private final URI apiURI;
private final String applicationKey;
private final String username;
private final String password;
@@ -61,9 +59,9 @@ public class CaptchaTrader {
* @param applicationKey
* the key
*/
public CaptchaTrader(URI apiURL, String applicationKey, String username,
public CaptchaTrader(URI apiURI, String applicationKey, String username,
String password) {
this.apiURL = apiURL;
this.apiURI = apiURI;
this.applicationKey = applicationKey;
this.username = username;
this.password = password;
@@ -74,7 +72,7 @@ public class CaptchaTrader {
*
* @param applicationKey
* the key
* @throws MalformedURLException
* @throws MalformedURIException
*/
public CaptchaTrader(String applicationKey, String username, String password) {
this(URI.create("http://api.captchatrader.com/"), applicationKey,
@@ -84,27 +82,27 @@ public class CaptchaTrader {
/**
* Submit a CAPTCHA already hosted on an existing website.
*
* @param url
* The URL of the CAPTCHA image.
* @param uri
* The URI of the CAPTCHA image.
* @return The decoded CAPTCHA.
* @throws Any
* exceptions sent by the server.
*/
public ResolvedCaptcha submit(URL url) throws CaptchaTraderException,
public ResolvedCaptcha submit(URI uri) throws CaptchaTraderException,
IOException {
final URI requestUri = apiURL.resolve("submit");
final URI requestUri = apiURI.resolve("submit");
final HttpPost request = new HttpPost(requestUri);
final MultipartEntity entity = new MultipartEntity();
entity.addPart("api_key", new StringBody(applicationKey));
entity.addPart("username", new StringBody(username));
entity.addPart("password", new StringBody(password));
entity.addPart("value", new StringBody(url.toString()));
entity.addPart("value", new StringBody(uri.toString()));
request.setEntity(entity);
final List<Object> response = validate(execute(request));
return new ResolvedCaptcha(this, ((Long) response.get(0)).intValue(),
return new ResolvedCaptcha(this, ((Long) response.get(0)).toString(),
(String) response.get(1));
}
@@ -118,17 +116,16 @@ public class CaptchaTrader {
* @throws CaptchaTraderException
* any of the possible errors
*/
public void response(ResolvedCaptcha captcha, boolean state)
public void respond(ResolvedCaptcha captcha, boolean state)
throws CaptchaTraderException, IOException {
final URI requestUri = apiURL.resolve("respond");
final URI requestUri = apiURI.resolve("respond");
final HttpPost request = new HttpPost(requestUri);
final MultipartEntity entity = new MultipartEntity();
entity.addPart("is_correct", new StringBody(state ? "1" : "0"));
entity.addPart("username", new StringBody(username));
entity.addPart("password", new StringBody(password));
entity.addPart("ticket",
new StringBody(Integer.toString(captcha.getID())));
entity.addPart("ticket", new StringBody(captcha.getID()));
entity.addPart("username", new StringBody(username));
request.setEntity(entity);
validate(execute(request));
@@ -143,7 +140,7 @@ public class CaptchaTrader {
*/
public int getCredits() throws CaptchaTraderException, IOException {
return ((Number) validate(
execute(new HttpGet(apiURL.resolve("get_credits/username:"
execute(new HttpGet(apiURI.resolve("get_credits/username:"
+ username + "/password:" + password + "/")))).get(1))
.intValue();
}
@@ -185,7 +182,7 @@ public class CaptchaTrader {
return new InvalidApplicationKeyException();
case "INVALID PARAMETERS":
return new InvalidParametersException();
case "INVALID URL":
case "INVALID URI":
return new InvalidURLException();
case "INVALID USER":
return new InvalidUserException();

View File

@@ -13,16 +13,16 @@ import com.captchatrader.exception.CaptchaTraderException;
*/
public class ResolvedCaptcha {
private final CaptchaTrader api;
private final int id;
private final String id;
private final String answer;
public ResolvedCaptcha(CaptchaTrader api, int id, String answer) {
public ResolvedCaptcha(CaptchaTrader api, String id, String answer) {
this.api = api;
this.id = id;
this.answer = answer;
}
public int getID() {
public String getID() {
return id;
}
@@ -31,10 +31,10 @@ public class ResolvedCaptcha {
}
public void valid() throws CaptchaTraderException, IOException {
api.response(this, true);
api.respond(this, true);
}
public void invalid() throws CaptchaTraderException, IOException {
api.response(this, true);
api.respond(this, true);
}
}

View File

@@ -32,7 +32,7 @@ public class CaptchaTraderService implements ImageCaptchaService {
/**
* The current application key to be used
*/
private String currentApplicationKey = APP_KEY;
private String currentApplicationKey = CaptchaTraderService.APP_KEY;
/**
* The CaptchaTrader.com API object
@@ -56,8 +56,8 @@ public class CaptchaTraderService implements ImageCaptchaService {
public void solve(ImageCaptcha captcha)
throws UnsolvableCaptchaServiceException {
try {
logger.debug("Resolving CAPTCHA {}", captcha.getImageURL());
final ResolvedCaptcha resolved = api.submit(captcha.getImageURL());
logger.debug("Resolving CAPTCHA {}", captcha.getImageURI());
final ResolvedCaptcha resolved = api.submit(captcha.getImageURI());
captcha.setAnswer(resolved.getAnswer());
captcha.setAttachment(resolved);
logger.debug("CAPTCHA solved, answer is \"{}\"",

View File

@@ -3,7 +3,7 @@
*/
package com.captchatrader;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
@@ -33,7 +33,7 @@ public class CaptchaTraderTest {
"2acc44805ec208cc4d6b00c75a414996", p.getProperty("username"),
p.getProperty("password"));
final ResolvedCaptcha resolved = api
.submit(new URL(
.submit(new URI(
"http://www.google.com/recaptcha/api/image?c=03AHJ_VusNSxAzZgs9OEvH79rOWOFDYXE2ElE5qkCr9kFU-ZU7gqy72tqEL3j_qCLYwdXgh4jaxU1iECISuUwt0zHbelni-lq8c7RVGSjUtJiMyHwlTTsG5CxWKIEus--yy3GPvwaW9l4N7hFnT57lLq272EOxcFDGYA"));
System.out.println(resolved);
resolved.valid();

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-captcha</artifactId>
@@ -20,7 +20,7 @@
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-api</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-channelcopy</artifactId>
@@ -14,18 +14,19 @@
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-api</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.rogiel.httpchannel.services</groupId>
<artifactId>httpchannel-service-megaupload</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.rogiel.httpchannel.services</groupId>
<artifactId>httpchannel-service-multiupload</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.copy;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
@@ -41,7 +41,7 @@ import com.rogiel.httpchannel.service.helper.Services;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ChannelCopy implements Callable<List<URL>> {
public class ChannelCopy implements Callable<List<URI>> {
/**
* The input channel
*/
@@ -101,12 +101,12 @@ public class ChannelCopy implements Callable<List<URL>> {
}
/**
* Initializes with an {@link URL}. First tries to open an
* Initializes with an {@link URI}. First tries to open an
* {@link DownloadChannel}, if no service is found,
* {@link NoServiceFoundException} is thrown.
*
* @param url
* the source {@link URL}
* @param uri
* the source {@link URI}
* @throws DownloadLinkNotFoundException
* if the download link could not be found
* @throws DownloadLimitExceededException
@@ -114,17 +114,17 @@ public class ChannelCopy implements Callable<List<URL>> {
* @throws DownloadNotAuthorizedException
* if the download was not authorized by the service
* @throws NoServiceFoundException
* if no service could be found for the {@link URL}
* if no service could be found for the {@link URI}
* @throws IOException
* if any IO error occur
*/
public ChannelCopy(URL url) throws DownloadLinkNotFoundException,
public ChannelCopy(URI uri) throws DownloadLinkNotFoundException,
DownloadLimitExceededException, DownloadNotAuthorizedException,
IOException {
final DownloadService<?> service = Services.matchURL(url);
final DownloadService<?> service = Services.matchURI(uri);
if (service == null)
throw new NoServiceFoundException(url.toString());
final DownloadChannel downloadChannel = service.getDownloader(url)
throw new NoServiceFoundException(uri.toString());
final DownloadChannel downloadChannel = service.getDownloader(uri)
.openChannel();
this.downloadChannel = downloadChannel;
@@ -173,7 +173,7 @@ public class ChannelCopy implements Callable<List<URL>> {
}
@Override
public List<URL> call() throws IOException {
public List<URI> call() throws IOException {
final ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
try {
while (downloadChannel.read(buffer) >= 0) {
@@ -196,11 +196,11 @@ public class ChannelCopy implements Callable<List<URL>> {
}
}
final List<URL> urls = new ArrayList<>();
final List<URI> uris = new ArrayList<>();
for (final UploadChannel channel : uploadChannels) {
urls.add(channel.getDownloadLink());
uris.add(channel.getDownloadLink());
}
return urls;
return uris;
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-depositfiles</artifactId>

View File

@@ -43,16 +43,16 @@ public class DepositFilesService extends AbstractHttpService implements
*/
public static final ServiceID SERVICE_ID = ServiceID.create("depositfiles");
private static final Pattern UPLOAD_URL_PATTERN = Pattern
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://fileshare([0-9]*)\\.depositfiles\\.com/(.*)/\\?X-Progress-ID=(.*)");
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://(www\\.)?depositfiles\\.com/files/([0-9A-z]*)");
private static final Pattern VALID_LOGIN_REDIRECT = Pattern
.compile("window.location.href");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -139,14 +139,14 @@ public class DepositFilesService extends AbstractHttpService implements
logger.debug("Starting upload to depositfiles.com");
final HTMLPage page = get("http://www.depositfiles.com/").asPage();
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
final String maxFileSize = page.getInputValue("MAX_FILE_SIZE");
logger.debug("Upload URL: {}, ID: {}", url, uploadID);
logger.debug("Upload URI: {}, ID: {}", uri, uploadID);
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url).parameter("files", channel)
uploadFuture = multipartPost(uri).parameter("files", channel)
.parameter("go", true)
.parameter("UPLOAD_IDENTIFIER", uploadID)
.parameter("agree", true)
@@ -158,7 +158,7 @@ public class DepositFilesService extends AbstractHttpService implements
public String finish() throws IOException {
try {
final String link = uploadFuture.get().findScript(
DOWNLOAD_URL_PATTERN, 0);
DOWNLOAD_URI_PATTERN, 0);
if (link == null)
return null;
return link;

View File

@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -31,9 +31,9 @@ public class DepositFilesServiceTest {
UploaderCapability.UNAUTHENTICATED_UPLOAD));
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
final URL url = ChannelUtils.upload(service, path);
final URI uri = ChannelUtils.upload(service, path);
Assert.assertNotNull(url);
System.out.println(url);
Assert.assertNotNull(uri);
System.out.println(uri);
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-filesonic</artifactId>

View File

@@ -4,7 +4,7 @@
package com.rogiel.httpchannel.filesonic;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import javax.xml.bind.JAXB;
@@ -16,7 +16,7 @@ import com.rogiel.httpchannel.filesonic.xml.FSUpload;
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class FileSonicAPI {
private static final String BASE_URL = "http://api.filesonic.com/";
private static final String BASE_URI = "http://api.filesonic.com/";
private String email;
private String password;
@@ -25,10 +25,10 @@ public class FileSonicAPI {
return id;
}
public URL getUploadURL() throws IOException {
return new URL(((FSGetUploadURL) execute(FSUpload.class,
public URI getUploadURI() throws IOException {
return URI.create((((FSGetUploadURL) execute(FSUpload.class,
"upload?method=getUploadUrl").getResponse()).getResponse()
.getUploadURL());
.getUploadURI()));
}
public long getMaxFilesize() throws IOException {
@@ -47,10 +47,10 @@ public class FileSonicAPI {
this.password = null;
}
private <T extends FSAPI> T execute(Class<T> type, String requestURL)
private <T extends FSAPI> T execute(Class<T> type, String requestURI)
throws IOException {
final URL url = new URL(BASE_URL + requestURL + "&u=" + email + "&p="
+ password + "&format=xml");
return JAXB.unmarshal(url.openStream(), type);
final URI uri = URI.create(BASE_URI + requestURI + "&u=" + email
+ "&p=" + password + "&format=xml");
return JAXB.unmarshal(uri.toURL().openStream(), type);
}
}

View File

@@ -20,13 +20,13 @@ public class FSGetUploadURL extends FSResponse {
@XmlAccessorType(XmlAccessType.NONE)
public static class FSGetUploadURLResponse {
@XmlElement(name = "url")
private String uploadURL;
@XmlElement(name = "uri")
private String uploadURI;
@XmlElement(name = "max-filesize")
private long maxFilesize;
public String getUploadURL() {
return uploadURL;
public String getUploadURI() {
return uploadURI;
}
public long getMaxFilesize() {

View File

@@ -57,9 +57,9 @@ public class FileSonicService extends AbstractHttpService implements Service,
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
/**
* The download URL pattern
* The download URI pattern
*/
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://www.filesonic.com/file/[0-9A-z]*");
/**
* The FileSonic API
@@ -67,7 +67,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
private final FileSonicAPI api = new FileSonicAPI();
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -156,7 +156,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to filesonic.com");
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(api.getUploadURL().toString())
uploadFuture = multipartPost(api.getUploadURI().toString())
.parameter("files[]", channel).asStringAsync();
return waitChannelLink(channel, uploadFuture);
}
@@ -164,7 +164,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return PatternUtils.find(DOWNLOAD_URL_PATTERN,
return PatternUtils.find(DOWNLOAD_URI_PATTERN,
uploadFuture.get());
} catch (InterruptedException e) {
return null;

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-hotfile</artifactId>

View File

@@ -17,7 +17,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
@@ -71,7 +71,7 @@ public class HotFileService extends AbstractHttpService implements Service,
*/
public static final ServiceID SERVICE_ID = ServiceID.create("hotfile");
private static final Pattern UPLOAD_URL_PATTERN = Pattern
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://u[0-9]*\\.hotfile\\.com/upload\\.cgi\\?[0-9]*");
private static final Pattern DOWNLOAD_DIRECT_LINK_PATTERN = Pattern
@@ -81,11 +81,11 @@ public class HotFileService extends AbstractHttpService implements Service,
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://hotfile\\.com/dl/([0-9]*)/([A-Za-z0-9]*)/(.*)");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -135,14 +135,14 @@ public class HotFileService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -151,8 +151,8 @@ public class HotFileService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -198,9 +198,9 @@ public class HotFileService extends AbstractHttpService implements Service,
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to hotfile.com");
final HTMLPage page = get("http://www.hotfile.com/").asPage();
final String action = page.findFormAction(UPLOAD_URL_PATTERN);
final String action = page.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URL is {}", action);
logger.debug("Upload URI is {}", action);
final LinkedUploadChannel channel = createLinkedChannel(this);
@@ -212,7 +212,7 @@ public class HotFileService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return uploadFuture.get().getInputValue(DOWNLOAD_URL_PATTERN);
return uploadFuture.get().getInputValue(DOWNLOAD_URI_PATTERN);
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
@@ -223,15 +223,15 @@ public class HotFileService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> {
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
super(url, configuration);
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
logger.debug("Downloading {} from hotfile.com", url);
final HTMLPage page = get(url).asPage();
logger.debug("Downloading {} from hotfile.com", uri);
final HTMLPage page = get(uri).asPage();
// // try to find timer
// final String stringTimer = PatternUtils.find(DOWNLOAD_TIMER,

View File

@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
@@ -80,7 +80,7 @@ public class HotFileServiceTest {
@Test
public void testServiceId() {
assertEquals(ServiceID.create("hotfile"), service.getID());
assertEquals(ServiceID.create("hotfile"), service.getServiceID());
}
@Test
@@ -146,10 +146,10 @@ public class HotFileServiceTest {
@Test
public void testDownloader() throws IOException {
final URL downloadUrl = new URL(
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.htm");
final URI downloadUrl = URI
.create("http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.htm");
final DownloadService<?> service = Services.matchURL(downloadUrl);
final DownloadService<?> service = Services.matchURI(downloadUrl);
final DownloadChannel channel = service.getDownloader(downloadUrl)
.openChannel(null, 0);
@@ -165,8 +165,7 @@ public class HotFileServiceTest {
final DownloadChannel channel = service
.getDownloader(
new URL(
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
URI.create("http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
.openChannel(null, 0);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-megaupload</artifactId>

View File

@@ -17,7 +17,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
@@ -71,7 +71,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
*/
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
private static final Pattern UPLOAD_URL_PATTERN = Pattern
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://www([0-9]*)\\.megaupload\\.com/upload_done\\.php\\?UPLOAD_IDENTIFIER=[0-9]*");
private static final Pattern DOWNLOAD_DIRECT_LINK_PATTERN = Pattern
@@ -81,14 +81,14 @@ public class MegaUploadService extends AbstractHttpService implements Service,
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://www\\.megaupload\\.com/\\?d=([A-Za-z0-9]*)");
private static final Pattern LOGIN_USERNAME_PATTERN = Pattern
.compile("flashvars\\.username = \"(.*)\";");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -139,14 +139,14 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
@Override
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URL url,
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URI uri,
MegaUploadDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -155,8 +155,8 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -208,11 +208,11 @@ public class MegaUploadService extends AbstractHttpService implements Service,
logger.debug("Starting upload to megaupload.com");
final HTMLPage page = get("http://www.megaupload.com/multiupload/")
.asPage();
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
logger.debug("Upload URL is {}", url);
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url)
uploadFuture = multipartPost(uri)
.parameter("multimessage_0", configuration.description())
.parameter("multifile_0", channel).asStringAsync();
return waitChannelLink(channel, uploadFuture);
@@ -221,7 +221,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return PatternUtils.find(DOWNLOAD_URL_PATTERN,
return PatternUtils.find(DOWNLOAD_URI_PATTERN,
uploadFuture.get());
} catch (InterruptedException e) {
return null;
@@ -234,16 +234,16 @@ public class MegaUploadService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<MegaUploadDownloaderConfiguration> implements
Downloader<MegaUploadDownloaderConfiguration> {
public DownloaderImpl(URL url,
public DownloaderImpl(URI uri,
MegaUploadDownloaderConfiguration configuration) {
super(url, configuration);
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
logger.debug("Starting {} download from megaupload.com", url);
HttpResponse response = get(url).request();
logger.debug("Starting {} download from megaupload.com", uri);
HttpResponse response = get(uri).request();
// disable direct downloads, we don't support them!
if (response.getEntity().getContentType().getValue()
@@ -259,7 +259,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
.parameter("set_ddl", "0").request();
// execute and re-request download
response = get(url).request();
response = get(uri).request();
}
final HTMLPage page = HttpClientUtils.toPage(response);

View File

@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
@@ -79,7 +79,7 @@ public class MegaUploadServiceTest {
@Test
public void testServiceId() {
assertEquals(ServiceID.create("megaupload"), service.getID());
assertEquals(ServiceID.create("megaupload"), service.getServiceID());
}
@Test
@@ -145,7 +145,7 @@ public class MegaUploadServiceTest {
@Test
public void testFreeDownloader() throws IOException {
final DownloadChannel channel = service.getDownloader(
new URL("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
URI.create("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
new DownloadListener() {
@Override
public boolean timer(long time) {
@@ -166,7 +166,7 @@ public class MegaUploadServiceTest {
.login();
final DownloadChannel channel = service.getDownloader(
new URL("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
URI.create("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
new DownloadListener() {
@Override
public boolean timer(long time) {
@@ -190,7 +190,7 @@ public class MegaUploadServiceTest {
@SuppressWarnings({ "unused" })
final DownloadChannel channel = service.getDownloader(
new URL("http://www.megaupload.com/?d=CVQKJ1KM"), config)
URI.create("http://www.megaupload.com/?d=CVQKJ1KM"), config)
.openChannel(new DownloadListener() {
@Override
public boolean timer(long time) {

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-multiupload</artifactId>

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
@@ -56,7 +56,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
public static final ServiceID SERVICE_ID = ServiceID.create("multiupload");
// http://www52.multiupload.com/upload/?UPLOAD_IDENTIFIER=73132658610746
private static final Pattern UPLOAD_URL_PATTERN = Pattern
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://www([0-9]*)\\.multiupload\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
@@ -66,7 +66,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
.compile("http://www[0-9]*\\.multiupload\\.com(:[0-9]*)?/files/([0-9a-zA-Z]*)/(.*)");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -119,14 +119,14 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -135,8 +135,8 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_LINK_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_LINK_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -184,12 +184,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to multiupload.com");
final String url = get("http://www.multiupload.com/").asPage()
.findFormAction(UPLOAD_URL_PATTERN);
logger.debug("Upload URL is {}", url);
final String uri = get("http://www.multiupload.com/").asPage()
.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this);
PostMultipartRequest request = multipartPost(url).parameter(
PostMultipartRequest request = multipartPost(uri).parameter(
"description_0", configuration.description()).parameter(
"file_0", channel);
for (final MultiUploadMirrorService mirror : configuration
@@ -223,9 +223,9 @@ public class MultiUploadService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
protected DownloaderImpl(URL url,
protected DownloaderImpl(URI uri,
NullDownloaderConfiguration configuration) {
super(url, configuration);
super(uri, configuration);
}
@Override
@@ -233,7 +233,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
long position) throws IOException,
DownloadLinkNotFoundException, DownloadLimitExceededException,
DownloadNotAuthorizedException, DownloadNotResumableException {
final HTMLPage page = get(url).asPage();
final HTMLPage page = get(uri).asPage();
final String link = page.findLink(DIRECT_DOWNLOAD_LINK_PATTERN);
logger.debug("Direct download link is {}", link);
if (link == null)

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
@@ -33,16 +33,16 @@ public class MultiUploadServiceTest {
@Test
public void testUploader() throws IOException {
final URL url = ChannelUtils.upload(service, TEST_UPLOAD_FILE);
Assert.assertNotNull(url);
System.out.println("Uploaded file to " + url);
final URI uri = ChannelUtils.upload(service, TEST_UPLOAD_FILE);
Assert.assertNotNull(uri);
System.out.println("Uploaded file to " + uri);
}
@Test
public void testDownloader() throws IOException, NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
new URL("http://www.multiupload.com/TJOYWB4JEW"))
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
.openChannel());
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_FULL_CHECKSUM);
@@ -53,7 +53,7 @@ public class MultiUploadServiceTest {
NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
new URL("http://www.multiupload.com/TJOYWB4JEW"))
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
.openChannel(50));
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_RESUME_CHECKSUM);

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-uploadhere</artifactId>

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
@@ -54,21 +54,21 @@ public class UploadHereService extends AbstractHttpService implements Service,
*/
public static final ServiceID SERVICE_ID = ServiceID.create("uploadhere");
private static final Pattern UPLOAD_URL_PATTERN = Pattern
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://www([0-9]*)\\.uploadhere\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://(www\\.)?uploadhere.\\com/[0-9A-z]*");
private static final Pattern TIMER_PATTERN = Pattern.compile(
"count = ([0-9]*);", Pattern.COMMENTS);
private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadhere\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -118,14 +118,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -134,8 +134,8 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -185,14 +185,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
final HTMLPage page = get("http://www.uploadhere.com/").asPage();
final String userCookie = page.getInputValueById("usercookie");
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
new Object[] { url, userCookie, uploadID });
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
new Object[] { uri, userCookie, uploadID });
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url).parameter("file_0", channel)
uploadFuture = multipartPost(uri).parameter("file_0", channel)
.parameter("u", userCookie)
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
return waitChannelLink(channel, uploadFuture);
@@ -222,14 +222,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
super(url, configuration);
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
HTMLPage page = get(url).asPage();
HTMLPage page = get(uri).asPage();
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
logger.debug("Wait time is {}", waitTime);
@@ -251,12 +251,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
logger.debug("CAPTCHA solving took longer than timer, skipping it");
}
String content = post(url)
String content = post(uri)
.parameter("recaptcha_challenge_field", captcha.getID())
.parameter("recaptcha_response_field",
captcha.getAnswer()).asString();
String downloadLink = PatternUtils.find(
DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
if (downloadLink == null) {
captchaService.invalid(captcha);
throw new InvalidCaptchaException();
@@ -265,7 +265,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
"/");
logger.debug("Direct download URL is {}", downloadLink);
logger.debug("Direct download URI is {}", downloadLink);
return download(get(downloadLink).position(position));
}
throw new DownloadLinkNotFoundException();

View File

@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -31,10 +31,10 @@ public class UploadHereServiceTest {
UploaderCapability.UNAUTHENTICATED_UPLOAD));
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
final URL url = ChannelUtils.upload(service, path);
final URI uri = ChannelUtils.upload(service, path);
Assert.assertNotNull(url);
System.out.println(url);
Assert.assertNotNull(uri);
System.out.println(uri);
}
// @Test
@@ -43,7 +43,7 @@ public class UploadHereServiceTest {
// @Override
// public boolean resolve(Captcha rawCaptcha) {
// final ImageCaptcha captcha = (ImageCaptcha) rawCaptcha;
// System.out.println(captcha.getImageURL());
// System.out.println(captcha.getImageURI());
// try {
// captcha.setAnswer(new BufferedReader(new InputStreamReader(
// System.in)).readLine());
@@ -56,7 +56,7 @@ public class UploadHereServiceTest {
// });
//
// final DownloadChannel channel = service.getDownloader(
// new URL("http://www.uploadhere.com/9WCEQF1Q07")).openChannel();
// new URI("http://www.uploadhere.com/9WCEQF1Q07")).openChannel();
// System.out.println(new String(ChannelUtils.toByteArray(channel)));
// }
}

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-uploadking</artifactId>
@@ -15,7 +15,7 @@
<dependency>
<groupId>com.rogiel.httpchannel.captcha</groupId>
<artifactId>httpchannel-captcha-captchatrader</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
@@ -54,21 +54,21 @@ public class UploadKingService extends AbstractHttpService implements Service,
*/
public static final ServiceID SERVICE_ID = ServiceID.create("uploadking");
private static final Pattern UPLOAD_URL_PATTERN = Pattern
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://www([0-9]*)\\.uploadking\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
private static final Pattern TIMER_PATTERN = Pattern.compile(
"count = ([0-9]*);", Pattern.COMMENTS);
private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -118,14 +118,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -134,8 +134,8 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -185,14 +185,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
final HTMLPage page = get("http://www.uploadking.com/").asPage();
final String userCookie = page.getInputValueById("usercookie");
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
new Object[] { url, userCookie, uploadID });
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
new Object[] { uri, userCookie, uploadID });
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url).parameter("file", channel)
uploadFuture = multipartPost(uri).parameter("file", channel)
.parameter("u", userCookie)
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
return waitChannelLink(channel, uploadFuture);
@@ -219,15 +219,15 @@ public class UploadKingService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
super(url, configuration);
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
logger.debug("Downloading {} with uploadking.com");
HTMLPage page = get(url).asPage();
HTMLPage page = get(uri).asPage();
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
logger.debug("Wait time is {}", waitTime);
@@ -250,12 +250,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
logger.debug("CAPTCHA solving took longer than timer, skipping it");
}
String content = post(url)
String content = post(uri)
.parameter("recaptcha_challenge_field", captcha.getID())
.parameter("recaptcha_response_field",
captcha.getAnswer()).asString();
String downloadLink = PatternUtils.find(
DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
if (downloadLink == null) {
captchaService.invalid(captcha);
throw new InvalidCaptchaException();
@@ -264,7 +264,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
"/");
logger.debug("Direct download URL is {}", downloadLink);
logger.debug("Direct download URI is {}", downloadLink);
return download(get(downloadLink).position(position));
}
throw new DownloadLinkNotFoundException();

View File

@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -37,10 +37,10 @@ public class UploadKingServiceTest {
UploaderCapability.UNAUTHENTICATED_UPLOAD));
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
final URL url = ChannelUtils.upload(service, path);
final URI uri = ChannelUtils.upload(service, path);
Assert.assertNotNull(url);
System.out.println(url);
Assert.assertNotNull(uri);
System.out.println(uri);
}
@Test
@@ -55,7 +55,8 @@ public class UploadKingServiceTest {
service.setCaptchaService(s);
final DownloadChannel channel = service.getDownloader(
new URL("http://www.uploadking.com/WM3PHD9JAY")).openChannel(0);
URI.create("http://www.uploadking.com/WM3PHD9JAY"))
.openChannel(0);
System.out.println(new String(ChannelUtils.toByteArray(channel)));
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-zshare</artifactId>

View File

@@ -30,22 +30,22 @@ public class ZShareService extends AbstractHttpService implements Service/*
*/
public static final ServiceID SERVICE_ID = ServiceID.create("zshare");
// private static final Pattern UPLOAD_URL_PATTERN = Pattern
// private static final Pattern UPLOAD_URI_PATTERN = Pattern
// .compile("http://dl([0-9]*)\\.zshare\\.net(\\:[0-9]*)?/",
// Pattern.CASE_INSENSITIVE);
// private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
// .compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
// private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
// private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
// .compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
// private static final Pattern TIMER_PATTERN = Pattern.compile(
// "count = ([0-9]*);", Pattern.COMMENTS);
// private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
// private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
// .compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
//
// private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -95,14 +95,14 @@ public class ZShareService extends AbstractHttpService implements Service/*
// }
// @Override
// public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
// public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
// NullDownloaderConfiguration configuration) {
// return new DownloaderImpl(url, configuration);
// return new DownloaderImpl(uri, configuration);
// }
//
// @Override
// public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
// return getDownloader(url, newDownloaderConfiguration());
// public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
// return getDownloader(uri, newDownloaderConfiguration());
// }
//
// @Override
@@ -111,8 +111,8 @@ public class ZShareService extends AbstractHttpService implements Service/*
// }
//
// @Override
// public boolean matchURL(URL url) {
// return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
// public boolean matchURI(URI uri) {
// return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
// }
//
// @Override
@@ -162,12 +162,12 @@ public class ZShareService extends AbstractHttpService implements Service/*
// public UploadChannel openChannel() throws IOException {
// final HTMLPage page = get("http://www.zshare.net/").asPage();
//
// final String url = page.findFormAction(UPLOAD_URL_PATTERN);
// System.out.println(url+"cgi-bin/ubr_upload.pl");
// final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
// System.out.println(uri+"cgi-bin/ubr_upload.pl");
//
// final LinkedUploadChannel channel = createLinkedChannel(this);
// uploadFuture =
// multipartPost(url+"cgi-bin/ubr_upload.pl").parameter("file", channel)
// multipartPost(uri+"cgi-bin/ubr_upload.pl").parameter("file", channel)
// .parameter("descr", configuration.description())
// .parameter("TOS", true).parameter("is_private", false)
// .asStringAsync();
@@ -196,15 +196,15 @@ public class ZShareService extends AbstractHttpService implements Service/*
// protected class DownloaderImpl extends
// AbstractHttpDownloader<NullDownloaderConfiguration> implements
// Downloader<NullDownloaderConfiguration> {
// public DownloaderImpl(URL url, NullDownloaderConfiguration configuration)
// public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration)
// {
// super(url, configuration);
// super(uri, configuration);
// }
//
// @Override
// public DownloadChannel openChannel(DownloadListener listener,
// long position) throws IOException {
// HTMLPage page = get(url).asPage();
// HTMLPage page = get(uri).asPage();
//
// final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
//
@@ -218,12 +218,12 @@ public class ZShareService extends AbstractHttpService implements Service/*
// // if (delta < waitTime)
// // timer(listener, waitTime - delta);
// //
// // String content = post(url)
// // String content = post(uri)
// // .parameter("recaptcha_challenge_field", captcha.getID())
// // .parameter("recaptcha_response_field",
// // captcha.getAnswer()).asString();
// // String downloadLink = PatternUtils.find(
// // DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
// // DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
// // if (downloadLink == null)
// // throw new InvalidCaptchaException();
// // downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service</artifactId>
@@ -26,12 +26,12 @@
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-api</artifactId>
<version>${project.version}</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-util</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-util</artifactId>
@@ -12,7 +12,7 @@
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-api</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>

View File

@@ -4,8 +4,7 @@
package com.rogiel.httpchannel.captcha;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URI;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.http.HttpContext;
@@ -13,46 +12,73 @@ import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
* This class provides utility methods to extract an {@link ImageCaptcha} from
* an page containing an Google ReCaptcha CAPTCHA embedded into it.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class ReCaptchaExtractor {
/**
* This pattern extracts the SITE-ID from the Ajax ReCaptcha API
*/
private static final Pattern CAPTCHA_ID_PATTERN = Pattern
.compile("Recaptcha\\.create\\(\"([0-9A-z|_|\\-]*)\", ");
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
private static final Pattern CAPTCHA_URI_PATTERN = Pattern
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
.compile("challenge : '(.*)'");
private static final String CHALLENGE_BASE_URL = "http://www.google.com/recaptcha/api/challenge?ajax=1&k=";
private static final String IMAGE_BASE_URL = "http://www.google.com/recaptcha/api/image?c=";
private static final String CHALLENGE_BASE_URI = "http://www.google.com/recaptcha/api/challenge?ajax=1&k=";
private static final String IMAGE_BASE_URI = "http://www.google.com/recaptcha/api/image?c=";
/**
* Extracts the {@link ImageCaptcha} for an ReCAPTCHA using the standard JS
* include method
*
* @param page
* the page
* @param ctx
* the {@link HttpContext}
* @return the {@link ImageCaptcha} embedded at the given <code>page</code>
*/
public static ImageCaptcha extractCaptcha(HTMLPage page, HttpContext ctx) {
final String url = page.findScriptSrc(CAPTCHA_URL_PATTERN);
if (url == null)
final String uri = page.findScriptSrc(CAPTCHA_URI_PATTERN);
if (uri == null)
return null;
try {
return doExtract(ctx.get(url).asString());
return doExtract(ctx.get(uri).asString());
} catch (IOException e) {
return null;
}
}
/**
* Extracts the {@link ImageCaptcha} for an ReCAPTCHA using the Ajax API
*
* @param page
* the page
* @param ctx
* the {@link HttpContext}
* @return the {@link ImageCaptcha} contained at the given <code>page</code>
*/
public static ImageCaptcha extractAjaxCaptcha(HTMLPage page, HttpContext ctx) {
final String siteID = page.findScript(CAPTCHA_ID_PATTERN, 1);
try {
return doExtract(ctx.get(CHALLENGE_BASE_URL + siteID).asString());
return doExtract(ctx.get(CHALLENGE_BASE_URI + siteID).asString());
} catch (IOException e) {
return null;
}
}
/**
* Actually performs the extracting job.
*
* @param content
* the page content
* @return the {@link ImageCaptcha}
*/
private static ImageCaptcha doExtract(String content) {
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, content, 1);
try {
return new ImageCaptcha(id, new URL(IMAGE_BASE_URL + id));
} catch (MalformedURLException e) {
return null;
}
return new ImageCaptcha(id, URI.create(IMAGE_BASE_URI + id));
}
}

View File

@@ -11,13 +11,13 @@ import org.apache.http.client.methods.HttpGet;
public class GetRequest extends Request {
private long position = 0;
public GetRequest(HttpContext ctx, String url) {
super(ctx, url);
public GetRequest(HttpContext ctx, String uri) {
super(ctx, uri);
}
@Override
public HttpResponse request() throws IOException {
final HttpGet get = new HttpGet(url);
final HttpGet get = new HttpGet(uri);
if (position > 0)
get.addHeader("Range", "bytes=" + position + "-");
return ctx.client.execute(get);

View File

@@ -3,7 +3,7 @@
*/
package com.rogiel.httpchannel.http;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -22,19 +22,19 @@ public class HttpContext {
*/
protected DefaultHttpClient client = new DefaultHttpClient();
public GetRequest get(String url) {
return new GetRequest(this, url);
public GetRequest get(String uri) {
return new GetRequest(this, uri);
}
public GetRequest get(URL url) {
return get(url.toString());
public GetRequest get(URI uri) {
return get(uri.toString());
}
public PostRequest post(String url) {
return new PostRequest(this, url);
public PostRequest post(String uri) {
return new PostRequest(this, uri);
}
public PostMultipartRequest multipartPost(String url) {
return new PostMultipartRequest(this, url);
public PostMultipartRequest multipartPost(String uri) {
return new PostMultipartRequest(this, uri);
}
}

View File

@@ -18,14 +18,14 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
public class PostMultipartRequest extends PostRequest {
private final MultipartEntity entity;
public PostMultipartRequest(HttpContext ctx, String url) {
super(ctx, url);
public PostMultipartRequest(HttpContext ctx, String uri) {
super(ctx, uri);
this.entity = new MultipartEntity();
}
@Override
public HttpResponse request() throws IOException {
final HttpPost post = new HttpPost(url);
final HttpPost post = new HttpPost(uri);
post.setEntity(entity);
return ctx.client.execute(post);
}

View File

@@ -17,13 +17,13 @@ import org.apache.http.message.BasicNameValuePair;
public class PostRequest extends Request {
protected final List<NameValuePair> params = new ArrayList<NameValuePair>();
public PostRequest(HttpContext ctx, String url) {
super(ctx, url);
public PostRequest(HttpContext ctx, String uri) {
super(ctx, uri);
}
@Override
public HttpResponse request() throws IOException {
final HttpPost post = new HttpPost(url);
final HttpPost post = new HttpPost(uri);
post.setEntity(new UrlEncodedFormEntity(params));
return ctx.client.execute(post);
}

View File

@@ -15,11 +15,11 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
public abstract class Request {
protected final HttpContext ctx;
protected final String url;
protected final String uri;
public Request(HttpContext ctx, String url) {
public Request(HttpContext ctx, String uri) {
this.ctx = ctx;
this.url = url;
this.uri = uri;
}
public abstract HttpResponse request() throws IOException;
@@ -59,7 +59,7 @@ public abstract class Request {
});
}
public String getURL() {
return url;
public String getURI() {
return uri;
}
}

View File

@@ -2,7 +2,7 @@ package com.rogiel.httpchannel.service;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URI;
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
@@ -23,9 +23,9 @@ import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
public abstract class AbstractDownloader<C extends DownloaderConfiguration>
implements Downloader<C> {
/**
* The download URL
* The download URI
*/
protected final URL url;
protected final URI uri;
/**
* The {@link Downloader} configuration
@@ -35,13 +35,13 @@ public abstract class AbstractDownloader<C extends DownloaderConfiguration>
/**
* Creates a new instance
*
* @param url
* the download url
* @param uri
* the download uri
* @param configuration
* the configuration object
*/
protected AbstractDownloader(URL url, C configuration) {
this.url = url;
protected AbstractDownloader(URI uri, C configuration) {
this.uri = uri;
this.configuration = configuration;
}

View File

@@ -17,7 +17,7 @@
package com.rogiel.httpchannel.service;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.Header;
@@ -39,8 +39,8 @@ public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration>
extends AbstractDownloader<C> implements Downloader<C> {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
protected AbstractHttpDownloader(URL url, C configuration) {
super(url, configuration);
protected AbstractHttpDownloader(URI uri, C configuration) {
super(uri, configuration);
}
protected long getContentLength(HttpResponse response) {
@@ -70,7 +70,7 @@ public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration>
.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT))
throw new DownloadLinkNotFoundException();
final String filename = FilenameUtils.getName(request.getURL());
final String filename = FilenameUtils.getName(request.getURI());
final long contentLength = getContentLength(response);
return createInputStreamChannel(response.getEntity().getContent(),
contentLength, filename);

View File

@@ -16,7 +16,7 @@
*/
package com.rogiel.httpchannel.service;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.Future;
import com.rogiel.httpchannel.http.GetRequest;
@@ -45,23 +45,23 @@ public abstract class AbstractHttpService extends AbstractService implements
return channel;
}
public GetRequest get(String url) {
return http.get(url);
public GetRequest get(String uri) {
return http.get(uri);
}
public GetRequest get(URL url) {
return http.get(url);
public GetRequest get(URI uri) {
return http.get(uri);
}
public PostRequest post(String url) {
return http.post(url);
public PostRequest post(String uri) {
return http.post(uri);
}
public PostRequest post(URL url) {
return post(url.toString());
public PostRequest post(URI uri) {
return post(uri.toString());
}
public PostMultipartRequest multipartPost(String url) {
return http.multipartPost(url);
public PostMultipartRequest multipartPost(String uri) {
return http.multipartPost(uri);
}
}

View File

@@ -17,8 +17,9 @@
package com.rogiel.httpchannel.service.channel;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.Channel;
import java.nio.channels.ClosedChannelException;
import java.nio.channels.WritableByteChannel;
@@ -29,19 +30,43 @@ import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.exception.UploadLinkNotFoundException;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
* This channel is linked onto another {@link Channel} that actually writes data
* into the network stream.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class LinkedUploadChannel implements UploadChannel {
/**
* The logger instance
*/
private final Logger logger = LoggerFactory.getLogger(this.getClass());
/**
* The destionation {@link Channel}. Data writted is forwarded to this
* channel.
*/
private WritableByteChannel channel;
/**
* The close callback, that notifies once the channel has been closed
*/
private final LinkedUploadChannelCloseCallback closeCallback;
/**
* The length of the data being uploaded
*/
private final long length;
/**
* The file name
*/
private final String filename;
private URL downloadLink;
/**
* Only set when {@link #close()} is called and the download has finished.
*/
private URI downloadLink;
/**
* Whether the channel is still open or not
*/
private boolean open = true;
public LinkedUploadChannel(LinkedUploadChannelCloseCallback closeCallback,
@@ -55,11 +80,11 @@ public class LinkedUploadChannel implements UploadChannel {
public int write(ByteBuffer src) throws IOException {
if (channel == null)
throw new IOException("Channel is not linked yet");
if(!open)
if (!open)
throw new ClosedChannelException();
try {
return channel.write(src);
} catch(IOException e) {
} catch (IOException e) {
close();
throw e;
}
@@ -77,7 +102,7 @@ public class LinkedUploadChannel implements UploadChannel {
logger.debug("Download link returned by service is {}", downloadLink);
if (downloadLink == null)
throw new UploadLinkNotFoundException();
this.downloadLink = new URL(downloadLink);
this.downloadLink = URI.create(downloadLink);
}
public interface LinkedUploadChannelCloseCallback {
@@ -95,16 +120,33 @@ public class LinkedUploadChannel implements UploadChannel {
}
@Override
public URL getDownloadLink() {
public URI getDownloadLink() {
return downloadLink;
}
/**
* Links this {@link Channel} to the destionation {@link Channel}. All data
* written in this channel will be redirected to the destination
* {@link Channel}.
*
* @param channel
* the target channel
* @throws IOException
* if the channel is already linked or the destination channel
* is closed
*/
protected void linkChannel(WritableByteChannel channel) throws IOException {
if (this.channel != null)
throw new IOException("This channel is already linked.");
throw new IOException("This channel is already linked");
if (!channel.isOpen())
throw new IOException("The destination channel is closed");
this.channel = channel;
}
/**
* @return <code>true</code> if the channel is linked with the destination
* {@link Channel}
*/
public boolean isLinked() {
return channel != null;
}

View File

@@ -18,7 +18,7 @@ package com.rogiel.httpchannel.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
@@ -65,7 +65,7 @@ public class ChannelUtils {
return out.toByteArray();
}
public static URL upload(UploadService<?> service, Path path)
public static URI upload(UploadService<?> service, Path path)
throws IOException {
final UploadChannel uploadChannel = UploadServices
.upload(service, path).openChannel();

View File

@@ -35,14 +35,14 @@ public class HttpClientUtils {
private static final ExecutorService threadPool = Executors
.newCachedThreadPool();
public static HttpResponse get(HttpClient client, String url)
public static HttpResponse get(HttpClient client, String uri)
throws IOException {
return client.execute(new HttpGet(url));
return client.execute(new HttpGet(uri));
}
public static String getString(HttpClient client, String url)
public static String getString(HttpClient client, String uri)
throws IOException {
return toString(get(client, url));
return toString(get(client, uri));
}
public static String execute(HttpClient client, HttpUriRequest request)

View File

@@ -104,7 +104,7 @@ public class HTMLPage {
}
/**
* Tries to find a link that has an URL following the given pattern
* Tries to find a link that has an URI following the given pattern
*
* @param pattern
* the pattern
@@ -119,11 +119,11 @@ public class HTMLPage {
}
/**
* Tries to find a frame that has an URL following the given pattern
* Tries to find a frame that has an URI following the given pattern
*
* @param pattern
* the pattern
* @return the iframe url, if found. <code>null</code> otherwise
* @return the iframe uri, if found. <code>null</code> otherwise
*/
public String findFrame(final Pattern pattern) {
for (final TagNode tag : filter(TagNode.class, new FramePatternFilter(
@@ -134,11 +134,11 @@ public class HTMLPage {
}
/**
* Tries to find a image that has an URL following the given pattern
* Tries to find a image that has an URI following the given pattern
*
* @param pattern
* the pattern
* @return the iframe url, if found. <code>null</code> otherwise
* @return the iframe uri, if found. <code>null</code> otherwise
*/
public String findImage(final Pattern pattern) {
for (final ImageTag tag : filter(ImageTag.class,
@@ -154,7 +154,7 @@ public class HTMLPage {
*
* @param pattern
* the pattern
* @return the URL found, if any. <code>null</code> otherwise
* @return the URI found, if any. <code>null</code> otherwise
*/
public String findFormAction(final Pattern pattern) {
for (final FormTag tag : filter(FormTag.class,

136
pom.xml
View File

@@ -4,18 +4,70 @@
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>HttpChannel</name>
<description>Library capable of downloading and uploading files from free servers using channels.</description>
<url>http://httpchannel.rogiel.com/</url>
<scm>
<developerConnection>scm:git:${basedir}</developerConnection>
<connection>scm:git:${basedir}</connection>
</scm>
<distributionManagement>
<downloadUrl>http://httpchannel.rogiel.com/maven2/com/rogiel/httpchannel</downloadUrl>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>httpchannel-repository</id>
<name>HttpChannel Maven Repository</name>
<url>scp://rogiels@rogiel.com/home/rogiels/httpchannel.rogiel.com/maven2</url>
<layout>default</layout>
</repository>
<site>
<id>httpchannel-site</id>
<name>httpchannel-site</name>
<url>scp://rogiels@rogiel.com/home/rogiels/httpchannel.rogiel.com</url>
</site>
</distributionManagement>
<issueManagement>
<system>GitHub</system>
<url>https://github.com/seedbox/httpchannel/issues</url>
</issueManagement>
<ciManagement>
<system>GitHub</system>
<url>https://github.com/seedbox/httpchannel</url>
</ciManagement>
<developers>
<developer>
<id>Rogiel</id>
<name>Rogiel</name>
<email>rogiel@rogiel.com</email>
<url>http://www.rogiel.com/</url>
<timezone>-3</timezone>
<roles>
<role>Creator</role>
<role>API Designer</role>
</roles>
</developer>
</developers>
<licenses>
<license>
<name>GNU General Public License version 3</name>
<url>http://www.gnu.org/licenses/gpl.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<modules>
<module>httpchannel-api</module>
<module>httpchannel-service</module>
<module>httpchannel-util</module>
<module>httpchannel-channelcopy</module>
<module>httpchannel-captcha</module>
<module>httpchannel-channelcopy</module>
<module>httpchannel-util</module>
</modules>
<build>
@@ -38,20 +90,70 @@
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/distribution-bin.xml</descriptor>
</descriptors>
<outputEncoding>UTF-8</outputEncoding>
<reportPlugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version>
<configuration>
<developerConnection>scm:git@github.com:seedbox/httpchannel.git</developerConnection>
<anonymousConnection>scm:git://github.com/seedbox/httpchannel.git</anonymousConnection>
<webAccessUrl>https://github.com/seedbox/httpchannel</webAccessUrl>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changelog-plugin</artifactId>
<version>2.2</version>
<configuration>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jxr-plugin</artifactId>
<version>2.3</version>
<configuration>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
</reportPlugins>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assembly</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<configuration>
<uniqueVersion>false</uniqueVersion>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
@@ -74,9 +176,7 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.4</version>
<scope>runtime</scope>
<optional>true</optional>
<scope>test</scope>
</dependency>
</dependencies>
<url>http://httpchannel.rogiel.com/</url>
</project>

View File

@@ -1,29 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<formats>
<format>zip</format>
</formats>
<baseDirectory></baseDirectory>
<moduleSets>
<moduleSet>
<includeSubModules>true</includeSubModules>
<binaries>
<unpack>true</unpack>
<useStrictFiltering>true</useStrictFiltering>
<unpackOptions>
<includes>
<include>com/rogiel/httpchannel/**</include>
</includes>
</unpackOptions>
<includeDependencies>false</includeDependencies>
<includes>
<include>httpchannel-api</include>
<include>httpchannel-service</include>
</includes>
</binaries>
</moduleSet>
</moduleSets>
</assembly>