]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-6281: More changes to upgrade to RESTEasy 3.0.9
authorremillet <remillet@yahoo.com>
Thu, 16 Jul 2015 22:30:04 +0000 (15:30 -0700)
committerremillet <remillet@yahoo.com>
Thu, 16 Jul 2015 22:30:04 +0000 (15:30 -0700)
pom.xml
services/client/pom.xml
services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
services/common/src/main/java/org/collectionspace/services/common/publicitem/PublicItemResource.java
services/common/src/main/java/org/collectionspace/services/common/security/SecurityInterceptor.java
services/pom.xml

diff --git a/pom.xml b/pom.xml
index 065f6c5963add999ad12e445705e7efbadd40f7b..bf5bd6e6025aa9142d59f5de5562eea702d694a1 100644 (file)
--- a/pom.xml
+++ b/pom.xml
                        </snapshots>
                </repository>
 
+               <!--
                <repository>
                        <id>codehaus repo</id>
                        <name>codehaus repo</name>
                                <enabled>false</enabled>
                        </snapshots>
                </repository>
+               -->
 
                <repository>
                        <id>nuxeo-public</id>
index f9bb6ec3f9c5a2647903f686f742714d5a3ae451..80efbc41d04e00ec0cd32ac4723b5531b3c727a0 100644 (file)
             <groupId>commons-io</groupId>
             <artifactId>commons-io</artifactId>
         </dependency>
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+        </dependency>
+        <dependency>
+                       <groupId>org.apache.httpcomponents</groupId>
+                       <artifactId>httpclient</artifactId>
+                       <version>4.3.3</version>
+        </dependency>
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>resteasy-jaxrs</artifactId>
index b9102852f6f04bd65372e09085ff7e8a858c9580..2b85244e7e14016a7d17c1ed36e64059f6d71c05 100644 (file)
@@ -34,16 +34,15 @@ import javax.ws.rs.core.Response;
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope; //import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
-
+import org.apache.http.impl.client.DefaultHttpClient;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
 import org.collectionspace.services.jaxb.AbstractCommonList;
-
 import org.jboss.resteasy.client.ClientResponse; //import org.collectionspace.services.common.context.ServiceContext;
 import org.jboss.resteasy.client.ProxyFactory;
-import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor;
+import org.jboss.resteasy.client.core.executors.ApacheHttpClient4Executor;
+//import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor;
 import org.jboss.resteasy.plugins.providers.RegisterBuiltin;
 import org.jboss.resteasy.spi.ResteasyProviderFactory;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -75,6 +74,8 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
     private URL url;
     /** The http client. */
     private HttpClient httpClient;
+    private org.apache.http.client.HttpClient httpClient4;
+
     /** The RESTEasy proxy */
     private P proxy;
 
@@ -147,6 +148,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
     protected AbstractServiceClientImpl() {
         readProperties();
         setupHttpClient();
+        setupHttpClient4(); // temp fix for CSPACE-6281
         ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance();
         RegisterBuiltin.register(factory);
         setProxy();        
@@ -221,6 +223,10 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
         return httpClient;
     }
 
+    public org.apache.http.client.HttpClient getHttpClient4() {
+        return httpClient4;
+    }
+    
     /*
      * (non-Javadoc)
      *
@@ -342,6 +348,40 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
                e.printStackTrace();
        }
     }
+    
+    /*
+     * This is a temp fix for RESTEasy upgrade in CSPACE-6281.  The long-term solution will be to use
+     * the non-deprecated approach per the RESTEasy documentation.
+     */
+    public void setupHttpClient4() {
+       try {
+               this.httpClient4 = new DefaultHttpClient();
+               if (useAuth()) {
+                   String user = properties.getProperty(USER_PROPERTY);
+                   String password = properties.getProperty(PASSWORD_PROPERTY);
+                   if (logger.isDebugEnabled()) {
+                       logger.debug("setupHttpClient() using url=" + url + " user="
+                               + user + " password=" + password);
+                   }
+       
+                   httpClient.getState().setCredentials(
+                           new AuthScope(url.getHost(), url.getPort(),
+                           AuthScope.ANY_REALM),
+                           new UsernamePasswordCredentials(user, password));
+                   // JAXRS client library requires HTTP preemptive authentication
+                   httpClient.getParams().setAuthenticationPreemptive(true);
+                   if (logger.isDebugEnabled()) {
+                       logger.debug("setupHttpClient: set preemptive authentication");
+                   }
+               } else {
+                   if (logger.isDebugEnabled()) {
+                       logger.debug("setupHttpClient() : no auth mode!");
+                   }
+               }
+       } catch (Throwable e) {
+               e.printStackTrace();
+       }
+    }    
 
     /*
      * (non-Javadoc)
@@ -368,7 +408,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
        Class<P> proxyClass = this.getProxyClass();
         if (useAuth()) {
             proxy = ProxyFactory.create(proxyClass,
-                    getBaseURL(), new ApacheHttpClientExecutor(getHttpClient()));
+                    getBaseURL(), new ApacheHttpClient4Executor(getHttpClient4()));
         } else {
                proxy = ProxyFactory.create(proxyClass,
                     getBaseURL());
@@ -397,6 +437,7 @@ public abstract class AbstractServiceClientImpl<CLT, REQUEST_PT, RESPONSE_PT, P
             removeProperty(CollectionSpaceClient.AUTH_PROPERTY);
         }
         setupHttpClient();
+        setupHttpClient(); // temp fix for CSPACE-6281
         setProxy();
     }
     
index 5ec16b6f9a23ffde300bbd7e6f8b109c88e173a6..d9361b40adf83bcee1275e0951048162bb78ce54 100644 (file)
@@ -46,8 +46,9 @@ import org.collectionspace.services.common.repository.RepositoryClientFactory;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.common.storage.StorageClient;
 import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;
-import org.jboss.resteasy.core.ResourceMethod;
+//import org.jboss.resteasy.core.ResourceMethod;
 import org.jboss.resteasy.spi.HttpRequest;
+import org.jboss.resteasy.spi.metadata.ResourceMethod;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
index c8bec4b507198e33c2039eea426d695b4ab59d52..9a56bf45846d29d2ccca725e7a586171e12d9c69 100644 (file)
  */
 package org.collectionspace.services.common;
 
+import java.lang.reflect.Method;
+
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.context.ServiceContextFactory;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.storage.StorageClient;
-import org.jboss.resteasy.core.ResourceMethod;
+//import org.jboss.resteasy.core.ResourceMethod;
 import org.jboss.resteasy.spi.HttpRequest;
+import org.jboss.resteasy.spi.metadata.ResourceMethod;
 
 /**
  * The Interface CollectionSpaceResource.
@@ -94,6 +97,6 @@ public interface CollectionSpaceResource<IT, OT> {
      */
 //                     <sec:filter-chain pattern="/publicitems/*/*/content"
 //                              filters="none"/>
-       public boolean allowAnonymousAccess(HttpRequest request, ResourceMethod method);
+       public boolean allowAnonymousAccess(HttpRequest request, Method method);
     
 }
index cac53c19d72545acdcc79a26ec6c62097e36733c..f105b0c112c47f6c2fa0273fe5602cde0d1d9e72 100644 (file)
@@ -24,6 +24,7 @@
 package org.collectionspace.services.common.publicitem;
 
 import java.io.InputStream;
+import java.lang.reflect.Method;
 
 import org.collectionspace.authentication.spi.AuthNContext;
 import org.collectionspace.services.publicitem.PublicitemsCommon;
@@ -35,9 +36,9 @@ import org.collectionspace.services.common.ServiceMessages;
 import org.collectionspace.services.common.blob.BlobOutput;
 import org.collectionspace.services.common.context.RemoteServiceContext;
 import org.collectionspace.services.common.imaging.nuxeo.NuxeoBlobUtils;
-import org.jboss.resteasy.core.ResourceMethod;
+//import org.jboss.resteasy.core.ResourceMethod;
 import org.jboss.resteasy.spi.HttpRequest;
-
+import org.jboss.resteasy.spi.metadata.ResourceMethod;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -76,7 +77,7 @@ public class PublicItemResource extends NuxeoBasedResource {
 
        @Override
        public boolean allowAnonymousAccess(HttpRequest request,
-                       ResourceMethod method) {
+                       Method method) {
                return true;
        }
        
index d244a17a9cc9ce35812dc8f67075b649012df49e..2f16595921e166b60c765f425fc3f0ecd125f44f 100644 (file)
  */
 package org.collectionspace.services.common.security;
 
+import java.lang.reflect.Method;
 import java.security.Principal;
 import java.util.HashMap;
 import java.util.Set;
 
-import org.jboss.resteasy.core.ResourceMethod;
+//import org.jboss.resteasy.core.ResourceMethod;
+import org.jboss.resteasy.core.ResourceMethodInvoker;
 import org.jboss.resteasy.core.ServerResponse;
 import org.jboss.resteasy.spi.interception.PostProcessInterceptor;
 import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
@@ -39,7 +41,6 @@ import org.jboss.resteasy.annotations.interception.SecurityPrecedence;
 import org.jboss.resteasy.annotations.interception.ServerInterceptor;
 import org.jboss.resteasy.spi.Failure;
 import org.jboss.resteasy.spi.HttpRequest;
-
 import org.nuxeo.runtime.api.Framework;
 
 import javax.security.auth.Subject;
@@ -58,7 +59,6 @@ import org.collectionspace.services.common.CollectionSpaceResource;
 import org.collectionspace.services.common.document.JaxbUtils;
 import org.collectionspace.services.common.storage.jpa.JpaStorageUtils;
 import org.collectionspace.services.common.security.SecurityUtils;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -89,10 +89,10 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
     private static final String ERROR_NUXEO_LOGOUT = "Attempt to logout when Nuxeo login context was null";
     private static final String ERROR_UNBALANCED_LOGINS = "The number of Logins vs Logouts to the Nuxeo framework was unbalanced.";    
            
-    private boolean isAnonymousRequest(HttpRequest request, ResourceMethod resourceMethod) {
+    private boolean isAnonymousRequest(HttpRequest request, Method resourceMethod) {
        boolean result = false;
        
-               Class<?> resourceClass = resourceMethod.getResourceClass();
+               Class<?> resourceClass = resourceMethod.getClass();
                try {
                        CollectionSpaceResource resourceInstance = (CollectionSpaceResource)resourceClass.newInstance();
                        result = resourceInstance.allowAnonymousAccess(request, resourceMethod);
@@ -109,9 +109,10 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
         * @see org.jboss.resteasy.spi.interception.PreProcessInterceptor#preProcess(org.jboss.resteasy.spi.HttpRequest, org.jboss.resteasy.core.ResourceMethod)
         */
        @Override
-       public ServerResponse preProcess(HttpRequest request, ResourceMethod resourceMethod)
+       public ServerResponse preProcess(HttpRequest request, ResourceMethodInvoker resourceMethodInvoker)
                        throws Failure, CSWebApplicationException {
                ServerResponse result = null; // A null value essentially means success for this method
+               Method resourceMethod = resourceMethodInvoker.getMethod();
                
                try {
                        if (isAnonymousRequest(request, resourceMethod) == true) {
@@ -268,7 +269,7 @@ public class SecurityInterceptor implements PreProcessInterceptor, PostProcessIn
        //
        // Nuxeo login support
        //
-       public ServerResponse nuxeoPreProcess(HttpRequest request, ResourceMethod resourceMethod)
+       public ServerResponse nuxeoPreProcess(HttpRequest request, Method resourceMethod)
                        throws Failure, CSWebApplicationException {
                try {
                        nuxeoLogin();
index 92f195f956e75a0f0de370d4580ed469851e11b6..d62e7c05a229aacae8653450d5062f08dd7add81 100644 (file)
@@ -16,6 +16,7 @@
                <jaxb2-basics.version>0.6.2</jaxb2-basics.version>
                <maven-jaxb2-plugin.version>0.12.3</maven-jaxb2-plugin.version>
                <jaxb.version>2.2.4-1</jaxb.version>
+               <resteasy.version>3.0.9.Final</resteasy.version>
                <mysql.driver.version>5.1.8</mysql.driver.version>
                <postgres.driver.version>9.1-901.jdbc4</postgres.driver.version>
                <!-- The default life cycle policy for Nuxeo document types -->
             <dependency>
                 <groupId>org.jboss.resteasy</groupId>
                 <artifactId>jaxrs-api</artifactId>
-                <version>2.2.2.GA</version>
+                <version>${resteasy.version}</version>
             </dependency>
             <dependency>
                 <groupId>org.jboss.resteasy</groupId>
                 <artifactId>resteasy-jaxrs</artifactId>
-                <version>2.2.2.GA</version>
+                <version>${resteasy.version}</version>
             </dependency>
             <dependency>
                 <groupId>org.jboss.resteasy</groupId>
                 <artifactId>resteasy-jaxb-provider</artifactId>
-                <version>2.2.2.GA</version>
+                <version>${resteasy.version}</version>
             </dependency>
             <dependency>
                 <groupId>org.jboss.resteasy</groupId>
                 <artifactId>resteasy-multipart-provider</artifactId>
-                <version>2.2.2.GA</version>
+                <version>${resteasy.version}</version>
             </dependency>
             <dependency>
                 <groupId>commons-httpclient</groupId>