public T getServiceConfiguration() {
return configuration;
}
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void setServiceConfiguration(ServiceConfiguration configuration) {
+ this.configuration = (T) configuration;
+ }
+
+ @Override
+ public Service clone() {
+ try {
+ return (Service) super.clone();
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java
index 01e19f9..1358a94 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Downloader.java
@@ -20,6 +20,8 @@ import java.io.IOException;
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
+import com.rogiel.httpchannel.service.exception.DownloadNotAuthorizedException;
+import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
/**
* This interfaces provides downloading for an service.
@@ -29,12 +31,26 @@ import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
*/
public interface Downloader {
/**
- * Starts the download process.
+ * Opens a new {@link DownloadChannel} that will be immediately ready to
+ * read data from the download stream.
+ *
+ * Whether an channel is returned or any exception is thrown it is possible
+ * to reuse the same instance for more than one download, this, however, is
+ * very unlikely to be done. The most common usage usage scenario for this
+ * is when an {@link DownloadNotResumableException} is thrown and you wish
+ * to restart the download from start giving position equal to
+ * zero.
+ *
+ * Please remember to close the channel by calling
+ * {@link DownloadChannel#close()}, otherwise some of the resources (such as
+ * network connections and file handlers) might still be open for the whole
+ * runtime or until they time out, which could never occur.
*
* @param listener
* the listener to keep a track on the download progress
* @param position
* the download start position. If seek is supported by service.
+ * If zero, download will start from the beginning.
*
* @return the {@link DownloadChannel} instance
* @throws IOException
@@ -45,8 +61,15 @@ public interface Downloader {
* @throws DownloadLimitExceededException
* if the download limit has been exceed, most times thrown when
* downloading as a non-premium user
+ * @throws DownloadNotAuthorizedException
+ * if the user (or guest) account does not have necessary rights
+ * to download the file
+ * @throws DownloadNotResumableException
+ * if the download cannot be started at position. Will
+ * only be thrown if position > 0.
*/
DownloadChannel download(DownloadListener listener, long position)
throws IOException, DownloadLinkNotFoundException,
- DownloadLimitExceededException;
+ DownloadLimitExceededException, DownloadNotAuthorizedException,
+ DownloadNotResumableException;
}
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 01b0ff6..4be10d1 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
@@ -30,13 +30,13 @@ import com.rogiel.httpchannel.service.config.ServiceConfiguration;
* @author Rogiel
* @since 1.0
*/
-public interface Service {
+public interface Service extends Cloneable {
/**
- * Get the ServiceID.
+ * Get the {@link ServiceID}.
*
* @return the id of the service
*/
- String getID();
+ ServiceID getID();
/**
* Get Major version of this service
@@ -58,4 +58,17 @@ public interface Service {
* @return the {@link ServiceConfiguration} instance
*/
ServiceConfiguration getServiceConfiguration();
+
+ /**
+ * Sets this {@link ServiceConfiguration} instance
+ *
+ * @param configuration
+ * the {@link ServiceConfiguration} instance
+ */
+ void setServiceConfiguration(ServiceConfiguration configuration);
+
+ /**
+ * @return a cloned version of this service
+ */
+ Service clone();
}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/ServiceID.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/ServiceID.java
new file mode 100644
index 0000000..6a5ea29
--- /dev/null
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/ServiceID.java
@@ -0,0 +1,108 @@
+/*
+ * This file is part of seedbox .
+ *
+ * seedbox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * seedbox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with seedbox. If not, see .
+ */
+package com.rogiel.httpchannel.service;
+
+import java.io.Serializable;
+
+/**
+ * An ID used to represent the given service
+ *
+ * @author Rogiel
+ */
+public class ServiceID implements Serializable, Cloneable {
+ /**
+ * This class serialization version UID
+ */
+ private static final long serialVersionUID = -1078456596792552200L;
+
+ /**
+ * The raw ID
+ */
+ private final String id;
+
+ /**
+ * @param id
+ * the raw id
+ */
+ private ServiceID(final String id) {
+ this.id = id;
+ }
+
+ /**
+ * @return the raw id
+ */
+ public String getRawID() {
+ return id;
+ }
+
+ /**
+ * @param id
+ * the raw id
+ */
+ public static ServiceID create(String id) {
+ return new ServiceID(id);
+ }
+
+ /**
+ * Returns the service associated to this ID. This has the same effect as
+ * calling:
+ *
+ *
+ * ServiceID id = ...;
+ * Services.getService(id);
+ *
+ *
+ * @return the associated service, if any.
+ */
+ public Service getService() {
+ return Services.getService(this);
+ }
+
+ @Override
+ public ServiceID clone() {
+ try {
+ return (ServiceID) super.clone();
+ } catch (CloneNotSupportedException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ ServiceID other = (ServiceID) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Services.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Services.java
new file mode 100644
index 0000000..1037385
--- /dev/null
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Services.java
@@ -0,0 +1,116 @@
+/*
+ * This file is part of seedbox .
+ *
+ * seedbox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * seedbox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with seedbox. If not, see .
+ */
+package com.rogiel.httpchannel.service;
+
+import java.net.URL;
+import java.util.Iterator;
+import java.util.ServiceLoader;
+
+/**
+ * @author Rogiel
+ */
+public class Services {
+ private static ServiceLoader services = ServiceLoader
+ .load(Service.class);
+
+ /**
+ * Reloads the list of available services in the classpath
+ *
+ * @see java.util.ServiceLoader#reload()
+ */
+ public static void reload() {
+ services.reload();
+ }
+
+ /**
+ * Tries to detect which service should be used to download the given URL
+ *
+ * @param url
+ * the URL
+ * @return the matched service
+ */
+ public static DownloadService matchURL(URL url) {
+ for (final Service service : iterate()) {
+ if (!(service instanceof DownloadService))
+ continue;
+ if (((DownloadService) service).matchURL(url))
+ return (DownloadService) service;
+ }
+ return null;
+ }
+
+ /**
+ * Tries to detect which service has the given id
+ *
+ * @param id
+ * the service id
+ * @return the matched service
+ */
+ public static Service getService(ServiceID id) {
+ for (final Service service : iterate()) {
+ if (service.getID().equals(id))
+ return service;
+ }
+ return null;
+ }
+
+ /**
+ * Creates a new {@link Iterable} instance to iterate over services
+ *
+ * @return the {@link Iterable} instance
+ */
+ public static Iterable iterate() {
+ return new Iterable() {
+ @Override
+ public Iterator iterator() {
+ return services.iterator();
+ }
+ };
+ }
+
+ /**
+ * Creates a new {@link Iterable} instance to iterate over service ids
+ *
+ * @return the {@link Iterable} instance
+ */
+ public static Iterable iterateIDs() {
+ return new Iterable() {
+ @Override
+ public Iterator iterator() {
+ return new Iterator() {
+ private final Iterator iterator = iterate()
+ .iterator();
+
+ @Override
+ public boolean hasNext() {
+ return iterator.hasNext();
+ }
+
+ @Override
+ public ServiceID next() {
+ return iterator.next().getID();
+ }
+
+ @Override
+ public void remove() {
+ iterator.remove();
+ }
+ };
+ }
+ };
+ }
+}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Uploader.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Uploader.java
index 230edf1..cc2ad9c 100644
--- a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Uploader.java
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/Uploader.java
@@ -26,7 +26,20 @@ import java.io.IOException;
*/
public interface Uploader {
/**
- * Starts the upload process on this service.
+ * Opens a new {@link UploadChannel} that will be immediately ready to
+ * receive data to be sent to the upload stream.
+ *
+ * Whether an channel is returned or any exception is thrown it is NOT possible to reuse the same instance for
+ * more than one upload!
+ *
+ * Please remember to close the channel before calling
+ * {@link UploadChannel#getDownloadLink()} or aborting the upload. The
+ * {@link UploadChannel#close()} method will finish upload (may take some
+ * time) and release any of the resources (such as network connections and
+ * file handlers) that could continue open for the whole runtime or until
+ * they time out, which could never occur. Note that you should close the
+ * channel even when an exception is thrown.
*
* @return the {@link UploadChannel} instance
* @throws IOException
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/exception/DownloadNotAuthorizedException.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/exception/DownloadNotAuthorizedException.java
new file mode 100644
index 0000000..5bc0a0a
--- /dev/null
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/exception/DownloadNotAuthorizedException.java
@@ -0,0 +1,60 @@
+/*
+ * This file is part of seedbox .
+ *
+ * seedbox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * seedbox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with seedbox. If not, see .
+ */
+package com.rogiel.httpchannel.service.exception;
+
+/**
+ * Exception thrown if the file exists, but the user (or guest) does not have
+ * authorization to download it.
+ *
+ * @author Rogiel
+ */
+public class DownloadNotAuthorizedException extends DownloadServiceException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new empty instance of this exception
+ */
+ public DownloadNotAuthorizedException() {
+ super();
+ }
+
+ /**
+ * @param message
+ * the message
+ * @param cause
+ * the root cause
+ */
+ public DownloadNotAuthorizedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ * the message
+ */
+ public DownloadNotAuthorizedException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ * the root cause
+ */
+ public DownloadNotAuthorizedException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/exception/DownloadNotResumableException.java b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/exception/DownloadNotResumableException.java
new file mode 100644
index 0000000..50585c0
--- /dev/null
+++ b/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/exception/DownloadNotResumableException.java
@@ -0,0 +1,59 @@
+/*
+ * This file is part of seedbox .
+ *
+ * seedbox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * seedbox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with seedbox. If not, see .
+ */
+package com.rogiel.httpchannel.service.exception;
+
+/**
+ * Exception thrown if the download cannot be resumed at the given point.
+ *
+ * @author Rogiel
+ */
+public class DownloadNotResumableException extends DownloadServiceException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new empty instance of this exception
+ */
+ public DownloadNotResumableException() {
+ super();
+ }
+
+ /**
+ * @param message
+ * the message
+ * @param cause
+ * the root cause
+ */
+ public DownloadNotResumableException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ * the message
+ */
+ public DownloadNotResumableException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ * the root cause
+ */
+ public DownloadNotResumableException(Throwable cause) {
+ super(cause);
+ }
+}
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 cb91f71..ddb3379 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
@@ -42,6 +42,7 @@ import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
+import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -51,6 +52,7 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
+import com.rogiel.httpchannel.service.config.ServiceConfigurationHelper;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.impl.HotFileService.HotFileServiceConfiguration;
import com.rogiel.httpchannel.util.ThreadUtils;
@@ -65,6 +67,11 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
public class HotFileService extends
AbstractHttpService implements Service,
UploadService, DownloadService, AuthenticationService {
+ /**
+ * This service ID
+ */
+ public static final ServiceID SERVICE_ID = ServiceID.create("hotfile");
+
private static final Pattern UPLOAD_URL_PATTERN = Pattern
.compile("http://u[0-9]*\\.hotfile\\.com/upload\\.cgi\\?[0-9]*");
@@ -78,13 +85,14 @@ public class HotFileService extends
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
.compile("http://hotfile\\.com/dl/([0-9]*)/([A-Za-z0-9]*)/(.*)");
- public HotFileService(final HotFileServiceConfiguration configuration) {
- super(configuration);
+ public HotFileService() {
+ super(ServiceConfigurationHelper
+ .defaultConfiguration(HotFileServiceConfiguration.class));
}
@Override
- public String getID() {
- return "hotfile";
+ public ServiceID getID() {
+ return SERVICE_ID;
}
@Override
@@ -169,7 +177,8 @@ public class HotFileService extends
filesize, filename);
final MultipartEntity entity = new MultipartEntity();
- entity.addPart("uploads[]", new LinkedUploadChannelContentBody(channel));
+ entity.addPart("uploads[]", new LinkedUploadChannelContentBody(
+ channel));
uploadFuture = postAsPageAsync(action, entity);
while (!channel.isLinked() && !uploadFuture.isDone()) {
diff --git a/httpchannel-service/httpchannel-service-hotfile/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service b/httpchannel-service/httpchannel-service-hotfile/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
new file mode 100644
index 0000000..a46dd2c
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-hotfile/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
@@ -0,0 +1 @@
+com.rogiel.httpchannel.service.impl.HotFileService
\ No newline at end of file
diff --git a/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/DiscoveryTest.java b/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/DiscoveryTest.java
new file mode 100644
index 0000000..5034e69
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/DiscoveryTest.java
@@ -0,0 +1,34 @@
+/*
+ * This file is part of seedbox .
+ *
+ * seedbox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * seedbox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with seedbox. If not, see .
+ */
+package com.rogiel.httpchannel.service.impl;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import com.rogiel.httpchannel.service.Services;
+
+/**
+ * @author Rogiel
+ *
+ */
+public class DiscoveryTest {
+ @Test
+ public void testDiscovery() {
+ Assert.assertNotNull(Services.getService(HotFileService.SERVICE_ID));
+ }
+}
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 c0f18d1..afefead 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
@@ -44,12 +44,12 @@ import com.rogiel.httpchannel.service.DownloadChannel;
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceHelper;
+import com.rogiel.httpchannel.service.ServiceID;
+import com.rogiel.httpchannel.service.Services;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.UploaderCapability;
-import com.rogiel.httpchannel.service.config.ServiceConfigurationHelper;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
-import com.rogiel.httpchannel.service.impl.HotFileService.HotFileServiceConfiguration;
import com.rogiel.httpchannel.util.ChannelUtils;
public class HotFileServiceTest {
@@ -75,9 +75,7 @@ public class HotFileServiceTest {
@Before
public void setUp() throws Exception {
// MegaUploadServiceConfiguration.class;
- service = new HotFileService(
- ServiceConfigurationHelper
- .defaultConfiguration(HotFileServiceConfiguration.class));
+ service = new HotFileService();
helper = new ServiceHelper(service);
final Properties properties = new Properties();
@@ -90,7 +88,7 @@ public class HotFileServiceTest {
@Test
public void testServiceId() {
System.out.println("Service: " + service.toString());
- assertEquals("hotfile", service.getID());
+ assertEquals(ServiceID.create("hotfile"), service.getID());
}
@Test
@@ -157,10 +155,12 @@ public class HotFileServiceTest {
@Test
public void testDownloader() throws IOException, MalformedURLException {
- final DownloadChannel channel = ((DownloadService) service)
- .getDownloader(
- new URL(
- "http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
+ final URL downloadUrl = new URL(
+ "http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.htm");
+
+ final DownloadService service = Services.matchURL(downloadUrl);
+
+ final DownloadChannel channel = service.getDownloader(downloadUrl)
.download(null, 0);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
IOUtils.copy(Channels.newInputStream(channel), bout);
diff --git a/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/ServiceCloningTest.java b/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/ServiceCloningTest.java
new file mode 100644
index 0000000..67f9468
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-hotfile/src/test/java/com/rogiel/httpchannel/service/impl/ServiceCloningTest.java
@@ -0,0 +1,41 @@
+/*
+ * This file is part of seedbox .
+ *
+ * seedbox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * seedbox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with seedbox. If not, see .
+ */
+package com.rogiel.httpchannel.service.impl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import com.rogiel.httpchannel.service.Service;
+
+/**
+ * @author Rogiel
+ *
+ */
+public class ServiceCloningTest {
+ @Test
+ public void testDiscovery() {
+ Service original = HotFileService.SERVICE_ID.getService();
+ Service service = HotFileService.SERVICE_ID.getService().clone();
+
+ // set configuration to anything else
+ service.setServiceConfiguration(null);
+
+ Assert.assertNotSame(service, original);
+ Assert.assertNotSame(service.getServiceConfiguration(),
+ original.getServiceConfiguration());
+ }
+}
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 b02266a..ada154d 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
@@ -46,6 +46,7 @@ import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.DownloaderCapability;
import com.rogiel.httpchannel.service.Service;
+import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
@@ -55,6 +56,7 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
+import com.rogiel.httpchannel.service.config.ServiceConfigurationHelper;
import com.rogiel.httpchannel.service.config.ServiceConfigurationProperty;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
@@ -75,6 +77,11 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
public class MegaUploadService extends
AbstractHttpService implements Service,
UploadService, DownloadService, AuthenticationService {
+ /**
+ * This service ID
+ */
+ public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
+
private static final Pattern UPLOAD_URL_PATTERN = Pattern
.compile("http://www([0-9]*)\\.megaupload\\.com/upload_done\\.php\\?UPLOAD_IDENTIFIER=[0-9]*");
@@ -91,13 +98,14 @@ public class MegaUploadService extends
private static final Pattern LOGIN_USERNAME_PATTERN = Pattern
.compile("flashvars\\.username = \"(.*)\";");
- public MegaUploadService(final MegaUploadServiceConfiguration configuration) {
- super(configuration);
+ public MegaUploadService() {
+ super(ServiceConfigurationHelper
+ .defaultConfiguration(MegaUploadServiceConfiguration.class));
}
@Override
- public String getID() {
- return "megaupload";
+ public ServiceID getID() {
+ return SERVICE_ID;
}
@Override
diff --git a/httpchannel-service/httpchannel-service-megaupload/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service b/httpchannel-service/httpchannel-service-megaupload/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
new file mode 100644
index 0000000..b8dea6b
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-megaupload/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
@@ -0,0 +1 @@
+com.rogiel.httpchannel.service.impl.MegaUploadService
\ No newline at end of file
diff --git a/httpchannel-service/httpchannel-service-megaupload/src/test/java/com/rogiel/httpchannel/service/impl/DiscoveryTest.java b/httpchannel-service/httpchannel-service-megaupload/src/test/java/com/rogiel/httpchannel/service/impl/DiscoveryTest.java
new file mode 100644
index 0000000..f2cd971
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-megaupload/src/test/java/com/rogiel/httpchannel/service/impl/DiscoveryTest.java
@@ -0,0 +1,34 @@
+/*
+ * This file is part of seedbox .
+ *
+ * seedbox is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * seedbox is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with seedbox. If not, see .
+ */
+package com.rogiel.httpchannel.service.impl;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+import com.rogiel.httpchannel.service.Services;
+
+/**
+ * @author Rogiel
+ *
+ */
+public class DiscoveryTest {
+ @Test
+ public void testDiscovery() {
+ Assert.assertNotNull(Services.getService(MegaUploadService.SERVICE_ID));
+ }
+}
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 773fef9..c3695d1 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
@@ -45,6 +45,7 @@ import com.rogiel.httpchannel.service.DownloadListener;
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceHelper;
+import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.UploaderCapability;
@@ -76,9 +77,7 @@ public class MegaUploadServiceTest {
@Before
public void setUp() throws Exception {
// MegaUploadServiceConfiguration.class;
- service = new MegaUploadService(
- ServiceConfigurationHelper
- .defaultConfiguration(MegaUploadServiceConfiguration.class));
+ service = new MegaUploadService();
helper = new ServiceHelper(service);
final Properties properties = new Properties();
@@ -91,7 +90,7 @@ public class MegaUploadServiceTest {
@Test
public void testServiceId() {
System.out.println("Service: " + service.toString());
- assertEquals("megaupload", service.getID());
+ assertEquals(ServiceID.create("megaupload"), service.getID());
}
@Test
@@ -116,14 +115,14 @@ public class MegaUploadServiceTest {
final UploadChannel channel = helper.upload(path,
"httpchannel test upload");
final SeekableByteChannel inChannel = Files.newByteChannel(path);
-
+
try {
ChannelUtils.copy(inChannel, channel);
} finally {
inChannel.close();
channel.close();
}
-
+
System.out.println(channel.getDownloadLink());
Assert.assertNotNull(channel.getDownloadLink());
}
@@ -142,14 +141,14 @@ public class MegaUploadServiceTest {
final UploadChannel channel = helper.upload(path,
"httpchannel test upload");
final SeekableByteChannel inChannel = Files.newByteChannel(path);
-
+
try {
ChannelUtils.copy(inChannel, channel);
} finally {
inChannel.close();
channel.close();
}
-
+
System.out.println(channel.getDownloadLink());
Assert.assertNotNull(channel.getDownloadLink());
}
@@ -195,7 +194,8 @@ public class MegaUploadServiceTest {
@Test
public void testNoWaitDownloader() throws IOException,
MalformedURLException {
- service = new MegaUploadService(ServiceConfigurationHelper.file(
+ service = new MegaUploadService();
+ service.setServiceConfiguration(ServiceConfigurationHelper.file(
MegaUploadServiceConfiguration.class, new File(
"src/test/resources/megaupload-nowait.properties")));
diff --git a/httpchannel-util/pom.xml b/httpchannel-util/pom.xml
index cddcbd2..b271131 100644
--- a/httpchannel-util/pom.xml
+++ b/httpchannel-util/pom.xml
@@ -1,17 +1,66 @@
-
- 4.0.0
-
- httpchannel
- com.rogiel.httpchannel
- 1.0.0
- ..
-
- httpchannel-util
-
-
- com.rogiel.httpchannel
- httpchannel-api
- 1.0.0
-
-
+
+ 4.0.0
+
+ httpchannel
+ com.rogiel.httpchannel
+ 1.0.0
+ ..
+
+ httpchannel-util
+
+
+ com.rogiel.httpchannel
+ httpchannel-api
+ 1.0.0
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.1.2
+ jar
+ compile
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ org.apache.httpcomponents
+ httpmime
+ 4.1.2
+ jar
+ compile
+
+
+ org.apache.commons
+ commons-io
+ 1.3.2
+ jar
+ compile
+
+
+ org.slf4j
+ jcl-over-slf4j
+ 1.6.2
+ jar
+ compile
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.6.2
+ jar
+ compile
+
+
+ org.htmlparser
+ htmlparser
+ 2.1
+ jar
+ compile
+
+
\ No newline at end of file
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java
similarity index 100%
rename from httpchannel-api/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java
rename to httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/InputStreamDownloadChannel.java
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java
similarity index 100%
rename from httpchannel-api/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java
rename to httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannel.java
diff --git a/httpchannel-api/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java
similarity index 100%
rename from httpchannel-api/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java
rename to httpchannel-util/src/main/java/com/rogiel/httpchannel/service/channel/LinkedUploadChannelContentBody.java
diff --git a/pom.xml b/pom.xml
index e89a125..52b7c4d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,14 +1,31 @@
4.0.0
+
com.rogiel.httpchannel
httpchannel
1.0.0
+ pom
+
Seedbox - HTTP Channel library
Library capable of downloading and uploading files from free servers using channels.
+
+ httpchannel-api
+ httpchannel-service
+ httpchannel-util
+
+
+ package
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+ true
+
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -17,6 +34,47 @@
1.7
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+ package
+
+ jar
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-install-plugin
+
+
+ package
+
+ install
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+
+
+ assembly/distribution-bin.xml
+
+
+
+
+ package
+
+ assembly
+
+
+
+
@@ -28,59 +86,5 @@
jar
test
-
- org.apache.httpcomponents
- httpclient
- 4.1.2
- jar
- compile
-
-
- commons-logging
- commons-logging
-
-
-
-
- org.apache.httpcomponents
- httpmime
- 4.1.2
- jar
- compile
-
-
- org.apache.commons
- commons-io
- 1.3.2
- jar
- compile
-
-
- org.slf4j
- jcl-over-slf4j
- 1.6.2
- jar
- compile
-
-
- org.slf4j
- slf4j-log4j12
- 1.6.2
- jar
- compile
-
-
- org.htmlparser
- htmlparser
- 2.1
- jar
- compile
-
-
- httpchannel-api
- httpchannel-service
- httpchannel-util
-
- pom
\ No newline at end of file