From cb2adae917e317b6ec1901dc2752f147f1a738a9 Mon Sep 17 00:00:00 2001 From: Sean Flanigan Date: Thu, 12 Sep 2013 12:54:36 +1000 Subject: [PATCH 1/2] Update to api 3.1-SNAPSHOT; work around Seam RESTEasy problem --- pom.xml | 2 +- .../zanata/rest/ZanataResteasyBootstrap.java | 39 +++++++++++++++++++ .../zanata/rest/service/AccountService.java | 2 + .../AsynchronousProcessResourceService.java | 5 ++- .../service/CopyTransResourceService.java | 3 +- .../org/zanata/rest/service/FileService.java | 2 + .../zanata/rest/service/GlossaryService.java | 2 + .../rest/service/ProjectIterationService.java | 2 + .../zanata/rest/service/ProjectService.java | 2 + .../zanata/rest/service/ProjectsService.java | 2 + .../service/SourceDocResourceService.java | 3 ++ .../service/TranslatedDocResourceService.java | 9 +++-- .../TranslationMemoryResourceService.java | 2 + .../zanata/rest/service/VersionService.java | 2 + .../seam/resteasy/IgnoreInterfacePath.java | 17 ++++++++ 15 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 zanata-war/src/main/java/org/zanata/seam/resteasy/IgnoreInterfacePath.java diff --git a/pom.xml b/pom.xml index ae3a0b24b8..a7221297aa 100644 --- a/pom.xml +++ b/pom.xml @@ -32,7 +32,7 @@ 1.2.1 0.22 - 3.0.2 + 3.1-SNAPSHOT 3.0.1 3.0.1 diff --git a/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java b/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java index 685f499654..fb25b2e098 100644 --- a/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java +++ b/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java @@ -1,6 +1,7 @@ package org.zanata.rest; import java.io.IOException; +import java.lang.annotation.Annotation; import java.util.Collection; import javax.ws.rs.core.Response.Status; @@ -24,6 +25,7 @@ import org.jboss.seam.log.Log; import org.jboss.seam.resteasy.ResteasyBootstrap; import org.jboss.seam.resteasy.SeamResteasyProviderFactory; +import org.zanata.seam.resteasy.IgnoreInterfacePath; @Name("org.jboss.seam.resteasy.bootstrap") @Scope(ScopeType.APPLICATION) @@ -88,4 +90,41 @@ public void invoke(HttpRequest request, HttpResponse response) } }; } + + /** + * If the seam bean is annotated with @IgnoreInterfacePath, any @Path + * annotation on the bean's interfaces will be ignored when deciding whether + * to inject @Context variables based on the interface class or the bean + * class. + * @param annotation + * @param seamComponent + * @return + */ + @Override + protected Class getAnnotatedInterface(Class annotation, + Component seamComponent) + { + if (annotation == javax.ws.rs.Path.class && + hasAnnotation(seamComponent.getBeanClass(), IgnoreInterfacePath.class)) + { + return null; + } + else + { + return super.getAnnotatedInterface(annotation, seamComponent); + } + } + + private static boolean hasAnnotation(Class clazz, + Class type) + { + for (Annotation annotation : clazz.getAnnotations()) + { + if (annotation.annotationType() == type) + { + return true; + } + } + return false; + } } diff --git a/zanata-war/src/main/java/org/zanata/rest/service/AccountService.java b/zanata-war/src/main/java/org/zanata/rest/service/AccountService.java index d2f1db64bf..747c2c34c8 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/AccountService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/AccountService.java @@ -35,10 +35,12 @@ import org.zanata.model.HPerson; import org.zanata.rest.MediaTypes; import org.zanata.rest.dto.Account; +import org.zanata.seam.resteasy.IgnoreInterfacePath; @Name("accountService") @Path("/accounts/u/{username:[a-z\\d_]{3,20}}") @Transactional +@IgnoreInterfacePath public class AccountService implements AccountResource { diff --git a/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java b/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java index 168d5a4f25..7e4ae60371 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/AsynchronousProcessResourceService.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Set; import java.util.concurrent.ExecutionException; + import javax.ws.rs.DefaultValue; import javax.ws.rs.Path; import javax.ws.rs.PathParam; @@ -50,6 +51,7 @@ import org.zanata.rest.dto.ProcessStatus; import org.zanata.rest.dto.resource.Resource; import org.zanata.rest.dto.resource.TranslationsResource; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.security.ZanataIdentity; import org.zanata.service.AsyncTaskManagerService; import org.zanata.service.DocumentService; @@ -57,10 +59,10 @@ import org.zanata.service.TranslationService; import org.zanata.service.impl.DocumentServiceImpl; import org.zanata.service.impl.TranslationServiceImpl; + import com.google.common.collect.Lists; import lombok.extern.slf4j.Slf4j; - import static org.zanata.rest.dto.ProcessStatus.ProcessStatusCode; /** @@ -73,6 +75,7 @@ @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) @Transactional @Slf4j +@IgnoreInterfacePath public class AsynchronousProcessResourceService implements AsynchronousProcessResource { @In diff --git a/zanata-war/src/main/java/org/zanata/rest/service/CopyTransResourceService.java b/zanata-war/src/main/java/org/zanata/rest/service/CopyTransResourceService.java index 8c9adc91cd..6845e685d2 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/CopyTransResourceService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/CopyTransResourceService.java @@ -25,13 +25,13 @@ import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; -import org.jboss.seam.annotations.security.Restrict; import org.zanata.action.CopyTransManager; import org.zanata.async.tasks.CopyTransTask; import org.zanata.dao.DocumentDAO; import org.zanata.model.HDocument; import org.zanata.rest.NoSuchEntityException; import org.zanata.rest.dto.CopyTransStatus; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.security.ZanataIdentity; /** @@ -39,6 +39,7 @@ */ @Name("copyTransResourceService") @Path("/copytrans") +@IgnoreInterfacePath public class CopyTransResourceService implements CopyTransResource { @In diff --git a/zanata-war/src/main/java/org/zanata/rest/service/FileService.java b/zanata-war/src/main/java/org/zanata/rest/service/FileService.java index a3cb7ce381..dcd74487aa 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/FileService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/FileService.java @@ -66,6 +66,7 @@ import org.zanata.rest.dto.resource.Resource; import org.zanata.rest.dto.resource.TextFlowTarget; import org.zanata.rest.dto.resource.TranslationsResource; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.service.FileSystemService; import org.zanata.service.FileSystemService.DownloadDescriptorProperties; import org.zanata.service.TranslationFileService; @@ -78,6 +79,7 @@ @Path(FileResource.FILE_RESOURCE) @Produces( { MediaType.APPLICATION_OCTET_STREAM }) @Consumes( { MediaType.APPLICATION_OCTET_STREAM }) +@IgnoreInterfacePath public class FileService implements FileResource { private static final String FILE_TYPE_OFFLINE_PO = "offlinepo"; diff --git a/zanata-war/src/main/java/org/zanata/rest/service/GlossaryService.java b/zanata-war/src/main/java/org/zanata/rest/service/GlossaryService.java index 62d9a870b8..45c652ab9a 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/GlossaryService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/GlossaryService.java @@ -34,11 +34,13 @@ import org.zanata.rest.dto.Glossary; import org.zanata.rest.dto.GlossaryEntry; import org.zanata.rest.dto.GlossaryTerm; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.service.GlossaryFileService; @Name("glossaryService") @Path(GlossaryService.SERVICE_PATH) @Transactional +@IgnoreInterfacePath public class GlossaryService implements GlossaryResource { @Context diff --git a/zanata-war/src/main/java/org/zanata/rest/service/ProjectIterationService.java b/zanata-war/src/main/java/org/zanata/rest/service/ProjectIterationService.java index 5b6122ca7a..83cbcdbfc3 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/ProjectIterationService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/ProjectIterationService.java @@ -58,12 +58,14 @@ import org.zanata.model.validator.SlugValidator; import org.zanata.rest.MediaTypes; import org.zanata.rest.dto.ProjectIteration; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import com.google.common.base.Objects; @Name("projectIterationService") @Path(ProjectIterationService.SERVICE_PATH) @Transactional +@IgnoreInterfacePath public class ProjectIterationService implements ProjectIterationResource { diff --git a/zanata-war/src/main/java/org/zanata/rest/service/ProjectService.java b/zanata-war/src/main/java/org/zanata/rest/service/ProjectService.java index 81a7b52ced..b1d909ef70 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/ProjectService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/ProjectService.java @@ -45,12 +45,14 @@ import org.zanata.rest.dto.Link; import org.zanata.rest.dto.Project; import org.zanata.rest.dto.ProjectIteration; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import com.google.common.base.Objects; @Name("projectService") @Path(ProjectService.SERVICE_PATH) @Transactional +@IgnoreInterfacePath public class ProjectService implements ProjectResource { diff --git a/zanata-war/src/main/java/org/zanata/rest/service/ProjectsService.java b/zanata-war/src/main/java/org/zanata/rest/service/ProjectsService.java index 7b1ffbc408..3da10fc408 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/ProjectsService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/ProjectsService.java @@ -52,12 +52,14 @@ import org.zanata.rest.MediaTypes; import org.zanata.rest.dto.Link; import org.zanata.rest.dto.Project; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import com.google.common.base.Objects; @Name("projectsService") @Path("/projects") @Transactional +@IgnoreInterfacePath public class ProjectsService implements ProjectsResource { diff --git a/zanata-war/src/main/java/org/zanata/rest/service/SourceDocResourceService.java b/zanata-war/src/main/java/org/zanata/rest/service/SourceDocResourceService.java index 990f3bca46..6a9653ffdf 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/SourceDocResourceService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/SourceDocResourceService.java @@ -45,6 +45,7 @@ import org.zanata.rest.dto.resource.Resource; import org.zanata.rest.dto.resource.ResourceMeta; import org.zanata.rest.dto.resource.TextFlow; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.service.DocumentService; import org.zanata.service.LocaleService; @@ -67,6 +68,7 @@ import javax.ws.rs.core.Request; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; + import java.lang.reflect.Type; import java.net.URI; import java.util.ArrayList; @@ -83,6 +85,7 @@ @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Transactional +@IgnoreInterfacePath public class SourceDocResourceService implements SourceDocResource { public static final String SERVICE_PATH = ProjectIterationService.SERVICE_PATH + "/r"; diff --git a/zanata-war/src/main/java/org/zanata/rest/service/TranslatedDocResourceService.java b/zanata-war/src/main/java/org/zanata/rest/service/TranslatedDocResourceService.java index 380eb68eaf..29a50e8f9f 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/TranslatedDocResourceService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/TranslatedDocResourceService.java @@ -65,20 +65,23 @@ import org.zanata.model.HProjectIteration; import org.zanata.model.HTextFlowTarget; import org.zanata.rest.dto.resource.TranslationsResource; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.security.ZanataIdentity; import org.zanata.service.CopyTransService; import org.zanata.service.LocaleService; import org.zanata.service.TranslationService; + import com.google.common.base.Optional; +/** + * This service allows clients to push and pull both source documents and translations. + */ @Name("translatedDocResourceService") @Path(TranslatedDocResourceService.SERVICE_PATH) @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) @Transactional -/** - * This service allows clients to push and pull both source documents and translations. - */ +@IgnoreInterfacePath public class TranslatedDocResourceService implements TranslatedDocResource { diff --git a/zanata-war/src/main/java/org/zanata/rest/service/TranslationMemoryResourceService.java b/zanata-war/src/main/java/org/zanata/rest/service/TranslationMemoryResourceService.java index 201e85f861..5ca24602b4 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/TranslationMemoryResourceService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/TranslationMemoryResourceService.java @@ -49,6 +49,7 @@ import org.zanata.model.ITextFlow; import org.zanata.model.tm.TransMemory; import org.zanata.model.tm.TransMemoryUnit; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.service.LocaleService; import org.zanata.service.LockManagerService; import org.zanata.tmx.TMXParser; @@ -60,6 +61,7 @@ @Transactional(TransactionPropagationType.SUPPORTS) @Slf4j @ParametersAreNonnullByDefault +@IgnoreInterfacePath // TODO options to export obsolete docs and textflows to TMX? public class TranslationMemoryResourceService implements TranslationMemoryResource { diff --git a/zanata-war/src/main/java/org/zanata/rest/service/VersionService.java b/zanata-war/src/main/java/org/zanata/rest/service/VersionService.java index a2527a34af..ba653b16ae 100644 --- a/zanata-war/src/main/java/org/zanata/rest/service/VersionService.java +++ b/zanata-war/src/main/java/org/zanata/rest/service/VersionService.java @@ -10,11 +10,13 @@ import org.jboss.seam.annotations.Name; import org.zanata.rest.MediaTypes; import org.zanata.rest.dto.VersionInfo; +import org.zanata.seam.resteasy.IgnoreInterfacePath; import org.zanata.util.VersionUtility; @Name("versionService") @Path(VersionService.SERVICE_PATH) +@IgnoreInterfacePath public class VersionService implements VersionResource { public static final String SERVICE_PATH = "/version"; diff --git a/zanata-war/src/main/java/org/zanata/seam/resteasy/IgnoreInterfacePath.java b/zanata-war/src/main/java/org/zanata/seam/resteasy/IgnoreInterfacePath.java new file mode 100644 index 0000000000..1be523955f --- /dev/null +++ b/zanata-war/src/main/java/org/zanata/seam/resteasy/IgnoreInterfacePath.java @@ -0,0 +1,17 @@ +package org.zanata.seam.resteasy; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +/** + * Tells ZanataResteasyBootstrap to ignore the @Path annotation on any + * interfaces in favour of the Bean itself. + * @see org.zanata.rest.ZanataResteasyBootstrap#getAnnotatedInterface(Class, org.jboss.seam.Component) + */ +public @interface IgnoreInterfacePath +{ +} From 7a3bc998ad947e81ee10a1e89bd7a8e6180c23fe Mon Sep 17 00:00:00 2001 From: Sean Flanigan Date: Thu, 12 Sep 2013 13:52:51 +1000 Subject: [PATCH 2/2] Simplify annotation check --- .../org/zanata/rest/ZanataResteasyBootstrap.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java b/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java index fb25b2e098..d4663589e4 100644 --- a/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java +++ b/zanata-war/src/main/java/org/zanata/rest/ZanataResteasyBootstrap.java @@ -105,7 +105,8 @@ protected Class getAnnotatedInterface(Class annotation, Component seamComponent) { if (annotation == javax.ws.rs.Path.class && - hasAnnotation(seamComponent.getBeanClass(), IgnoreInterfacePath.class)) + seamComponent.getBeanClass().isAnnotationPresent( + IgnoreInterfacePath.class)) { return null; } @@ -115,16 +116,4 @@ protected Class getAnnotatedInterface(Class annotation, } } - private static boolean hasAnnotation(Class clazz, - Class type) - { - for (Annotation annotation : clazz.getAnnotations()) - { - if (annotation.annotationType() == type) - { - return true; - } - } - return false; - } }