mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Add support for new services on multiupload, removes the maven archetype
This commit is contained in:
@@ -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>
|
|
||||||
@@ -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>
|
|
||||||
@@ -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>
|
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
${package}.${serviceName}Service
|
|
||||||
@@ -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
|
|
||||||
@@ -76,9 +76,9 @@ public class HotFileServiceTest {
|
|||||||
|
|
||||||
final Properties properties = new Properties();
|
final Properties properties = new Properties();
|
||||||
properties.load(new FileInputStream(
|
properties.load(new FileInputStream(
|
||||||
"src/test/resources/login.properties"));
|
"../src/test/resources/login.properties"));
|
||||||
VALID_USERNAME = properties.getProperty("username");
|
VALID_USERNAME = properties.getProperty("hotfile.username");
|
||||||
VALID_PASSWORD = properties.getProperty("password");
|
VALID_PASSWORD = properties.getProperty("hotfile.password");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
<artifactId>httpchannel-service-multiupload</artifactId>
|
<artifactId>httpchannel-service-multiupload</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel.services</groupId>
|
<groupId>com.rogiel.httpchannel.services</groupId>
|
||||||
<name>HttpChannel/Service/MultiUpload</name>
|
<name>HttpChannel/Service/MultiUpload</name>
|
||||||
<description>Provides upload access to multiupload.com</description>
|
<description>Provides upload access to multiupload.nl</description>
|
||||||
</project>
|
</project>
|
||||||
@@ -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
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class MultiUploadService extends AbstractHttpService implements Service,
|
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");
|
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
|
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
|
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
||||||
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
||||||
private static final Pattern DOWNLOAD_LINK_PATTERN = Pattern
|
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
|
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
|
@Override
|
||||||
public ServiceID getServiceID() {
|
public ServiceID getServiceID() {
|
||||||
@@ -217,8 +217,8 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UploadChannel openChannel() throws IOException {
|
public UploadChannel openChannel() throws IOException {
|
||||||
logger.debug("Starting upload to multiupload.com");
|
logger.debug("Starting upload to multiupload.nl");
|
||||||
final String uri = get("http://www.multiupload.com/").asPage()
|
final String uri = get("http://www.multiupload.nl/").asPage()
|
||||||
.findFormAction(UPLOAD_URI_PATTERN);
|
.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
logger.debug("Upload URI is {}", uri);
|
logger.debug("Upload URI is {}", uri);
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
@@ -247,10 +247,10 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
try {
|
try {
|
||||||
final String linkId = PatternUtils.find(DOWNLOAD_ID_PATTERN,
|
final String linkId = PatternUtils.find(DOWNLOAD_ID_PATTERN,
|
||||||
uploadFuture.get(), 1);
|
uploadFuture.get(), 1);
|
||||||
logger.debug("Upload to multiupload.com finished");
|
logger.debug("Upload to multiupload.nl finished");
|
||||||
if (linkId == null)
|
if (linkId == null)
|
||||||
return null;
|
return null;
|
||||||
return new StringBuilder("http://www.multiupload.com/").append(
|
return new StringBuilder("http://www.multiupload.nl/").append(
|
||||||
linkId).toString();
|
linkId).toString();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return null;
|
return null;
|
||||||
@@ -292,7 +292,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AccountDetails login() throws IOException {
|
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("username", credential.getUsername())
|
||||||
.parameter("password", credential.getPassword()).asPage();
|
.parameter("password", credential.getPassword()).asPage();
|
||||||
|
|
||||||
@@ -303,7 +303,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void logout() throws IOException {
|
public void logout() throws IOException {
|
||||||
post("http://www.multiupload.com/login").parameter("do", "logout")
|
post("http://www.multiupload.nl/login").parameter("do", "logout")
|
||||||
.request();
|
.request();
|
||||||
// TODO check logout status
|
// TODO check logout status
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ public class MultiUploadUploaderConfiguration extends
|
|||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public enum MultiUploadMirrorService {
|
public enum MultiUploadMirrorService {
|
||||||
MEGAUPLOAD(1), UPLOADKING(16), DEPOSIT_FILES(7), HOTFILE(9), UPLOAD_HERE(
|
MEGAUPLOAD(1), UPLOADKING(16), DEPOSIT_FILES(7), HOTFILE(9), TWO_SHARED(
|
||||||
17), ZSHARE(6), FILE_SONIC(15), FILE_SERVE(18), WUPLOAD(19);
|
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
|
* The internal multiupload id
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public class MultiUploadServiceTest {
|
|||||||
public void testDownloader() throws IOException, NoSuchAlgorithmException {
|
public void testDownloader() throws IOException, NoSuchAlgorithmException {
|
||||||
final byte[] data = ChannelUtils
|
final byte[] data = ChannelUtils
|
||||||
.toByteArray(((DownloadService<?>) service).getDownloader(
|
.toByteArray(((DownloadService<?>) service).getDownloader(
|
||||||
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
|
URI.create("http://www.multiupload.nl/ITPPI2YSYX"))
|
||||||
.openChannel());
|
.openChannel());
|
||||||
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
||||||
data, EXPECTED_FULL_CHECKSUM);
|
data, EXPECTED_FULL_CHECKSUM);
|
||||||
@@ -72,7 +72,7 @@ public class MultiUploadServiceTest {
|
|||||||
NoSuchAlgorithmException {
|
NoSuchAlgorithmException {
|
||||||
final byte[] data = ChannelUtils
|
final byte[] data = ChannelUtils
|
||||||
.toByteArray(((DownloadService<?>) service).getDownloader(
|
.toByteArray(((DownloadService<?>) service).getDownloader(
|
||||||
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
|
URI.create("http://www.multiupload.nl/ITPPI2YSYX"))
|
||||||
.openChannel(50));
|
.openChannel(50));
|
||||||
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
||||||
data, EXPECTED_RESUME_CHECKSUM);
|
data, EXPECTED_RESUME_CHECKSUM);
|
||||||
|
|||||||
@@ -14,8 +14,6 @@
|
|||||||
<description>Parent module that all service implementations should inherit</description>
|
<description>Parent module that all service implementations should inherit</description>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>httpchannel-service-archetype</module>
|
|
||||||
<module>httpchannel-service-megaupload</module>
|
|
||||||
<module>httpchannel-service-multiupload</module>
|
<module>httpchannel-service-multiupload</module>
|
||||||
<module>httpchannel-service-uploadking</module>
|
<module>httpchannel-service-uploadking</module>
|
||||||
<module>httpchannel-service-uploadhere</module>
|
<module>httpchannel-service-uploadhere</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user