1
0
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:
2011-11-21 00:57:03 -02:00
parent 1c8db5cf36
commit f210afd16a
23 changed files with 717 additions and 106 deletions

View File

@@ -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()) {

View File

@@ -0,0 +1 @@
com.rogiel.httpchannel.service.impl.HotFileService

View File

@@ -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));
}
}

View File

@@ -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);

View File

@@ -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());
}
}