mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Implement AccountDetails object that provides account information
This commit is contained in:
@@ -24,6 +24,7 @@ import org.slf4j.LoggerFactory;
|
||||
import com.rogiel.httpchannel.captcha.Captcha;
|
||||
import com.rogiel.httpchannel.captcha.CaptchaService;
|
||||
import com.rogiel.httpchannel.captcha.exception.UnsolvableCaptchaServiceException;
|
||||
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
|
||||
import com.rogiel.httpchannel.service.exception.NoCaptchaServiceException;
|
||||
|
||||
/**
|
||||
@@ -41,9 +42,9 @@ public abstract class AbstractService implements Service {
|
||||
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
/**
|
||||
* The currently active service mode
|
||||
* The currently active account
|
||||
*/
|
||||
protected ServiceMode serviceMode = ServiceMode.UNAUTHENTICATED;
|
||||
protected AccountDetails account;
|
||||
|
||||
/**
|
||||
* This service {@link CaptchaService} that is used to resolve CAPTCHAS
|
||||
@@ -52,7 +53,16 @@ public abstract class AbstractService implements Service {
|
||||
|
||||
@Override
|
||||
public ServiceMode getServiceMode() {
|
||||
return serviceMode;
|
||||
if (account == null) {
|
||||
return ServiceMode.UNAUTHENTICATED;
|
||||
} else {
|
||||
if (account.is(PremiumAccountDetails.class)) {
|
||||
return (account.as(PremiumAccountDetails.class).isPremium() ? ServiceMode.PREMIUM
|
||||
: ServiceMode.NON_PREMIUM);
|
||||
} else {
|
||||
return ServiceMode.NON_PREMIUM;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,10 +4,149 @@
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* An {@link AccountDetails} instance can provide several information about an
|
||||
* authenticated account. This instance itself provides little information,
|
||||
* restricted to whether the account {@link #isActive() is active} and its
|
||||
* {@link #getUsername() username}. More details are provided by additional
|
||||
* interfaces:
|
||||
* <ul>
|
||||
* <li>{@link PremiumAccountDetails} - for services that provide premium
|
||||
* accounts</li>
|
||||
* <li>{@link DiskQuotaAccountDetails} - for services that have limited disk
|
||||
* quota</li>
|
||||
* <li>{@link BandwidthQuotaAccountDetails} - for services that have limited
|
||||
* bandwidth quota</li>
|
||||
* </ul>
|
||||
* You should not try to cast instances by yourself, instead they should be
|
||||
* safely casted as such:
|
||||
*
|
||||
* <pre>
|
||||
* final {@link AccountDetails} details = ...;
|
||||
* if(details.{@link #is(Class) is}({@link PremiumAccountDetails}.class)) {
|
||||
* details.{@link #as(Class) as}({@link PremiumAccountDetails}.class).{@link PremiumAccountDetails#isPremium() isPremium()};
|
||||
* }
|
||||
* </pre>
|
||||
*
|
||||
* A single {@link AccountDetails} can implement none, one extended or even more
|
||||
* than one extended details interfaces, however all instances are required to
|
||||
* implement at least the basic methods defined in this interface.
|
||||
* <p>
|
||||
* Services could implement their own methods for details, but this should be
|
||||
* avoided because it would make user code dependent on implementation meta data
|
||||
* which is not stable and could break compatibility with other implementation
|
||||
* versions. If possible, it is recommended to add a new interface into the API
|
||||
* module.
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface AccountDetails {
|
||||
/**
|
||||
* @return the account username
|
||||
*/
|
||||
String getUsername();
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the account is currently active
|
||||
*/
|
||||
boolean isActive();
|
||||
|
||||
/**
|
||||
* @return the service that provided this account
|
||||
*/
|
||||
AuthenticationService<?> getService();
|
||||
|
||||
/**
|
||||
* Checks whether the account object can be casted to <code>type</code>
|
||||
*
|
||||
* @param type
|
||||
* the casting type
|
||||
* @return <code>true</code> if this object can be casted to
|
||||
* <code>type</code>
|
||||
*/
|
||||
boolean is(Class<? extends AccountDetails> type);
|
||||
|
||||
/**
|
||||
* Casts this object to <code>type</code>. If cannot be casted,
|
||||
* <code>null</code> is returned.
|
||||
*
|
||||
* @param type
|
||||
* the casting type
|
||||
* @return the casted account
|
||||
*/
|
||||
<T extends AccountDetails> T as(Class<T> type);
|
||||
|
||||
/**
|
||||
* Service accounts that has premium accounts must implement this interface
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface PremiumAccountDetails extends AccountDetails {
|
||||
/**
|
||||
* @return <code>true</code> if the account is premium
|
||||
*/
|
||||
boolean isPremium();
|
||||
}
|
||||
|
||||
/**
|
||||
* Service accounts that has accounts with limited disk space should
|
||||
* implement this interface
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface DiskQuotaAccountDetails extends AccountDetails {
|
||||
/**
|
||||
* @return the currently free disk space. <code>-1</code> means no limit
|
||||
*/
|
||||
long getFreeDiskSpace();
|
||||
|
||||
/**
|
||||
* @return the currently used disk space. Cannot be negative.
|
||||
*/
|
||||
long getUsedDiskSpace();
|
||||
|
||||
/**
|
||||
* @return the maximum amount of disk space. <code>-1</code> means no
|
||||
* limit
|
||||
*/
|
||||
long getMaximumDiskSpace();
|
||||
}
|
||||
|
||||
/**
|
||||
* Service accounts that has accounts with limited bandwidth should
|
||||
* implement this interface
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface BandwidthQuotaAccountDetails extends AccountDetails {
|
||||
/**
|
||||
* @return the currently free bandwidth. <code>-1</code> means no limit
|
||||
*/
|
||||
long getFreeBandwidth();
|
||||
|
||||
/**
|
||||
* @return the currently used bandwidth. Cannot be negative.
|
||||
*/
|
||||
long getUsedBandwidth();
|
||||
|
||||
/**
|
||||
* @return the maximum amount of bandwidth available. <code>-1</code>
|
||||
* means no limit
|
||||
*/
|
||||
long getMaximumBandwidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Service accounts that has accounts with limited bandwidth should
|
||||
* implement this interface
|
||||
*
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public interface FilesizeLimitAccountDetails extends AccountDetails {
|
||||
/**
|
||||
* @return the maximum filesize for the account. <code>-1</code> means
|
||||
* no limit
|
||||
*/
|
||||
long getMaximumFilesize();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,4 +69,10 @@ public interface AuthenticationService<C extends AuthenticatorConfiguration>
|
||||
* @see AuthenticatorCapability
|
||||
*/
|
||||
CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability();
|
||||
|
||||
/**
|
||||
* @return the currently authenticated account. Can be <code>null</code> and
|
||||
* this indicates that the service is not authenticated.
|
||||
*/
|
||||
AccountDetails getAccountDetails();
|
||||
}
|
||||
|
||||
@@ -38,6 +38,16 @@ public interface Authenticator<C extends AuthenticatorConfiguration> {
|
||||
* persistent for the entire service's operation.<br>
|
||||
* <b>Note</b>: If you want to logout the user, see
|
||||
* {@link Authenticator#logout()}
|
||||
* <p>
|
||||
* Return <code>null</code> is only allowed if
|
||||
* {@link AuthenticatorCapability#ACCOUNT_DETAILS} is not supported by the
|
||||
* service.
|
||||
*
|
||||
* @return the authenticated account {@link AccountDetails}. If
|
||||
* {@link AuthenticationService#getAuthenticationCapability()}
|
||||
* contains {@link AuthenticatorCapability#ACCOUNT_DETAILS}
|
||||
* <code>null</code> cannot be returned. Otherwise,
|
||||
* <code>null</code> should always be returned.
|
||||
*
|
||||
* @throws IOException
|
||||
* if any IO error occur
|
||||
@@ -51,7 +61,8 @@ public interface Authenticator<C extends AuthenticatorConfiguration> {
|
||||
* if the service required an {@link CaptchaService}
|
||||
* implementation to be present, but none was available
|
||||
*/
|
||||
void login() throws IOException, AuthenticationInvalidCredentialException,
|
||||
AccountDetails login() throws IOException,
|
||||
AuthenticationInvalidCredentialException,
|
||||
UnsolvableCaptchaServiceException, NoCaptchaServiceException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,7 +26,7 @@ package com.rogiel.httpchannel.service;
|
||||
*/
|
||||
public enum AuthenticatorCapability {
|
||||
/**
|
||||
* Mark an {@link Authenticator} capable of fetching account information.
|
||||
* Mark an {@link Authenticator} capable of providing account details.
|
||||
*/
|
||||
FETCH_ACCOUNT_INFORMATION;
|
||||
ACCOUNT_DETAILS;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
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;
|
||||
} catch (ApiException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
<groupId>com.rogiel.httpchannel.services</groupId>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
@@ -1 +1 @@
|
||||
com.rogiel.httpchannel.service.impl.MyService
|
||||
${package}.${serviceName}Service
|
||||
@@ -3,3 +3,5 @@ package=it.pkg
|
||||
version=0.1-SNAPSHOT
|
||||
groupId=archetype.it
|
||||
artifactId=basic
|
||||
serviceName = TestService
|
||||
serviceID = testservice
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
protected class UploaderImpl extends
|
||||
@Override
|
||||
public AccountDetails getAccountDetails() {
|
||||
return account;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
protected class UploaderImpl extends
|
||||
@Override
|
||||
public AccountDetails getAccountDetails() {
|
||||
return account;
|
||||
}
|
||||
|
||||
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() + "."
|
||||
|
||||
@@ -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() + "."
|
||||
|
||||
@@ -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() + "."
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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() + "."
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.rogiel.httpchannel.service;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class AbstractAccountDetails implements AccountDetails {
|
||||
protected final String username;
|
||||
protected final AuthenticationService<?> service;
|
||||
|
||||
public AbstractAccountDetails(AuthenticationService<?> service,
|
||||
String username) {
|
||||
this.service = service;
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthenticationService<?> getService() {
|
||||
return service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean is(Class<? extends AccountDetails> type) {
|
||||
return type.isAssignableFrom(this.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T extends AccountDetails> T as(Class<T> type) {
|
||||
if (!is(type))
|
||||
return null;
|
||||
return type.cast(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user