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

Implements ifile.it upload service

This commit is contained in:
2012-05-05 19:45:08 -03:00
parent 55cb79d599
commit d838636f2a
47 changed files with 366 additions and 26 deletions

View File

@@ -8,6 +8,9 @@
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-api</artifactId>
<packaging>jar</packaging>
<name>HttpChannel/API</name>
<description>Module that defines the HttpChannel API. HttpChannels abstract complex download and upload steps into a simple and easy to use NIO Channel. NIO Channels can be wrapped into an InputStream or OutputStream and used in any way you may find possible to. Aside from that, Channels can be used natively in most next-gen libraries, meaning that you don't even need to wrap anything, just start writing or reading data to or from the channel wth a ByteBuffer.

View File

@@ -20,8 +20,8 @@ package com.rogiel.httpchannel.service.helper;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.Authenticator.AuthenticatorConfiguration;
import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.Authenticator.AuthenticatorConfiguration;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>

View File

@@ -0,0 +1,23 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HttpChannel API
Bundle-SymbolicName: com.rogiel.httpchannel;singleton:=true
Bundle-Version: 1.0.0
Export-Package: com.rogiel.httpchannel.captcha,
com.rogiel.httpchannel.captcha.exception;uses:="com.rogiel.httpchannel.service.exception",
com.rogiel.httpchannel.channel;uses:="com.rogiel.httpchannel.service",
com.rogiel.httpchannel.osgi;uses:="org.osgi.framework",
com.rogiel.httpchannel.service;uses:="com.rogiel.httpchannel.captcha,org.slf4j",
com.rogiel.httpchannel.service.config;uses:="com.rogiel.httpchannel.service",
com.rogiel.httpchannel.service.exception,
com.rogiel.httpchannel.service.helper;uses:="com.rogiel.httpchannel.service"
Bundle-Activator: com.rogiel.httpchannel.osgi.Activator
Import-Package: com.rogiel.httpchannel.captcha,
com.rogiel.httpchannel.captcha.exception,
com.rogiel.httpchannel.channel,
com.rogiel.httpchannel.osgi,
com.rogiel.httpchannel.service,
com.rogiel.httpchannel.service.config,
com.rogiel.httpchannel.service.exception,
com.rogiel.httpchannel.service.helper, org.osgi.framework

View File

@@ -30,9 +30,6 @@ 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,6 +42,9 @@ 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.AccountDetails.DiskQuotaAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.FilesizeLimitAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;

View File

@@ -28,7 +28,6 @@ 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;
@@ -41,6 +40,7 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;

View File

@@ -1,4 +1,5 @@
<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>

View File

@@ -33,7 +33,6 @@ 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;
@@ -51,6 +50,7 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;

View File

@@ -0,0 +1,14 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-ifileit</artifactId>
<groupId>com.rogiel.httpchannel.services</groupId>
<name>HttpChannel/Service/iFileIt</name>
<description>Provides download and upload access to ifile.it</description>
</project>

View File

@@ -0,0 +1,160 @@
/*
* 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.ifile;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.CapabilityMatrix;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.ServiceMode;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
import com.rogiel.httpchannel.service.UploaderCapability;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
/**
* This service handles login, upload and download to HotFile.com.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
* @since 1.0
*/
public class IFileService extends AbstractHttpService implements Service,
UploadService<NullUploaderConfiguration> {
/**
* This service ID
*/
public static final ServiceID SERVICE_ID = ServiceID.create("ifileit");
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://i[0-9]+\\.ifile\\.it/upload\\?response=redirect");
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://ifile\\.it/[a-z0-9]{7}/.*");
@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,
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
}
@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() {
return NullUploaderConfiguration.SHARED_INSTANCE;
}
@Override
public long getMaximumFilesize() {
return 1 * 1024 * 1024 * 1024;
}
@Override
public String[] getSupportedExtensions() {
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(IFileService.this, filename, filesize, configuration);
}
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to ifile.it");
final HTMLPage page = get("http://ifile.it/upload-classic.html")
.asPage();
final String action = page.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", action);
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(action).parameter("Filedata", channel)
.asPageAsync();
return waitChannelLink(channel);
}
@Override
public String finish() throws IOException {
try {
return uploadFuture.get().getInputValue(DOWNLOAD_URI_PATTERN);
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
throw (IOException) e.getCause();
}
}
}
@Override
public String toString() {
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
+ getMinorVersion();
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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.ifile;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import junit.framework.Assert;
import org.junit.Before;
import org.junit.Test;
import com.rogiel.httpchannel.service.ServiceID;
import com.rogiel.httpchannel.service.UploadChannel;
import com.rogiel.httpchannel.service.helper.UploadServices;
import com.rogiel.httpchannel.util.ChannelUtils;
public class IFileServiceTest {
private IFileService service;
@Before
public void setUp() throws Exception {
service = new IFileService();
}
@Test
public void testServiceId() {
assertEquals(ServiceID.create("hotfile"), service.getServiceID());
}
@Test
public void testNonLoguedInUploader() throws IOException {
final Path path = Paths
.get("../src/test/resources/upload-test-file.txt");
final UploadChannel channel = UploadServices.upload(service, path)
.openChannel();
final SeekableByteChannel inChannel = Files.newByteChannel(path);
try {
ChannelUtils.copy(inChannel, channel);
} finally {
inChannel.close();
channel.close();
}
System.out.println(channel.getDownloadLink());
Assert.assertNotNull(channel.getDownloadLink());
}
}

View File

@@ -34,7 +34,6 @@ 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;
@@ -52,6 +51,7 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;

View File

@@ -31,7 +31,6 @@ 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;
@@ -49,15 +48,16 @@ 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.AccountDetails.PremiumAccountDetails;
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;

View File

@@ -32,7 +32,6 @@ 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,6 +49,7 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;

View File

@@ -32,7 +32,6 @@ 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,6 +49,7 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;

View File

@@ -28,7 +28,6 @@ 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;
@@ -41,6 +40,7 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;

View File

@@ -24,6 +24,7 @@
<module>httpchannel-service-zshare</module>
<module>httpchannel-service-4shared</module>
<module>httpchannel-service-2shared</module>
<module>httpchannel-service-ifile</module>
</modules>
<dependencies>

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.net.URI;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.http.HttpContext;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;

View File

@@ -22,8 +22,13 @@ import java.net.URI;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.ProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.params.ClientParamBean;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultRedirectStrategy;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
@@ -35,7 +40,29 @@ public class HttpContext {
/**
* The {@link HttpClient} instance for this service
*/
protected DefaultHttpClient client = new DefaultHttpClient();
protected final DefaultHttpClient client = new DefaultHttpClient();
protected final ClientParamBean params;
public HttpContext() {
// default configuration
params = new ClientParamBean(client.getParams());
params.setHandleRedirects(true);
params.setAllowCircularRedirects(true);
params.setRejectRelativeRedirect(false);
params.setMaxRedirects(10);
// browser behavior
client.setRedirectStrategy(new DefaultRedirectStrategy() {
@Override
public boolean isRedirected(HttpRequest request,
HttpResponse response,
org.apache.http.protocol.HttpContext context)
throws ProtocolException {
return response.containsHeader("Location");
}
});
}
public GetRequest get(String uri) {
return new GetRequest(this, uri);

View File

@@ -21,6 +21,7 @@ package com.rogiel.httpchannel.http;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
@@ -35,12 +36,20 @@ public class PostMultipartRequest extends PostRequest {
public PostMultipartRequest(HttpContext ctx, String uri) {
super(ctx, uri);
this.entity = new MultipartEntity();
this.entity = new MultipartEntity() {
@Override
protected String generateBoundary() {
return "---------------------------9849436581144108930470211272";
}
};
}
@Override
public HttpResponse request() throws IOException {
final HttpPost post = new HttpPost(uri);
for (final Header header : headers) {
post.addHeader(header);
}
post.setEntity(entity);
return ctx.client.execute(post);
}

View File

@@ -23,6 +23,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
@@ -39,6 +40,9 @@ public class PostRequest extends Request {
@Override
public HttpResponse request() throws IOException {
final HttpPost post = new HttpPost(uri);
for(final Header header : headers) {
post.addHeader(header);
}
post.setEntity(new UrlEncodedFormEntity(params));
return ctx.client.execute(post);
}

View File

@@ -20,11 +20,15 @@ package com.rogiel.httpchannel.http;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicHeader;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
@@ -34,6 +38,8 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
public abstract class Request {
private static final JSONParser jsonParser = new JSONParser();
protected final List<Header> headers = new ArrayList<>();
protected final HttpContext ctx;
protected final String uri;
@@ -42,6 +48,11 @@ public abstract class Request {
this.uri = uri;
}
public Request header(String name, String value) {
headers.add(new BasicHeader(name, value));
return this;
}
public abstract HttpResponse request() throws IOException;
public Future<HttpResponse> requestAsync() throws IOException {

View File

@@ -3,6 +3,9 @@
*/
package com.rogiel.httpchannel.service;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
/**
* @author <a href="http://www.rogiel.com">Rogiel</a>
*

View File

@@ -18,6 +18,8 @@
*/
package com.rogiel.httpchannel.service;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.Credential;
import com.rogiel.httpchannel.service.Authenticator.AuthenticatorConfiguration;
/**

View File

@@ -22,6 +22,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import com.rogiel.httpchannel.service.DownloadChannel;
import com.rogiel.httpchannel.service.DownloadListener;
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;

View File

@@ -29,6 +29,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.rogiel.httpchannel.http.Request;
import com.rogiel.httpchannel.service.DownloadListener;
import com.rogiel.httpchannel.service.DownloadService;
import com.rogiel.httpchannel.service.Downloader;
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;

View File

@@ -25,6 +25,8 @@ import com.rogiel.httpchannel.http.GetRequest;
import com.rogiel.httpchannel.http.HttpContext;
import com.rogiel.httpchannel.http.PostMultipartRequest;
import com.rogiel.httpchannel.http.PostRequest;
import com.rogiel.httpchannel.service.AbstractService;
import com.rogiel.httpchannel.service.Service;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.exception.UploadServiceException;

View File

@@ -18,6 +18,8 @@
*/
package com.rogiel.httpchannel.service;
import com.rogiel.httpchannel.service.UploadService;
import com.rogiel.httpchannel.service.Uploader;
import com.rogiel.httpchannel.service.Uploader.UploaderConfiguration;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;