From 0a908a7756f221f97b8751bd81a133d505c2a7e0 Mon Sep 17 00:00:00 2001 From: Rogiel Date: Wed, 18 Jan 2012 19:12:26 -0200 Subject: [PATCH] Adds a maven archetype for easier service implementation --- .../httpchannel-service-archetype/pom.xml | 31 ++++ .../META-INF/maven/archetype-metadata.xml | 34 ++++ .../resources/archetype-resources/pom.xml | 15 ++ .../src/main/java/MyServiceService.java | 154 ++++++++++++++++++ .../com.rogiel.httpchannel.service.Service | 1 + .../projects/basic/archetype.properties | 5 + .../test/resources/projects/basic/goal.txt | 0 .../httpchannel-service-depositfiles/pom.xml | 25 +-- httpchannel-service/pom.xml | 75 ++++----- .../src/main/archetype-resources/pom.xml | 16 ++ .../httpchannel/service/impl/MyService.java | 153 +++++++++++++++++ .../com.rogiel.httpchannel.service.Service | 1 + .../META-INF/maven/archetype-metadata.xml | 13 ++ 13 files changed, 474 insertions(+), 49 deletions(-) create mode 100644 httpchannel-service/httpchannel-service-archetype/pom.xml create mode 100644 httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml create mode 100644 httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml create mode 100644 httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceService.java create mode 100644 httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service create mode 100644 httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties create mode 100644 httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/goal.txt create mode 100644 httpchannel-service/src/main/archetype-resources/pom.xml create mode 100644 httpchannel-service/src/main/archetype-resources/src/main/java/com/rogiel/httpchannel/service/impl/MyService.java create mode 100644 httpchannel-service/src/main/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service create mode 100644 httpchannel-service/src/main/resources/META-INF/maven/archetype-metadata.xml diff --git a/httpchannel-service/httpchannel-service-archetype/pom.xml b/httpchannel-service/httpchannel-service-archetype/pom.xml new file mode 100644 index 0000000..aa24f79 --- /dev/null +++ b/httpchannel-service/httpchannel-service-archetype/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + com.rogiel.httpchannel.services + httpchannel-service-archetype + 1.0.1-SNAPSHOT + maven-archetype + + HttpChannel/Service/Archetype + Provides an maven archetype for service creation + + + + + org.apache.maven.archetype + archetype-packaging + 2.2 + + + + + + + maven-archetype-plugin + 2.2 + + + + + diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml b/httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..3fe0f9c --- /dev/null +++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,34 @@ + + + + + src/main/java + + **/*.java + + + + src/main/resources + + **/*.Service + + + + .settings + + **/*.prefs + + + + + + .classpath + .project + + + + diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml new file mode 100644 index 0000000..e03635e --- /dev/null +++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + httpchannel-service + com.rogiel.httpchannel + 1.0.1-SNAPSHOT + .. + + ${artifactId} + ${groupId} + HttpChannel/Service/MyService + Provides an maven archetype for service creation + ${version} + diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceService.java b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceService.java new file mode 100644 index 0000000..0c80f50 --- /dev/null +++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/java/MyServiceService.java @@ -0,0 +1,154 @@ +#set( $symbol_pound = '#' ) +#set( $symbol_dollar = '$' ) +#set( $symbol_escape = '\' ) +/* + * 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 ${package}; + +import java.io.IOException; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +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 uploads to MyService.com. + * + * @author Rogiel + * @since 1.0 + */ +public class MyServiceService extends AbstractHttpService implements + Service, UploadService { + /** + * 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 getPossibleServiceModes() { + return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED); + } + + @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() { + // no configuration + return NullUploaderConfiguration.SHARED_INSTANCE; + } + + @Override + public long getMaximumFilesize() { + // no filesize limit + return -1; + } + + @Override + public String[] getSupportedExtensions() { + // no extension restriction + return null; + } + + @Override + public CapabilityMatrix getUploadCapabilities() { + return new CapabilityMatrix( + UploaderCapability.UNAUTHENTICATED_UPLOAD); + } + + protected class UploaderImpl extends + AbstractUploader implements + Uploader, + LinkedUploadChannelCloseCallback { + private Future uploadFuture; + + public UploaderImpl(String filename, long filesize, + NullUploaderConfiguration configuration) { + super(MyServiceService.this, filename, filesize, configuration); + } + + @Override + public UploadChannel openChannel() throws IOException { + logger.debug("Starting upload to myservice.com"); + final HTMLPage page = get("http://www.example.com/").asPage(); + + // locate upload uri + String uri = null; + + logger.debug("Upload URI: {}", uri); + + // create a new channel + final LinkedUploadChannel channel = createLinkedChannel(this); + uploadFuture = multipartPost(uri).parameter("[file-parameter]", channel).asPageAsync(); + + // wait for channel link + return waitChannelLink(channel, uploadFuture); + } + + @Override + public String finish() throws IOException { + try { + final HTMLPage page = uploadFuture.get(); + // find link + return null; + } catch (InterruptedException e) { + return null; + } catch (ExecutionException e) { + throw (IOException) e.getCause(); + } + } + } +} diff --git a/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service new file mode 100644 index 0000000..caaa717 --- /dev/null +++ b/httpchannel-service/httpchannel-service-archetype/src/main/resources/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service @@ -0,0 +1 @@ +com.rogiel.httpchannel.service.impl.MyService \ No newline at end of file diff --git a/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties b/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties new file mode 100644 index 0000000..1872146 --- /dev/null +++ b/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/archetype.properties @@ -0,0 +1,5 @@ +#Wed Jan 18 19:02:46 BRST 2012 +package=it.pkg +version=0.1-SNAPSHOT +groupId=archetype.it +artifactId=basic diff --git a/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/goal.txt b/httpchannel-service/httpchannel-service-archetype/src/test/resources/projects/basic/goal.txt new file mode 100644 index 0000000..e69de29 diff --git a/httpchannel-service/httpchannel-service-depositfiles/pom.xml b/httpchannel-service/httpchannel-service-depositfiles/pom.xml index 7b34ec7..80e9934 100644 --- a/httpchannel-service/httpchannel-service-depositfiles/pom.xml +++ b/httpchannel-service/httpchannel-service-depositfiles/pom.xml @@ -1,13 +1,14 @@ - - 4.0.0 - - httpchannel-service - com.rogiel.httpchannel - 1.0.1-SNAPSHOT - .. - - httpchannel-service-depositfiles - com.rogiel.httpchannel.services - HttpChannel/Service/DepositFiles - Provides upload access to depositfiles.com + + 4.0.0 + + httpchannel-service + com.rogiel.httpchannel + 1.0.1-SNAPSHOT + .. + + httpchannel-service-depositfiles + com.rogiel.httpchannel.services + HttpChannel/Service/DepositFiles + Provides upload access to depositfiles.com \ No newline at end of file diff --git a/httpchannel-service/pom.xml b/httpchannel-service/pom.xml index 72b1e5b..93d9992 100644 --- a/httpchannel-service/pom.xml +++ b/httpchannel-service/pom.xml @@ -1,38 +1,39 @@ - - 4.0.0 - - httpchannel - com.rogiel.httpchannel - 1.0.1-SNAPSHOT - .. - - httpchannel-service - pom - - HttpChannel/Service - Parent module that all service implementations should inherit - - - httpchannel-service-megaupload - httpchannel-service-multiupload - httpchannel-service-uploadking - httpchannel-service-uploadhere - httpchannel-service-depositfiles - httpchannel-service-hotfile - httpchannel-service-filesonic - httpchannel-service-zshare - - - - - com.rogiel.httpchannel - httpchannel-api - 1.0.1-SNAPSHOT - - - com.rogiel.httpchannel - httpchannel-util - 1.0.1-SNAPSHOT - - + + 4.0.0 + + httpchannel + com.rogiel.httpchannel + 1.0.1-SNAPSHOT + .. + + httpchannel-service + pom + + HttpChannel/Service + Parent module that all service implementations should inherit + + + httpchannel-service-archetype + httpchannel-service-megaupload + httpchannel-service-multiupload + httpchannel-service-uploadking + httpchannel-service-uploadhere + httpchannel-service-depositfiles + httpchannel-service-hotfile + httpchannel-service-filesonic + httpchannel-service-zshare + + + + + com.rogiel.httpchannel + httpchannel-api + 1.0.1-SNAPSHOT + + + com.rogiel.httpchannel + httpchannel-util + 1.0.1-SNAPSHOT + + \ No newline at end of file diff --git a/httpchannel-service/src/main/archetype-resources/pom.xml b/httpchannel-service/src/main/archetype-resources/pom.xml new file mode 100644 index 0000000..f933d96 --- /dev/null +++ b/httpchannel-service/src/main/archetype-resources/pom.xml @@ -0,0 +1,16 @@ + + 4.0.0 + + httpchannel-service + com.rogiel.httpchannel + 1.0.1-SNAPSHOT + .. + + ${groupId} + ${artifactId} + ${version} + jar + HttpChannel/Service/MyService + Provides upload access to myservice.com + \ No newline at end of file diff --git a/httpchannel-service/src/main/archetype-resources/src/main/java/com/rogiel/httpchannel/service/impl/MyService.java b/httpchannel-service/src/main/archetype-resources/src/main/java/com/rogiel/httpchannel/service/impl/MyService.java new file mode 100644 index 0000000..0e7ff53 --- /dev/null +++ b/httpchannel-service/src/main/archetype-resources/src/main/java/com/rogiel/httpchannel/service/impl/MyService.java @@ -0,0 +1,153 @@ +/* + * 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 Rogiel + * @since 1.0 + */ +public class DepositFilesService extends AbstractHttpService implements + Service, UploadService { + /** + * 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 getPossibleServiceModes() { + return new CapabilityMatrix(ServiceMode.UNAUTHENTICATED); + } + + @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() { + // 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 getUploadCapabilities() { + return new CapabilityMatrix( + UploaderCapability.UNAUTHENTICATED_UPLOAD, + UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD, + UploaderCapability.PREMIUM_ACCOUNT_UPLOAD); + } + + protected class UploaderImpl extends + AbstractUploader implements + Uploader, + LinkedUploadChannelCloseCallback { + private Future 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(); + } + } + } +} diff --git a/httpchannel-service/src/main/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service b/httpchannel-service/src/main/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service new file mode 100644 index 0000000..caaa717 --- /dev/null +++ b/httpchannel-service/src/main/archetype-resources/src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service @@ -0,0 +1 @@ +com.rogiel.httpchannel.service.impl.MyService \ No newline at end of file diff --git a/httpchannel-service/src/main/resources/META-INF/maven/archetype-metadata.xml b/httpchannel-service/src/main/resources/META-INF/maven/archetype-metadata.xml new file mode 100644 index 0000000..1074aae --- /dev/null +++ b/httpchannel-service/src/main/resources/META-INF/maven/archetype-metadata.xml @@ -0,0 +1,13 @@ + + httpchannel-service + + src/main/java/com/rogiel/httpchannel/service/impl/MyService.java + + + + src/main/resources/META-INF/services/com.rogiel.httpchannel.service.Service + + \ No newline at end of file