I have encountered an issue with the resteasy-spring module that
relates to RESTEASY-511. I have attached a git patch file that
contains a test case to demonstrate the problem (spring and rest not
sharing instances) and fixes that work with both my test case and the
other test cases in that module. Could someone let me know if this is
the right place to post patches and if there is anything else I need
to do to get the issue resolved in a future baseline?

thanks,
jim

Besides the testcase, the following represents the primary changes

--- 
a/resteasy-spring/src/main/java/org/jboss/resteasy/plugins/spring/SpringBeanProcessor.java
+++ 
b/resteasy-spring/src/main/java/org/jboss/resteasy/plugins/spring/SpringBeanProcessor.java
@@ -248,7 +248,8 @@ public class SpringBeanProcessor implements
BeanFactoryPostProcessor, SmartAppli
            continue;

         BeanDefinition beanDef = beanFactory.getBeanDefinition(name);
-         if (beanDef.getBeanClassName() == null || beanDef.isAbstract())
+         if ((beanDef.getBeanClassName() == null &&
beanDef.getFactoryBeanName() == null)
+                 || beanDef.isAbstract())
            continue;

         processBean(beanFactory, dependsOnProviders, name, beanDef);
@@ -395,7 +396,7 @@ public class SpringBeanProcessor implements
BeanFactoryPostProcessor, SmartAppli
            }
         }

-         for (Method method :
getBeanClass(factoryClassName).getDeclaredMethods())
+         for (Method method : getBeanClass(factoryClassName).getMethods())
         {
            if (method.getName().equals(factoryMethodName))
            {
From 9df38ca3af13059a16a23eb3dce1cdf65c1adea7 Mon Sep 17 00:00:00 2001
From: Jim Stafford <jcst...@apl.jhu.edu>
Date: Sat, 3 Mar 2012 17:19:49 -0500
Subject: [PATCH 1/2] added a testcase the demonstrates the JavaConfig issue

---
 .../spring/beanprocessor/ServerConfiguration.java  |    1 +
 .../test/javaconfig/JavaConfigApplication.java     |    8 +++
 .../spring/test/javaconfig/JavaConfigResource.java |   33 +++++++++++++
 .../spring/test/javaconfig/JavaConfigService.java  |   10 ++++
 .../spring/test/javaconfig/JavaConfigTest.java     |   45 ++++++++++++++++++
 .../spring/test/javaconfig/TestConfig.java         |   19 ++++++++
 .../src/test/resources/javaconfig/WEB-INF/web.xml  |   49 ++++++++++++++++++++
 .../src/test/resources/javaconfig/index.html       |    8 +++
 8 files changed, 173 insertions(+), 0 deletions(-)
 create mode 100644 resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigApplication.java
 create mode 100644 resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigResource.java
 create mode 100644 resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigService.java
 create mode 100644 resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigTest.java
 create mode 100644 resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/TestConfig.java
 create mode 100644 resteasy-spring/src/test/resources/javaconfig/WEB-INF/web.xml
 create mode 100644 resteasy-spring/src/test/resources/javaconfig/index.html

diff --git a/resteasy-spring/src/test/java/org/jboss/resteasy/spring/beanprocessor/ServerConfiguration.java b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/beanprocessor/ServerConfiguration.java
index b99a744..7627176 100644
--- a/resteasy-spring/src/test/java/org/jboss/resteasy/spring/beanprocessor/ServerConfiguration.java
+++ b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/beanprocessor/ServerConfiguration.java
@@ -1,6 +1,7 @@
 package org.jboss.resteasy.spring.beanprocessor;
 
 import org.jboss.resteasy.plugins.spring.EmbeddedContainerBean;
+
 import org.jboss.resteasy.plugins.spring.SpringBeanProcessor;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
diff --git a/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigApplication.java b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigApplication.java
new file mode 100644
index 0000000..86bce72
--- /dev/null
+++ b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigApplication.java
@@ -0,0 +1,8 @@
+package org.jboss.resteasy.spring.test.javaconfig;
+
+import javax.ws.rs.ApplicationPath;
+import javax.ws.rs.core.Application;
+
+@ApplicationPath("rest")
+public class JavaConfigApplication extends Application {
+}
diff --git a/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigResource.java b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigResource.java
new file mode 100644
index 0000000..10dde17
--- /dev/null
+++ b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigResource.java
@@ -0,0 +1,33 @@
+package org.jboss.resteasy.spring.test.javaconfig;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+
+import org.springframework.beans.factory.annotation.Autowired;
+
+/**
+ * This class provides a web-based facade for an injected service.
+ */
+@Path("")
+public class JavaConfigResource {
+    JavaConfigService service;
+    @Autowired
+    public void setService(JavaConfigService service) {
+        System.out.println("*** service injected=" + service);
+        this.service = service;
+    }    
+    
+    public JavaConfigResource() {
+        System.out.println("*** resource created:" + super.toString());
+    }
+    
+    
+    @GET
+    @Path("invoke")
+    @Produces(MediaType.TEXT_PLAIN)
+    public String invoke() {
+        return service.invoke();
+    }
+}
diff --git a/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigService.java b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigService.java
new file mode 100644
index 0000000..d18f60c
--- /dev/null
+++ b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigService.java
@@ -0,0 +1,10 @@
+package org.jboss.resteasy.spring.test.javaconfig;
+
+/**
+ * This POJO service bean will get injected into the resource.
+ */
+public class JavaConfigService {
+    public String invoke() {
+        return "hello";
+    }
+}
diff --git a/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigTest.java b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigTest.java
new file mode 100644
index 0000000..301767d
--- /dev/null
+++ b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/JavaConfigTest.java
@@ -0,0 +1,45 @@
+package org.jboss.resteasy.spring.test.javaconfig;
+
+import static org.junit.Assert.*;
+
+import java.io.InputStream;
+
+import org.jboss.resteasy.client.ClientRequest;
+import org.jboss.resteasy.client.ClientResponse;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.webapp.WebAppContext;
+
+import com.meterware.servletunit.ServletRunner;
+
+/**
+ * This test will verify that the resource invoked by RESTEasy has been
+ * initialized by spring when defined using spring's JavaConfig.
+ */
+public class JavaConfigTest {
+    private static final String CONTEXT_PATH = "/";
+    private static final String BASE_URL = "http://localhost:9092";;
+    private static final String PATH = "/rest/invoke";
+
+   @BeforeClass
+   public static void before() throws Exception {
+      Server server = new Server(9092);
+      WebAppContext context = new WebAppContext();
+      context.setResourceBase("src/test/resources/javaconfig");
+      context.setContextPath(CONTEXT_PATH);
+      context.setParentLoaderPriority(true);
+      server.setHandler(context);
+      server.start();
+   }
+
+   @Test
+   public void test() throws Exception {
+       ClientRequest request = new ClientRequest(BASE_URL + CONTEXT_PATH + PATH);
+       @SuppressWarnings("unchecked")
+    ClientResponse<String> response = request.get();
+       assertEquals("unexpected response code", 200, response.getResponseStatus().getStatusCode());
+       assertEquals("unexpected response msg", "hello", response.getEntity(String.class));
+   }
+}
diff --git a/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/TestConfig.java b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/TestConfig.java
new file mode 100644
index 0000000..4ddb7b8
--- /dev/null
+++ b/resteasy-spring/src/test/java/org/jboss/resteasy/spring/test/javaconfig/TestConfig.java
@@ -0,0 +1,19 @@
+package org.jboss.resteasy.spring.test.javaconfig;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * This java class defines the beans for the application.
+ */
+@Configuration
+public class TestConfig {    
+    @Bean
+    public JavaConfigService service() {
+        return new JavaConfigService();
+    }
+    @Bean
+    public JavaConfigResource resource() {
+        return new JavaConfigResource();
+    }
+}
diff --git a/resteasy-spring/src/test/resources/javaconfig/WEB-INF/web.xml b/resteasy-spring/src/test/resources/javaconfig/WEB-INF/web.xml
new file mode 100644
index 0000000..f528142
--- /dev/null
+++ b/resteasy-spring/src/test/resources/javaconfig/WEB-INF/web.xml
@@ -0,0 +1,49 @@
+<!DOCTYPE web-app PUBLIC
+        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+        "http://java.sun.com/dtd/web-app_2_3.dtd"; >
+
+<web-app>
+   <display-name>Spring JavaConfig-Powered Webapp Test</display-name>
+
+    <context-param>
+        <param-name>contextClass</param-name>
+        <param-value>
+            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
+        </param-value>    
+    </context-param>
+    <context-param>
+        <param-name>contextConfigLocation</param-name>
+        <param-value>org.jboss.resteasy.spring.test.javaconfig.TestConfig</param-value>
+    </context-param>
+    <context-param>
+        <param-name>resteasy.resources</param-name>
+        <param-value>org.jboss.resteasy.spring.test.javaconfig.JavaConfigResource</param-value>
+    </context-param>    
+    <context-param>
+        <param-name>resteasy.servlet.mapping.prefix</param-name>
+        <param-value>/rest</param-value>
+    </context-param>
+
+   <listener>
+      <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
+   </listener>
+   <listener>
+      <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
+   </listener>
+
+   <servlet>
+      <servlet-name>Resteasy</servlet-name>
+      <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
+        <init-param>
+             <param-name>javax.ws.rs.Application</param-name>
+             <param-value>org.jboss.resteasy.spring.test.javaconfig.JavaConfigApplication</param-value>
+         </init-param>
+      </servlet>
+
+   <servlet-mapping>
+      <servlet-name>Resteasy</servlet-name>
+      <url-pattern>/rest/*</url-pattern>
+   </servlet-mapping>
+
+</web-app>
+
diff --git a/resteasy-spring/src/test/resources/javaconfig/index.html b/resteasy-spring/src/test/resources/javaconfig/index.html
new file mode 100644
index 0000000..893d667
--- /dev/null
+++ b/resteasy-spring/src/test/resources/javaconfig/index.html
@@ -0,0 +1,8 @@
+<html>
+    <head>
+        <title>JavaConfig Test</title>
+    </head>
+<body>
+    <a href="/rest/invoke">Say Hello</a>
+</body>    
+</html>
\ No newline at end of file
-- 
1.7.0.4


From 4a7e4859d20a37c40032546e138b5305d27af56f Mon Sep 17 00:00:00 2001
From: Jim Stafford <jcst...@apl.jhu.edu>
Date: Sat, 3 Mar 2012 18:44:04 -0500
Subject: [PATCH 2/2] fixed issue I am having with JavaConfig created beans and test to work with rest of resteasy-spring tests

---
 resteasy-spring/pom.xml                            |   10 +++++-----
 .../plugins/spring/SpringBeanProcessor.java        |    5 +++--
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/resteasy-spring/pom.xml b/resteasy-spring/pom.xml
index aa7cdd2..7d594d0 100644
--- a/resteasy-spring/pom.xml
+++ b/resteasy-spring/pom.xml
@@ -9,7 +9,7 @@
     <groupId>org.jboss.resteasy</groupId>
     <artifactId>resteasy-spring</artifactId>
     <packaging>jar</packaging>
-    <version>2.3.2.Final</version>
+    <version>2.3.2.javacfg1</version>
     <name>Resteasy Spring integration</name>
     <description/>
 
@@ -48,17 +48,17 @@
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>resteasy-jaxrs</artifactId>
-            <version>${project.version}</version>
+    <version>2.3.2.Final</version>
         </dependency>
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>jaxrs-api</artifactId>
-            <version>${project.version}</version>
+    <version>2.3.2.Final</version>
         </dependency>
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>resteasy-jettison-provider</artifactId>
-            <version>${project.version}</version>
+    <version>2.3.2.Final</version>
         </dependency>
         <dependency>
             <groupId>org.springframework</groupId>
@@ -145,7 +145,7 @@
         <dependency>
             <groupId>org.jboss.resteasy</groupId>
             <artifactId>tjws</artifactId>
-            <version>${project.version}</version>
+    <version>2.3.2.Final</version>
             <scope>provided</scope>
         </dependency>
         <!--
diff --git a/resteasy-spring/src/main/java/org/jboss/resteasy/plugins/spring/SpringBeanProcessor.java b/resteasy-spring/src/main/java/org/jboss/resteasy/plugins/spring/SpringBeanProcessor.java
index ddc7cf6..9da6745 100644
--- a/resteasy-spring/src/main/java/org/jboss/resteasy/plugins/spring/SpringBeanProcessor.java
+++ b/resteasy-spring/src/main/java/org/jboss/resteasy/plugins/spring/SpringBeanProcessor.java
@@ -248,7 +248,8 @@ public class SpringBeanProcessor implements BeanFactoryPostProcessor, SmartAppli
             continue;
 
          BeanDefinition beanDef = beanFactory.getBeanDefinition(name);
-         if (beanDef.getBeanClassName() == null || beanDef.isAbstract())
+         if ((beanDef.getBeanClassName() == null && beanDef.getFactoryBeanName() == null)
+                 || beanDef.isAbstract())
             continue;
 
          processBean(beanFactory, dependsOnProviders, name, beanDef);
@@ -395,7 +396,7 @@ public class SpringBeanProcessor implements BeanFactoryPostProcessor, SmartAppli
             }
          }
 
-         for (Method method : getBeanClass(factoryClassName).getDeclaredMethods())
+         for (Method method : getBeanClass(factoryClassName).getMethods())
          {
             if (method.getName().equals(factoryMethodName))
             {
-- 
1.7.0.4

------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to