From 673bfc66392bb56cca292399700ec24eb3453e95 Mon Sep 17 00:00:00 2001 From: Rogiel Date: Tue, 17 Jan 2012 17:07:48 -0200 Subject: [PATCH] Adds -SNAPSHOT to Maven version parameter and few modifications to API --- httpchannel-api/pom.xml | 2 +- .../httpchannel/captcha/ImageCaptcha.java | 16 +-- .../httpchannel/service/DownloadService.java | 28 ++-- .../rogiel/httpchannel/service/Service.java | 2 +- .../httpchannel/service/UploadChannel.java | 4 +- .../service/helper/DownloadServices.java | 6 +- .../httpchannel/service/helper/Services.java | 16 +-- .../httpchannel-captcha-captchatrader/pom.xml | 2 +- .../java/com/captchatrader/CaptchaTrader.java | 35 +++-- .../com/captchatrader/ResolvedCaptcha.java | 10 +- .../captcha/impl/CaptchaTraderService.java | 6 +- .../com/captchatrader/CaptchaTraderTest.java | 4 +- httpchannel-captcha/pom.xml | 4 +- httpchannel-channelcopy/pom.xml | 9 +- .../rogiel/httpchannel/copy/ChannelCopy.java | 28 ++-- .../httpchannel-service-depositfiles/pom.xml | 2 +- .../service/impl/DepositFilesService.java | 14 +- .../service/impl/DepositFilesServiceTest.java | 8 +- .../httpchannel-service-filesonic/pom.xml | 2 +- .../httpchannel/filesonic/FileSonicAPI.java | 18 +-- .../filesonic/xml/FSGetUploadURL.java | 8 +- .../service/impl/FileSonicService.java | 10 +- .../httpchannel-service-hotfile/pom.xml | 2 +- .../service/impl/HotFileService.java | 34 ++--- .../service/impl/HotFileServiceTest.java | 13 +- .../httpchannel-service-megaupload/pom.xml | 2 +- .../service/impl/MegaUploadService.java | 38 ++--- .../service/impl/MegaUploadServiceTest.java | 10 +- .../httpchannel-service-multiupload/pom.xml | 2 +- .../service/impl/MultiUploadService.java | 32 ++--- .../service/impl/MultiUploadServiceTest.java | 12 +- .../httpchannel-service-uploadhere/pom.xml | 2 +- .../service/impl/UploadHereService.java | 42 +++--- .../service/impl/UploadHereServiceTest.java | 12 +- .../httpchannel-service-uploadking/pom.xml | 4 +- .../service/impl/UploadKingService.java | 42 +++--- .../service/impl/UploadKingServiceTest.java | 11 +- .../httpchannel-service-zshare/pom.xml | 2 +- .../service/impl/ZShareService.java | 36 ++--- httpchannel-service/pom.xml | 6 +- httpchannel-util/pom.xml | 4 +- .../captcha/ReCaptchaExtractor.java | 56 ++++++-- .../rogiel/httpchannel/http/GetRequest.java | 6 +- .../rogiel/httpchannel/http/HttpContext.java | 18 +-- .../http/PostMultipartRequest.java | 6 +- .../rogiel/httpchannel/http/PostRequest.java | 6 +- .../com/rogiel/httpchannel/http/Request.java | 10 +- .../service/AbstractDownloader.java | 14 +- .../service/AbstractHttpDownloader.java | 8 +- .../service/AbstractHttpService.java | 22 +-- .../service/channel/LinkedUploadChannel.java | 60 ++++++-- .../rogiel/httpchannel/util/ChannelUtils.java | 4 +- .../httpchannel/util/HttpClientUtils.java | 8 +- .../httpchannel/util/htmlparser/HTMLPage.java | 12 +- pom.xml | 136 +++++++++++++++--- src/main/assembly/distribution-bin.xml | 29 ---- 56 files changed, 536 insertions(+), 399 deletions(-) delete mode 100644 src/main/assembly/distribution-bin.xml diff --git a/httpchannel-api/pom.xml b/httpchannel-api/pom.xml index 1851b80..b7f8987 100644 --- a/httpchannel-api/pom.xml +++ b/httpchannel-api/pom.xml @@ -4,7 +4,7 @@ httpchannel com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-api diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/captcha/ImageCaptcha.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/captcha/ImageCaptcha.java index 375e947..e0ffafb 100644 --- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/captcha/ImageCaptcha.java +++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/captcha/ImageCaptcha.java @@ -3,7 +3,7 @@ */ package com.rogiel.httpchannel.captcha; -import java.net.URL; +import java.net.URI; /** * @author Rogiel @@ -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 + "]"; } } diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadService.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadService.java index bad72e1..3ea9671 100644 --- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadService.java +++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/DownloadService.java @@ -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 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 getDownloader(URL url, C configuration); + Downloader 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 getDownloader(URL url); + Downloader getDownloader(URI uri); /** * Creates a new configuration object. If a service does not support or @@ -65,17 +65,17 @@ public interface DownloadService 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. *

* Please note 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}. diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java index 986cea6..4627084 100644 --- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java +++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Service.java @@ -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 diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java index e3ec2d5..7de30c8 100644 --- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java +++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/UploadChannel.java @@ -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 diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java index ae14334..a8b3184 100644 --- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java +++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/DownloadServices.java @@ -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 Rogiel */ 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); } } diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/Services.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/Services.java index 9918923..fd50859 100644 --- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/Services.java +++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/helper/Services.java @@ -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 diff --git a/httpchannel-captcha/httpchannel-captcha-captchatrader/pom.xml b/httpchannel-captcha/httpchannel-captcha-captchatrader/pom.xml index 62ad5db..1c429db 100644 --- a/httpchannel-captcha/httpchannel-captcha-captchatrader/pom.xml +++ b/httpchannel-captcha/httpchannel-captcha-captchatrader/pom.xml @@ -4,7 +4,7 @@ httpchannel-captcha com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. com.rogiel.httpchannel.captcha diff --git a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/CaptchaTrader.java b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/CaptchaTrader.java index 0d78ce9..ef9a551 100644 --- a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/CaptchaTrader.java +++ b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/CaptchaTrader.java @@ -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 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(); diff --git a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/ResolvedCaptcha.java b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/ResolvedCaptcha.java index 02a9472..c40529e 100644 --- a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/ResolvedCaptcha.java +++ b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/captchatrader/ResolvedCaptcha.java @@ -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); } } diff --git a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/rogiel/httpchannel/captcha/impl/CaptchaTraderService.java b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/rogiel/httpchannel/captcha/impl/CaptchaTraderService.java index 4a5da63..27678a5 100644 --- a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/rogiel/httpchannel/captcha/impl/CaptchaTraderService.java +++ b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/main/java/com/rogiel/httpchannel/captcha/impl/CaptchaTraderService.java @@ -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 \"{}\"", diff --git a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/test/java/com/captchatrader/CaptchaTraderTest.java b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/test/java/com/captchatrader/CaptchaTraderTest.java index de42b39..8a2b64e 100644 --- a/httpchannel-captcha/httpchannel-captcha-captchatrader/src/test/java/com/captchatrader/CaptchaTraderTest.java +++ b/httpchannel-captcha/httpchannel-captcha-captchatrader/src/test/java/com/captchatrader/CaptchaTraderTest.java @@ -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(); diff --git a/httpchannel-captcha/pom.xml b/httpchannel-captcha/pom.xml index f3241ed..01914ec 100644 --- a/httpchannel-captcha/pom.xml +++ b/httpchannel-captcha/pom.xml @@ -4,7 +4,7 @@ httpchannel com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-captcha @@ -20,7 +20,7 @@ com.rogiel.httpchannel httpchannel-api - 1.0.0 + 1.0.0-SNAPSHOT \ No newline at end of file diff --git a/httpchannel-channelcopy/pom.xml b/httpchannel-channelcopy/pom.xml index 3ca84d7..b8eddfc 100644 --- a/httpchannel-channelcopy/pom.xml +++ b/httpchannel-channelcopy/pom.xml @@ -4,7 +4,7 @@ httpchannel com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-channelcopy @@ -14,18 +14,19 @@ com.rogiel.httpchannel httpchannel-api - 1.0.0 + 1.0.0-SNAPSHOT com.rogiel.httpchannel.services httpchannel-service-megaupload - 1.0.0 + 1.0.0-SNAPSHOT test com.rogiel.httpchannel.services httpchannel-service-multiupload - 1.0.0 + 1.0.0-SNAPSHOT + test \ No newline at end of file diff --git a/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java b/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java index bc8ca13..319ed83 100644 --- a/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java +++ b/httpchannel-channelcopy/src/main/java/com/rogiel/httpchannel/copy/ChannelCopy.java @@ -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 Rogiel */ -public class ChannelCopy implements Callable> { +public class ChannelCopy implements Callable> { /** * The input channel */ @@ -101,12 +101,12 @@ public class ChannelCopy implements Callable> { } /** - * 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> { * @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> { } @Override - public List call() throws IOException { + public List 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> { } } - final List urls = new ArrayList<>(); + final List uris = new ArrayList<>(); for (final UploadChannel channel : uploadChannels) { - urls.add(channel.getDownloadLink()); + uris.add(channel.getDownloadLink()); } - return urls; + return uris; } } diff --git a/httpchannel-service/httpchannel-service-depositfiles/pom.xml b/httpchannel-service/httpchannel-service-depositfiles/pom.xml index 43525c6..15d8a05 100644 --- a/httpchannel-service/httpchannel-service-depositfiles/pom.xml +++ b/httpchannel-service/httpchannel-service-depositfiles/pom.xml @@ -3,7 +3,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-depositfiles diff --git a/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java b/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java index 1ea57e3..5ffc3b6 100644 --- a/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java +++ b/httpchannel-service/httpchannel-service-depositfiles/src/main/java/com/rogiel/httpchannel/service/impl/DepositFilesService.java @@ -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; diff --git a/httpchannel-service/httpchannel-service-depositfiles/src/test/java/com/rogiel/httpchannel/service/impl/DepositFilesServiceTest.java b/httpchannel-service/httpchannel-service-depositfiles/src/test/java/com/rogiel/httpchannel/service/impl/DepositFilesServiceTest.java index 9eb7353..e8901a0 100644 --- a/httpchannel-service/httpchannel-service-depositfiles/src/test/java/com/rogiel/httpchannel/service/impl/DepositFilesServiceTest.java +++ b/httpchannel-service/httpchannel-service-depositfiles/src/test/java/com/rogiel/httpchannel/service/impl/DepositFilesServiceTest.java @@ -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); } } diff --git a/httpchannel-service/httpchannel-service-filesonic/pom.xml b/httpchannel-service/httpchannel-service-filesonic/pom.xml index 2846625..b7c2711 100644 --- a/httpchannel-service/httpchannel-service-filesonic/pom.xml +++ b/httpchannel-service/httpchannel-service-filesonic/pom.xml @@ -3,7 +3,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-filesonic diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/FileSonicAPI.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/FileSonicAPI.java index 4776d18..f59961e 100644 --- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/FileSonicAPI.java +++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/FileSonicAPI.java @@ -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 Rogiel */ 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 execute(Class type, String requestURL) + private T execute(Class 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); } } diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/xml/FSGetUploadURL.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/xml/FSGetUploadURL.java index e9a29ea..032db9c 100644 --- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/xml/FSGetUploadURL.java +++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/filesonic/xml/FSGetUploadURL.java @@ -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() { diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java index e15693f..d744bc2 100644 --- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java +++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/impl/FileSonicService.java @@ -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; diff --git a/httpchannel-service/httpchannel-service-hotfile/pom.xml b/httpchannel-service/httpchannel-service-hotfile/pom.xml index f799833..ce8183a 100644 --- a/httpchannel-service/httpchannel-service-hotfile/pom.xml +++ b/httpchannel-service/httpchannel-service-hotfile/pom.xml @@ -3,7 +3,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-hotfile diff --git a/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java b/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java index 4f285aa..1053ebc 100644 --- a/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java +++ b/httpchannel-service/httpchannel-service-hotfile/src/main/java/com/rogiel/httpchannel/service/impl/HotFileService.java @@ -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 getDownloader(URL url, + public Downloader getDownloader(URI uri, NullDownloaderConfiguration configuration) { - return new DownloaderImpl(url, configuration); + return new DownloaderImpl(uri, configuration); } @Override - public Downloader getDownloader(URL url) { - return getDownloader(url, newDownloaderConfiguration()); + public Downloader 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 { - 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, diff --git a/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java b/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java index 2ff56ad..8405da6 100644 --- a/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java +++ b/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/HotFileServiceTest.java @@ -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(); diff --git a/httpchannel-service/httpchannel-service-megaupload/pom.xml b/httpchannel-service/httpchannel-service-megaupload/pom.xml index cd94c3c..5f67a19 100644 --- a/httpchannel-service/httpchannel-service-megaupload/pom.xml +++ b/httpchannel-service/httpchannel-service-megaupload/pom.xml @@ -3,7 +3,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-megaupload diff --git a/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java b/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java index 3097d2d..e9457aa 100644 --- a/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java +++ b/httpchannel-service/httpchannel-service-megaupload/src/main/java/com/rogiel/httpchannel/service/impl/MegaUploadService.java @@ -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 getDownloader(URL url, + public Downloader getDownloader(URI uri, MegaUploadDownloaderConfiguration configuration) { - return new DownloaderImpl(url, configuration); + return new DownloaderImpl(uri, configuration); } @Override - public Downloader getDownloader(URL url) { - return getDownloader(url, newDownloaderConfiguration()); + public Downloader 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 implements Downloader { - 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); diff --git a/httpchannel-service/httpchannel-service-megaupload/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java b/httpchannel-service/httpchannel-service-megaupload/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java index 57ab707..c8f1d51 100644 --- a/httpchannel-service/httpchannel-service-megaupload/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java +++ b/httpchannel-service/httpchannel-service-megaupload/src/test/java/com/rogiel/httpchannel/service/impl/MegaUploadServiceTest.java @@ -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) { diff --git a/httpchannel-service/httpchannel-service-multiupload/pom.xml b/httpchannel-service/httpchannel-service-multiupload/pom.xml index 6dad15d..1fc53b9 100644 --- a/httpchannel-service/httpchannel-service-multiupload/pom.xml +++ b/httpchannel-service/httpchannel-service-multiupload/pom.xml @@ -4,7 +4,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-multiupload diff --git a/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java b/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java index c07bfd3..162ab96 100644 --- a/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java +++ b/httpchannel-service/httpchannel-service-multiupload/src/main/java/com/rogiel/httpchannel/service/impl/MultiUploadService.java @@ -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 getDownloader(URL url, + public Downloader getDownloader(URI uri, NullDownloaderConfiguration configuration) { - return new DownloaderImpl(url, configuration); + return new DownloaderImpl(uri, configuration); } @Override - public Downloader getDownloader(URL url) { - return getDownloader(url, newDownloaderConfiguration()); + public Downloader 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 implements Downloader { - 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) diff --git a/httpchannel-service/httpchannel-service-multiupload/src/test/java/com/rogiel/httpchannel/service/impl/MultiUploadServiceTest.java b/httpchannel-service/httpchannel-service-multiupload/src/test/java/com/rogiel/httpchannel/service/impl/MultiUploadServiceTest.java index b62a33c..946d241 100644 --- a/httpchannel-service/httpchannel-service-multiupload/src/test/java/com/rogiel/httpchannel/service/impl/MultiUploadServiceTest.java +++ b/httpchannel-service/httpchannel-service-multiupload/src/test/java/com/rogiel/httpchannel/service/impl/MultiUploadServiceTest.java @@ -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); diff --git a/httpchannel-service/httpchannel-service-uploadhere/pom.xml b/httpchannel-service/httpchannel-service-uploadhere/pom.xml index 613c705..2de9e24 100644 --- a/httpchannel-service/httpchannel-service-uploadhere/pom.xml +++ b/httpchannel-service/httpchannel-service-uploadhere/pom.xml @@ -3,7 +3,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-uploadhere diff --git a/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java b/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java index e60574e..6954c85 100644 --- a/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java +++ b/httpchannel-service/httpchannel-service-uploadhere/src/main/java/com/rogiel/httpchannel/service/impl/UploadHereService.java @@ -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 getDownloader(URL url, + public Downloader getDownloader(URI uri, NullDownloaderConfiguration configuration) { - return new DownloaderImpl(url, configuration); + return new DownloaderImpl(uri, configuration); } @Override - public Downloader getDownloader(URL url) { - return getDownloader(url, newDownloaderConfiguration()); + public Downloader 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 implements Downloader { - 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(); diff --git a/httpchannel-service/httpchannel-service-uploadhere/src/test/java/com/rogiel/httpchannel/service/impl/UploadHereServiceTest.java b/httpchannel-service/httpchannel-service-uploadhere/src/test/java/com/rogiel/httpchannel/service/impl/UploadHereServiceTest.java index a523beb..2517b60 100644 --- a/httpchannel-service/httpchannel-service-uploadhere/src/test/java/com/rogiel/httpchannel/service/impl/UploadHereServiceTest.java +++ b/httpchannel-service/httpchannel-service-uploadhere/src/test/java/com/rogiel/httpchannel/service/impl/UploadHereServiceTest.java @@ -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))); // } } diff --git a/httpchannel-service/httpchannel-service-uploadking/pom.xml b/httpchannel-service/httpchannel-service-uploadking/pom.xml index 9fd42d4..5b56204 100644 --- a/httpchannel-service/httpchannel-service-uploadking/pom.xml +++ b/httpchannel-service/httpchannel-service-uploadking/pom.xml @@ -4,7 +4,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-uploadking @@ -15,7 +15,7 @@ com.rogiel.httpchannel.captcha httpchannel-captcha-captchatrader - 1.0.0 + 1.0.0-SNAPSHOT test diff --git a/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java b/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java index 20f9847..074d8b7 100644 --- a/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java +++ b/httpchannel-service/httpchannel-service-uploadking/src/main/java/com/rogiel/httpchannel/service/impl/UploadKingService.java @@ -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 getDownloader(URL url, + public Downloader getDownloader(URI uri, NullDownloaderConfiguration configuration) { - return new DownloaderImpl(url, configuration); + return new DownloaderImpl(uri, configuration); } @Override - public Downloader getDownloader(URL url) { - return getDownloader(url, newDownloaderConfiguration()); + public Downloader 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 implements Downloader { - 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(); diff --git a/httpchannel-service/httpchannel-service-uploadking/src/test/java/com/rogiel/httpchannel/service/impl/UploadKingServiceTest.java b/httpchannel-service/httpchannel-service-uploadking/src/test/java/com/rogiel/httpchannel/service/impl/UploadKingServiceTest.java index 0b855a6..d263578 100644 --- a/httpchannel-service/httpchannel-service-uploadking/src/test/java/com/rogiel/httpchannel/service/impl/UploadKingServiceTest.java +++ b/httpchannel-service/httpchannel-service-uploadking/src/test/java/com/rogiel/httpchannel/service/impl/UploadKingServiceTest.java @@ -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))); } } diff --git a/httpchannel-service/httpchannel-service-zshare/pom.xml b/httpchannel-service/httpchannel-service-zshare/pom.xml index 683ccc4..310eec4 100644 --- a/httpchannel-service/httpchannel-service-zshare/pom.xml +++ b/httpchannel-service/httpchannel-service-zshare/pom.xml @@ -3,7 +3,7 @@ httpchannel-service com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service-zshare diff --git a/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java b/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java index e2fc424..f589d9f 100644 --- a/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java +++ b/httpchannel-service/httpchannel-service-zshare/src/main/java/com/rogiel/httpchannel/service/impl/ZShareService.java @@ -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 getDownloader(URL url, + // public Downloader getDownloader(URI uri, // NullDownloaderConfiguration configuration) { - // return new DownloaderImpl(url, configuration); + // return new DownloaderImpl(uri, configuration); // } // // @Override - // public Downloader getDownloader(URL url) { - // return getDownloader(url, newDownloaderConfiguration()); + // public Downloader 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 implements // Downloader { - // 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("\\/"), diff --git a/httpchannel-service/pom.xml b/httpchannel-service/pom.xml index 6aee4ee..c389440 100644 --- a/httpchannel-service/pom.xml +++ b/httpchannel-service/pom.xml @@ -4,7 +4,7 @@ httpchannel com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-service @@ -26,12 +26,12 @@ com.rogiel.httpchannel httpchannel-api - ${project.version} + 1.0.0-SNAPSHOT com.rogiel.httpchannel httpchannel-util - 1.0.0 + 1.0.0-SNAPSHOT \ No newline at end of file diff --git a/httpchannel-util/pom.xml b/httpchannel-util/pom.xml index 42d8164..78259c9 100644 --- a/httpchannel-util/pom.xml +++ b/httpchannel-util/pom.xml @@ -4,7 +4,7 @@ httpchannel com.rogiel.httpchannel - 1.0.0 + 1.0.0-SNAPSHOT .. httpchannel-util @@ -12,7 +12,7 @@ com.rogiel.httpchannel httpchannel-api - 1.0.0 + 1.0.0-SNAPSHOT org.apache.httpcomponents diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/captcha/ReCaptchaExtractor.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/captcha/ReCaptchaExtractor.java index 89b623e..8fdb99a 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/captcha/ReCaptchaExtractor.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/captcha/ReCaptchaExtractor.java @@ -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 Rogiel + * This class provides utility methods to extract an {@link ImageCaptcha} from + * an page containing an Google ReCaptcha CAPTCHA embedded into it. * + * @author Rogiel */ 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 page + */ 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 page + */ 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)); } } diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/GetRequest.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/GetRequest.java index b8123c8..ae3904e 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/GetRequest.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/GetRequest.java @@ -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); diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/HttpContext.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/HttpContext.java index 3b6a799..5594208 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/HttpContext.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/HttpContext.java @@ -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); } } diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostMultipartRequest.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostMultipartRequest.java index 970e60b..4fcbd43 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostMultipartRequest.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostMultipartRequest.java @@ -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); } diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostRequest.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostRequest.java index 4039473..05e2819 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostRequest.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/PostRequest.java @@ -17,13 +17,13 @@ import org.apache.http.message.BasicNameValuePair; public class PostRequest extends Request { protected final List params = new ArrayList(); - 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); } diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java index 948a452..a842657 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java @@ -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; } } \ No newline at end of file diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java index af31858..14ba846 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractDownloader.java @@ -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 implements Downloader { /** - * 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 /** * 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; } diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java index 0c9a3eb..6e78a9f 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpDownloader.java @@ -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 extends AbstractDownloader implements Downloader { 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 .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); diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpService.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpService.java index a568cfd..cf9bd59 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpService.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/AbstractHttpService.java @@ -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); } } diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java index 099d97b..f8b3fa5 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java @@ -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 Rogiel + * This channel is linked onto another {@link Channel} that actually writes data + * into the network stream. * + * @author Rogiel */ 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 true if the channel is linked with the destination + * {@link Channel} + */ public boolean isLinked() { return channel != null; } diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/ChannelUtils.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/ChannelUtils.java index f7cef4e..4cc1b2a 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/ChannelUtils.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/ChannelUtils.java @@ -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(); diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/HttpClientUtils.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/HttpClientUtils.java index 49aa909..8b48756 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/HttpClientUtils.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/HttpClientUtils.java @@ -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) diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/htmlparser/HTMLPage.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/htmlparser/HTMLPage.java index e4361ba..2fe5bf1 100644 --- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/htmlparser/HTMLPage.java +++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/util/htmlparser/HTMLPage.java @@ -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. null otherwise + * @return the iframe uri, if found. null 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. null otherwise + * @return the iframe uri, if found. null 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. null otherwise + * @return the URI found, if any. null otherwise */ public String findFormAction(final Pattern pattern) { for (final FormTag tag : filter(FormTag.class, diff --git a/pom.xml b/pom.xml index 356f7b2..b26a655 100644 --- a/pom.xml +++ b/pom.xml @@ -4,18 +4,70 @@ com.rogiel.httpchannel httpchannel - 1.0.0 + 1.0.0-SNAPSHOT pom HttpChannel Library capable of downloading and uploading files from free servers using channels. + http://httpchannel.rogiel.com/ + + + scm:git:${basedir} + scm:git:${basedir} + + + http://httpchannel.rogiel.com/maven2/com/rogiel/httpchannel + + false + httpchannel-repository + HttpChannel Maven Repository + scp://rogiels@rogiel.com/home/rogiels/httpchannel.rogiel.com/maven2 + default + + + httpchannel-site + httpchannel-site + scp://rogiels@rogiel.com/home/rogiels/httpchannel.rogiel.com + + + + GitHub + https://github.com/seedbox/httpchannel/issues + + + + GitHub + https://github.com/seedbox/httpchannel + + + + + Rogiel + Rogiel + rogiel@rogiel.com + http://www.rogiel.com/ + -3 + + Creator + API Designer + + + + + + + GNU General Public License version 3 + http://www.gnu.org/licenses/gpl.txt + repo + + httpchannel-api httpchannel-service - httpchannel-util - httpchannel-channelcopy httpchannel-captcha + httpchannel-channelcopy + httpchannel-util @@ -38,20 +90,70 @@ org.apache.maven.plugins - maven-assembly-plugin + maven-site-plugin + 3.0 - - src/main/assembly/distribution-bin.xml - + UTF-8 + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.8 + + UTF-8 + + + + org.apache.maven.plugins + maven-project-info-reports-plugin + 2.4 + + scm:git@github.com:seedbox/httpchannel.git + scm:git://github.com/seedbox/httpchannel.git + https://github.com/seedbox/httpchannel + + + + org.apache.maven.plugins + maven-changelog-plugin + 2.2 + + UTF-8 + + + + org.apache.maven.plugins + maven-jxr-plugin + 2.3 + + UTF-8 + UTF-8 + + + - - - package - - assembly - - - + + + org.apache.maven.wagon + wagon-ssh + 2.1 + + + + + org.apache.maven.plugins + maven-deploy-plugin + 2.7 + + false + + + + org.apache.maven.wagon + wagon-ssh + 2.1 + + @@ -74,9 +176,7 @@ org.slf4j slf4j-jdk14 1.6.4 - runtime - true + test - http://httpchannel.rogiel.com/ \ No newline at end of file diff --git a/src/main/assembly/distribution-bin.xml b/src/main/assembly/distribution-bin.xml deleted file mode 100644 index 86a8414..0000000 --- a/src/main/assembly/distribution-bin.xml +++ /dev/null @@ -1,29 +0,0 @@ - - bin - - zip - - - - - true - - true - true - - - com/rogiel/httpchannel/** - - - false - - httpchannel-api - httpchannel-service - - - - - \ No newline at end of file