|
|
|
|
@@ -1,153 +0,0 @@
|
|
|
|
|
/*
|
|
|
|
|
* 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 com.rogiel.httpchannel.service.impl;
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.concurrent.Future;
|
|
|
|
|
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.AbstractAuthenticator;
|
|
|
|
|
import com.rogiel.httpchannel.service.AbstractHttpService;
|
|
|
|
|
import com.rogiel.httpchannel.service.AbstractUploader;
|
|
|
|
|
import com.rogiel.httpchannel.service.AuthenticationService;
|
|
|
|
|
import com.rogiel.httpchannel.service.Authenticator;
|
|
|
|
|
import com.rogiel.httpchannel.service.AuthenticatorCapability;
|
|
|
|
|
import com.rogiel.httpchannel.service.CapabilityMatrix;
|
|
|
|
|
import com.rogiel.httpchannel.service.Credential;
|
|
|
|
|
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.NullAuthenticatorConfiguration;
|
|
|
|
|
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
|
|
|
|
|
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
|
|
|
|
|
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This service handles uploads to MyService.com.
|
|
|
|
|
*
|
|
|
|
|
* @author <a href="http://www.rogiel.com/">Rogiel</a>
|
|
|
|
|
* @since 1.0
|
|
|
|
|
*/
|
|
|
|
|
public class DepositFilesService extends AbstractHttpService implements
|
|
|
|
|
Service, UploadService<NullUploaderConfiguration> {
|
|
|
|
|
/**
|
|
|
|
|
* This service ID
|
|
|
|
|
*/
|
|
|
|
|
public static final ServiceID SERVICE_ID = ServiceID.create("myservice");
|
|
|
|
|
|
|
|
|
|
@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 limit
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String[] getSupportedExtensions() {
|
|
|
|
|
// all extensions
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public CapabilityMatrix<UploaderCapability> getUploadCapabilities() {
|
|
|
|
|
return new CapabilityMatrix<UploaderCapability>(
|
|
|
|
|
UploaderCapability.UNAUTHENTICATED_UPLOAD,
|
|
|
|
|
UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD,
|
|
|
|
|
UploaderCapability.PREMIUM_ACCOUNT_UPLOAD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected class UploaderImpl extends
|
|
|
|
|
AbstractUploader<NullUploaderConfiguration> implements
|
|
|
|
|
Uploader<NullUploaderConfiguration>,
|
|
|
|
|
LinkedUploadChannelCloseCallback {
|
|
|
|
|
private Future<HTMLPage> uploadFuture;
|
|
|
|
|
|
|
|
|
|
public UploaderImpl(String filename, long filesize,
|
|
|
|
|
NullUploaderConfiguration configuration) {
|
|
|
|
|
super(DepositFilesService.this, filename, filesize, configuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public UploadChannel openChannel() throws IOException {
|
|
|
|
|
// TODO start upload
|
|
|
|
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
|
|
|
|
// TODO execute upload post
|
|
|
|
|
return waitChannelLink(channel, uploadFuture);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public String finish() throws IOException {
|
|
|
|
|
try {
|
|
|
|
|
final HTMLPage page = uploadFuture.get();
|
|
|
|
|
// return download link here
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
return null;
|
|
|
|
|
} catch (ExecutionException e) {
|
|
|
|
|
throw (IOException) e.getCause();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|