cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r746947 - in /cxf/trunk: distribution/bundle/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ rt/transp...
Date Mon, 23 Feb 2009 10:15:36 GMT
Author: sergeyb
Date: Mon Feb 23 10:15:34 2009
New Revision: 746947

URL: http://svn.apache.org/viewvc?rev=746947&view=rev
Log:
JAXRS: client api support for bus configuration and outbound chains, more updates to follow shortly 

Added:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java   (with props)
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/BookHttpsServer.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java   (with props)
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml   (with props)
Modified:
    cxf/trunk/distribution/bundle/jaxrs/pom.xml
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
    cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java

Modified: cxf/trunk/distribution/bundle/jaxrs/pom.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/distribution/bundle/jaxrs/pom.xml?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/distribution/bundle/jaxrs/pom.xml (original)
+++ cxf/trunk/distribution/bundle/jaxrs/pom.xml Mon Feb 23 10:15:34 2009
@@ -115,11 +115,9 @@
                             antlr*;resolution:=optional,
                             com.ibm*;resolution:=optional,
                             com.sun*;resolution:=optional,
-                            javax.jms*;resolution:=optional,
-                            javax.ws.rs*;resolution:=optional,
+                            javax.ws.rs*,
                             repackage;resolution:=optional,
                             javax.resource*;resolution:=optional,
-                            javax.xml.soap,
                             junit.framework*;resolution:=optional,
                             org.apache.abdera*;resolution:=optional,
                             org.apache.commons.lang*;resolution:=optional,
@@ -127,7 +125,6 @@
                             org.apache.log4j*;resolution:=optional,
                             org.apache.velocity*;resolution:=optional,
                             org.apache.xmlbeans*;resolution:=optional,
-                            org.apache.ws.security*;resolution:=optional,
                             org.codehaus.jra*;resolution:=optional,
                             org.codehaus.jettison*;resolution:=optional,
                             org.jaxen*;resolution:=optional,

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java?rev=746947&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/AbstractJAXRSFactoryBean.java Mon Feb 23 10:15:34 2009
@@ -0,0 +1,163 @@
+/**
+ * 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;
+
+import org.apache.cxf.BusException;
+import org.apache.cxf.binding.BindingConfiguration;
+import org.apache.cxf.binding.BindingFactory;
+import org.apache.cxf.binding.BindingFactoryManager;
+import org.apache.cxf.endpoint.AbstractEndpointFactory;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.endpoint.EndpointException;
+import org.apache.cxf.endpoint.EndpointImpl;
+import org.apache.cxf.service.Service;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.transport.DestinationFactory;
+import org.apache.cxf.transport.DestinationFactoryManager;
+
+
+/**
+ * Bean to help easily create Server endpoints for JAX-RS. Example:
+ * <pre>
+ * JAXRSServerFactoryBean sf = JAXRSServerFactoryBean();
+ * sf.setResourceClasses(Book.class);
+ * sf.setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
+ * sf.setAddress("http://localhost:9080/");
+ * sf.create();
+ * </pre>
+ * This will start a server for you and register it with the ServerManager.
+ */
+public class AbstractJAXRSFactoryBean extends AbstractEndpointFactory {
+    
+    protected JAXRSServiceFactoryBean serviceFactory;
+    
+    protected AbstractJAXRSFactoryBean() {
+        this(new JAXRSServiceFactoryBean());
+    }
+    
+    protected AbstractJAXRSFactoryBean(JAXRSServiceFactoryBean serviceFactory) {
+        this.serviceFactory = serviceFactory;
+        setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
+    }
+    
+    
+    /*
+     * EndpointInfo contains information form WSDL's physical part such as
+     * endpoint address, binding, transport etc. For JAX-RS based EndpointInfo,
+     * as there is no WSDL, these information are set manually, eg, default
+     * transport is http, binding is JAX-RS binding, endpoint address is from
+     * server mainline.
+     */    
+    protected EndpointInfo createEndpointInfo() throws BusException {
+        String transportId = getTransportId();
+        if (transportId == null && getAddress() != null) {
+            DestinationFactory df = getDestinationFactory();
+            if (df == null) {
+                DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
+                df = dfm.getDestinationFactoryForUri(getAddress());
+            }
+
+            if (df != null) {
+                transportId = df.getTransportIds().get(0);
+            }
+        }
+
+        //default to http transport
+        if (transportId == null) {
+            transportId = "http://schemas.xmlsoap.org/wsdl/soap/http";
+        }
+
+        setTransportId(transportId);
+
+        EndpointInfo ei = new EndpointInfo();
+        ei.setTransportId(transportId);
+        ei.setName(serviceFactory.getService().getName());
+        ei.setAddress(getAddress());        
+
+        BindingInfo bindingInfo = createBindingInfo();
+        ei.setBinding(bindingInfo);
+
+        return ei;
+    }
+
+    protected BindingInfo createBindingInfo() {
+        BindingFactoryManager mgr = getBus().getExtension(BindingFactoryManager.class);
+        String binding = getBindingId();
+        BindingConfiguration bindingConfig = getBindingConfig();
+
+        if (binding == null && bindingConfig != null) {
+            binding = bindingConfig.getBindingId();
+        }
+
+        if (binding == null) {
+            binding = JAXRSBindingFactory.JAXRS_BINDING_ID;
+        }
+
+        try {
+            BindingFactory bindingFactory = mgr.getBindingFactory(binding);
+            setBindingFactory(bindingFactory);
+            return bindingFactory.createBindingInfo(serviceFactory.getService(),
+                                                    binding, bindingConfig);
+        } catch (BusException ex) {
+            ex.printStackTrace();
+            //do nothing
+        }
+        return null;
+    }
+
+    public JAXRSServiceFactoryBean getServiceFactory() {
+        return serviceFactory;
+    }
+
+    public void setServiceFactory(JAXRSServiceFactoryBean serviceFactory) {
+        this.serviceFactory = serviceFactory;
+    }
+
+    protected Endpoint createEndpoint() throws BusException, EndpointException {
+        Service service = serviceFactory.getService();
+
+        if (service == null) {
+            service = serviceFactory.create();
+        }
+
+        EndpointInfo ei = createEndpointInfo();
+        Endpoint ep = new EndpointImpl(getBus(), getServiceFactory().getService(), ei);
+        
+        if (properties != null) {
+            ep.putAll(properties);
+        }
+        
+        if (getInInterceptors() != null) {
+            ep.getInInterceptors().addAll(getInInterceptors());
+        }
+        if (getOutInterceptors() != null) {
+            ep.getOutInterceptors().addAll(getOutInterceptors());
+        }
+        if (getInFaultInterceptors() != null) {
+            ep.getInFaultInterceptors().addAll(getInFaultInterceptors());
+        }
+        if (getOutFaultInterceptors() != null) {
+            ep.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
+        }
+        return ep;
+    }
+    
+
+}

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java Mon Feb 23 10:15:34 2009
@@ -20,34 +20,28 @@
 
 import java.io.IOException;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 import org.apache.cxf.BusException;
-import org.apache.cxf.binding.BindingConfiguration;
-import org.apache.cxf.binding.BindingFactory;
-import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.endpoint.AbstractEndpointFactory;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.endpoint.EndpointException;
-import org.apache.cxf.endpoint.EndpointImpl;
 import org.apache.cxf.endpoint.Server;
 import org.apache.cxf.endpoint.ServerImpl;
 import org.apache.cxf.feature.AbstractFeature;
 import org.apache.cxf.jaxrs.impl.RequestPreprocessor;
+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.provider.ProviderFactory;
-import org.apache.cxf.service.Service;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.service.factory.ServiceConstructionException;
 import org.apache.cxf.service.invoker.Invoker;
-import org.apache.cxf.service.model.BindingInfo;
-import org.apache.cxf.service.model.EndpointInfo;
-import org.apache.cxf.transport.DestinationFactory;
-import org.apache.cxf.transport.DestinationFactoryManager;
 
 
 /**
@@ -61,16 +55,16 @@
  * </pre>
  * This will start a server for you and register it with the ServerManager.
  */
-public class JAXRSServerFactoryBean extends AbstractEndpointFactory {
+public class JAXRSServerFactoryBean extends AbstractJAXRSFactoryBean {
     
     private static final Logger LOG = LogUtils.getL7dLogger(JAXRSServerFactoryBean.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(JAXRSServerFactoryBean.class);
     
-    protected boolean doInit;
+    protected Map<Class, ResourceProvider> resourceProviders = new HashMap<Class, ResourceProvider>();
+    
     private Server server;
     private Invoker invoker;
     private boolean start = true;
-    private JAXRSServiceFactoryBean serviceFactory;
     private List<Object> serviceBeans;
     private List<?> entityProviders;
     private Map<Object, Object> languageMappings;
@@ -82,9 +76,7 @@
     }
 
     public JAXRSServerFactoryBean(JAXRSServiceFactoryBean sf) {
-        this.serviceFactory = sf;
-        doInit = true;
-        setBindingId(JAXRSBindingFactory.JAXRS_BINDING_ID);
+        super(sf);
     }
     
     public void setSchemaLocations(List<String> schemas) {
@@ -104,6 +96,11 @@
                 LOG.severe(msg.toString());
                 throw new EndpointException(msg);
             }
+            if (serviceFactory.getService() == null) {
+                serviceFactory.create();
+                updateClassResourceProviders();
+            }
+            
             Endpoint ep = createEndpoint();
             server = new ServerImpl(getBus(), 
                                     ep, 
@@ -155,99 +152,6 @@
         }
     }
 
-    protected Endpoint createEndpoint() throws BusException, EndpointException {
-        Service service = serviceFactory.getService();
-
-        if (service == null) {
-            service = serviceFactory.create();
-        }
-
-        EndpointInfo ei = createEndpointInfo();
-        Endpoint ep = new EndpointImpl(getBus(), getServiceFactory().getService(), ei);
-        
-        if (properties != null) {
-            ep.putAll(properties);
-        }
-        
-        if (getInInterceptors() != null) {
-            ep.getInInterceptors().addAll(getInInterceptors());
-        }
-        if (getOutInterceptors() != null) {
-            ep.getOutInterceptors().addAll(getOutInterceptors());
-        }
-        if (getInFaultInterceptors() != null) {
-            ep.getInFaultInterceptors().addAll(getInFaultInterceptors());
-        }
-        if (getOutFaultInterceptors() != null) {
-            ep.getOutFaultInterceptors().addAll(getOutFaultInterceptors());
-        }
-        return ep;
-    }
-
-    /*
-     * EndpointInfo contains information form WSDL's physical part such as
-     * endpoint address, binding, transport etc. For JAX-RS based EndpointInfo,
-     * as there is no WSDL, these information are set manually, eg, default
-     * transport is http, binding is JAX-RS binding, endpoint address is from
-     * server mainline.
-     */    
-    protected EndpointInfo createEndpointInfo() throws BusException {
-        String transportId = getTransportId();
-        if (transportId == null && getAddress() != null) {
-            DestinationFactory df = getDestinationFactory();
-            if (df == null) {
-                DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
-                df = dfm.getDestinationFactoryForUri(getAddress());
-            }
-
-            if (df != null) {
-                transportId = df.getTransportIds().get(0);
-            }
-        }
-
-        //default to http transport
-        if (transportId == null) {
-            transportId = "http://schemas.xmlsoap.org/wsdl/soap/http";
-        }
-
-        setTransportId(transportId);
-
-        EndpointInfo ei = new EndpointInfo();
-        ei.setTransportId(transportId);
-        ei.setName(serviceFactory.getService().getName());
-        ei.setAddress(getAddress());        
-
-        BindingInfo bindingInfo = createBindingInfo();
-        ei.setBinding(bindingInfo);
-
-        return ei;
-    }
-
-    protected BindingInfo createBindingInfo() {
-        BindingFactoryManager mgr = getBus().getExtension(BindingFactoryManager.class);
-        String binding = getBindingId();
-        BindingConfiguration bindingConfig = getBindingConfig();
-
-        if (binding == null && bindingConfig != null) {
-            binding = bindingConfig.getBindingId();
-        }
-
-        if (binding == null) {
-            binding = JAXRSBindingFactory.JAXRS_BINDING_ID;
-        }
-
-        try {
-            BindingFactory bindingFactory = mgr.getBindingFactory(binding);
-            setBindingFactory(bindingFactory);
-            return bindingFactory.createBindingInfo(serviceFactory.getService(),
-                                                    binding, bindingConfig);
-        } catch (BusException ex) {
-            ex.printStackTrace();
-            //do nothing
-        }
-        return null;
-    }
-
     public void setLanguageMappings(Map<Object, Object> lMaps) {
         languageMappings = lMaps;
     }
@@ -292,7 +196,7 @@
     }
     
     public void setResourceProvider(Class c, ResourceProvider rp) {
-        serviceFactory.setResourceProvider(c, rp);
+        resourceProviders.put(c, rp);
     }
 
     /**
@@ -317,4 +221,30 @@
         this.start = start;
     }
 
+    private void injectContexts() {
+        for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
+            if (cri.isSingleton()) {
+                InjectionUtils.injectContextProxies(cri, 
+                                                    cri.getResourceProvider().getInstance());
+            }
+        }
+    }
+    
+    private void updateClassResourceProviders() {
+        for (ClassResourceInfo cri : serviceFactory.getClassResourceInfo()) {
+            if (cri.getResourceProvider() != null) {
+                continue;
+            }
+            
+            ResourceProvider rp = resourceProviders.get(cri.getResourceClass());
+            if (rp != null) {
+                cri.setResourceProvider(rp);
+            } else {
+                //default lifecycle is per-request
+                rp = new PerRequestResourceProvider(cri.getResourceClass());
+                cri.setResourceProvider(rp);  
+            }
+        }
+        injectContexts();
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceFactoryBean.java Mon Feb 23 10:15:34 2009
@@ -22,17 +22,16 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executor;
 
+import javax.ws.rs.Path;
+
 import org.apache.cxf.common.util.ClassHelper;
-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.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.service.Service;
 import org.apache.cxf.service.factory.AbstractServiceFactoryBean;
@@ -46,7 +45,6 @@
     
     protected List<ClassResourceInfo> classResourceInfos = 
         new ArrayList<ClassResourceInfo>();
-    protected Map<Class, ResourceProvider> resourceProviders = new HashMap<Class, ResourceProvider>();
     
     private Invoker invoker;
     private Executor executor;
@@ -115,15 +113,32 @@
         return Collections.unmodifiableList(classResourceInfos);
     }
     
+    public void setResourceClass(Class cls) {
+        classResourceInfos.clear();
+        boolean isRoot = AnnotationUtils.getClassAnnotation(cls, Path.class) != null;
+        createResourceInfo(cls, isRoot);
+    }
+    
+    public void setResourceClassFromBean(Object o) {
+        classResourceInfos.clear();
+        Class<?> realClass = ClassHelper.getRealClass(o);
+        boolean isRoot = AnnotationUtils.getClassAnnotation(realClass, Path.class) != null;
+        createResourceInfo(realClass, isRoot);
+    }
+    
     public void setResourceClasses(List<Class> classes) {
         for (Class resourceClass : classes) {
-            ClassResourceInfo classResourceInfo = 
-                ResourceUtils.createClassResourceInfo(resourceClass, resourceClass, true, enableStatic);
-            if (classResourceInfo != null) {
-                classResourceInfos.add(classResourceInfo);
-            }
+            createResourceInfo(resourceClass, true);
+        }
+    }
+    
+    protected ClassResourceInfo createResourceInfo(Class cls, boolean isRoot) {
+        ClassResourceInfo classResourceInfo = 
+            ResourceUtils.createClassResourceInfo(cls, cls, isRoot, enableStatic);
+        if (classResourceInfo != null) {
+            classResourceInfos.add(classResourceInfo);
         }
-        injectContexts();
+        return classResourceInfo;
     }
 
     public void setResourceClasses(Class... classes) {
@@ -146,23 +161,8 @@
         }
     }
     
-    private void injectContexts() {
-        for (ClassResourceInfo cri : classResourceInfos) {
-            if (cri.isSingleton()) {
-                InjectionUtils.injectContextProxies(cri, 
-                                                    cri.getResourceProvider().getInstance());
-            }
-        }
-    }
-    
-    public void setResourceProvider(Class c, ResourceProvider rp) {
-        resourceProviders.put(c, rp);
-    }
-    
     protected void initializeServiceModel() {
         
-        updateClassResourceProviders();
-        
         JAXRSServiceImpl service = new JAXRSServiceImpl(classResourceInfos);
 
         setService(service);
@@ -172,29 +172,11 @@
         }
     }
 
-    private void updateClassResourceProviders() {
-        for (ClassResourceInfo cri : classResourceInfos) {
-            if (cri.getResourceProvider() != null) {
-                continue;
-            }
-            
-            ResourceProvider rp = resourceProviders.get(cri.getResourceClass());
-            if (rp != null) {
-                cri.setResourceProvider(rp);
-            } else {
-                //default lifecycle is per-request
-                rp = new PerRequestResourceProvider(cri.getResourceClass());
-                cri.setResourceProvider(rp);  
-            }
-        }
-        injectContexts();
-    }
-    
-    
-    
-    
     protected Invoker createInvoker() {
         return new JAXRSInvoker();
     }
 
+    public void setService(Service service) {
+        super.setService(service);
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServiceImpl.java Mon Feb 23 10:15:34 2009
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -26,6 +27,7 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.cxf.common.util.PackageUtils;
 import org.apache.cxf.configuration.Configurable;
 import org.apache.cxf.databinding.DataBinding;
 import org.apache.cxf.endpoint.Endpoint;
@@ -43,9 +45,14 @@
     private Executor executor;
     private Invoker invoker;
     private Map<QName, Endpoint> endpoints = new HashMap<QName, Endpoint>();
+    private String address;
     
     public JAXRSServiceImpl() {
     }
+    
+    public JAXRSServiceImpl(String address) {
+        this.address = address;
+    }
 
     public JAXRSServiceImpl(List<ClassResourceInfo> cri) {
         this.classResourceInfos = cri;
@@ -56,9 +63,14 @@
         return getName().toString();
     }
 
-    public QName getName() {    
-        Class primaryClass = classResourceInfos.get(0).getServiceClass();
-        return new QName("jaxrs", primaryClass.getSimpleName());
+    public QName getName() {
+        if (address == null) {
+            Class primaryClass = classResourceInfos.get(0).getServiceClass();
+            String ns = PackageUtils.getNamespace(PackageUtils.getPackageName(primaryClass));
+            return new QName(ns + "/jaxrs", primaryClass.getSimpleName());
+        } else {
+            return new QName(address, "WebResource");
+        }
     }
 
     public List<ClassResourceInfo> getClassResourceInfos() {
@@ -66,8 +78,7 @@
     }
     
     public List<ServiceInfo> getServiceInfos() {
-        //NOT APPLICABLE
-        return null;
+        return Collections.emptyList();
     }
     
     public EndpointInfo getEndpointInfo(QName endpoint) {        

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Mon Feb 23 10:15:34 2009
@@ -44,25 +44,39 @@
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
+import org.apache.cxf.Bus;
+import org.apache.cxf.endpoint.ConduitSelector;
+import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.IOUtils;
+import org.apache.cxf.interceptor.Interceptor;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.phase.PhaseChainCache;
+import org.apache.cxf.phase.PhaseInterceptorChain;
+import org.apache.cxf.phase.PhaseManager;
+import org.apache.cxf.transport.MessageObserver;
 
 /**
  * Common proxy and http-centric client implementation
  *
  */
 public class AbstractClient implements Client {
+
+    protected ConduitSelector conduitSelector;
+    protected Bus bus;
     
     private MultivaluedMap<String, String> requestHeaders = new MetadataMap<String, String>();
     private ResponseBuilder responseBuilder;
     
     private URI baseURI;
     private UriBuilder currentBuilder;
-    
+
     protected AbstractClient(URI baseURI, URI currentURI) {
         this.baseURI = baseURI;
         this.currentBuilder = new UriBuilderImpl(currentURI);
@@ -243,6 +257,58 @@
     }
 
     
+    public void setConduitSelector(ConduitSelector cs) {
+        this.conduitSelector = cs;
+    }
+    
+    public void setBus(Bus bus) {
+        this.bus = bus;
+    }
+    
+    protected void prepareConduitSelector(Message message) {
+        conduitSelector.prepare(message);
+        message.getExchange().put(ConduitSelector.class, conduitSelector);
+    }
+    
+    protected PhaseInterceptorChain setupInterceptorChain(Endpoint endpoint) { 
+        PhaseManager pm = bus.getExtension(PhaseManager.class);
+        List<Interceptor> i1 = bus.getOutInterceptors();
+        // TODO : make sure we don't forget the out interceptors of this client
+        List<Interceptor> i2 = endpoint.getOutInterceptors();
+        return new PhaseChainCache().get(pm.getOutPhases(), i1, i2);
+    }
+    
+    protected Message createMessage(String httpMethod, 
+                                    MultivaluedMap<String, String> headers,
+                                    String address,
+                                    MessageObserver observer) {
+        Message m = conduitSelector.getEndpoint().getBinding().createMessage();
+        m.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
+        m.put(Message.INBOUND_MESSAGE, Boolean.FALSE);
+        
+        m.put(Message.HTTP_REQUEST_METHOD, httpMethod);
+        m.put(Message.PROTOCOL_HEADERS, headers);
+        m.put(Message.ENDPOINT_ADDRESS, address);
+        m.put(Message.CONTENT_TYPE, headers.getFirst(HttpHeaders.CONTENT_TYPE));
+        
+        
+        Exchange exchange = new ExchangeImpl();
+        exchange.setSynchronous(true);
+        exchange.setOutMessage(m);
+        exchange.put(Bus.class, bus);
+        exchange.put(MessageObserver.class, observer);
+        exchange.setOneWay(false);
+        m.setExchange(exchange);
+        
+        PhaseInterceptorChain chain = setupInterceptorChain(conduitSelector.getEndpoint());
+        m.setInterceptorChain(chain);
+        
+        //setup conduit selector
+        prepareConduitSelector(m);
+        
+        return m;
+    }
+    
     protected List<MediaType> getAccept() {
         List<String> headers = requestHeaders.get(HttpHeaders.ACCEPT);
         if (headers == null || headers.size() == 0) {
@@ -278,7 +344,12 @@
         currentBuilder = new UriBuilderImpl(uri);
     }
     
-    protected ResponseBuilder setResponseBuilder(HttpURLConnection conn) throws IOException {
+    protected ResponseBuilder setResponseBuilder(HttpURLConnection conn) throws Throwable {
+        
+        if (conn == null) {
+            throw new WebApplicationException(); 
+        }
+        
         int status = conn.getResponseCode();
         responseBuilder = Response.status(status);
         for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java Mon Feb 23 10:15:34 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.client;
 
+import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
@@ -41,6 +42,8 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 
+import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
 import org.apache.cxf.jaxrs.model.OperationResourceInfo;
@@ -49,15 +52,20 @@
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.jaxrs.utils.ParameterType;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.HTTPConduit;
 
 /**
  * Proxy-based client implementation
  *
  */
-public class ClientProxyImpl extends AbstractClient implements InvocationHandler {
+public class ClientProxyImpl extends AbstractClient implements InvocationHandler, MessageObserver {
 
     private ClassResourceInfo cri;
-    private boolean inheritHeaders; 
+    private boolean inheritHeaders;
     
     public ClientProxyImpl(URI baseURI, URI currentURI, ClassResourceInfo cri, boolean inheritHeaders) {
         super(baseURI, currentURI);
@@ -108,8 +116,15 @@
         handleCookies(paramHeaders, types, params);
                 
         if (ori.isSubResourceLocator()) {
-            Object proxy = 
-                JAXRSClientFactory.create(getBaseURI(), uri, m.getReturnType(), false, inheritHeaders);
+            ClassResourceInfo subCri = cri.getSubResource(m.getReturnType(), m.getReturnType());
+            if (subCri == null) {
+                throw new WebApplicationException();
+            }
+            ClientProxyImpl proxyImpl = new ClientProxyImpl(getBaseURI(), uri, subCri, inheritHeaders);
+            proxyImpl.setBus(bus);
+            proxyImpl.setConduitSelector(conduitSelector);
+            
+            Object proxy = JAXRSClientFactory.create(m.getReturnType(), proxyImpl);
             if (inheritHeaders) {
                 WebClient.client(proxy).headers(headers);
             }
@@ -118,31 +133,14 @@
         } 
         
         headers.putAll(paramHeaders);
-        
-        HttpURLConnection connect = createHttpConnection(uri, ori.getHttpMethod());
-        setRequestHeaders(connect, headers, ori, types.containsKey(ParameterType.FORM), 
+        setRequestHeaders(headers, ori, types.containsKey(ParameterType.FORM), 
             bodyIndex == -1 ? null : params[bodyIndex].getClass(), m.getReturnType());
-        if (bodyIndex != -1 || types.containsKey(ParameterType.FORM)) {
-            if (bodyIndex != -1) {
-                writeBody(params[bodyIndex], params[bodyIndex].getClass(), 
-                          m.getGenericParameterTypes()[bodyIndex],
-                          m.getParameterAnnotations()[bodyIndex], headers, connect.getOutputStream());
-            } else {
-                MultivaluedMap<String, String> form = handleForm(types, params);
-                writeBody(form, form.getClass(), form.getClass(), m.getDeclaredAnnotations(),
-                          headers, connect.getOutputStream());
-            }
-        }
         
-        Response r = setResponseBuilder(connect).clone().build();
-        
-        checkResponse(m, r);
-        if (m.getReturnType() == Void.class) { 
-            return null;
+        if (conduitSelector == null) {
+            return doDirectInvocation(uri, headers, ori, params, bodyIndex, types);
+        } else {
+            return doChainedInvocation(uri, headers, ori, params, bodyIndex, types);
         }
-        
-        return readBody(r, connect, m.getReturnType(), 
-                        m.getGenericReturnType(), m.getDeclaredAnnotations());
     }
 
     private static MultivaluedMap<ParameterType, Parameter> getParametersInfo(OperationResourceInfo ori, 
@@ -198,42 +196,36 @@
     }
     
     
-    private MultivaluedMap<String, String> setRequestHeaders(HttpURLConnection conn,
-                                                             MultivaluedMap<String, String> headers,          
+    private MultivaluedMap<String, String> setRequestHeaders(MultivaluedMap<String, String> headers,          
                                                              OperationResourceInfo ori,
                                                              boolean formParams,
                                                              Class<?> bodyClass,
                                                              Class<?> responseClass) {
-        try {
-            if (headers.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
-                if (formParams || bodyClass != null && MultivaluedMap.class.isAssignableFrom(bodyClass)) {
-                    headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
-                } else {
-                    String cType = 
-                        bodyClass != null && InjectionUtils.isPrimitive(bodyClass) 
-                            ? MediaType.TEXT_PLAIN : ori.getConsumeTypes().isEmpty() 
-                        || ori.getConsumeTypes().get(0).equals(MediaType.WILDCARD) 
-                        ? MediaType.APPLICATION_XML : ori.getConsumeTypes().get(0).toString();   
-                    headers.putSingle(HttpHeaders.CONTENT_TYPE, cType);
-                }
+        if (headers.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
+            if (formParams || bodyClass != null && MultivaluedMap.class.isAssignableFrom(bodyClass)) {
+                headers.putSingle(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED);
+            } else {
+                String cType = 
+                    bodyClass != null && InjectionUtils.isPrimitive(bodyClass) 
+                        ? MediaType.TEXT_PLAIN : ori.getConsumeTypes().isEmpty() 
+                    || ori.getConsumeTypes().get(0).equals(MediaType.WILDCARD) 
+                    ? MediaType.APPLICATION_XML : ori.getConsumeTypes().get(0).toString();   
+                headers.putSingle(HttpHeaders.CONTENT_TYPE, cType);
             }
-            
-            List<MediaType> accepts = getAccept();
-            if (accepts == null) {
-                accepts = InjectionUtils.isPrimitive(responseClass) 
-                    ? Collections.singletonList(MediaType.TEXT_PLAIN_TYPE)
-                    : ori.getProduceTypes().size() == 0 
-                    || ori.getConsumeTypes().get(0).equals(MediaType.WILDCARD_TYPE) 
-                    ? Collections.singletonList(MediaType.APPLICATION_XML_TYPE) : ori.getProduceTypes();
-                for (MediaType mt : accepts) {
-                    headers.add(HttpHeaders.ACCEPT, mt.toString());
-                }
+        }
+        
+        List<MediaType> accepts = getAccept();
+        if (accepts == null) {
+            accepts = InjectionUtils.isPrimitive(responseClass) 
+                ? Collections.singletonList(MediaType.TEXT_PLAIN_TYPE)
+                : ori.getProduceTypes().size() == 0 
+                || ori.getConsumeTypes().get(0).equals(MediaType.WILDCARD_TYPE) 
+                ? Collections.singletonList(MediaType.APPLICATION_XML_TYPE) : ori.getProduceTypes();
+            for (MediaType mt : accepts) {
+                headers.add(HttpHeaders.ACCEPT, mt.toString());
             }
-            setAllHeaders(headers, conn);
-            
-        } catch (Exception ex) {
-            throw new WebApplicationException();
         }
+            
         return headers;
     }
     
@@ -356,6 +348,71 @@
         
     }
     
+    protected Object doDirectInvocation(URI uri, MultivaluedMap<String, String> headers, 
+        OperationResourceInfo ori, Object[] params, int bodyIndex, 
+        MultivaluedMap<ParameterType, Parameter> types) throws Throwable {
+
+        // TODO : we need to refactor bits of HTTPConduit such that it can be reused
+        
+        HttpURLConnection connect = createHttpConnection(uri, ori.getHttpMethod());
+        setAllHeaders(headers, connect);
+        Method m = ori.getMethodToInvoke();
+        if (bodyIndex != -1 || types.containsKey(ParameterType.FORM)) {
+            if (bodyIndex != -1) {
+                writeBody(params[bodyIndex], params[bodyIndex].getClass(), 
+                          m.getGenericParameterTypes()[bodyIndex],
+                          m.getParameterAnnotations()[bodyIndex], headers, connect.getOutputStream());
+            } else {
+                MultivaluedMap<String, String> form = handleForm(types, params);
+                writeBody(form, form.getClass(), form.getClass(), m.getDeclaredAnnotations(),
+                          headers, connect.getOutputStream());
+            }
+        }
+        
+        return handleResponse(connect, ori);
+        
+    }
+    
+    private Object doChainedInvocation(URI uri, MultivaluedMap<String, String> headers, 
+                          OperationResourceInfo ori, Object[] params, int bodyIndex, 
+                          MultivaluedMap<ParameterType, Parameter> types) throws Throwable {
+        Message m = createMessage(ori.getHttpMethod(), headers, uri.toString(), this);
+        
+        if (bodyIndex != -1 || types.containsKey(ParameterType.FORM)) {
+            m.setContent(OperationResourceInfo.class, ori);
+            m.put("BODY_INDEX", bodyIndex);
+            Object body = bodyIndex != -1 ? params[bodyIndex] : handleForm(types, params); 
+            MessageContentsList contents = new MessageContentsList(new Object[]{body});
+            m.setContent(List.class, contents);
+            m.getInterceptorChain().add(new BodyWriter());
+        }
+        
+        // execute chain        
+        try {
+            m.getInterceptorChain().doIntercept(m);
+        } catch (Throwable ex) {
+            // we'd like a user to get the whole Response anyway if needed
+        }
+        
+        // TODO : this needs to be done in an inbound chain instead
+        HttpURLConnection connect = (HttpURLConnection)m.get(HTTPConduit.KEY_HTTP_CONNECTION);
+        
+        return handleResponse(connect, ori);
+        
+    }
+    
+    protected Object handleResponse(HttpURLConnection connect, OperationResourceInfo ori) 
+        throws Throwable {
+        Response r = setResponseBuilder(connect).clone().build();
+        Method method = ori.getMethodToInvoke();
+        checkResponse(method, r);
+        if (method.getReturnType() == Void.class) { 
+            return null;
+        }
+        
+        return readBody(r, connect, method.getReturnType(), 
+                        method.getGenericReturnType(), method.getDeclaredAnnotations());
+    }
     
     private static class Parameter {
         private ParameterType type;
@@ -386,4 +443,53 @@
             return isEncoded;
         }
     }
+
+    public void onMessage(Message message) {
+        // just do nothing for now
+    }
+    
+    // TODO : what we really need to do is to refactor JAXRSOutInterceptor so that
+    // it can handle both client requests and server responses - it may need to be split into
+    // several interceptors - in fact we need to do the same for JAXRSInInterceptor so that we can do
+    // on onMessage() properly
+    
+    private class BodyWriter extends AbstractOutDatabindingInterceptor {
+
+        public BodyWriter() {
+            super(Phase.WRITE);
+        }
+        
+        @SuppressWarnings("unchecked")
+        public void handleMessage(Message m) throws Fault {
+            
+            OperationResourceInfo ori = m.getContent(OperationResourceInfo.class);
+            OutputStream os = m.getContent(OutputStream.class);
+            if (os == null || ori == null) {
+                return;
+            }
+            MessageContentsList objs = MessageContentsList.getContentsList(m);
+            if (objs == null || objs.size() == 0) {
+                return;
+            }
+            MultivaluedMap<String, String> headers = (MultivaluedMap)m.get(Message.PROTOCOL_HEADERS);
+            Method method = ori.getMethodToInvoke();
+            int bodyIndex = (Integer)m.get("BODY_INDEX");
+            Object body = objs.get(0);
+            try {
+                if (bodyIndex != -1) {
+                    writeBody(body, body.getClass(), 
+                          method.getGenericParameterTypes()[bodyIndex],
+                          method.getParameterAnnotations()[bodyIndex], headers, os);
+                } else {
+                    writeBody(body, body.getClass(), body.getClass(), method.getDeclaredAnnotations(),
+                            headers, os);
+                }
+                os.flush();
+            } catch (Exception ex) {
+                throw new Fault(ex);
+            }
+            
+        }
+        
+    }
 }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java Mon Feb 23 10:15:34 2009
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.jaxrs.client;
 
+import java.lang.reflect.InvocationHandler;
 import java.net.URI;
 
 import javax.ws.rs.Path;
@@ -55,7 +56,7 @@
      * @return typed proxy
      */
     public static <T> T create(URI baseURI, Class<T> cls) {
-        return create(baseURI, baseURI, cls, true, false);
+        return create(baseURI, cls, false);
     }
     
     /**
@@ -65,7 +66,33 @@
      * @return typed proxy
      */
     public static <T> T create(URI baseURI, Class<T> cls, boolean inheritHeaders) {
-        return create(baseURI, baseURI, cls, true, inheritHeaders);
+        
+        return create(baseURI, cls, inheritHeaders, false);
+    }
+    
+    /**
+     * Creates a proxy
+     * @param baseURI baseURI
+     * @param cls proxy class, if not interface then a CGLIB proxy will be created
+     * @param direct if true then no bus and chains will be created
+     * @return typed proxy
+     */
+    public static <T> T create(URI baseURI, Class<T> cls, boolean inheritHeaders, boolean direct) {
+        
+        if (!direct) {
+            JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+            bean.setAddress(baseURI.toString());
+            bean.setResourceClass(cls);
+            bean.setInheritHeaders(inheritHeaders);
+            return bean.create(cls);
+        } else {
+            boolean isRoot = AnnotationUtils.getClassAnnotation(cls, Path.class) != null;
+            ClassResourceInfo cri = ResourceUtils.createClassResourceInfo(cls, cls, isRoot, true);
+            
+            return cls.cast(ProxyHelper.getProxy(cls.getClassLoader(),
+                            new Class[]{cls, Client.class}, 
+                            new ClientProxyImpl(baseURI, baseURI, cri, inheritHeaders)));
+        }
     }
     
     /**
@@ -90,6 +117,9 @@
      * @return typed proxy
      */
     public static <T> T fromClient(Client client, Class<T> cls) {
+        if (cls.isAssignableFrom(client.getClass())) {
+            return cls.cast(client);
+        }
         return fromClient(client, cls, false);
     }
     
@@ -102,22 +132,29 @@
      * @return typed proxy
      */
     public static <T> T fromClient(Client client, Class<T> cls, boolean inheritHeaders) {
-        if (client.getClass().isAssignableFrom(cls)) {
-            return cls.cast(client);
-        }
-        T proxy = create(client.getCurrentURI(), client.getCurrentURI(), cls, 
-                         AnnotationUtils.getClassAnnotation(cls, Path.class) != null, inheritHeaders);
+        return fromClient(client, cls, inheritHeaders, false);
+    }
+    
+    /**
+     * Creates a proxy, baseURI will be set to Client currentURI
+     * @param client Client instance
+     * @param cls proxy class, if not interface then a CGLIB proxy will be created
+     * @param inheritHeaders if existing Client headers can be inherited by new proxy 
+     *        and subresource proxies if any 
+     * @return typed proxy
+     */
+    public static <T> T fromClient(Client client, Class<T> cls, boolean inheritHeaders, boolean direct) {
+        
+        T proxy = create(client.getCurrentURI(), cls, inheritHeaders, direct);
         if (inheritHeaders) {
             WebClient.client(proxy).headers(client.getHeaders());
         }
         return proxy;
     }
     
-    static <T> T create(URI baseURI, URI currentURI, Class<T> cls, boolean root, boolean inheritHeaders) {
-        ClassResourceInfo classResourceInfo = ResourceUtils.createClassResourceInfo(cls, cls, root, true);
+    static <T> T create(Class<T> cls, InvocationHandler handler) {
         
         return cls.cast(ProxyHelper.getProxy(cls.getClassLoader(),
-                        new Class[]{cls, Client.class},
-                        new ClientProxyImpl(baseURI, currentURI, classResourceInfo, inheritHeaders)));
+                        new Class[]{cls, Client.class}, handler));
     }
 }

Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java?rev=746947&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactoryBean.java Mon Feb 23 10:15:34 2009
@@ -0,0 +1,117 @@
+/**
+ * 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.client;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.WebApplicationException;
+
+import org.apache.cxf.common.util.ProxyHelper;
+import org.apache.cxf.endpoint.ConduitSelector;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.endpoint.UpfrontConduitSelector;
+import org.apache.cxf.jaxrs.AbstractJAXRSFactoryBean;
+import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
+import org.apache.cxf.jaxrs.JAXRSServiceImpl;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.service.Service;
+
+public class JAXRSClientFactoryBean extends AbstractJAXRSFactoryBean {
+    
+    private boolean inheritHeaders; 
+    
+    public JAXRSClientFactoryBean() {
+        this(new JAXRSServiceFactoryBean());
+    }
+    
+    public JAXRSClientFactoryBean(JAXRSServiceFactoryBean serviceFactory) {
+        super(serviceFactory);
+        serviceFactory.setEnableStaticResolution(true);
+        
+    }
+    
+    public void setInheritHeaders(boolean ih) {
+        inheritHeaders = ih;
+    }
+    
+    public void setResourceClass(Class cls) {
+        serviceFactory.setResourceClass(cls);
+    }
+    
+    public void setResourceBean(Object o) {
+        serviceFactory.setResourceClassFromBean(o);
+    }
+    
+    public WebClient createWebClient() {
+        
+        Service service = new JAXRSServiceImpl(getAddress());
+        getServiceFactory().setService(service);
+        
+        try {
+            Endpoint ep = createEndpoint();
+            WebClient client = new WebClient(getAddress());
+            client.setConduitSelector(getConduitSelector(ep));
+            client.setBus(getBus());
+            
+            return client;
+        } catch (Exception ex) {
+            throw new WebApplicationException();
+        }
+    }
+    
+    public <T> T create(Class<T> cls) {
+        return cls.cast(create());
+    }
+    
+    
+    
+    public Client create() {
+        List<ClassResourceInfo> list = serviceFactory.getClassResourceInfo();
+        if (list.isEmpty()) {
+            throw new WebApplicationException();
+        }
+        
+        try {
+            Endpoint ep = createEndpoint();
+            URI baseURI = URI.create(getAddress());
+            ClassResourceInfo cri = list.get(0);
+            
+            ClientProxyImpl proxyImpl = new ClientProxyImpl(baseURI, baseURI, cri, inheritHeaders);
+            proxyImpl.setConduitSelector(getConduitSelector(ep));
+            proxyImpl.setBus(getBus());
+            
+            return (Client)ProxyHelper.getProxy(cri.getServiceClass().getClassLoader(),
+                                        new Class[]{cri.getServiceClass(), Client.class}, 
+                                        proxyImpl);
+        } catch (Exception ex) {
+            throw new WebApplicationException();
+        }
+        
+        
+    }
+    
+    protected ConduitSelector getConduitSelector(Endpoint ep) {
+        ConduitSelector cs = getConduitSelector();
+        cs = cs == null ? new UpfrontConduitSelector() : cs;
+        cs.setEndpoint(ep);
+        return cs;
+    }
+    
+} 

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

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

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java Mon Feb 23 10:15:34 2009
@@ -20,6 +20,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.net.HttpURLConnection;
 import java.net.URI;
@@ -37,16 +38,23 @@
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 
+import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
+import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.ext.form.Form;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.phase.Phase;
+import org.apache.cxf.transport.MessageObserver;
+import org.apache.cxf.transport.http.HTTPConduit;
 
 
 /**
  * Http-centric web client
  *
  */
-public class WebClient extends AbstractClient {
+public class WebClient extends AbstractClient implements MessageObserver {
     
     /**
      * Creates WebClient
@@ -285,6 +293,13 @@
         return (Client)proxy;
     }
     
+    public static WebClient createClient(String baseAddress) {
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress(baseAddress);
+        return bean.createWebClient();
+    }
+    
+    
     @Override
     public WebClient type(MediaType ct) {
         return (WebClient)super.type(ct);
@@ -356,7 +371,6 @@
     }
     
     private Response doInvoke(String httpMethod, Object body, Class<?> responseClass) {
-        HttpURLConnection conn = getConnection(httpMethod);
         
         MultivaluedMap<String, String> headers = getHeaders();
         if (body != null && headers.getFirst(HttpHeaders.CONTENT_TYPE) == null) {
@@ -365,6 +379,18 @@
         if (responseClass != null && headers.getFirst(HttpHeaders.ACCEPT) == null) {
             headers.putSingle(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_TYPE.toString());
         }
+        if (conduitSelector == null) {
+            return doDirectInvocation(httpMethod, headers, body, responseClass);
+        } else {
+            return doChainedInvocation(httpMethod, headers, body, responseClass);
+        }
+    }
+
+    protected Response doDirectInvocation(String httpMethod, 
+        MultivaluedMap<String, String> headers, Object body, Class<?> responseClass) {
+        
+        HttpURLConnection conn = getConnection(httpMethod);
+        
         setAllHeaders(headers, conn);
         if (body != null) {
             try {
@@ -374,6 +400,32 @@
                 throw new WebApplicationException(ex);
             }
         }
+        return handleResponse(conn, responseClass);
+    }
+    
+    protected Response doChainedInvocation(String httpMethod, 
+        MultivaluedMap<String, String> headers, Object body, Class<?> responseClass) {
+
+        Message m = createMessage(httpMethod, headers, getCurrentURI().toString(), this);
+        
+        if (body != null) {
+            MessageContentsList contents = new MessageContentsList(body);
+            m.setContent(List.class, contents);
+            m.getInterceptorChain().add(new BodyWriter());
+        }
+        
+        try {
+            m.getInterceptorChain().doIntercept(m);
+        } catch (Throwable ex) {
+            // we'd like a user to get the whole Response anyway if needed
+        }
+        
+        // TODO : this needs to be done in an inbound chain instead
+        HttpURLConnection connect = (HttpURLConnection)m.get(HTTPConduit.KEY_HTTP_CONNECTION);
+        return handleResponse(connect, responseClass);
+    }
+    
+    protected Response handleResponse(HttpURLConnection conn, Class<?> responseClass) {
         try {
             ResponseBuilder rb = setResponseBuilder(conn).clone();
             Response currentResponse = rb.clone().build();
@@ -382,7 +434,7 @@
             rb.entity(entity);
             
             return rb.build();
-        } catch (IOException ex) {
+        } catch (Throwable ex) {
             throw new WebApplicationException(ex);
         }
     }
@@ -391,6 +443,37 @@
         return createHttpConnection(getCurrentBuilder().clone().build(), methodName);
     }
     
-    
-    
+    private class BodyWriter extends AbstractOutDatabindingInterceptor {
+
+        public BodyWriter() {
+            super(Phase.WRITE);
+        }
+        
+        @SuppressWarnings("unchecked")
+        public void handleMessage(Message m) throws Fault {
+            
+            OutputStream os = m.getContent(OutputStream.class);
+            if (os == null) {
+                return;
+            }
+            MessageContentsList objs = MessageContentsList.getContentsList(m);
+            if (objs == null || objs.size() == 0) {
+                return;
+            }
+            MultivaluedMap<String, String> headers = (MultivaluedMap)m.get(Message.PROTOCOL_HEADERS);
+            Object body = objs.get(0);
+            try {
+                writeBody(body, body.getClass(), body.getClass(), new Annotation[]{}, headers, os);
+                os.flush();
+            } catch (Exception ex) {
+                throw new Fault(ex);
+            }
+            
+        }
+        
+    }
+
+    public void onMessage(Message message) {
+        // do nothing for now
+    }
 }

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java (original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPConduit.java Mon Feb 23 10:15:34 2009
@@ -33,6 +33,7 @@
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -74,7 +75,6 @@
 import org.apache.cxf.ws.policy.PolicyEngine;
 import org.apache.cxf.wsdl.EndpointReferenceUtils;
 
-
 import static org.apache.cxf.message.Message.DECOUPLED_CHANNEL_MESSAGE;
 
 
@@ -801,7 +801,7 @@
         Map<String, List<String>> headers =
             CastUtils.cast((Map<?, ?>)message.get(Message.PROTOCOL_HEADERS));        
         if (null == headers) {
-            headers = new HashMap<String, List<String>>();
+            headers = new LinkedHashMap<String, List<String>>();
             message.put(Message.PROTOCOL_HEADERS, headers);
         }
         return headers;
@@ -813,16 +813,20 @@
      * from the PROTOCOL_HEADERS in the message.
      */
     private void transferProtocolHeadersToURLConnection(
-        Message       message,
+        Message message,
         URLConnection connection
     ) {
-        Map<String, List<String>> headers =
-            getSetProtocolHeaders(message);
+        Map<String, List<String>> headers = getSetProtocolHeaders(message);
         for (String header : headers.keySet()) {
             List<String> headerList = headers.get(header);
-            for (String value : headerList) {
-                connection.addRequestProperty(header, value);
+            StringBuilder b = new StringBuilder();
+            for (int i = 0; i < headerList.size(); i++) {
+                b.append(headerList.get(i));
+                if (i + 1 < headerList.size()) {
+                    b.append(',');
+                }
             }
+            connection.setRequestProperty(header, b.toString());
         }
         if (!connection.getRequestProperties().containsKey("User-Agent")) {
             connection.addRequestProperty("User-Agent", Version.getCompleteVersionString());
@@ -834,14 +838,13 @@
      * Message at the specified logging level.
      * 
      * @param level   The Logging Level.
-     * @param message The Message.
+     * @param headers The Message protocol headers.
      */
     private void logProtocolHeaders(
         Level   level,
         Message message
     ) {
-        Map<String, List<String>> headers =
-            getSetProtocolHeaders(message);
+        Map<String, List<String>> headers = getSetProtocolHeaders(message);
         for (String header : headers.keySet()) {
             List<String> headerList = headers.get(header);
             for (String value : headerList) {
@@ -1180,7 +1183,7 @@
         if (policy.isSetAccept()) {
             headers.put("Accept",
                         createMutableList(policy.getAccept()));
-        } else {
+        } else if (!headers.containsKey("Accept")) {
             headers.put("Accept", createMutableList("*/*"));
         }
         if (policy.isSetAcceptEncoding()) {
@@ -1866,7 +1869,7 @@
             // Trust is okay, set up for writing the request.
             
             // If this is a GET method we must not touch the output
-            // stream as this automagically turns the reqest into a POST.
+            // stream as this automagically turns the request into a POST.
             if ("GET".equals(connection.getRequestMethod())) {
                 return;
             }
@@ -2100,9 +2103,8 @@
                    : connection.getErrorStream()
                  : in;
                    
-            if (in == null) {
-                LOG.log(Level.WARNING, "Input Stream is null!");
-            }
+            // if (in == null) : it's perfectly ok for non-soap http services
+            // have no response body : those interceptors which do need it will check anyway        
             inMessage.setContent(InputStream.class, in);
             
             

Modified: cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java (original)
+++ cxf/trunk/rt/transports/http/src/test/java/org/apache/cxf/transport/http/HTTPConduitURLEasyMockTest.java Mon Feb 23 10:15:34 2009
@@ -313,9 +313,14 @@
     private void setUpHeaders(Message message) {
         Map<String, List<String>> headers = new HashMap<String, List<String>>();
         List<String> contentTypes = new ArrayList<String>();
-        contentTypes.add("text/xml");
-        contentTypes.add("charset=utf8");
+        contentTypes.add("text/xml;charset=utf8");
         headers.put("content-type", contentTypes);
+        
+        List<String> acceptTypes = new ArrayList<String>();
+        acceptTypes.add("text/xml;charset=utf8");
+        acceptTypes.add("text/plain");
+        headers.put("Accept", acceptTypes);
+        
         message.put(Message.PROTOCOL_HEADERS, headers);
         
         AuthorizationPolicy authPolicy = new AuthorizationPolicy();
@@ -552,14 +557,14 @@
         
         message.put(HTTPConduit.KEY_HTTP_CONNECTION, connection);
         if (expectHeaders) {
-            connection.addRequestProperty(EasyMock.eq("Authorization"),
+            connection.setRequestProperty(EasyMock.eq("Authorization"),
                                           EasyMock.eq("Basic Qko6dmFsdWU="));            
             EasyMock.expectLastCall();
-            connection.addRequestProperty(EasyMock.eq("content-type"),
-                                          EasyMock.eq("text/xml"));
+            connection.setRequestProperty(EasyMock.eq("content-type"),
+                                          EasyMock.eq("text/xml;charset=utf8"));
             EasyMock.expectLastCall();
-            connection.addRequestProperty(EasyMock.eq("content-type"),
-                                          EasyMock.eq("charset=utf8"));
+            connection.setRequestProperty(EasyMock.eq("Accept"),
+                                          EasyMock.eq("text/xml;charset=utf8,text/plain"));
             EasyMock.expectLastCall();
         }
         connection.getRequestProperties();

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStoreJaxrsJaxws.java Mon Feb 23 10:15:34 2009
@@ -38,6 +38,7 @@
     @WebMethod
     @GET
     @Path("/{id}")
+    @Consumes("*/*")
     Book getBook(@PathParam("id") @WebParam(name = "id") Long id) throws BookNotFoundFault;
 
     @WebMethod

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Mon Feb 23 10:15:34 2009
@@ -45,7 +45,7 @@
     @BeforeClass
     public static void startServers() throws Exception {
         assertTrue("server did not launch correctly",
-                   launchServer(BookServer.class, true));
+                   launchServer(BookServer.class));
     }
     
     @Test

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java?rev=746947&r1=746946&r2=746947&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java (original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSSoapBookTest.java Mon Feb 23 10:15:34 2009
@@ -99,6 +99,16 @@
     }
     
     @Test
+    public void testGetBook123WebClientBean() throws Exception {
+        String baseAddress = "http://localhost:9092/test/services/rest";
+        WebClient client = WebClient.createClient(baseAddress);
+        client.path("/bookstore/123").accept(MediaType.APPLICATION_XML_TYPE);
+        Book b = client.get(Book.class);
+        assertEquals(123, b.getId());
+        assertEquals("CXF in Action", b.getName());
+    }
+    
+    @Test
     public void testNoBookWebClient() throws Exception {
         String baseAddress = "http://localhost:9092/test/services/rest";
         WebClient client = new WebClient(baseAddress);
@@ -157,11 +167,30 @@
     }
     
     @Test
-    public void testGetBookSubresourceWebClientProxy() throws Exception {
+    public void testGetBookSubresourceWebClientProxyDirect() throws Exception {
         
         WebClient client = new WebClient("http://localhost:9092/test/services/rest");
-        client.type(MediaType.TEXT_PLAIN_TYPE).accept(MediaType.APPLICATION_XML_TYPE);
-        BookStoreJaxrsJaxws proxy = JAXRSClientFactory.fromClient(client, BookStoreJaxrsJaxws.class, true);
+        client.type(MediaType.TEXT_PLAIN_TYPE)
+              .accept(MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE);
+        BookStoreJaxrsJaxws proxy = 
+            JAXRSClientFactory.fromClient(client, BookStoreJaxrsJaxws.class, true, true);
+        
+        doTestSubresource(proxy);
+        
+        BookStoreJaxrsJaxws proxy2 = JAXRSClientFactory.fromClient(
+            WebClient.client(proxy), BookStoreJaxrsJaxws.class);
+        doTestSubresource(proxy2);
+        
+    }
+    
+    @Test
+    public void testGetBookSubresourceWebClientProxyBean() throws Exception {
+        
+        WebClient client = new WebClient("http://localhost:9092/test/services/rest");
+        client.type(MediaType.TEXT_PLAIN_TYPE)
+            .accept(MediaType.APPLICATION_XML_TYPE, MediaType.TEXT_XML_TYPE);
+        BookStoreJaxrsJaxws proxy = 
+            JAXRSClientFactory.fromClient(client, BookStoreJaxrsJaxws.class, true);
         
         doTestSubresource(proxy);
         

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/BookHttpsServer.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/BookHttpsServer.java?rev=746947&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/BookHttpsServer.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/BookHttpsServer.java Mon Feb 23 10:15:34 2009
@@ -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.security;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
+import org.apache.cxf.systest.jaxrs.BookStore;
+import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+    
+public class BookHttpsServer extends AbstractBusTestServerBase {
+
+    private static final String SERVER_CONFIG_FILE =
+        "org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml";
+    
+    protected void run() {
+        
+        SpringBusFactory bf = new SpringBusFactory();
+        Bus bus = bf.createBus(SERVER_CONFIG_FILE);
+        BusFactory.setDefaultBus(bus);
+        
+        JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
+        sf.setResourceClasses(BookStore.class);
+        //default lifecycle is per-request, change it to singleton
+        sf.setResourceProvider(BookStore.class,
+                               new SingletonResourceProvider(new BookStore()));
+        sf.setAddress("https://localhost:9095/");
+
+        sf.create();        
+    }
+
+    public static void main(String[] args) {
+        try {
+            BookHttpsServer s = new BookHttpsServer();
+            s.start();
+        } catch (Exception ex) {
+            ex.printStackTrace();
+            System.exit(-1);
+        } finally {
+            System.out.println("done!");
+        }
+    }
+}

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

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

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java?rev=746947&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java Mon Feb 23 10:15:34 2009
@@ -0,0 +1,79 @@
+/**
+ * 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.security;
+
+import javax.ws.rs.core.MediaType;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.BusFactory;
+import org.apache.cxf.bus.spring.SpringBusFactory;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.systest.jaxrs.Book;
+import org.apache.cxf.systest.jaxrs.BookStore;
+import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class JAXRSHttpsBookTest extends AbstractBusClientServerTestBase {
+
+    private static final String CLIENT_CONFIG_FILE =
+        "org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml";
+        
+    @BeforeClass
+    public static void startServers() throws Exception {
+        assertTrue("server did not launch correctly",
+                   launchServer(BookHttpsServer.class));
+    }
+    
+    @Test
+    public void testGetBook123Client() throws Exception {
+        
+        SpringBusFactory bf = new SpringBusFactory();
+        Bus bus = bf.createBus(CLIENT_CONFIG_FILE);
+        BusFactory.setDefaultBus(bus);
+        
+        BookStore bs = JAXRSClientFactory.create("https://localhost:9095", BookStore.class);
+        // just to verify the interface call goes through CGLIB proxy too
+        assertEquals("https://localhost:9095", WebClient.client(bs).getBaseURI().toString());
+        Book b = bs.getBook("123");
+        assertEquals(b.getId(), 123);
+    }
+    
+    @Test
+    public void testGetBook123WebClient() throws Exception {
+        
+        SpringBusFactory bf = new SpringBusFactory();
+        Bus bus = bf.createBus(CLIENT_CONFIG_FILE);
+        BusFactory.setDefaultBus(bus);
+        
+        JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+        bean.setAddress("https://localhost:9095");
+        WebClient client = bean.createWebClient();
+        assertEquals("https://localhost:9095", client.getBaseURI().toString());
+        
+        client.path("/bookstore/books/123").accept(MediaType.APPLICATION_XML_TYPE);
+        Book b = client.get(Book.class);
+        assertEquals(123, b.getId());
+    }
+    
+}

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

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

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml?rev=746947&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml (added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml Mon Feb 23 10:15:34 2009
@@ -0,0 +1,64 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:http="http://cxf.apache.org/transports/http/configuration"
+       xmlns:httpj="http://cxf.apache.org/transports/http-jetty/configuration"
+       xmlns:sec="http://cxf.apache.org/configuration/security"
+       xsi:schemaLocation="
+        http://www.springframework.org/schema/beans                 http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+        http://cxf.apache.org/transports/http/configuration         http://cxf.apache.org/schemas/configuration/http-conf.xsd
+        http://cxf.apache.org/transports/http-jetty/configuration   http://cxf.apache.org/schemas/configuration/http-jetty.xsd
+        http://cxf.apache.org/configuration/security                http://cxf.apache.org/schemas/configuration/security.xsd
+        ">
+
+    <httpj:engine-factory id="port-9095-tls-config">
+        <httpj:engine port="9095">
+            <httpj:tlsServerParameters>
+               <sec:keyManagers keyPassword="password">
+	           <sec:keyStore type="JKS" password="password" 
+	                file="src/test/java/org/apache/cxf/systest/http/resources/Bethal.jks"/>
+	      		</sec:keyManagers>
+	      		<sec:trustManagers>
+	          	<sec:keyStore type="JKS" password="password"
+	               file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/>
+	     		</sec:trustManagers>
+            </httpj:tlsServerParameters>
+        </httpj:engine>
+    </httpj:engine-factory>
+
+    <!-- -->
+    <!-- HTTP/S configuration for clients -->
+    <!-- -->
+    <http:conduit name="*.http-conduit">
+        <http:client ConnectionTimeout="3000000" ReceiveTimeout="3000000"/>
+        <http:tlsClientParameters disableCNCheck="true">
+            <sec:keyManagers keyPassword="password">
+	           <sec:keyStore type="JKS" password="password" 
+	                file="src/test/java/org/apache/cxf/systest/http/resources/Morpit.jks"/>
+	           </sec:keyManagers>
+	        <sec:trustManagers>
+	           <sec:keyStore type="JKS" password="password"
+	               file="src/test/java/org/apache/cxf/systest/http/resources/Truststore.jks"/>
+	        </sec:trustManagers>
+        </http:tlsClientParameters>
+    </http:conduit>
+
+</beans>
\ No newline at end of file

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

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

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/jaxrs-https.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message