1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-06 07:32:50 +00:00

Implement AccountDetails object that provides account information

This commit is contained in:
2012-01-22 19:27:33 -02:00
parent 885de35de5
commit 3b06f0b9e6
33 changed files with 598 additions and 121 deletions

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -3,6 +3,7 @@ package com.pmstation.shared.soap.client;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

View File

@@ -25,9 +25,14 @@ import java.util.concurrent.Future;
import com.pmstation.shared.soap.client.ApiException;
import com.pmstation.shared.soap.client.DesktopAppJax2;
import com.pmstation.shared.soap.client.DesktopAppJax2Service;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.DiskQuotaAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.FilesizeLimitAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -45,7 +50,6 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadCh
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.exception.AuthenticationServiceException;
import com.rogiel.httpchannel.service.exception.ChannelServiceException;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
@@ -67,9 +71,6 @@ public class FourSharedService extends AbstractHttpService implements Service,
private final DesktopAppJax2 api = new DesktopAppJax2Service()
.getDesktopAppJax2Port();
private String username;
private String password;
@Override
public ServiceID getServiceID() {
return SERVICE_ID;
@@ -110,16 +111,16 @@ public class FourSharedService extends AbstractHttpService implements Service,
@Override
public long getMaximumFilesize() {
try {
final long free = api.getFreeSpace(username, password);
final long max = api.getMaxFileSize(username, password);
if (max < free)
return max;
else
return free;
} catch (ApiException e) {
return 0;
}
final long max = account.as(FilesizeLimitAccountDetails.class)
.getMaximumFilesize();
if(max <= -1)
return -1;
final long free = account.as(DiskQuotaAccountDetails.class)
.getFreeDiskSpace();
if (max < free)
return max;
else
return free;
}
@Override
@@ -154,10 +155,16 @@ public class FourSharedService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(
AuthenticatorCapability.ACCOUNT_DETAILS);
}
protected class UploaderImpl extends
@Override
public AccountDetails getAccountDetails() {
return account;
}
private class UploaderImpl extends
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
@@ -172,14 +179,14 @@ public class FourSharedService extends AbstractHttpService implements Service,
public UploadChannel openChannel() throws IOException {
try {
logger.debug("Starting upload to 4shared.com");
final String sessionID = api.createUploadSessionKey(username,
password, -1);
final String sessionID = api.createUploadSessionKey(
account.getUsername(), getPassword(), -1);
logger.debug("SessionID: {}", sessionID);
if (sessionID == null || sessionID.length() == 0)
throw new ChannelServiceException("SessionID is invalid");
final long datacenterID = api.getNewFileDataCenter(username,
password);
final long datacenterID = api.getNewFileDataCenter(
account.getUsername(), getPassword());
logger.debug("DatacenterID: {}", datacenterID);
if (datacenterID <= 0)
throw new ChannelServiceException("DatacenterID is invalid");
@@ -205,7 +212,8 @@ public class FourSharedService extends AbstractHttpService implements Service,
try {
final long linkID = Long.parseLong(uploadFuture.get()
.getInputValueById("uploadedFileId"));
return api.getFileDownloadLink(username, password, linkID);
return api.getFileDownloadLink(account.getUsername(),
getPassword(), linkID);
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
@@ -216,7 +224,7 @@ public class FourSharedService extends AbstractHttpService implements Service,
}
}
protected class AuthenticatorImpl extends
private class AuthenticatorImpl extends
AbstractAuthenticator<NullAuthenticatorConfiguration> implements
Authenticator<NullAuthenticatorConfiguration> {
public AuthenticatorImpl(Credential credential,
@@ -225,31 +233,90 @@ public class FourSharedService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
logger.debug("Logging to 4shared.com");
final String response = api.login(credential.getUsername(),
credential.getPassword());
username = credential.getUsername();
password = credential.getPassword();
try {
if (api.isAccountPremium(username, password))
serviceMode = ServiceMode.PREMIUM;
else
serviceMode = ServiceMode.NON_PREMIUM;
} catch (ApiException e) {
throw new AuthenticationServiceException(e);
}
if (!response.isEmpty())
throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername(),
credential.getPassword()));
}
@Override
public void logout() throws IOException {
username = null;
password = null;
account = null;
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails, DiskQuotaAccountDetails,
FilesizeLimitAccountDetails {
private final String password;
private AccountDetailsImpl(String username, String password) {
super(FourSharedService.this, username);
this.password = password;
}
@Override
public boolean isActive() {
try {
return api.isAccountActive(username, password);
} catch (ApiException e) {
return false;
}
}
@Override
public boolean isPremium() {
try {
return api.isAccountPremium(username, password);
} catch (ApiException e) {
return false;
}
}
@Override
public long getFreeDiskSpace() {
try {
return api.getFreeSpace(username, password);
} catch (ApiException e) {
return -1;
}
}
@Override
public long getUsedDiskSpace() {
return getMaximumDiskSpace() - getFreeDiskSpace();
}
@Override
public long getMaximumDiskSpace() {
try {
return api.getSpaceLimit(username, password);
} catch (ApiException e) {
return -1;
}
}
@Override
public long getMaximumFilesize() {
try {
return api.getMaxFileSize(username, password);
} catch (ApiException e) {
return -1;
}
}
}
private String getPassword() {
if (account == null) {
return null;
} else {
return ((AccountDetailsImpl) account).password;
}
}

View File

@@ -1,31 +1,32 @@
<?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>
<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.services</groupId>
<artifactId>httpchannel-service-archetype</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<groupId>com.rogiel.httpchannel.services</groupId>
<artifactId>httpchannel-service-archetype</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>maven-archetype</packaging>
<name>HttpChannel/Service/Archetype</name>
<description>Provides an maven archetype for service creation</description>
<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>
<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>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@@ -4,6 +4,10 @@
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>
@@ -17,18 +21,5 @@
<include>**/*.Service</include>
</includes>
</fileSet>
<fileSet encoding="UTF-8">
<directory>.settings</directory>
<includes>
<include>**/*.prefs</include>
</includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
<directory></directory>
<includes>
<include>.classpath</include>
<include>.project</include>
</includes>
</fileSet>
</fileSets>
</archetype-descriptor>

View File

@@ -1,5 +1,6 @@
<?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">
<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>
@@ -9,7 +10,7 @@
</parent>
<artifactId>${artifactId}</artifactId>
<groupId>${groupId}</groupId>
<name>HttpChannel/Service/MyService</name>
<description>Provides an maven archetype for service creation</description>
<name>HttpChannel/Service/${serviceName}</name>
<description>Provides download and upload access for ${serviceName}</description>
<version>${version}</version>
</project>

View File

@@ -41,17 +41,17 @@ import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* This service handles uploads to MyService.com.
* This service handles uploads to ${serviceName}.
*
* @author <a href="http://www.rogiel.com/">Rogiel</a>
* @since 1.0
*/
public class MyServiceService extends AbstractHttpService implements
public class ${serviceName}Service extends AbstractHttpService implements
Service, UploadService<NullUploaderConfiguration> {
/**
* This service ID
*/
public static final ServiceID SERVICE_ID = ServiceID.create("myservice");
public static final ServiceID SERVICE_ID = ServiceID.create("${serviceID}");
@Override
public ServiceID getServiceID() {
@@ -122,7 +122,7 @@ public class MyServiceService extends AbstractHttpService implements
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to myservice.com");
logger.debug("Starting upload to ${serviceName}");
final HTMLPage page = get("http://www.example.com/").asPage();
// locate upload uri

View File

@@ -3,3 +3,5 @@ package=it.pkg
version=0.1-SNAPSHOT
groupId=archetype.it
artifactId=basic
serviceName = TestService
serviceID = testservice

View File

@@ -26,9 +26,11 @@ import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
import com.rogiel.httpchannel.captcha.exception.UnsolvableCaptchaServiceException;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -145,10 +147,15 @@ public class DepositFilesService extends AbstractHttpService implements
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
private class UploaderImpl extends
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
@@ -195,7 +202,7 @@ public class DepositFilesService extends AbstractHttpService implements
}
}
protected class AuthenticatorImpl extends
private class AuthenticatorImpl extends
AbstractAuthenticator<NullAuthenticatorConfiguration> implements
Authenticator<NullAuthenticatorConfiguration> {
public AuthenticatorImpl(Credential credential,
@@ -204,7 +211,7 @@ public class DepositFilesService extends AbstractHttpService implements
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
logger.debug("Authenticating into depositfiles.com");
HTMLPage page = post("http://depositfiles.com/login.php?return=%2F")
.parameter("go", true)
@@ -234,8 +241,7 @@ public class DepositFilesService extends AbstractHttpService implements
captchaService.valid(captcha);
if (!page.contains(VALID_LOGIN_REDIRECT))
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
}
@@ -246,4 +252,14 @@ public class DepositFilesService extends AbstractHttpService implements
// TODO check logout status
}
}
private class AccountDetailsImpl extends AbstractAccountDetails {
/**
* @param username
* the account username
*/
public AccountDetailsImpl(String username) {
super(DepositFilesService.this, username);
}
}
}

View File

@@ -23,9 +23,12 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -146,10 +149,15 @@ public class FileSonicService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
private class UploaderImpl extends
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
@@ -182,7 +190,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
}
}
protected class AuthenticatorImpl extends
private class AuthenticatorImpl extends
AbstractAuthenticator<NullAuthenticatorConfiguration> implements
Authenticator<NullAuthenticatorConfiguration> {
public AuthenticatorImpl(Credential credential,
@@ -191,12 +199,10 @@ public class FileSonicService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
logger.debug("Logging to filesonic.com");
api.login(credential.getUsername(), credential.getPassword());
serviceMode = ServiceMode.NON_PREMIUM;
// if (username == null)
// throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -205,6 +211,22 @@ public class FileSonicService extends AbstractHttpService implements Service,
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(FileSonicService.this, username);
}
@Override
public boolean isPremium() {
//TODO implement this
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."

View File

@@ -27,10 +27,13 @@ import java.util.regex.Pattern;
import org.apache.http.client.ClientProtocolException;
import org.htmlparser.Tag;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -186,7 +189,12 @@ public class HotFileService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
@@ -273,7 +281,8 @@ public class HotFileService extends AbstractHttpService implements Service,
}
@Override
public void login() throws ClientProtocolException, IOException {
public AccountDetails login() throws ClientProtocolException,
IOException {
logger.debug("Authenticating hotfile.com");
HTMLPage page = post("http://www.hotfile.com/login.php")
.parameter("returnto", "/index.php")
@@ -283,7 +292,7 @@ public class HotFileService extends AbstractHttpService implements Service,
final Tag accountTag = page.getTagByID("account");
if (accountTag == null)
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -294,6 +303,23 @@ public class HotFileService extends AbstractHttpService implements Service,
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(HotFileService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."

View File

@@ -28,10 +28,13 @@ import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -198,7 +201,12 @@ public class MegaUploadService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
@@ -312,7 +320,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
logger.debug("Starting login to megaupload.com");
final HTMLPage page = post("http://www.megaupload.com/?c=login")
.parameter("login", true)
@@ -322,7 +330,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
String username = page.findScript(LOGIN_USERNAME_PATTERN, 1);
if (username == null)
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -333,6 +341,23 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(MegaUploadService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."

View File

@@ -25,10 +25,13 @@ import java.util.concurrent.Future;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.http.PostMultipartRequest;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -50,15 +53,16 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
import com.rogiel.httpchannel.service.config.NullDownloaderConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
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;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.multiupload.MultiUploadUploaderConfiguration.MultiUploadMirrorService;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* This service handles uploads to MultiUpload.com.
*
@@ -192,7 +196,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
@@ -282,14 +291,14 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.multiupload.com/login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (!page.containsIgnoreCase(credential.getUsername()))
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -299,4 +308,21 @@ public class MultiUploadService extends AbstractHttpService implements Service,
// TODO check logout status
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(MultiUploadService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
}

View File

@@ -26,10 +26,13 @@ import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -191,7 +194,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
@@ -300,14 +308,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.uploadhere.com/login")
.parameter("do", "login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -317,4 +325,21 @@ public class UploadHereService extends AbstractHttpService implements Service,
// TODO check logout status
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(UploadHereService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
}

View File

@@ -26,10 +26,13 @@ import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -191,7 +194,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
@@ -297,14 +305,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.uploadking.com/login")
.parameter("do", "login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
throw new AuthenticationInvalidCredentialException();
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -314,4 +322,21 @@ public class UploadKingService extends AbstractHttpService implements Service,
// TODO check logout status
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(UploadKingService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
}

View File

@@ -23,9 +23,12 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -146,7 +149,13 @@ public class WUploadService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>();
return new CapabilityMatrix<AuthenticatorCapability>(
AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
}
protected class UploaderImpl extends
@@ -191,10 +200,10 @@ public class WUploadService extends AbstractHttpService implements Service,
}
@Override
public void login() throws IOException {
public AccountDetails login() throws IOException {
logger.debug("Logging to wupload.com");
api.login(credential.getUsername(), credential.getPassword());
serviceMode = ServiceMode.NON_PREMIUM;
return (account = new AccountDetailsImpl(credential.getUsername()));
}
@Override
@@ -203,6 +212,23 @@ public class WUploadService extends AbstractHttpService implements Service,
}
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
/**
* @param username
* the username
*/
public AccountDetailsImpl(String username) {
super(WUploadService.this, username);
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
}
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."