cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1040191 - in /cxf/branches/2.3.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ systests/jaxrs/...
Date Mon, 29 Nov 2010 17:01:30 GMT
Author: sergeyb
Date: Mon Nov 29 17:01:30 2010
New Revision: 1040191

URL: http://svn.apache.org/viewvc?rev=1040191&view=rev
Log:
Merged revisions 1040187 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1040187 | sergeyb | 2010-11-29 16:51:57 +0000 (Mon, 29 Nov 2010) | 1 line
  
  [CXF-3155] Support for ApplicationPath and RuntimeDelegate.createEndpoint
........

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RuntimeDelegateImpl.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
    cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
    cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Nov 29 17:01:30 2010
@@ -1 +1 @@
-/cxf/trunk:1038206,1038374,1038386,1038722,1038746,1039039,1039197,1039504
+/cxf/trunk:1038206,1038374,1038386,1038722,1038746,1039039,1039197,1039504,1040187

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RuntimeDelegateImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RuntimeDelegateImpl.java?rev=1040191&r1=1040190&r2=1040191&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RuntimeDelegateImpl.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RuntimeDelegateImpl.java
Mon Nov 29 17:01:30 2010
@@ -33,6 +33,10 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.Variant.VariantListBuilder;
 import javax.ws.rs.ext.RuntimeDelegate;
 
+import org.apache.cxf.endpoint.Server;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.utils.ResourceUtils;
+
 
 
 public class RuntimeDelegateImpl extends RuntimeDelegate {
@@ -93,9 +97,19 @@ public class RuntimeDelegateImpl extends
 
 
     @Override
-    public <T> T createEndpoint(Application applicationConfig, Class<T> endpointType)

+    public <T> T createEndpoint(Application app, Class<T> endpointType) 
         throws IllegalArgumentException, UnsupportedOperationException {
-        throw new UnsupportedOperationException();
+        if (app == null || (!Server.class.isAssignableFrom(endpointType)
+            && !JAXRSServerFactoryBean.class.isAssignableFrom(endpointType))) {
+            throw new IllegalArgumentException();
+        }
+        JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, false);
+        if (JAXRSServerFactoryBean.class.isAssignableFrom(endpointType)) {
+            return endpointType.cast(bean);
+        }
+        bean.setStart(false);
+        Server server = bean.create();
+        return endpointType.cast(server);
     }
     
 

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java?rev=1040191&r1=1040190&r2=1040191&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/servlet/CXFNonSpringJaxrsServlet.java
Mon Nov 29 17:01:30 2010
@@ -20,21 +20,17 @@ package org.apache.cxf.jaxrs.servlet;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 import javax.ws.rs.core.Application;
-import javax.ws.rs.ext.Provider;
 
 import org.apache.cxf.common.classloader.ClassLoaderUtils;
 import org.apache.cxf.common.logging.LogUtils;
@@ -45,6 +41,7 @@ import org.apache.cxf.jaxrs.lifecycle.Re
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
 import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
 
 public class CXFNonSpringJaxrsServlet extends CXFNonSpringServlet {
@@ -53,6 +50,7 @@ public class CXFNonSpringJaxrsServlet ex
     
     private static final String USER_MODEL_PARAM = "user.model";
     private static final String SERVICE_ADDRESS_PARAM = "jaxrs.address";
+    private static final String IGNORE_APP_PATH_PARAM = "jaxrs.application.address.ignore";
     private static final String SERVICE_CLASSES_PARAM = "jaxrs.serviceClasses";
     private static final String PROVIDERS_PARAM = "jaxrs.providers";
     private static final String OUT_INTERCEPTORS_PARAM = "jaxrs.outInterceptors";
@@ -271,42 +269,8 @@ public class CXFNonSpringJaxrsServlet ex
                                        + " can not be instantiated due to IllegalAccessException");

         }
         
-        verifySingletons(app.getSingletons());
-        
-        List<Class> resourceClasses = new ArrayList<Class>();
-        List<Object> providers = new ArrayList<Object>();
-        Map<Class, ResourceProvider> map = new HashMap<Class, ResourceProvider>();
-        
-        // at the moment we don't support per-request providers, only resource classes
-        // Note, app.getClasse() returns a list of per-resource classes
-        for (Class<?> c : app.getClasses()) {
-            if (isValidPerRequestResourceClass(c, app.getSingletons())) {
-                resourceClasses.add(c);
-                map.put(c, new PerRequestResourceProvider(c));
-            }
-        }
-        
-        // we can get either a provider or resource class here        
-        for (Object o : app.getSingletons()) {
-            boolean isProvider = o.getClass().getAnnotation(Provider.class) != null;
-            if (isProvider) {
-                providers.add(o);
-            } else {
-                resourceClasses.add(o.getClass());
-                map.put(o.getClass(), new SingletonResourceProvider(o));
-            }
-        }
-        
-        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
-        bean.setAddress("/");
-        bean.setResourceClasses(resourceClasses);
-        bean.setProviders(providers);
-        for (Map.Entry<Class, ResourceProvider> entry : map.entrySet()) {
-            bean.setResourceProvider(entry.getKey(), entry.getValue());
-        }
-        setSchemasLocations(bean, servletConfig);
-        setInterceptors(bean, servletConfig, OUT_INTERCEPTORS_PARAM);
-        setInterceptors(bean, servletConfig, IN_INTERCEPTORS_PARAM);
+        String ignoreParam = servletConfig.getInitParameter(IGNORE_APP_PATH_PARAM);
+        JAXRSServerFactoryBean bean = ResourceUtils.createApplication(app, MessageUtils.isTrue(ignoreParam));
         
         bean.create();
     }
@@ -323,41 +287,5 @@ public class CXFNonSpringJaxrsServlet ex
         }
     }
     
-    private boolean isValidResourceClass(Class<?> c) {
-        if (c.isInterface() || Modifier.isAbstract(c.getModifiers())) {
-            LOG.info("Ignoring invalid resource class " + c.getName());
-            return false;
-        }
-        return true;
-    }
-    
-    private boolean isValidPerRequestResourceClass(Class<?> c, Set<Object> singletons)
{
-        if (!isValidResourceClass(c)) {
-            return false;
-        }
-        for (Object s : singletons) {
-            if (c == s.getClass()) {
-                LOG.info("Ignoring per-request resource class " + c.getName() 
-                         + " as it is also registered as singleton");
-                return false;
-            }
-        }
-        return true;
-    }
-    
     
-    private void verifySingletons(Set<Object> singletons) throws ServletException {
-        if (singletons.isEmpty()) {
-            return;
-        }
-        Set<String> map = new HashSet<String>(); 
-        for (Object s : singletons) {
-            if (map.contains(s.getClass().getName())) {
-                throw new ServletException("More than one instance of the same singleton
class "
-                                           + s.getClass().getName() + " is available"); 
-            } else {
-                map.add(s.getClass().getName());
-            }
-        }
-    }
 }

Modified: cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java?rev=1040191&r1=1040190&r2=1040191&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ResourceUtils.java
Mon Nov 29 17:01:30 2010
@@ -26,19 +26,23 @@ import java.io.InputStreamReader;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.util.Set;
 import java.util.logging.Logger;
 
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
+import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.CookieParam;
 import javax.ws.rs.Encoded;
 import javax.ws.rs.FormParam;
@@ -47,9 +51,11 @@ import javax.ws.rs.MatrixParam;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.Provider;
 import javax.xml.bind.JAXBElement;
 
 import org.w3c.dom.Document;
@@ -62,6 +68,10 @@ import org.apache.cxf.common.i18n.Bundle
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.helpers.DOMUtils;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.MethodDispatcher;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -525,4 +535,88 @@ public final class ResourceUtils {
         }
         return values;
     }
+    
+    public static JAXRSServerFactoryBean createApplication(Application app, boolean ignoreAppPath)
{
+        
+        Set<Object> singletons = app.getSingletons();
+        verifySingletons(singletons);
+        
+        List<Class> resourceClasses = new ArrayList<Class>();
+        List<Object> providers = new ArrayList<Object>();
+        Map<Class, ResourceProvider> map = new HashMap<Class, ResourceProvider>();
+        
+        // at the moment we don't support per-request providers, only resource classes
+        // Note, app.getClasse() returns a list of per-resource classes
+        for (Class<?> c : app.getClasses()) {
+            if (isValidPerRequestResourceClass(c, singletons)) {
+                resourceClasses.add(c);
+                map.put(c, new PerRequestResourceProvider(c));
+            }
+        }
+        
+        // we can get either a provider or resource class here        
+        for (Object o : singletons) {
+            boolean isProvider = o.getClass().getAnnotation(Provider.class) != null;
+            if (isProvider) {
+                providers.add(o);
+            } else {
+                resourceClasses.add(o.getClass());
+                map.put(o.getClass(), new SingletonResourceProvider(o));
+            }
+        }
+        
+        JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
+        String address = "/";
+        if (!ignoreAppPath) {
+            ApplicationPath appPath = app.getClass().getAnnotation(ApplicationPath.class);
+            if (appPath != null) {
+                address = appPath.value().isEmpty() ? "/" : appPath.value();
+            }
+        }
+        bean.setAddress(address);
+        bean.setResourceClasses(resourceClasses);
+        bean.setProviders(providers);
+        for (Map.Entry<Class, ResourceProvider> entry : map.entrySet()) {
+            bean.setResourceProvider(entry.getKey(), entry.getValue());
+        }
+        
+        return bean;
+    }
+    
+    private static void verifySingletons(Set<Object> singletons) {
+        if (singletons.isEmpty()) {
+            return;
+        }
+        Set<String> map = new HashSet<String>(); 
+        for (Object s : singletons) {
+            if (map.contains(s.getClass().getName())) {
+                throw new RuntimeException("More than one instance of the same singleton
class "
+                                           + s.getClass().getName() + " is available"); 
+            } else {
+                map.add(s.getClass().getName());
+            }
+        }
+    }
+    
+    public static boolean isValidResourceClass(Class<?> c) {
+        if (c.isInterface() || Modifier.isAbstract(c.getModifiers())) {
+            LOG.info("Ignoring invalid resource class " + c.getName());
+            return false;
+        }
+        return true;
+    }
+    
+    private static boolean isValidPerRequestResourceClass(Class<?> c, Set<Object>
singletons) {
+        if (!isValidResourceClass(c)) {
+            return false;
+        }
+        for (Object s : singletons) {
+            if (c == s.getClass()) {
+                LOG.info("Ignoring per-request resource class " + c.getName() 
+                         + " as it is also registered as singleton");
+                return false;
+            }
+        }
+        return true;
+    }
 }

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java?rev=1040191&r1=1040190&r2=1040191&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookApplication.java
Mon Nov 29 17:01:30 2010
@@ -21,8 +21,10 @@ package org.apache.cxf.systest.jaxrs;
 import java.util.HashSet;
 import java.util.Set;
 
+import javax.ws.rs.ApplicationPath;
 import javax.ws.rs.core.Application;
 
+@ApplicationPath("/thebooks")
 public class BookApplication extends Application {
 
     @Override

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java?rev=1040191&r1=1040190&r2=1040191&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerNonSpringBookTest.java
Mon Nov 29 17:01:30 2010
@@ -89,6 +89,14 @@ public class JAXRSClientServerNonSpringB
         
     }
     
+    @Test
+    public void testGetBook123Application11Singleton() throws Exception {
+        getAndCompareAsStrings("http://localhost:" + PORT + "/application11/thebooks/bookstore/books/123",
+                               "resources/expected_get_book123.txt",
+                               "application/xml", 200);
+        
+    }
+    
     private void getAndCompareAsStrings(String address, 
                                         String resourcePath,
                                         String acceptType,

Modified: cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml?rev=1040191&r1=1040190&r2=1040191&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
(original)
+++ cxf/branches/2.3.x-fixes/systests/jaxrs/src/test/resources/jaxrs_non_spring/WEB-INF/web.xml
Mon Nov 29 17:01:30 2010
@@ -50,6 +50,10 @@
 		      <param-value>org.apache.cxf.systest.jaxrs.BookApplication</param-value>
   
 		</init-param>
 		<init-param>
+		      <param-name>jaxrs.application.address.ignore</param-name>
+		      <param-value>true</param-value>    
+		</init-param>
+		<init-param>
 		      <param-name>jaxrs.outInterceptors</param-name>
 		      <param-value>org.apache.cxf.interceptor.LoggingOutInterceptor</param-value>
   
 		</init-param>
@@ -95,6 +99,20 @@
 		</init-param>
 		<load-on-startup>1</load-on-startup>
 	</servlet>
+	
+	<servlet>
+		<servlet-name>CXFServlet5</servlet-name>
+		<display-name>CXF Servlet5</display-name>
+		<servlet-class>
+			org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet
+		</servlet-class>
+		<init-param>
+		      <param-name>javax.ws.rs.Application</param-name>
+		      <param-value>org.apache.cxf.systest.jaxrs.BookApplication</param-value>
   
+		</init-param>
+		<load-on-startup>1</load-on-startup>
+	</servlet>
+	
 	<servlet-mapping>
 		<servlet-name>CXFServlet</servlet-name>
 		<url-pattern>/singleton/*</url-pattern>
@@ -115,5 +133,9 @@
 		<url-pattern>/usermodel2/*</url-pattern>
 	</servlet-mapping>
 	
+	<servlet-mapping>
+		<servlet-name>CXFServlet5</servlet-name>
+		<url-pattern>/application11/*</url-pattern>
+	</servlet-mapping>
 </web-app>
 <!-- END SNIPPET: webxml -->
\ No newline at end of file



Mime
View raw message