cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r590613 - in /incubator/cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ rt/frontend/jaxws/src/main/...
Date Wed, 31 Oct 2007 10:12:22 GMT
Author: jliu
Date: Wed Oct 31 03:12:17 2007
New Revision: 590613

URL: http://svn.apache.org/viewvc?rev=590613&view=rev
Log:
more lifecycle supports in JSR-311 impl. CXF-1151. now support setting lifecycle through APIs
or through spring configuration, will add annotation support later.
 

Added:
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
  (with props)
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
  (with props)
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
  (with props)
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
  (with props)
Modified:
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
    incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=590613&r1=590612&r2=590613&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
Wed Oct 31 03:12:17 2007
@@ -57,10 +57,6 @@
         return invoke(exchange, resourceObject, m, params);
     }
 
-    
-    // REVISIT: Not sure how to deal with Resource class life cycle. The current
-    // spec suggests two models, per-request and singleton, and it is the
-    // reponsibility of JSR-311 runtime to create resource instances.
     public Object getServiceObject(Exchange exchange) {
         Object serviceObject = null;
         
@@ -77,11 +73,7 @@
         }
         
         if (serviceObject == null) {
-            try {
-                serviceObject = classResourceInfo.getResourceClass().newInstance();
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            serviceObject = classResourceInfo.getResourceProvider().getInstance();
         }
         
         return serviceObject;

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=590613&r1=590612&r2=590613&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Wed Oct 31 03:12:17 2007
@@ -34,6 +34,7 @@
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.feature.AbstractFeature;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.factory.ServiceConstructionException;
 import org.apache.cxf.service.invoker.Invoker;
@@ -62,7 +63,6 @@
     private JAXRSServiceFactoryBean serviceFactory;
     private List<Object> serviceBeans;
 
-
     public JAXRSServerFactoryBean() {
         this(new JAXRSServiceFactoryBean());
         doInit = true;
@@ -231,17 +231,30 @@
     }
     
     /**
-     * Set the backing service bean. If this is set a BeanInvoker is created for
-     * the provided bean.
+     * Set the backing service bean. If this is set, JAX-RS runtimi will not be
+     * responsible for the lifecycle of resource classes.
      * 
      * @return
      */
     public void setServiceBeans(Object... beans) {
         this.serviceBeans = new ArrayList<Object>(Arrays.asList(beans));
+        Class[] classes = new Class[beans.length];
+        for (int i = 0; i < beans.length; i++) {
+            classes[i] = beans[i].getClass();
+        }
+        serviceFactory.setResourceClasses(classes);
     }
     
     public void setServiceBeans(List<Object> beans) {
         this.serviceBeans = beans;
+        List<Class> classes = new ArrayList<Class>();
+        for (Object bean : beans) {
+            classes.add(bean.getClass());
+        }
+        serviceFactory.setResourceClasses(classes);
+    }
+    
+    public void setResourceProvider(Class c, ResourceProvider rp) {
+        serviceFactory.setResourceProvider(c, rp);
     }
-
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java?rev=590613&r1=590612&r2=590613&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
Wed Oct 31 03:12:17 2007
@@ -22,6 +22,7 @@
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executor;
@@ -29,6 +30,8 @@
 import javax.ws.rs.HttpMethod;
 import javax.ws.rs.UriTemplate;
 
+import org.apache.cxf.jaxrs.lifecycle.PerRequestResourceProvider;
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.MethodDispatcher;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -48,7 +51,8 @@
 
     protected List<ClassResourceInfo> classResourceInfos;
     protected List<Class> resourceClasses;
-
+    protected Map<Class, ResourceProvider> resourceProviders = new HashMap<Class,
ResourceProvider>();
+    
     private Invoker invoker;
     private Executor executor;
     private Map<String, Object> properties;
@@ -105,7 +109,11 @@
     public void setResourceClasses(Class... classes) {
         this.resourceClasses = new ArrayList<Class>(Arrays.asList(classes));
     }
-
+    
+    public void setResourceProvider(Class c, ResourceProvider rp) {
+        resourceProviders.put(c, rp);
+    }
+    
     protected void initializeServiceModel() {
         classResourceInfos = new ArrayList<ClassResourceInfo>();
 
@@ -124,26 +132,38 @@
     }
 
     protected ClassResourceInfo createClassResourceInfo(final Class<?> c) {
-        final UriTemplate annotation = c.getAnnotation(UriTemplate.class);
-        if (annotation == null) {
+        UriTemplate uriTemplateAnnotation = c.getAnnotation(UriTemplate.class);
+        if (uriTemplateAnnotation == null) {
             return null;
         }
 
-        ClassResourceInfo resourceClass = getClassResourceInfo(c);
+        ClassResourceInfo classResourceInfo = getClassResourceInfo(c);
 
-        MethodDispatcher md = createOperation(c, resourceClass);
-        resourceClass.setMethodDispatcher(md);
+        MethodDispatcher md = createOperation(c, classResourceInfo);
+        classResourceInfo.setMethodDispatcher(md);
         
-        String annotationValue = annotation.value();
+        String annotationValue = uriTemplateAnnotation.value();
         if (!annotationValue.startsWith("/")) {
             annotationValue = "/" + annotationValue;
         }
-        String rightHandPattern = (resourceClass.hasSubResources())
+        String rightHandPattern = (classResourceInfo.hasSubResources())
             ? URITemplate.SUB_RESOURCE_REGEX_SUFFIX : URITemplate.NONE_SUB_RESOURCE_REGEX_SUFFIX;
         URITemplate t = new URITemplate(annotationValue, rightHandPattern);
-        resourceClass.setURITemplate(t);
+        classResourceInfo.setURITemplate(t);
+        
+        //TODO: Using information from annotation to determine which lifecycle provider to
use
+        ResourceProvider rp = resourceProviders.get(c);
+        if (rp != null) {
+            rp.setResourceClass(c);
+            classResourceInfo.setResourceProvider(rp);
+        } else {
+            //default lifecycle is per-request
+            rp = new PerRequestResourceProvider();
+            rp.setResourceClass(c);
+            classResourceInfo.setResourceProvider(rp);  
+        }
         
-        return resourceClass;
+        return classResourceInfo;
     }
 
     protected ClassResourceInfo getClassResourceInfo(final Class<?> c) {

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java?rev=590613&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
Wed Oct 31 03:12:17 2007
@@ -0,0 +1,43 @@
+/**
+ * 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 org.apache.cxf.jaxrs.lifecycle;
+
+public class PerRequestResourceProvider implements ResourceProvider {
+    private Class<?> resourceClass;
+   
+    public PerRequestResourceProvider() {
+    }
+    
+    public void setResourceClass(Class<?> clazz) {
+        this.resourceClass = clazz;        
+    }
+
+    public Object getInstance() {  
+        Object resourceInstance = null;
+        try {
+            resourceInstance = resourceClass.newInstance();
+        } catch (InstantiationException ex) {
+            //TODO
+        } catch (IllegalAccessException ex) {
+            //TODO
+        }        
+        return resourceInstance;
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/PerRequestResourceProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java?rev=590613&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
Wed Oct 31 03:12:17 2007
@@ -0,0 +1,26 @@
+/**
+ * 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 org.apache.cxf.jaxrs.lifecycle;
+
+public interface ResourceProvider {
+
+    Object getInstance();
+    void setResourceClass(Class<?> clazz);
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/ResourceProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java?rev=590613&view=auto
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
Wed Oct 31 03:12:17 2007
@@ -0,0 +1,47 @@
+/**
+ * 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 org.apache.cxf.jaxrs.lifecycle;
+
+public class SingletonResourceProvider implements ResourceProvider {
+    private Class<?> resourceClass;
+    private Object resourceInstance;
+    
+    public SingletonResourceProvider() {
+    }
+    
+    public void setResourceClass(Class<?> clazz) {
+        this.resourceClass = clazz;        
+    }
+
+    public Object getInstance() {
+        if (resourceInstance != null) {
+            return resourceInstance;
+        }
+        
+        try {
+            resourceInstance = resourceClass.newInstance();
+        } catch (InstantiationException ex) {
+            //TODO
+        } catch (IllegalAccessException ex) {
+            //TODO
+        }        
+        return resourceInstance;
+    }
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/lifecycle/SingletonResourceProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java?rev=590613&r1=590612&r2=590613&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/ClassResourceInfo.java
Wed Oct 31 03:12:17 2007
@@ -19,12 +19,14 @@
 
 package org.apache.cxf.jaxrs.model;
 
+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;
 
 public class ClassResourceInfo {
     private Class resourceClass;
     private URITemplate uriTemplate;
     private MethodDispatcher methodDispatcher;
     private boolean hasSubResources;
+    private ResourceProvider resourceProvider;
 
     public ClassResourceInfo(Class theResourceClass) {
         resourceClass = theResourceClass;
@@ -57,4 +59,13 @@
     public void setHasSubResources(boolean flag) {
         hasSubResources = flag;
     }
+    
+
+    public ResourceProvider getResourceProvider() {
+        return resourceProvider;
+    }
+
+    public void setResourceProvider(ResourceProvider rp) {
+        resourceProvider = rp;
+    }    
 }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java?rev=590613&r1=590612&r2=590613&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WebFaultOutInterceptor.java
Wed Oct 31 03:12:17 2007
@@ -36,7 +36,6 @@
 import org.apache.cxf.databinding.DataWriter;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.interceptor.FaultOutInterceptor;
-import org.apache.cxf.jaxws.support.JaxWsServiceConfiguration;
 import org.apache.cxf.message.FaultMode;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.service.Service;
@@ -48,7 +47,7 @@
 public class WebFaultOutInterceptor extends FaultOutInterceptor {
 
     private static final Logger LOG = LogUtils.getL7dLogger(WebFaultOutInterceptor.class);
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JaxWsServiceConfiguration.class);
+    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(WebFaultOutInterceptor.class);
 
     public WebFaultOutInterceptor() {
         super();

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java?rev=590613&r1=590612&r2=590613&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
Wed Oct 31 03:12:17 2007
@@ -22,15 +22,16 @@
 
 import org.apache.cxf.jaxrs.JAXRSBindingFactory;
 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
 import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
     
 public class BookServer extends AbstractBusTestServerBase {
 
     protected void run() {
         JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
-        BookStore bs = new BookStore();
-        sf.setServiceBeans(bs);
         sf.setResourceClasses(BookStore.class);
+        //default lifecycle is per-request, change it to singleton
+        sf.setResourceProvider(BookStore.class, new SingletonResourceProvider());
         sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
         sf.setAddress("http://localhost:9080/");
 

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java?rev=590613&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
Wed Oct 31 03:12:17 2007
@@ -0,0 +1,50 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs;
+
+
+import org.apache.cxf.jaxrs.JAXRSBindingFactory;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+    
+public class BookServerFromResourceInstance extends AbstractBusTestServerBase {
+
+    protected void run() {
+        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+        BookStore bs = new BookStore();
+        sf.setServiceBeans(bs);
+        sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
+        sf.setAddress("http://localhost:9080/");
+
+        sf.create();        
+    }
+
+    public static void main(String[] args) {
+        try {
+            BookServer s = new BookServer();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookServerFromResourceInstance.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=590613&r1=590612&r2=590613&view=diff
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Wed Oct 31 03:12:17 2007
@@ -23,7 +23,6 @@
 import java.io.InputStream;
 import java.net.URL;
 
-
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.FileRequestEntity;
 import org.apache.commons.httpclient.methods.PostMethod;
@@ -34,7 +33,6 @@
 import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
 import org.junit.BeforeClass;
 import org.junit.Test;
-
 
 public class JAXRSClientServerBookTest extends AbstractBusClientServerTestBase {
 

Added: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java?rev=590613&view=auto
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
(added)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
Wed Oct 31 03:12:17 2007
@@ -0,0 +1,62 @@
+/**
+ * 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 org.apache.cxf.systest.jaxrs;
+
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.io.CachedOutputStream;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JAXRSClientServerFromResourceInstanceBookTest extends AbstractBusClientServerTestBase
{
+
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly", launchServer(BookServerFromResourceInstance.class));
+    }
+    
+    @Test
+    public void testGetBook123() throws Exception {
+        
+        String endpointAddress =
+            "http://localhost:9080/bookstore/books/123"; 
+        URL url = new URL(endpointAddress);
+        InputStream in = url.openStream();
+        assertNotNull(in);           
+
+        InputStream expected = getClass()
+            .getResourceAsStream("resources/expected_get_book123.txt");
+
+        assertEquals(getStringFromInputStream(expected), getStringFromInputStream(in)); 
+    }
+
+    private String getStringFromInputStream(InputStream in) throws Exception {        
+        CachedOutputStream bos = new CachedOutputStream();
+        IOUtils.copy(in, bos);
+        in.close();
+        bos.close();
+        //System.out.println(bos.getOut().toString());        
+        return bos.getOut().toString();        
+    }
+
+}

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerFromResourceInstanceBookTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message