diff --git a/httpchannel-service/httpchannel-service-4shared/src/test/java/org/httpchannel/service/fourshared/FourSharedServiceTest.java b/httpchannel-service/httpchannel-service-4shared/src/test/java/org/httpchannel/service/fourshared/FourSharedServiceTest.java
index 676e2a7..d6182de 100644
--- a/httpchannel-service/httpchannel-service-4shared/src/test/java/org/httpchannel/service/fourshared/FourSharedServiceTest.java
+++ b/httpchannel-service/httpchannel-service-4shared/src/test/java/org/httpchannel/service/fourshared/FourSharedServiceTest.java
@@ -33,7 +33,7 @@ public class FourSharedServiceTest {
}
@Test
- public void test() throws IOException {
+ public void testUpload() throws IOException {
AuthenticationServices.authenticator(service,
properties.getProperty("4shared.username"),
properties.getProperty("4shared.password")).login();
diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicAPI.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicAPI.java
index f2c8995..2fbb5a9 100644
--- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicAPI.java
+++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicAPI.java
@@ -23,6 +23,7 @@ import java.net.URI;
import javax.xml.bind.JAXB;
+import com.rogiel.httpchannel.http.HttpContext;
import com.rogiel.httpchannel.service.filesonic.xml.FSAPI;
import com.rogiel.httpchannel.service.filesonic.xml.FSGetUploadURL;
import com.rogiel.httpchannel.service.filesonic.xml.FSUpload;
@@ -32,12 +33,14 @@ import com.rogiel.httpchannel.service.filesonic.xml.FSUpload;
*/
public class FileSonicAPI {
private static final String BASE_URI = "http://api.filesonic.com/";
+
+ private final HttpContext ctx;
private String email;
private String password;
-
- public Object getInfo(int id) {
- return id;
+
+ public FileSonicAPI(HttpContext ctx) {
+ this.ctx = ctx;
}
public URI getUploadURI() throws IOException {
@@ -66,6 +69,6 @@ public class FileSonicAPI {
throws IOException {
final URI uri = URI.create(BASE_URI + requestURI + "&u=" + email
+ "&p=" + password + "&format=xml");
- return JAXB.unmarshal(uri.toURL().openStream(), type);
+ return JAXB.unmarshal(ctx.get(uri).asStream(), type);
}
}
diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java
index 5547da7..8ddd3f0 100644
--- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java
+++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/FileSonicService.java
@@ -56,17 +56,17 @@ public class FileSonicService extends AbstractHttpService implements Service,
/**
* This service ID
*/
- public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
+ public static final ServiceID SERVICE_ID = ServiceID.create("filesonic");
/**
* The download URI pattern
*/
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
- .compile("http://www.filesonic.com/file/[0-9A-z]*");
+ .compile("http://www\\.filesonic\\.com/file/[0-9A-z]*");
/**
* The FileSonic API
*/
- private final FileSonicAPI api = new FileSonicAPI();
+ private final FileSonicAPI api = new FileSonicAPI(http);
@Override
public ServiceID getServiceID() {
@@ -201,9 +201,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
@Override
public void logout() throws IOException {
- post("http://www.megaupload.com/?c=account").parameter("logout",
- true).request();
- // TODO check logout status
+ api.logout();
}
}
diff --git a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/xml/FSGetUploadURL.java b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/xml/FSGetUploadURL.java
index f199701..113d310 100644
--- a/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/xml/FSGetUploadURL.java
+++ b/httpchannel-service/httpchannel-service-filesonic/src/main/java/com/rogiel/httpchannel/service/filesonic/xml/FSGetUploadURL.java
@@ -35,7 +35,7 @@ public class FSGetUploadURL extends FSResponse {
@XmlAccessorType(XmlAccessType.NONE)
public static class FSGetUploadURLResponse {
- @XmlElement(name = "uri")
+ @XmlElement(name = "url")
private String uploadURI;
@XmlElement(name = "max-filesize")
private long maxFilesize;
diff --git a/httpchannel-service/httpchannel-service-wupload/pom.xml b/httpchannel-service/httpchannel-service-wupload/pom.xml
new file mode 100644
index 0000000..9048d12
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/pom.xml
@@ -0,0 +1,13 @@
+
+ 4.0.0
+
+ httpchannel-service
+ com.rogiel.httpchannel
+ 1.0.1-SNAPSHOT
+ ..
+
+ httpchannel-service-wupload
+ com.rogiel.httpchannel.services
+ HttpChannel/Service/WUpload
+ Provides download and upload access to wupload.com
+
\ No newline at end of file
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadAPI.java b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadAPI.java
new file mode 100644
index 0000000..3ec661f
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadAPI.java
@@ -0,0 +1,74 @@
+/*
+ * 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.wupload;
+
+import java.io.IOException;
+import java.net.URI;
+
+import javax.xml.bind.JAXB;
+
+import com.rogiel.httpchannel.http.HttpContext;
+import com.rogiel.httpchannel.service.wupload.xml.FSAPI;
+import com.rogiel.httpchannel.service.wupload.xml.FSGetUploadURL;
+import com.rogiel.httpchannel.service.wupload.xml.FSUpload;
+
+/**
+ * @author Rogiel
+ */
+public class WUploadAPI {
+ private static final String BASE_URI = "http://api.wupload.com/";
+
+ private final HttpContext ctx;
+
+ private String email;
+ private String password;
+
+ public WUploadAPI(HttpContext ctx) {
+ this.ctx = ctx;
+ }
+
+ public URI getUploadURI() throws IOException {
+ return URI.create((((FSGetUploadURL) execute(FSUpload.class,
+ "upload?method=getUploadUrl").getResponse()).getResponse()
+ .getUploadURI()));
+ }
+
+ public long getMaxFilesize() throws IOException {
+ return ((FSGetUploadURL) execute(FSUpload.class,
+ "upload?method=getUploadUrl").getResponse()).getResponse()
+ .getMaxFilesize();
+ }
+
+ public void login(String email, String password) {
+ this.email = email;
+ this.password = password;
+ }
+
+ public void logout() {
+ this.email = null;
+ this.password = null;
+ }
+
+ private T execute(Class type, String requestURI)
+ throws IOException {
+ final URI uri = URI.create(BASE_URI + requestURI + "&u=" + email
+ + "&p=" + password + "&format=xml");
+ return JAXB.unmarshal(ctx.get(uri).asStream(), type);
+ }
+}
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadService.java b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadService.java
new file mode 100644
index 0000000..1f860c2
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/WUploadService.java
@@ -0,0 +1,211 @@
+/*
+ * 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.wupload;
+
+import java.io.IOException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.regex.Pattern;
+
+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.util.PatternUtils;
+
+/**
+ * This service handles login, upload and download to WUpload.com.
+ *
+ * @author Rogiel
+ * @since 1.0
+ */
+public class WUploadService extends AbstractHttpService implements Service,
+ UploadService,
+ AuthenticationService {
+ /**
+ * This service ID
+ */
+ public static final ServiceID SERVICE_ID = ServiceID.create("wupload");
+
+ /**
+ * The download URI pattern
+ */
+ private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
+ .compile("http://www\\.wupload\\.com/file/[0-9]*(/.*)?");
+ /**
+ * The FileSonic API
+ */
+ private final WUploadAPI api = new WUploadAPI(http);
+
+ @Override
+ public ServiceID getServiceID() {
+ return SERVICE_ID;
+ }
+
+ @Override
+ public int getMajorVersion() {
+ return 1;
+ }
+
+ @Override
+ public int getMinorVersion() {
+ return 0;
+ }
+
+ @Override
+ public CapabilityMatrix getPossibleServiceModes() {
+ return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED,
+ ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
+ }
+
+ @Override
+ public Uploader getUploader(String filename,
+ long filesize, NullUploaderConfiguration configuration) {
+ return new UploaderImpl(filename, filesize, configuration);
+ }
+
+ @Override
+ public Uploader getUploader(String filename,
+ long filesize) {
+ return getUploader(filename, filesize, newUploaderConfiguration());
+ }
+
+ @Override
+ public NullUploaderConfiguration newUploaderConfiguration() {
+ return NullUploaderConfiguration.SHARED_INSTANCE;
+ }
+
+ @Override
+ public long getMaximumFilesize() {
+ try {
+ return api.getMaxFilesize();
+ } catch (IOException e) {
+ return -1;
+ }
+ }
+
+ @Override
+ public String[] getSupportedExtensions() {
+ return null;
+ }
+
+ @Override
+ public CapabilityMatrix getUploadCapabilities() {
+ return new CapabilityMatrix(
+ UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD,
+ UploaderCapability.PREMIUM_ACCOUNT_UPLOAD);
+ }
+
+ @Override
+ public Authenticator getAuthenticator(
+ Credential credential, NullAuthenticatorConfiguration configuration) {
+ return new AuthenticatorImpl(credential, configuration);
+ }
+
+ @Override
+ public Authenticator getAuthenticator(
+ Credential credential) {
+ return getAuthenticator(credential, newAuthenticatorConfiguration());
+ }
+
+ @Override
+ public NullAuthenticatorConfiguration newAuthenticatorConfiguration() {
+ return NullAuthenticatorConfiguration.SHARED_INSTANCE;
+ }
+
+ @Override
+ public CapabilityMatrix getAuthenticationCapability() {
+ return new CapabilityMatrix();
+ }
+
+ protected class UploaderImpl extends
+ AbstractUploader implements
+ Uploader,
+ LinkedUploadChannelCloseCallback {
+ private Future uploadFuture;
+
+ public UploaderImpl(String filename, long filesize,
+ NullUploaderConfiguration configuration) {
+ super(WUploadService.this, filename, filesize, configuration);
+ }
+
+ @Override
+ public UploadChannel openChannel() throws IOException {
+ logger.debug("Starting upload to wupload.com");
+ final LinkedUploadChannel channel = createLinkedChannel(this);
+ uploadFuture = multipartPost(api.getUploadURI().toString())
+ .parameter("files[]", channel).asStringAsync();
+ return waitChannelLink(channel, uploadFuture);
+ }
+
+ @Override
+ public String finish() throws IOException {
+ try {
+ return PatternUtils.find(DOWNLOAD_URI_PATTERN,
+ uploadFuture.get());
+ } catch (InterruptedException e) {
+ return null;
+ } catch (ExecutionException e) {
+ throw (IOException) e.getCause();
+ }
+ }
+ }
+
+ protected class AuthenticatorImpl extends
+ AbstractAuthenticator implements
+ Authenticator {
+ public AuthenticatorImpl(Credential credential,
+ NullAuthenticatorConfiguration configuration) {
+ super(credential, configuration);
+ }
+
+ @Override
+ public void login() throws IOException {
+ logger.debug("Logging to wupload.com");
+ api.login(credential.getUsername(), credential.getPassword());
+ serviceMode = ServiceMode.NON_PREMIUM;
+ }
+
+ @Override
+ public void logout() throws IOException {
+ api.logout();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
+ + getMinorVersion();
+ }
+}
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSAPI.java b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSAPI.java
new file mode 100644
index 0000000..1214b3b
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSAPI.java
@@ -0,0 +1,27 @@
+/*
+ * 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.wupload.xml;
+
+/**
+ * @author Rogiel
+ *
+ */
+public class FSAPI {
+
+}
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSGetUploadURL.java b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSGetUploadURL.java
new file mode 100644
index 0000000..4e75e30
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSGetUploadURL.java
@@ -0,0 +1,55 @@
+/*
+ * 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.wupload.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Rogiel
+ *
+ */
+@XmlRootElement(name = "getUploadUrl")
+@XmlAccessorType(XmlAccessType.NONE)
+public class FSGetUploadURL extends FSResponse {
+ @XmlElement(name = "response")
+ private FSGetUploadURLResponse response;
+
+ @XmlAccessorType(XmlAccessType.NONE)
+ public static class FSGetUploadURLResponse {
+ @XmlElement(name = "url")
+ private String uploadURI;
+ @XmlElement(name = "max-filesize")
+ private long maxFilesize;
+
+ public String getUploadURI() {
+ return uploadURI;
+ }
+
+ public long getMaxFilesize() {
+ return maxFilesize;
+ }
+ }
+
+ public FSGetUploadURLResponse getResponse() {
+ return response;
+ }
+}
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSResponse.java b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSResponse.java
new file mode 100644
index 0000000..e0bf22a
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSResponse.java
@@ -0,0 +1,36 @@
+/*
+ * 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.wupload.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+
+/**
+ * @author Rogiel
+ */
+@XmlAccessorType(XmlAccessType.NONE)
+public abstract class FSResponse {
+ @XmlElement(name = "status")
+ private String status;
+
+ public String getStatus() {
+ return status;
+ }
+}
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSUpload.java b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSUpload.java
new file mode 100644
index 0000000..66bfa71
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/java/com/rogiel/httpchannel/service/wupload/xml/FSUpload.java
@@ -0,0 +1,40 @@
+/*
+ * 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.wupload.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * @author Rogiel
+ *
+ */
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlRootElement(name = "FSApi_Upload")
+public class FSUpload extends FSAPI {
+ @XmlElements(value = { @XmlElement(name = "getUploadUrl", type = FSGetUploadURL.class) })
+ private FSResponse response;
+
+ public FSResponse getResponse() {
+ return response;
+ }
+}
diff --git a/httpchannel-service/httpchannel-service-wupload/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service b/httpchannel-service/httpchannel-service-wupload/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
new file mode 100644
index 0000000..902fd50
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service
@@ -0,0 +1 @@
+com.rogiel.httpchannel.service.wupload.WUploadService
\ No newline at end of file
diff --git a/httpchannel-service/httpchannel-service-wupload/src/test/java/com/rogiel/httpchannel/service/wupload/WUploadServiceTest.java b/httpchannel-service/httpchannel-service-wupload/src/test/java/com/rogiel/httpchannel/service/wupload/WUploadServiceTest.java
new file mode 100644
index 0000000..f3932be
--- /dev/null
+++ b/httpchannel-service/httpchannel-service-wupload/src/test/java/com/rogiel/httpchannel/service/wupload/WUploadServiceTest.java
@@ -0,0 +1,48 @@
+/**
+ *
+ */
+package com.rogiel.httpchannel.service.wupload;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Properties;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import com.rogiel.httpchannel.service.helper.AuthenticationServices;
+import com.rogiel.httpchannel.util.ChannelUtils;
+
+/**
+ * @author Rogiel
+ *
+ */
+public class WUploadServiceTest {
+ private final WUploadService service = new WUploadService();
+ private final Properties properties = new Properties();
+
+ @Before
+ public void setUp() throws IOException {
+ properties.load(Files.newInputStream(Paths
+ .get("../src/test/resources/login.properties")));
+ }
+
+ @Test
+ public void testUpload() throws IOException {
+ AuthenticationServices.authenticator(service,
+ properties.getProperty("wupload.username"),
+ properties.getProperty("wupload.password")).login();
+
+ final Path path = Paths
+ .get("../src/test/resources/upload-test-file.txt");
+ final URI uri = ChannelUtils.upload(service, path);
+
+ Assert.assertNotNull(uri);
+ System.out.println(uri);
+ }
+}
diff --git a/httpchannel-service/pom.xml b/httpchannel-service/pom.xml
index 0f670b7..368a71f 100644
--- a/httpchannel-service/pom.xml
+++ b/httpchannel-service/pom.xml
@@ -21,6 +21,7 @@
httpchannel-service-depositfileshttpchannel-service-hotfilehttpchannel-service-filesonic
+ httpchannel-service-wuploadhttpchannel-service-zsharehttpchannel-service-4shared
diff --git a/httpchannel-util/pom.xml b/httpchannel-util/pom.xml
index d4e3b51..5cbb34c 100644
--- a/httpchannel-util/pom.xml
+++ b/httpchannel-util/pom.xml
@@ -52,6 +52,11 @@
htmlparser2.1
+
+ com.googlecode.json-simple
+ json-simple
+ 1.1
+ HttpChannel/Service/UtilitiesModule providing several utilities to service implementations. Though this module is not required to implement services, it contains several shortcuts that can help implementing services.
diff --git a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java
index 2874afe..5581bce 100644
--- a/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java
+++ b/httpchannel-util/src/main/java/com/rogiel/httpchannel/http/Request.java
@@ -19,16 +19,21 @@
package com.rogiel.httpchannel.http;
import java.io.IOException;
+import java.io.InputStream;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
import com.rogiel.httpchannel.util.HttpClientUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
public abstract class Request {
+ private static final JSONParser jsonParser = new JSONParser();
+
protected final HttpContext ctx;
protected final String uri;
@@ -60,6 +65,19 @@ public abstract class Request {
}
});
}
+
+ public InputStream asStream() throws ClientProtocolException, IOException {
+ return request().getEntity().getContent();
+ }
+
+ public Future asStreamAsync() throws IOException {
+ return ctx.threadPool.submit(new Callable() {
+ @Override
+ public InputStream call() throws Exception {
+ return asStream();
+ }
+ });
+ }
public HTMLPage asPage() throws ClientProtocolException, IOException {
return HTMLPage.parse(asString());
@@ -73,6 +91,19 @@ public abstract class Request {
}
});
}
+
+ public Object asJson() throws ClientProtocolException, IOException, ParseException {
+ return jsonParser.parse(asString());
+ }
+
+ public Future