mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Improve documentation and implement a new ServiceID class
This commit is contained in:
22
assembly/distribution-bin.xml
Normal file
22
assembly/distribution-bin.xml
Normal file
@@ -0,0 +1,22 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>bin</id>
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
<baseDirectory></baseDirectory>
|
||||
<moduleSets>
|
||||
<moduleSet>
|
||||
<includeSubModules>false</includeSubModules>
|
||||
<binaries>
|
||||
<includeDependencies>false</includeDependencies>
|
||||
<includes>
|
||||
<include>httpchannel-service</include>
|
||||
<include>httpchannel-api</include>
|
||||
</includes>
|
||||
</binaries>
|
||||
</moduleSet>
|
||||
</moduleSets>
|
||||
</assembly>
|
||||
@@ -26,11 +26,12 @@ import com.rogiel.httpchannel.service.config.ServiceConfiguration;
|
||||
* @param <T>
|
||||
* The {@link ServiceConfiguration} <b>interface</b> type used by the
|
||||
* {@link Service}. Note that this <b>must</b> be an interface!s
|
||||
* @see ServiceConfiguration ServiceConfiguration for details on the configuration interface.
|
||||
* @see ServiceConfiguration ServiceConfiguration for details on the
|
||||
* configuration interface.
|
||||
*/
|
||||
public abstract class AbstractService<T extends ServiceConfiguration>
|
||||
implements Service {
|
||||
protected final T configuration;
|
||||
protected T configuration;
|
||||
|
||||
protected AbstractService(T configuration) {
|
||||
this.configuration = configuration;
|
||||
@@ -40,4 +41,19 @@ public abstract class AbstractService<T extends ServiceConfiguration>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
* <p>
|
||||
* 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 <tt>position</tt> equal to
|
||||
* zero.
|
||||
* <p>
|
||||
* 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 <tt>position</tt>. Will
|
||||
* only be thrown if <tt>position > 0</tt>.
|
||||
*/
|
||||
DownloadChannel download(DownloadListener listener, long position)
|
||||
throws IOException, DownloadLinkNotFoundException,
|
||||
DownloadLimitExceededException;
|
||||
DownloadLimitExceededException, DownloadNotAuthorizedException,
|
||||
DownloadNotResumableException;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* An ID used to represent the given service
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
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:
|
||||
*
|
||||
* <pre>
|
||||
* <code> ServiceID id = ...;
|
||||
* Services.getService(id);</code>
|
||||
* </pre>
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Iterator;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class Services {
|
||||
private static ServiceLoader<Service> 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 <tt>id</tt>
|
||||
*
|
||||
* @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<Service> iterate() {
|
||||
return new Iterable<Service>() {
|
||||
@Override
|
||||
public Iterator<Service> iterator() {
|
||||
return services.iterator();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Iterable} instance to iterate over service ids
|
||||
*
|
||||
* @return the {@link Iterable} instance
|
||||
*/
|
||||
public static Iterable<ServiceID> iterateIDs() {
|
||||
return new Iterable<ServiceID>() {
|
||||
@Override
|
||||
public Iterator<ServiceID> iterator() {
|
||||
return new Iterator<ServiceID>() {
|
||||
private final Iterator<Service> iterator = iterate()
|
||||
.iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return iterator.hasNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceID next() {
|
||||
return iterator.next().getID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
iterator.remove();
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
* <p>
|
||||
* Whether an channel is returned or any exception is thrown it is <b><span
|
||||
* style="color:red">NOT</span></b> possible to reuse the same instance for
|
||||
* more than one upload!
|
||||
* <p>
|
||||
* 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
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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 <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.exception;
|
||||
|
||||
/**
|
||||
* Exception thrown if the download cannot be resumed at the given point.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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<HotFileServiceConfiguration> 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()) {
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
com.rogiel.httpchannel.service.impl.HotFileService
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.rogiel.httpchannel.service.Services;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class DiscoveryTest {
|
||||
@Test
|
||||
public void testDiscovery() {
|
||||
Assert.assertNotNull(Services.getService(HotFileService.SERVICE_ID));
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
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());
|
||||
}
|
||||
}
|
||||
@@ -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<MegaUploadServiceConfiguration> 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
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
com.rogiel.httpchannel.service.impl.MegaUploadService
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.rogiel.httpchannel.service.Services;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class DiscoveryTest {
|
||||
@Test
|
||||
public void testDiscovery() {
|
||||
Assert.assertNotNull(Services.getService(MegaUploadService.SERVICE_ID));
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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")));
|
||||
|
||||
|
||||
@@ -1,17 +1,66 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>httpchannel</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-util</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>httpchannel</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-util</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.1.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.1.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.htmlparser</groupId>
|
||||
<artifactId>htmlparser</artifactId>
|
||||
<version>2.1</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
112
pom.xml
112
pom.xml
@@ -1,14 +1,31 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Seedbox - HTTP Channel library</name>
|
||||
<description>Library capable of downloading and uploading files from free servers using channels.</description>
|
||||
|
||||
<modules>
|
||||
<module>httpchannel-api</module>
|
||||
<module>httpchannel-service</module>
|
||||
<module>httpchannel-util</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
<defaultGoal>package</defaultGoal>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
@@ -17,6 +34,47 @@
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-install-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>install</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>assembly/distribution-bin.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>assembly</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
@@ -28,59 +86,5 @@
|
||||
<type>jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.1.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.1.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.6.2</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.htmlparser</groupId>
|
||||
<artifactId>htmlparser</artifactId>
|
||||
<version>2.1</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<modules>
|
||||
<module>httpchannel-api</module>
|
||||
<module>httpchannel-service</module>
|
||||
<module>httpchannel-util</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
</project>
|
||||
Reference in New Issue
Block a user