1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-05 23:22:51 +00:00

Add support for new services on multiupload, removes the maven archetype

This commit is contained in:
2012-04-29 14:07:42 -03:00
parent 1c8cc0e893
commit 55cb79d599
13 changed files with 21 additions and 260 deletions

View File

@@ -1,35 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-archetype</artifactId>
<packaging>maven-archetype</packaging>
<name>HttpChannel/Service/Archetype</name>
<description>Provides an maven archetype for service creation</description>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.archetype</groupId>
<artifactId>archetype-packaging</artifactId>
<version>2.2</version>
</extension>
</extensions>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
name="httpchannel-service-archetype"
xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<requiredProperties>
<requiredProperty key="serviceName" />
<requiredProperty key="serviceID" />
</requiredProperties>
<fileSets>
<fileSet filtered="true" packaged="true" encoding="UTF-8">
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>src/main/resources</directory>
<includes>
<include>**/*.Service</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>

View File

@@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>${artifactId}</artifactId>
<groupId>${groupId}</groupId>
<name>HttpChannel/Service/${serviceName}</name>
<description>Provides download and upload access for ${serviceName}</description>
<version>${version}</version>
</project>

View File

@@ -1,154 +0,0 @@
#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package ${package};
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
import com.rogiel.httpchannel.service.UploaderCapability;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* This service handles uploads to ${serviceName}.
*
* @author <a href="http://www.rogiel.com/">Rogiel</a>
* @since 1.0
*/
public class ${serviceName}Service extends AbstractHttpService implements
Service, UploadService<NullUploaderConfiguration> {
/**
* This service ID
*/
public static final ServiceID SERVICE_ID = ServiceID.create("${serviceID}");
@Override
public ServiceID getServiceID() {
return SERVICE_ID;
}
@Override
public int getMajorVersion() {
return 1;
}
@Override
public int getMinorVersion() {
return 0;
}
@Override
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED);
}
@Override
public Uploader<NullUploaderConfiguration> getUploader(String filename,
long filesize, NullUploaderConfiguration configuration) {
return new UploaderImpl(filename, filesize, configuration);
}
@Override
public Uploader<NullUploaderConfiguration> getUploader(String filename,
long filesize) {
return getUploader(filename, filesize, newUploaderConfiguration());
}
@Override
public NullUploaderConfiguration newUploaderConfiguration() {
// no configuration
return NullUploaderConfiguration.SHARED_INSTANCE;
}
@Override
public long getMaximumFilesize() {
// no filesize limit
return -1;
}
@Override
public String[] getSupportedExtensions() {
// no extension restriction
return null;
}
@Override
public CapabilityMatrix<UploaderCapability> getUploadCapabilities() {
return new CapabilityMatrix<UploaderCapability>(
UploaderCapability.UNAUTHENTICATED_UPLOAD);
}
protected class UploaderImpl extends
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<HTMLPage> uploadFuture;
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
super(MyServiceService.this, filename, filesize, configuration);
}
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to ${serviceName}");
final HTMLPage page = get("http://www.example.com/").asPage();
// locate upload uri
String uri = null;
logger.debug("Upload URI: {}", uri);
// create a new channel
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(uri).parameter("[file-parameter]", channel).asPageAsync();
// wait for channel link
return waitChannelLink(channel);
}
@Override
public String finish() throws IOException {
try {
final HTMLPage page = uploadFuture.get();
// find link
return null;
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
throw (IOException) e.getCause();
}
}
}
}

View File

@@ -1,7 +0,0 @@
#Wed Jan 18 19:02:46 BRST 2012
package=it.pkg
version=0.1-SNAPSHOT
groupId=archetype.it
artifactId=basic
serviceName = TestService
serviceID = testservice

View File

@@ -76,9 +76,9 @@ public class HotFileServiceTest {
final Properties properties = new Properties();
properties.load(new FileInputStream(
"src/test/resources/login.properties"));
VALID_USERNAME = properties.getProperty("username");
VALID_PASSWORD = properties.getProperty("password");
"../src/test/resources/login.properties"));
VALID_USERNAME = properties.getProperty("hotfile.username");
VALID_PASSWORD = properties.getProperty("hotfile.password");
}
@Test

View File

@@ -9,5 +9,5 @@
<artifactId>httpchannel-service-multiupload</artifactId>
<groupId>com.rogiel.httpchannel.services</groupId>
<name>HttpChannel/Service/MultiUpload</name>
<description>Provides upload access to multiupload.com</description>
<description>Provides upload access to multiupload.nl</description>
</project>

View File

@@ -64,9 +64,9 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* This service handles uploads to MultiUpload.com.
* This service handles uploads to MultiUpload.nl.
*
* @author <a href="http://www.rogiel.com/">Rogiel</a>
* @author <a href="http://www.rogiel.nl/">Rogiel</a>
* @since 1.0
*/
public class MultiUploadService extends AbstractHttpService implements Service,
@@ -78,15 +78,15 @@ public class MultiUploadService extends AbstractHttpService implements Service,
*/
public static final ServiceID SERVICE_ID = ServiceID.create("multiupload");
// http://www52.multiupload.com/upload/?UPLOAD_IDENTIFIER=73132658610746
// http://www52.multiupload.nl/upload/?UPLOAD_IDENTIFIER=73132658610746
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://www([0-9]*)\\.multiupload\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
.compile("http://www([0-9]*)\\.multiupload\\.nl/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
private static final Pattern DOWNLOAD_LINK_PATTERN = Pattern
.compile("http://(www\\.)?multiupload\\.com/([0-9a-zA-Z]*)");
.compile("http://(www\\.)?multiupload\\.nl/([0-9a-zA-Z]*)");
private static final Pattern DIRECT_DOWNLOAD_LINK_PATTERN = Pattern
.compile("http://www[0-9]*\\.multiupload\\.com(:[0-9]*)?/files/([0-9a-zA-Z]*)/(.*)");
.compile("http://www[0-9]*\\.multiupload\\.nl(:[0-9]*)?/files/([0-9a-zA-Z]*)/(.*)");
@Override
public ServiceID getServiceID() {
@@ -217,8 +217,8 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to multiupload.com");
final String uri = get("http://www.multiupload.com/").asPage()
logger.debug("Starting upload to multiupload.nl");
final String uri = get("http://www.multiupload.nl/").asPage()
.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this);
@@ -247,10 +247,10 @@ public class MultiUploadService extends AbstractHttpService implements Service,
try {
final String linkId = PatternUtils.find(DOWNLOAD_ID_PATTERN,
uploadFuture.get(), 1);
logger.debug("Upload to multiupload.com finished");
logger.debug("Upload to multiupload.nl finished");
if (linkId == null)
return null;
return new StringBuilder("http://www.multiupload.com/").append(
return new StringBuilder("http://www.multiupload.nl/").append(
linkId).toString();
} catch (InterruptedException e) {
return null;
@@ -292,7 +292,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.multiupload.com/login")
final HTMLPage page = post("http://www.multiupload.nl/login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
@@ -303,7 +303,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public void logout() throws IOException {
post("http://www.multiupload.com/login").parameter("do", "logout")
post("http://www.multiupload.nl/login").parameter("do", "logout")
.request();
// TODO check logout status
}

View File

@@ -54,8 +54,9 @@ public class MultiUploadUploaderConfiguration extends
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public enum MultiUploadMirrorService {
MEGAUPLOAD(1), UPLOADKING(16), DEPOSIT_FILES(7), HOTFILE(9), UPLOAD_HERE(
17), ZSHARE(6), FILE_SONIC(15), FILE_SERVE(18), WUPLOAD(19);
MEGAUPLOAD(1), UPLOADKING(16), DEPOSIT_FILES(7), HOTFILE(9), TWO_SHARED(
11), UPLOAD_HERE(17), ZSHARE(6), FILE_SONIC(15), FILE_SERVE(18), PUT_LOCKER(
19), ORON(20), FILE_FACTORY(21), FREAK_SHARED(23);
/**
* The internal multiupload id

View File

@@ -61,7 +61,7 @@ public class MultiUploadServiceTest {
public void testDownloader() throws IOException, NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
URI.create("http://www.multiupload.nl/ITPPI2YSYX"))
.openChannel());
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_FULL_CHECKSUM);
@@ -72,7 +72,7 @@ public class MultiUploadServiceTest {
NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
URI.create("http://www.multiupload.nl/ITPPI2YSYX"))
.openChannel(50));
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_RESUME_CHECKSUM);

View File

@@ -14,8 +14,6 @@
<description>Parent module that all service implementations should inherit</description>
<modules>
<module>httpchannel-service-archetype</module>
<module>httpchannel-service-megaupload</module>
<module>httpchannel-service-multiupload</module>
<module>httpchannel-service-uploadking</module>
<module>httpchannel-service-uploadhere</module>