cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1525545 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/ rt/rs/client/src/main/java/org/apache/cx...
Date Mon, 23 Sep 2013 09:41:06 GMT
Author: sergeyb
Date: Mon Sep 23 09:41:05 2013
New Revision: 1525545

URL: http://svn.apache.org/r1525545
Log:
[CXF-5135] More fixes bound to the trunk only

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
    cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
    cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurableImpl.java
Mon Sep 23 09:41:05 2013
@@ -83,9 +83,9 @@ public class ConfigurableImpl<C extends 
     public C register(Object provider, Map<Class<?>, Integer> contracts) {
         if (provider instanceof Feature) {
             Feature feature = (Feature)provider;
-            if (feature.configure(new FeatureContextImpl(this))) {
-                config.setFeature(feature);
-            }
+            boolean enabled = feature.configure(new FeatureContextImpl(this));
+            config.setFeature(feature, enabled);
+            
             return configurable;
         }
         config.register(provider, contracts);

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ConfigurationImpl.java
Mon Sep 23 09:41:05 2013
@@ -36,7 +36,7 @@ public class ConfigurationImpl implement
     private RuntimeType runtimeType;
     private Map<Object, Map<Class<?>, Integer>> providers = 
         new HashMap<Object, Map<Class<?>, Integer>>(); 
-    private Set<Feature> features = new HashSet<Feature>();
+    private Map<Feature, Boolean> features = new HashMap<Feature, Boolean>();
     
     public ConfigurationImpl(RuntimeType rt) {
         this.runtimeType = rt;
@@ -52,7 +52,8 @@ public class ConfigurationImpl implement
                 if (!(o instanceof Feature)) {
                     registerParentProvider(o, parent, defaultContracts);
                 } else {
-                    features.add((Feature)o);
+                    Feature f = (Feature)o;
+                    features.put(f, parent.isEnabled(f));
                 }
                 providerClasses.remove(o.getClass());
             }
@@ -95,7 +96,7 @@ public class ConfigurationImpl implement
     public Set<Object> getInstances() {
         Set<Object> allInstances = new HashSet<Object>();
         allInstances.addAll(providers.keySet());
-        allInstances.addAll(features);
+        allInstances.addAll(features.keySet());
         return Collections.unmodifiableSet(allInstances);
     }
 
@@ -111,7 +112,7 @@ public class ConfigurationImpl implement
 
     @Override
     public Collection<String> getPropertyNames() {
-        return props.keySet();
+        return Collections.unmodifiableSet(props.keySet());
     }
 
     @Override
@@ -121,12 +122,12 @@ public class ConfigurationImpl implement
 
     @Override
     public boolean isEnabled(Feature f) {
-        return features.contains(f);
+        return features.containsKey(f);
     }
 
     @Override
     public boolean isEnabled(Class<? extends Feature> f) {
-        for (Feature feature : features) {
+        for (Feature feature : features.keySet()) {
             if (feature.getClass().isAssignableFrom(f)) {
                 return true;
             }
@@ -157,8 +158,8 @@ public class ConfigurationImpl implement
         }
     }
     
-    public void setFeature(Feature f) {
-        features.add(f);
+    public void setFeature(Feature f, boolean enabled) {
+        features.put(f, enabled);
     }
     
     
@@ -166,7 +167,10 @@ public class ConfigurationImpl implement
         register(provider, initContractsMap(bindingPriority, contracts));
     }
     
-    public void register(Object provider, Map<Class<?>, Integer> contracts) {
   
+    public void register(Object provider, Map<Class<?>, Integer> contracts) {
+        if (provider.getClass() == Class.class) {
+            provider = createProvider((Class<?>)provider);
+        }
         Map<Class<?>, Integer> metadata = providers.get(provider);
         if (metadata == null) {
             metadata = new HashMap<Class<?>, Integer>();

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ContainerRequestContextImpl.java
Mon Sep 23 09:41:05 2013
@@ -20,8 +20,6 @@ package org.apache.cxf.jaxrs.impl;
 
 import java.io.InputStream;
 import java.net.URI;
-import java.util.List;
-import java.util.Map;
 
 import javax.ws.rs.HttpMethod;
 import javax.ws.rs.container.ContainerRequestContext;
@@ -78,11 +76,9 @@ public class ContainerRequestContextImpl
         m.setContent(InputStream.class, is);
     }
 
-    @SuppressWarnings("unchecked")
     public MultivaluedMap<String, String> getHeaders() {
         h = null;
-        return new MetadataMap<String, String>(
-            (Map<String, List<String>>)m.get(Message.PROTOCOL_HEADERS), false,
false, true);
+        return HttpUtils.getModifiableStringHeaders(m);
     }
 
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
Mon Sep 23 09:41:05 2013
@@ -23,7 +23,6 @@ import java.io.OutputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
 import java.util.List;
-import java.util.Map;
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -31,6 +30,7 @@ import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.WriterInterceptor;
 import javax.ws.rs.ext.WriterInterceptorContext;
 
+import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
@@ -61,11 +61,9 @@ public class WriterInterceptorContextImp
         return entity;
     }
 
-    @SuppressWarnings("unchecked")
     @Override
     public MultivaluedMap<String, Object> getHeaders() {
-        return new MetadataMap<String, Object>(
-            (Map<String, List<Object>>)m.get(Message.PROTOCOL_HEADERS), false,
false, true);
+        return HttpUtils.getModifiableHeaders(m);
     }
 
     @Override

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
Mon Sep 23 09:41:05 2013
@@ -24,6 +24,7 @@ import java.lang.reflect.Type;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
+import javax.ws.rs.ProcessingException;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -64,23 +65,25 @@ public class WriterInterceptorMBW implem
         MultivaluedMap<String, Object> headers = c.getHeaders();
         Object mtObject = headers.getFirst(HttpHeaders.CONTENT_TYPE);
         MediaType entityMt = mtObject == null ? c.getMediaType() : JAXRSUtils.toMediaType(mtObject.toString());
-        m.put(Message.CONTENT_TYPE, mtObject.toString());
+        m.put(Message.CONTENT_TYPE, entityMt.toString());
         
         Class<?> entityCls = c.getType();
         Type entityType = c.getGenericType();
         Annotation[] entityAnns = c.getAnnotations();
         
-        if (m.get(ProviderFactory.PROVIDER_SELECTION_PROPERTY_CHANGED) == Boolean.TRUE
+        if (writer == null
+            || m.get(ProviderFactory.PROVIDER_SELECTION_PROPERTY_CHANGED) == Boolean.TRUE
             && !writer.isWriteable(entityCls, entityType, entityAnns, entityMt))
{
             
             writer = (MessageBodyWriter<Object>)ProviderFactory.getInstance(m)
                 .createMessageBodyWriter(entityCls, entityType, entityAnns, entityMt, m);
             if (writer == null) {
-                throw new RuntimeException("No writer available");
+                String errorMessage = JAXRSUtils.logMessageHandlerProblem("NO_MSG_WRITER",
entityCls, entityMt);
+                throw new ProcessingException(errorMessage);
             }
         }
         
-        HttpUtils.convertHeaderValuesToStringIfNeeded(headers);
+        HttpUtils.convertHeaderValuesToString(headers, true);
         
         writer.writeTo(c.getEntity(), 
                        c.getType(), 

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/LinkBuilderImplTest.java
Mon Sep 23 09:41:05 2013
@@ -102,7 +102,7 @@ public class LinkBuilderImplTest extends
         Link.Builder linkBuilder = Link.fromMethod(TestResource.class, "consumesAppJson");
         Link link = linkBuilder.build();
         String resource = link.toString();
-        assertTrue(resource.contains("<resource/consumesappjson>"));
+        assertTrue(resource.contains("<consumesappjson>"));
     }
     
     @Path("resource")

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java Mon
Sep 23 09:41:05 2013
@@ -22,7 +22,6 @@ import java.io.Closeable;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.io.Reader;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Type;
@@ -37,12 +36,10 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.ResourceBundle;
 import java.util.logging.Logger;
 
 import javax.ws.rs.ProcessingException;
 import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.client.ResponseProcessingException;
 import javax.ws.rs.core.Cookie;
 import javax.ws.rs.core.EntityTag;
 import javax.ws.rs.core.Form;
@@ -53,13 +50,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.ResponseBuilder;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.ext.ParamConverter;
-import javax.ws.rs.ext.ReaderInterceptor;
 import javax.ws.rs.ext.WriterInterceptor;
-import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.cxf.Bus;
-import org.apache.cxf.common.i18n.BundleUtils;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.endpoint.ClientLifeCycleManager;
 import org.apache.cxf.endpoint.ConduitSelector;
@@ -73,6 +67,7 @@ import org.apache.cxf.interceptor.StaxIn
 import org.apache.cxf.jaxrs.client.spec.ClientRequestFilterInterceptor;
 import org.apache.cxf.jaxrs.client.spec.ClientResponseFilterInterceptor;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.impl.ResponseImpl;
 import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
@@ -107,8 +102,7 @@ public abstract class AbstractClient imp
     private static final String HEADER_SPLIT_PROPERTY =
         "org.apache.cxf.http.header.split";
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class);
-    private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractClient.class);
-    
+        
     protected ClientConfiguration cfg = new ClientConfiguration();
     private ClientState state;
     
@@ -353,6 +347,7 @@ public abstract class AbstractClient imp
     protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws
Exception {
         Response response = exchange.get(Response.class);
         if (response != null) {
+            outMessage.getExchange().getInMessage().put(Message.PROTOCOL_HEADERS, response.getStringHeaders());
             return JAXRSUtils.fromResponse(JAXRSUtils.copyResponseIfNeeded(response));
         }
         
@@ -449,10 +444,10 @@ public abstract class AbstractClient imp
                     realOs.flush();
                 }
             } catch (Exception ex) {
-                reportMessageHandlerProblem("MSG_WRITER_PROBLEM", cls, contentType, ex, null);
+                reportMessageHandlerProblem("MSG_WRITER_PROBLEM", cls, contentType, ex);
             }
         } else {
-            reportMessageHandlerProblem("NO_MSG_WRITER", cls, contentType, null, null);
+            reportMessageHandlerProblem("NO_MSG_WRITER", cls, contentType, null);
         }
                                                                                  
     }
@@ -468,7 +463,6 @@ public abstract class AbstractClient imp
         }
     }
     
-    @SuppressWarnings("unchecked")
     protected <T> T readBody(Response r, Message outMessage, Class<T> cls, 
                              Type type, Annotation[] anns) {
         
@@ -476,55 +470,11 @@ public abstract class AbstractClient imp
             return cls.cast(r);
         }
         
-        Message responseMessage = outMessage.getExchange().getInMessage();
-        
-        InputStream inputStream = (InputStream)r.getEntity();
-        if (inputStream == null) {
-            if (responseMessage == null) {
-                responseMessage = outMessage.getExchange().getInFaultMessage();    
-            }    
-            if (responseMessage == null
-                || responseMessage.getContent(XMLStreamReader.class) == null
-                    && responseMessage.getContent(Reader.class) == null) {
-            
-                return null;
-            }
-        }
-        
         int status = r.getStatus();
-        if (status < 200 || status == 204 || status >= 300) {
-            Object length = r.getMetadata().getFirst(HttpHeaders.CONTENT_LENGTH);
-            if (length == null || Integer.parseInt(length.toString()) == 0 || status >=
300) {
-                return null;
-            }
-        }
-        
-        MediaType contentType = getResponseContentType(r);
-        
-        List<ReaderInterceptor> readers 
-            = ClientProviderFactory.getInstance(outMessage).createMessageBodyReaderInterceptor(
-                cls, type, anns, contentType, outMessage, null);
-        if (readers != null) {
-            try {
-                responseMessage.put(Message.PROTOCOL_HEADERS, r.getMetadata());
-                return (T)JAXRSUtils.readFromMessageBodyReader(readers, cls, type, 
-                                                            anns, inputStream, contentType,

-                                                            responseMessage);
-            } catch (Exception ex) {
-                reportMessageHandlerProblem("MSG_READER_PROBLEM", cls, contentType, ex, r);
-            } finally {
-                if (inputStream != null && responseStreamCanBeClosed(outMessage,
cls)) {
-                    try {
-                        inputStream.close();
-                    } catch (IOException ex) { 
-                        // ignore
-                    }
-                }
-            }
-        } else {
-            reportMessageHandlerProblem("NO_MSG_READER", cls, contentType, null, r);
+        if ((status < 200 || status == 204) && r.getLength() <= 0 || status
>= 300) {
+            return null;
         }
-        return null;                                                
+        return ((ResponseImpl)r).doReadEntity(cls, type, anns);                         
                      
     }
     
     protected boolean responseStreamCanBeClosed(Message outMessage, Class<?> cls) {
@@ -754,27 +704,9 @@ public abstract class AbstractClient imp
         return pValue.toString();
     }
     
-    protected static void reportMessageHandlerProblem(String name, Class<?> cls, MediaType
ct, 
-                                                      Throwable cause, Response response)
{
-        org.apache.cxf.common.i18n.Message errorMsg = 
-            new org.apache.cxf.common.i18n.Message(name, 
-                                                   BUNDLE,
-                                                   cls,
-                                                   JAXRSUtils.mediaTypeToString(ct));
-        LOG.severe(errorMsg.toString());
-        if (response == null) {
-            throw new ProcessingException(errorMsg.toString(), cause);
-        } else {
-            throw new ResponseProcessingException(response, errorMsg.toString(), cause);
-        }
-    }
-    
-    private static MediaType getResponseContentType(Response r) {
-        MultivaluedMap<String, Object> map = r.getMetadata();
-        if (map.containsKey(HttpHeaders.CONTENT_TYPE)) {
-            return JAXRSUtils.toMediaType(map.getFirst(HttpHeaders.CONTENT_TYPE).toString());
-        }
-        return MediaType.WILDCARD_TYPE;
+    protected static void reportMessageHandlerProblem(String name, Class<?> cls, MediaType
ct, Throwable cause) {
+        String errorMessage = JAXRSUtils.logMessageHandlerProblem("NO_MSG_WRITER", cls, ct);
+        throw new ProcessingException(errorMessage, cause);
     }
     
     protected static void setAllHeaders(MultivaluedMap<String, String> headers, HttpURLConnection
conn) {

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties (original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/Messages.properties Mon
Sep 23 09:41:05 2013
@@ -24,8 +24,4 @@ SINGLE_BODY_ONLY=Resource method {0}.{1}
 ONLY_FORM_ALLOWED=Resource method {0}.{1} mixes JAXRS FormParam parameters with other types
of parameters
 NO_BODY_IN_SUBRESOURCE=SubResource method {0}.{1} expects request body, only URI-bound parameters
are supported
 NO_CONTEXT_PARAMETERS=Resource method {0}.{1} expects JAXRS Context parameter which is not
supported on the client side
-NO_MSG_READER =.No message body reader has been found for class : {0}, ContentType : {1}.
-MSG_READER_PROBLEM =.Problem with reading the response message, class : {0}, ContentType
: {1}.
-NO_MSG_WRITER =.No message body writer has been found for class : {0}, ContentType : {1}.
-MSG_WRITER_PROBLEM =.Problem with writing the request message, class : {0}, ContentType :
{1}.
 REMOTE_CONNECTION_PROBLEM=Problem with creating a remote connection
\ No newline at end of file

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientConfigurableImpl.java
Mon Sep 23 09:41:05 2013
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.jaxrs.client.spec;
 
+import javax.ws.rs.RuntimeType;
 import javax.ws.rs.client.ClientRequestFilter;
 import javax.ws.rs.client.ClientResponseFilter;
 import javax.ws.rs.core.Configurable;
@@ -42,7 +43,9 @@ public class ClientConfigurableImpl<C ex
     }
     
     public ClientConfigurableImpl(C configurable, Configuration config) {
-        super(configurable, CLIENT_FILTER_INTERCEPTOR_CLASSES, 
-              new ConfigurationImpl(config, CLIENT_FILTER_INTERCEPTOR_CLASSES));
+        super(configurable,
+              CLIENT_FILTER_INTERCEPTOR_CLASSES, 
+              config == null ? new ConfigurationImpl(RuntimeType.CLIENT)
+                  : new ConfigurationImpl(config, CLIENT_FILTER_INTERCEPTOR_CLASSES));
     }
 }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/ClientImpl.java
Mon Sep 23 09:41:05 2013
@@ -37,7 +37,6 @@ import javax.ws.rs.core.Feature;
 import javax.ws.rs.core.Link;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriBuilder;
-import javax.ws.rs.core.UriBuilderException;
 
 import org.apache.cxf.configuration.jsse.TLSClientParameters;
 import org.apache.cxf.jaxrs.client.ClientProviderFactory;
@@ -71,6 +70,7 @@ public class ClientImpl implements Clien
 
     @Override
     public Builder invocation(Link link) {
+        checkNull(link);
         checkClosed();
         Builder builder = target(link.getUriBuilder()).request();
         String type = link.getType();
@@ -82,14 +82,17 @@ public class ClientImpl implements Clien
 
     @Override
     public WebTarget target(UriBuilder builder) {
+        checkNull(builder);
         checkClosed();
+        
         return new WebTargetImpl(builder, getConfiguration());
     }
     
     
     @Override
     public WebTarget target(String address) {
-        if (address != null && address.isEmpty()) {
+        checkNull(address);
+        if (address.isEmpty()) {
             address = "/";
         }
         return target(UriBuilder.fromUri(address));
@@ -97,14 +100,23 @@ public class ClientImpl implements Clien
     
     @Override
     public WebTarget target(Link link) {
+        checkNull(link);
         return target(link.getUriBuilder());
     }
 
     @Override
     public WebTarget target(URI uri) {
+        checkNull(uri);
         return target(UriBuilder.fromUri(uri));
     }
 
+    private void checkNull(Object... target) {
+        for (Object o : target) {
+            if (o == null) {
+                throw new NullPointerException("Value is null");
+            }
+        }
+    }
     
     @Override
     public HostnameVerifier getHostnameVerifier() {
@@ -136,55 +148,65 @@ public class ClientImpl implements Clien
 
     @Override
     public Configuration getConfiguration() {
+        checkClosed();
         return configImpl.getConfiguration();
     }
 
     @Override
     public Client property(String name, Object value) {
+        checkClosed();
         return configImpl.property(name, value);
     }
 
     @Override
     public Client register(Class<?> cls) {
+        checkClosed();
         return configImpl.register(cls);
     }
 
     @Override
     public Client register(Object object) {
+        checkClosed();
         return configImpl.register(object);
     }
 
     @Override
     public Client register(Class<?> cls, int index) {
+        checkClosed();
         return configImpl.register(cls, index);
     }
 
     @Override
     public Client register(Class<?> cls, Class<?>... contracts) {
+        checkClosed();
         return configImpl.register(cls, contracts);
     }
 
     @Override
     public Client register(Class<?> cls, Map<Class<?>, Integer> map) {
+        checkClosed();
         return configImpl.register(cls, map);
     }
 
     @Override
     public Client register(Object object, int index) {
+        checkClosed();
         return configImpl.register(object, index);
     }
 
     @Override
     public Client register(Object object, Class<?>... contracts) {
+        checkClosed();
         return configImpl.register(object, contracts);
     }
 
     @Override
     public Client register(Object object, Map<Class<?>, Integer> map) {
+        checkClosed();
         return configImpl.register(object, map);
     }
     
-    class WebTargetImpl implements WebTarget {
+    public class WebTargetImpl implements WebTarget {
         private Configurable<WebTarget> configImpl;
         private UriBuilder uriBuilder;
         private WebClient targetClient;
@@ -205,7 +227,7 @@ public class ClientImpl implements Clien
         
         @Override
         public Builder request() {
-            ClientImpl.this.checkClosed();
+            checkClosed();
             
             initTargetClientIfNeeded(); 
             
@@ -264,31 +286,47 @@ public class ClientImpl implements Clien
 
         @Override
         public URI getUri() {
-            ClientImpl.this.checkClosed();
+            checkClosed();
             return uriBuilder.build();
         }
 
         @Override
         public UriBuilder getUriBuilder() {
-            ClientImpl.this.checkClosed();
+            checkClosed();
             return uriBuilder.clone();
         }
 
         @Override
-        public WebTarget matrixParam(String name, Object... values) {
-            return newWebTarget(getUriBuilder().matrixParam(name, values));
-        }
-        
-        @Override
         public WebTarget path(String path) {
+            checkNull(path);
             return newWebTarget(getUriBuilder().path(path));
         }
 
         @Override
         public WebTarget queryParam(String name, Object... values) {
-            return newWebTarget(getUriBuilder().queryParam(name, values));
+            checkNullValues(name, values);
+            UriBuilder thebuilder = getUriBuilder();
+            if (values == null || values.length == 1 && values[0] == null) {
+                thebuilder.replaceQueryParam(name, (Object[])null);
+            } else {
+                thebuilder.queryParam(name, values);
+            }
+            return newWebTarget(thebuilder);
         }
-
+        
+        @Override
+        public WebTarget matrixParam(String name, Object... values) {
+            checkNullValues(name, values);
+            
+            UriBuilder thebuilder = getUriBuilder();
+            if (values == null || values.length == 1 && values[0] == null) {
+                thebuilder.replaceMatrixParam(name, (Object[])null);
+            } else {
+                thebuilder.matrixParam(name, values);
+            }
+            return newWebTarget(thebuilder);
+        }
+        
         @Override
         public WebTarget resolveTemplate(String name, Object value) {
             return resolveTemplate(name, value, true);
@@ -296,11 +334,13 @@ public class ClientImpl implements Clien
 
         @Override
         public WebTarget resolveTemplate(String name, Object value, boolean encodeSlash)
{
+            checkNull(name, value);
             return newWebTarget(getUriBuilder().resolveTemplate(name, value, encodeSlash));
         }
 
         @Override
         public WebTarget resolveTemplateFromEncoded(String name, Object value) {
+            checkNull(name, value);
             return newWebTarget(getUriBuilder().resolveTemplateFromEncoded(name, value));
         }
 
@@ -311,7 +351,8 @@ public class ClientImpl implements Clien
 
         @Override
         public WebTarget resolveTemplates(Map<String, Object> templatesMap, boolean
encodeSlash) {
-            ClientImpl.this.checkClosed();
+            checkNullMap(templatesMap);
+            
             if (templatesMap.isEmpty()) {
                 return this;
             }
@@ -320,7 +361,7 @@ public class ClientImpl implements Clien
 
         @Override
         public WebTarget resolveTemplatesFromEncoded(Map<String, Object> templatesMap)
{
-            ClientImpl.this.checkClosed();
+            checkNullMap(templatesMap);
             if (templatesMap.isEmpty()) {
                 return this;
             }
@@ -328,12 +369,13 @@ public class ClientImpl implements Clien
         }
         
         private WebTarget newWebTarget(UriBuilder newBuilder) {
+            checkClosed();
             boolean complete = false;
             if (targetClient != null) {
                 try {
                     newBuilder.build();
                     complete = true;
-                } catch (UriBuilderException ex) {
+                } catch (IllegalArgumentException ex) {
                     //the builder still has unresolved vars
                 }
             }
@@ -346,52 +388,75 @@ public class ClientImpl implements Clien
         
         @Override
         public Configuration getConfiguration() {
+            checkClosed();
             return configImpl.getConfiguration();
         }
 
         @Override
         public WebTarget property(String name, Object value) {
+            checkClosed();
             return configImpl.property(name, value);
         }
 
         @Override
         public WebTarget register(Class<?> cls) {
+            checkClosed();
             return configImpl.register(cls);
         }
 
         @Override
         public WebTarget register(Object object) {
+            checkClosed();
             return configImpl.register(object);
         }
 
         @Override
         public WebTarget register(Class<?> cls, int index) {
+            checkClosed();
             return configImpl.register(cls, index);
         }
 
         @Override
         public WebTarget register(Class<?> cls, Class<?>... contracts) {
+            checkClosed();
             return configImpl.register(cls, contracts);
         }
 
         @Override
         public WebTarget register(Class<?> cls, Map<Class<?>, Integer>
map) {
+            checkClosed();
             return configImpl.register(cls, map);
         }
 
         @Override
         public WebTarget register(Object object, int index) {
+            checkClosed();
             return configImpl.register(object, index);
         }
 
         @Override
         public WebTarget register(Object object, Class<?>... contracts) {
+            checkClosed();
             return configImpl.register(object, contracts);
         }
 
         @Override
         public WebTarget register(Object object, Map<Class<?>, Integer> map)
{
+            checkClosed();
             return configImpl.register(object, map);
         }
+        
+        private void checkNullValues(Object name, Object... values) {
+            checkNull(name);
+            if (values != null && values.length > 1) {
+                checkNull(values);
+            }
+        }
+        
+        private void checkNullMap(Map<String, Object> templatesMap) {
+            checkNull(templatesMap);
+            checkNull(templatesMap.keySet().toArray());
+            checkNull(templatesMap.values().toArray());
+        }
     }
 }

Modified: cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
(original)
+++ cxf/trunk/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/spec/InvocationBuilderImpl.java
Mon Sep 23 09:41:05 2013
@@ -19,6 +19,7 @@
 package org.apache.cxf.jaxrs.client.spec;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.Future;
@@ -37,6 +38,8 @@ import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.RuntimeDelegate;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.client.WebClient;
@@ -231,16 +234,30 @@ public class InvocationBuilderImpl imple
 
     @Override
     public Builder header(String name, Object value) {
-        webClient.header(name, value);
+        RuntimeDelegate rd = HttpUtils.getOtherRuntimeDelegate();
+        doSetHeader(rd, name, value);
         return this;
     }
-
+    
     @Override
     public Builder headers(MultivaluedMap<String, Object> headers) {
-        
+        RuntimeDelegate rd = HttpUtils.getOtherRuntimeDelegate();
+        for (Map.Entry<String, List<Object>> entry : headers.entrySet()) {
+            for (Object value : entry.getValue()) {
+                doSetHeader(rd, entry.getKey(), value);
+            }
+        }
         return this;
     }
 
+    private void doSetHeader(RuntimeDelegate rd, String name, Object value) {
+        HeaderDelegate<Object> hd = HttpUtils.getHeaderDelegate(rd, value); 
+        if (hd != null) {
+            value = hd.toString(value);
+        }
+        webClient.header(name, value);
+    }
+    
     @Override
     public Builder property(String name, Object value) {
         Map<String, Object> contextProps = WebClient.getConfig(webClient).getRequestContext();

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
Mon Sep 23 09:41:05 2013
@@ -115,7 +115,7 @@ public class JAXRS20ClientServerBookTest
     public void testGetBookSpec() {
         String address = "http://localhost:" + PORT + "/bookstore/bookheaders/simple";
         Client client = ClientBuilder.newClient();
-        client.register(new ClientFilterClientAndConfigCheck());
+        client.register((Object)ClientFilterClientAndConfigCheck.class);
         client.property("clientproperty", "somevalue");
         Book book = client.target(address).request("application/xml").get(Book.class);
         assertEquals(124L, book.getId());
@@ -577,7 +577,7 @@ public class JAXRS20ClientServerBookTest
 
         @Override
         public void filter(ClientRequestContext context) throws IOException {
-            context.abortWith(Response.status(201).entity(context.getEntity()).build());
+            context.abortWith(Response.status(201).entity(context.getEntity()).type(MediaType.TEXT_XML_TYPE).build());
         }
     }
     
@@ -589,7 +589,7 @@ public class JAXRS20ClientServerBookTest
         }
     }
     
-    private static class ClientFilterClientAndConfigCheck implements ClientRequestFilter
{
+    public static class ClientFilterClientAndConfigCheck implements ClientRequestFilter {
 
         @Override
         public void filter(ClientRequestContext context) throws IOException {
@@ -618,7 +618,9 @@ public class JAXRS20ClientServerBookTest
         @Override
         public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException,
             WebApplicationException {
-            context.getHeaders().add("ClientReaderInterceptor", "clientRead");
+            if (context.getInputStream() != null) {
+                context.getHeaders().add("ClientReaderInterceptor", "clientRead");
+            }
             return context.proceed();
         }
         

Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=1525545&r1=1525544&r2=1525545&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Mon Sep 23 09:41:05 2013
@@ -1193,8 +1193,9 @@ public class JAXRSClientServerBookTest e
     
     @Test
     public void testNoMessageWriterFound() throws Exception {
-        String msg1 = "No message body writer has been found for response class GregorianCalendar.";
-        String msg2 = "No message body writer has been found for response class Calendar.";
+        String msg1 = 
+            "No message body writer has been found for class java.util.GregorianCalendar,
ContentType: */*";
+        String msg2 = "No message body writer has been found for class java.util.Calendar,
ContentType: */*";
         
         getAndCompareStrings("http://localhost:" + PORT + "/bookstore/timetable", 
                              new String[]{msg1, msg2}, "*/*", 500);



Mime
View raw message