cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1481920 - in /cxf/trunk/rt: frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ frontend/jaxrs/src/main/java/org/apache/cxf/...
Date Mon, 13 May 2013 15:28:16 GMT
Author: sergeyb
Date: Mon May 13 15:28:16 2013
New Revision: 1481920

URL: http://svn.apache.org/r1481920
Log:
[CXF-5000,CXF-5007] Delaying converting headeres to String till the stream is written (required),
minor updates to do with AsyncResponse exceptions, support for reading streams into File (only
to get TCK happy)

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
    cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSInvoker.java Mon May
13 15:28:16 2013
@@ -87,8 +87,12 @@ public class JAXRSInvoker extends Abstra
         if (asyncResp != null) {
             AsyncResponseImpl asyncImpl = (AsyncResponseImpl)asyncResp;
             asyncImpl.prepareContinuation();
-            asyncImpl.handleTimeout();
-            return handleAsyncResponse(exchange, asyncImpl);
+            try {
+                asyncImpl.handleTimeout();
+                return handleAsyncResponse(exchange, asyncImpl);
+            } catch (Throwable t) {
+                return handleAsyncFault(exchange, asyncImpl, t);
+            }
         }
         
         ResourceProvider provider = getResourceProvider(exchange);
@@ -125,19 +129,22 @@ public class JAXRSInvoker extends Abstra
     private Object handleAsyncResponse(Exchange exchange, AsyncResponseImpl ar) {
         Object asyncObj = ar.getResponseObject();
         if (asyncObj instanceof Throwable) {
-            try {
-                return handleFault(new Fault((Throwable)asyncObj), 
-                                   exchange.getInMessage(), null, null);
-            } catch (Fault ex) {
-                ar.setUnmappedThrowable(ex.getCause());
-                return new MessageContentsList(Response.serverError().build());
-            }
+            return handleAsyncFault(exchange, ar, (Throwable)asyncObj);
         } else {
             setResponseContentTypeIfNeeded(exchange.getInMessage(), asyncObj);
             return new MessageContentsList(asyncObj);
         }
     }
     
+    private Object handleAsyncFault(Exchange exchange, AsyncResponseImpl ar, Throwable t)
{
+        try {
+            return handleFault(new Fault(t), exchange.getInMessage(), null, null);
+        } catch (Fault ex) {
+            ar.setUnmappedThrowable(ex.getCause());
+            return new MessageContentsList(Response.serverError().build());
+        }
+    }
+    
     private void persistRoots(Exchange exchange, Object rootInstance, Object provider) {
         exchange.put(JAXRSUtils.ROOT_INSTANCE, rootInstance);
         exchange.put(JAXRSUtils.ROOT_PROVIDER, provider);
@@ -191,12 +198,12 @@ public class JAXRSInvoker extends Abstra
 
         Object result = null;
         ClassLoaderHolder contextLoader = null;
+        AsyncResponseImpl asyncResponse = null;
         try {
             if (setServiceLoaderAsContextLoader(inMessage)) {
                 contextLoader = ClassLoaderUtils
                     .setThreadContextClassloader(resourceObject.getClass().getClassLoader());
             }
-            AsyncResponseImpl asyncResponse = null;
             if (!ori.isSubResourceLocator()) {
                 asyncResponse = (AsyncResponseImpl)inMessage.get(AsyncResponse.class);
             }
@@ -205,7 +212,13 @@ public class JAXRSInvoker extends Abstra
                 result = handleAsyncResponse(exchange, asyncResponse);
             }
         } catch (Fault ex) {
-            return handleFault(ex, inMessage, cri, methodToInvoke);
+            Object faultResponse;
+            if (asyncResponse != null && !asyncResponse.suspendContinuationIfNeeded())
{
+                faultResponse = handleAsyncFault(exchange, asyncResponse, ex.getCause());
   
+            } else {
+                faultResponse = handleFault(ex, inMessage, cri, methodToInvoke);
+            }
+            return faultResponse;
         } finally {
             exchange.put(LAST_SERVICE_OBJECT, resourceObject);
             if (contextLoader != null) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Mon May 13 15:28:16 2013
@@ -21,7 +21,6 @@ package org.apache.cxf.jaxrs.impl;
 
 import java.lang.annotation.Annotation;
 import java.net.URI;
-import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
@@ -40,12 +39,11 @@ import javax.ws.rs.core.Response.Respons
 import javax.ws.rs.core.UriInfo;
 import javax.ws.rs.core.Variant;
 
-import org.apache.cxf.jaxrs.utils.HttpUtils;
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
 
 public final class ResponseBuilderImpl extends ResponseBuilder implements Cloneable {
+    
     private int status = 200;
     private boolean statusSet;
     private Object entity;
@@ -90,7 +88,7 @@ public final class ResponseBuilderImpl e
     }
 
     public ResponseBuilder type(MediaType type) {
-        return type(type == null ? null : JAXRSUtils.mediaTypeToString(type));
+        return setHeader(HttpHeaders.CONTENT_TYPE, type);
     }
 
     public ResponseBuilder type(String type) {
@@ -99,7 +97,7 @@ public final class ResponseBuilderImpl e
 
     @Override
     public ResponseBuilder language(Locale locale) {
-        return language(locale == null ? null : locale.toString());
+        return setHeader(HttpHeaders.CONTENT_LANGUAGE, locale);
     }
     
     public ResponseBuilder language(String language) {
@@ -126,17 +124,19 @@ public final class ResponseBuilderImpl e
     }
 
     public ResponseBuilder tag(EntityTag tag) {
-        return setHeader(HttpHeaders.ETAG, tag == null ? null : tag.toString());
+        return setHeader(HttpHeaders.ETAG, tag);
     }
 
     public ResponseBuilder tag(String tag) {
-        // String tag value needs to be parsed as it may 
-        // contain parameters indicating it's a weak tag, etc
-        return tag(tag == null ? null : EntityTag.valueOf(tag));
+        final String doubleQuote = "\"";
+        if (tag != null && !tag.startsWith(doubleQuote)) {
+            tag = doubleQuote + tag + doubleQuote;
+        }
+        return setHeader(HttpHeaders.ETAG, tag);
     }
 
     public ResponseBuilder lastModified(Date date) {
-        return setHeader(HttpHeaders.LAST_MODIFIED, date == null ? null : toHttpDate(date));
+        return setHeader(HttpHeaders.LAST_MODIFIED, date);
     }
 
     public ResponseBuilder cacheControl(CacheControl cacheControl) {
@@ -145,7 +145,7 @@ public final class ResponseBuilderImpl e
 
     @Override
     public ResponseBuilder expires(Date date) {
-        return setHeader(HttpHeaders.EXPIRES, date == null ? null : toHttpDate(date));
+        return setHeader(HttpHeaders.EXPIRES, date);
     }
 
     @Override
@@ -154,14 +154,7 @@ public final class ResponseBuilderImpl e
     }
     
     public ResponseBuilder header(String name, Object value) {
-        if (HttpUtils.isDateRelatedHeader(name)) {
-            Object theValue = value instanceof Date ? toHttpDate((Date)value) : value;  
-            return setHeader(name, theValue);
-        } else if (HttpHeaders.LOCATION.equals(name)) {
-            return location(URI.create(value.toString()));
-        } else {
-            return addHeader(name, value);
-        }
+        return addHeader(name, value);
     }
 
     
@@ -233,16 +226,11 @@ public final class ResponseBuilderImpl e
         status = 200;
     }
     
-    private String toHttpDate(Date date) {
-        SimpleDateFormat format = HttpUtils.getHttpDateFormat();
-        return format.format(date);
-    }
-    
     private ResponseBuilder setHeader(String name, Object value) {
         if (value == null) {
             metadata.remove(name);
         } else {
-            metadata.putSingle(name, value.toString());
+            metadata.putSingle(name, value);
         }
         return this;
     }
@@ -251,7 +239,7 @@ public final class ResponseBuilderImpl e
         if (values != null && values.length >= 1 && values[0] != null)
{
             for (Object value : values) {
                 if (!valueExists(name, value)) {
-                    metadata.add(name, value.toString());
+                    metadata.add(name, value);
                 }
             }
         } else {
@@ -262,7 +250,7 @@ public final class ResponseBuilderImpl e
     
     private boolean valueExists(String key, Object value) {
         List<Object> values = metadata.get(key);
-        return values == null ? false : values.contains(value.toString());
+        return values == null ? false : values.contains(value);
     }
 
     @Override

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
Mon May 13 15:28:16 2013
@@ -46,6 +46,8 @@ import javax.ws.rs.core.NewCookie;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.Response.Status.Family;
 import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.RuntimeDelegate;
+import javax.ws.rs.ext.RuntimeDelegate.HeaderDelegate;
 
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
@@ -149,29 +151,30 @@ public final class ResponseImpl extends 
     public MultivaluedMap<String, String> getStringHeaders() {
         MetadataMap<String, String> headers = new MetadataMap<String, String>(metadata.size());
         for (Map.Entry<String, List<Object>> entry : metadata.entrySet()) {
-            headers.put(entry.getKey(), toListOfStrings(entry.getValue()));
+            String headerName = entry.getKey();
+            headers.put(headerName, toListOfStrings(headerName, entry.getValue()));
         }
         return headers;
     }
 
-    private String getHeader(String header) {
-        Object value = metadata.getFirst(header);
-        return value == null ? null : value.toString();
-    }
-    
     public String getHeaderString(String header) {
         List<Object> methodValues = metadata.get(header);
-        return HttpUtils.getHeaderString(toListOfStrings(methodValues));
+        return HttpUtils.getHeaderString(toListOfStrings(header, methodValues));
     }
     
     // This conversion is needed as some values may not be Strings
-    private List<String> toListOfStrings(List<Object> values) {
+    private List<String> toListOfStrings(String headerName, List<Object> values)
{
         if (values == null) {
             return null; 
         } else {
             List<String> stringValues = new ArrayList<String>(values.size());
+            RuntimeDelegate rd = RuntimeDelegate.getInstance();
+            @SuppressWarnings("unchecked")
+            HeaderDelegate<Object> hd = rd == null || values.isEmpty() 
+                ? null : (HeaderDelegate<Object>)rd.createHeaderDelegate(values.get(0).getClass());
             for (Object value : values) {
-                stringValues.add(value.toString());
+                String actualValue = hd == null ? value.toString() : hd.toString(value);

+                stringValues.add(actualValue);
             }
             return stringValues;
         }
@@ -211,16 +214,21 @@ public final class ResponseImpl extends 
     }
 
     private Date doGetDate(String dateHeader) {
-        return HttpUtils.getHttpDate(getHeader(dateHeader));
+        Object value = metadata.getFirst(dateHeader);
+        return value == null || value instanceof Date ? (Date)value
+            : HttpUtils.getHttpDate(value.toString());
     }
     
     public EntityTag getEntityTag() {
-        String header = getHeader(HttpHeaders.ETAG);
-        return header == null ? null : EntityTag.valueOf(header);
+        Object header = metadata.getFirst(HttpHeaders.ETAG);
+        return header == null || header instanceof EntityTag ? (EntityTag)header
+            : EntityTag.valueOf(header.toString());
     }
 
     public Locale getLanguage() {
-        return HttpUtils.getLocale(getHeader(HttpHeaders.CONTENT_LANGUAGE));
+        Object header = metadata.getFirst(HttpHeaders.CONTENT_LANGUAGE);
+        return header == null || header instanceof Locale ? (Locale)header
+            : HttpUtils.getLocale(header.toString());
     }
 
     public Date getLastModified() {
@@ -228,17 +236,20 @@ public final class ResponseImpl extends 
     }
 
     public int getLength() {
-        return HttpUtils.getContentLength(getHeader(HttpHeaders.CONTENT_LENGTH));
+        Object header = metadata.getFirst(HttpHeaders.CONTENT_LENGTH);
+        return HttpUtils.getContentLength(header == null ? null : header.toString());
     }
 
     public URI getLocation() {
-        String header = getHeader(HttpHeaders.LOCATION);
-        return header == null ? null : URI.create(header);
+        Object header = metadata.getFirst(HttpHeaders.LOCATION);
+        return header == null || header instanceof URI ? (URI)header
+            : URI.create(header.toString());
     }
 
     public MediaType getMediaType() {
-        String header = getHeader(HttpHeaders.CONTENT_TYPE);
-        return header == null ? null : JAXRSUtils.toMediaType(header);
+        Object header = metadata.getFirst(HttpHeaders.CONTENT_TYPE);
+        return header == null || header instanceof MediaType ? (MediaType)header 
+            : (MediaType)JAXRSUtils.toMediaType(header.toString());
     }
     
     public boolean hasLink(String relation) {

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/BinaryDataProvider.java
Mon May 13 15:28:16 2013
@@ -23,6 +23,7 @@ import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -32,6 +33,8 @@ import java.io.Reader;
 import java.io.Writer;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Type;
+import java.util.UUID;
+import java.util.logging.Logger;
 
 import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
@@ -40,6 +43,8 @@ import javax.ws.rs.core.StreamingOutput;
 import javax.ws.rs.ext.MessageBodyReader;
 import javax.ws.rs.ext.MessageBodyWriter;
 
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.FileUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.message.Message;
@@ -50,6 +55,7 @@ public class BinaryDataProvider<T> exten
     implements MessageBodyReader<T>, MessageBodyWriter<T> {
     
     private static final String HTTP_RANGE_PROPERTY = "http.range.support";
+    private static final Logger LOG = LogUtils.getL7dLogger(BinaryDataProvider.class);
     
     private static final int BUFFER_SIZE = 4096;
     private boolean reportByteArraySize;
@@ -57,7 +63,8 @@ public class BinaryDataProvider<T> exten
     public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations,
MediaType mt) {
         return byte[].class.isAssignableFrom(type)
                || InputStream.class.isAssignableFrom(type)
-               || Reader.class.isAssignableFrom(type);
+               || Reader.class.isAssignableFrom(type)
+               || File.class.isAssignableFrom(type);
     }
 
     public T readFrom(Class<T> clazz, Type genericType, Annotation[] annotations, MediaType
type, 
@@ -72,6 +79,19 @@ public class BinaryDataProvider<T> exten
         if (byte[].class.isAssignableFrom(clazz)) {
             return clazz.cast(IOUtils.readBytesFromStream(is));
         }
+        if (File.class.isAssignableFrom(clazz)) {
+            LOG.warning("Reading data into File objects with the help of pre-packaged" 
+                + " providers is not recommended - use InputStream or custom File reader");
+            // create a temp file, delete on exit
+            File f = FileUtils.createTempFile("File" + UUID.randomUUID().toString(), 
+                                              "jaxrs",
+                                              null,
+                                              true);
+            FileOutputStream fos = new FileOutputStream(f);
+            IOUtils.copy(is, fos);
+            fos.close();
+            return clazz.cast(f);
+        }
         throw new IOException("Unrecognized class");
     }
 

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java Mon
May 13 15:28:16 2013
@@ -31,7 +31,6 @@ import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.ResourceBundle;
-import java.util.TimeZone;
 import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -55,6 +54,7 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.Destination;
 import org.apache.cxf.transport.http.AbstractHTTPDestination;
+import org.apache.cxf.transport.http.Headers;
 import org.apache.cxf.transport.servlet.BaseUrlHelper;
 
 public final class HttpUtils {
@@ -187,11 +187,11 @@ public final class HttpUtils {
     }
     
     public static SimpleDateFormat getHttpDateFormat() {
-        SimpleDateFormat dateFormat = 
-            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
-        TimeZone tZone = TimeZone.getTimeZone("GMT");
-        dateFormat.setTimeZone(tZone);
-        return dateFormat;
+        return Headers.getHttpDateFormat();
+    }
+    
+    public static String toHttpDate(Date date) {
+        return Headers.toHttpDate(date);
     }
     
     public static Date getHttpDate(String value) {
@@ -199,7 +199,7 @@ public final class HttpUtils {
             return null;
         }
         try {
-            return HttpUtils.getHttpDateFormat().parse(value);
+            return Headers.getHttpDateFormat().parse(value);
         } catch (ParseException ex) {
             return null;
         }

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Mon
May 13 15:28:16 2013
@@ -1368,7 +1368,8 @@ public final class JAXRSUtils {
                 }
             }
             writer.writeTo(entity, type, genericType, annotations, mediaType,
-                           httpHeaders, entityStream);
+                           httpHeaders, 
+                           entityStream);
         }
     }
     //CHECKSTYLE:ON

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
Mon May 13 15:28:16 2013
@@ -161,7 +161,7 @@ public class RequestImplTest extends Ass
         Response r = rb.build();
         assertEquals("If-Match precondition was not met", 412, r.getStatus());
         assertEquals("Response should include ETag", 
-                     "\"123\"", r.getMetadata().getFirst("ETag"));
+                     "\"123\"", r.getMetadata().getFirst("ETag").toString());
     }
     
     @Test

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImplTest.java
Mon May 13 15:28:16 2013
@@ -161,7 +161,7 @@ public class ResponseBuilderImplTest ext
     @Test
     public void testAbsoluteLocation() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.putSingle("Location", "http://localhost/rest");
+        m.putSingle("Location", URI.create("http://localhost/rest"));
         checkBuild(Response.ok().location(URI.create("http://localhost/rest")).build(), 200,
null, m);
     }
     
@@ -183,15 +183,15 @@ public class ResponseBuilderImplTest ext
     @Test
     public void testLinkStr() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.putSingle("Link", "<http://example.com/page3>;rel=\"next\"");
+        m.putSingle("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
         checkBuild(Response.ok().link("http://example.com/page3", "next").build(), 200, null,
m);
     }
 
     @Test
     public void testLinkStrMultiple() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Link", "<http://example.com/page1>;rel=\"previous\"");
-        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        m.add("Link", Link.valueOf("<http://example.com/page1>;rel=\"previous\""));
+        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
         checkBuild(Response.ok().link("http://example.com/page1", "previous")
                        .link("http://example.com/page3", "next").build(), 200, null, m);
     }
@@ -199,8 +199,8 @@ public class ResponseBuilderImplTest ext
     @Test
     public void testLinkStrMultipleSameRel() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Link", "<http://example.com/page2.pdf>;rel=\"alternate\"");
-        m.add("Link", "<http://example.com/page2.txt>;rel=\"alternate\"");
+        m.add("Link", Link.valueOf("<http://example.com/page2.pdf>;rel=\"alternate\""));
+        m.add("Link", Link.valueOf("<http://example.com/page2.txt>;rel=\"alternate\""));
         checkBuild(Response.ok().link("http://example.com/page2.pdf", "alternate")
                        .link("http://example.com/page2.txt", "alternate").build(), 200, null,
m);
     }
@@ -209,15 +209,15 @@ public class ResponseBuilderImplTest ext
     public void testLinkURI() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
         URI uri = URI.create("http://example.com/page3");
-        m.putSingle("Link", "<http://example.com/page3>;rel=\"next\"");
+        m.putSingle("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
         checkBuild(Response.ok().link(uri, "next").build(), 200, null, m);
     }
 
     @Test
     public void testLinks() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Link", "<http://example.com/page1>;rel=\"previous\"");
-        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        m.add("Link", Link.valueOf("<http://example.com/page1>;rel=\"previous\""));
+        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
         RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
         Link.Builder linkBuilder = delegate.createLinkBuilder();
         Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
@@ -230,8 +230,8 @@ public class ResponseBuilderImplTest ext
     @Test
     public void testLinksNoReset() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Link", "<http://example.com/page1>;rel=\"previous\"");
-        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        m.add("Link", Link.valueOf("<http://example.com/page1>;rel=\"previous\""));
+        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
         RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
         Link.Builder linkBuilder = delegate.createLinkBuilder();
         Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
@@ -243,7 +243,7 @@ public class ResponseBuilderImplTest ext
     @Test
     public void testLinksWithReset() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Link", "<http://example.com/page3>;rel=\"next\"");
+        m.add("Link", Link.valueOf("<http://example.com/page3>;rel=\"next\""));
         RuntimeDelegateImpl delegate = new RuntimeDelegateImpl();
         Link.Builder linkBuilder = delegate.createLinkBuilder();
         Link prevLink = linkBuilder.uri("http://example.com/page1").rel("previous").build();
@@ -268,8 +268,8 @@ public class ResponseBuilderImplTest ext
     @Test
     public void testAddCookie() {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Set-Cookie", "a=b;Version=1");
-        m.add("Set-Cookie", "c=d;Version=1");
+        m.add("Set-Cookie", new NewCookie("a", "b"));
+        m.add("Set-Cookie", new NewCookie("c", "d"));
         checkBuild(Response.ok().cookie(new NewCookie("a", "b"))
                                 .cookie(new NewCookie("c", "d")).build(), 
                   200, null, m);
@@ -305,14 +305,18 @@ public class ResponseBuilderImplTest ext
     
     @Test
     public void testExpires() throws Exception {
-        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.putSingle("Expires", "Tue, 21 Oct 2008 17:00:00 GMT");
         SimpleDateFormat format = HttpUtils.getHttpDateFormat();
         Date date = format.parse("Tue, 21 Oct 2008 17:00:00 GMT");
-        checkBuild(Response.ok().expires(date).build(), 200, null, m);
-        checkBuild(Response.ok().expires(date)
-                   .header(HttpHeaders.EXPIRES, date).build(), 200, null, m);
-        checkBuild(Response.ok().header(HttpHeaders.EXPIRES, date).build(), 200, null, m);
+        
+        MetadataMap<String, Object> m = new MetadataMap<String, Object>();
+        m.putSingle("Expires", date);
+        checkBuild(Response.ok()
+                   .expires(format.parse("Tue, 21 Oct 2008 17:00:00 GMT"))
+                   .build(), 200, null, m);
+        checkBuild(Response.ok()
+                   .header(HttpHeaders.EXPIRES, 
+                           format.parse("Tue, 21 Oct 2008 17:00:00 GMT"))
+                   .build(), 200, null, m);
     }
     
     @Test
@@ -327,8 +331,8 @@ public class ResponseBuilderImplTest ext
     public void testVariant() throws Exception {
         
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.putSingle("Content-Type", "text/xml");
-        m.putSingle("Content-Language", "en");
+        m.putSingle("Content-Type", MediaType.TEXT_XML_TYPE);
+        m.putSingle("Content-Language", new Locale("en"));
         m.putSingle("Content-Encoding", "gzip");
         Variant v = new Variant(MediaType.TEXT_XML_TYPE, new Locale("en"), "gzip");
         
@@ -346,7 +350,7 @@ public class ResponseBuilderImplTest ext
         List<Object> enc = response.getHeaders().get(HttpHeaders.CONTENT_ENCODING);
         assertTrue(encoding.containsAll(enc));
         List<Object> ct = response.getHeaders().get(HttpHeaders.CONTENT_TYPE);
-        assertTrue(ct.contains(mt.toString()));
+        assertTrue(ct.contains(mt));
     }
     
     protected static List<Variant> getVariantList(List<String> encoding,
@@ -363,7 +367,7 @@ public class ResponseBuilderImplTest ext
     public void testCreatedNoEntity() throws Exception {
         
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.putSingle("Location", "http://foo");
+        m.putSingle("Location", URI.create("http://foo"));
         
         checkBuild(Response.created(new URI("http://foo")).build(),
                    201, null, m);
@@ -384,14 +388,14 @@ public class ResponseBuilderImplTest ext
     public void testVariantsArray() throws Exception {
         
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Content-Type", "application/json");
-        m.add("Content-Language", "en_uk");
-        m.add("Content-Language", "en_gb");
+        m.add("Content-Type", MediaType.APPLICATION_JSON_TYPE);
+        m.add("Content-Language", new Locale("en_uk"));
+        m.add("Content-Language", new Locale("en_gb"));
         m.add("Vary", "Accept");
         m.add("Vary", "Accept-Language");
         
-        Variant json = new Variant(MediaType.APPLICATION_JSON_TYPE, "en_uk", null);
-        Variant xml = new Variant(MediaType.APPLICATION_JSON_TYPE, "en_gb", null);
+        Variant json = new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en_uk"),
null);
+        Variant xml = new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en_gb"), null);
 
         checkBuild(Response.ok().variants(json, xml).build(), 200, null, m);
     }
@@ -399,9 +403,9 @@ public class ResponseBuilderImplTest ext
     @Test
     public void testVariantsList() throws Exception {
         MetadataMap<String, Object> m = new MetadataMap<String, Object>();
-        m.add("Content-Type", "text/xml");
-        m.add("Content-Language", "en_UK");
-        m.add("Content-Language", "en_GB");
+        m.add("Content-Type", MediaType.TEXT_XML_TYPE);
+        m.add("Content-Language", new Locale("en", "UK"));
+        m.add("Content-Language", new Locale("en", "GB"));
         m.add("Content-Encoding", "compress");
         m.add("Content-Encoding", "gzip");
         m.add("Vary", "Accept");

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/ResponseImplTest.java
Mon May 13 15:28:16 2013
@@ -47,7 +47,6 @@ import org.apache.cxf.jaxrs.resources.Bo
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 
 import org.junit.Assert;
-import org.junit.Ignore;
 import org.junit.Test;
 
 
@@ -68,7 +67,6 @@ public class ResponseImplTest extends As
     }
     
     @Test
-    @Ignore
     public void testGetHeaderStringUsingHeaderDelegate() throws Exception {
         StringBean bean = new StringBean("s3");
         RuntimeDelegate original = RuntimeDelegate.getInstance();

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/model/wadl/WadlGeneratorTest.java
Mon May 13 15:28:16 2013
@@ -275,7 +275,7 @@ public class WadlGeneratorTest extends A
     private void checkResponse(Response r) throws Exception {
         assertNotNull(r);
         assertEquals(MediaType.APPLICATION_XML,
-                     r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
+                     r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE).toString());
 //        File f = new File("test.xml");
 //        f.delete();
 //        f.createNewFile();
@@ -300,7 +300,7 @@ public class WadlGeneratorTest extends A
         Message m = mockMessage("http://localhost:8080/baz", "", WadlGenerator.WADL_QUERY,
cris);
         Response r = handleRequest(wg, m);
         assertEquals(WadlGenerator.WADL_TYPE.toString(),
-                     r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE));
+                     r.getMetadata().getFirst(HttpHeaders.CONTENT_TYPE).toString());
         String wadl = r.getEntity().toString();
         Document doc = DOMUtils.readXml(new StringReader(wadl));
         checkGrammars(doc.getDocumentElement(), "thebook", "books", "thebook2", "thechapter");

Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/BinaryDataProviderTest.java
Mon May 13 15:28:16 2013
@@ -54,7 +54,7 @@ public class BinaryDataProviderTest exte
         MessageBodyReader<Object> p = new BinaryDataProvider<Object>();
         assertTrue(p.isReadable(byte[].class, null, null, null)
                    && p.isReadable(InputStream.class, null, null, null)
-                   && !p.isReadable(File.class, null, null, null)
+                   && p.isReadable(File.class, null, null, null)
                    && !p.isReadable(int[].class, null, null, null));
     }
     

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java?rev=1481920&r1=1481919&r2=1481920&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
Mon May 13 15:28:16 2013
@@ -21,16 +21,19 @@ package org.apache.cxf.transport.http;
 import java.io.IOException;
 import java.net.HttpURLConnection;
 import java.net.URLConnection;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.Date;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
+import java.util.TimeZone;
 import java.util.TreeMap;
-
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -416,7 +419,11 @@ public class Headers {
             } else {
                 StringBuilder sb = new StringBuilder();
                 for (int i = 0; i < headerList.size(); i++) {
-                    sb.append(headerList.get(i));
+                    Object headerValue = headerList.get(i);
+                    if (headerValue instanceof Date) {
+                        headerValue = toHttpDate((Date)headerValue);
+                    }
+                    sb.append(headerValue.toString());
                     if (i + 1 < headerList.size()) {
                         sb.append(',');
                     }
@@ -443,4 +450,16 @@ public class Headers {
         }
     }
 
+    public static SimpleDateFormat getHttpDateFormat() {
+        SimpleDateFormat dateFormat = 
+            new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US);
+        TimeZone tZone = TimeZone.getTimeZone("GMT");
+        dateFormat.setTimeZone(tZone);
+        return dateFormat;
+    }
+    
+    public static String toHttpDate(Date date) {
+        SimpleDateFormat format = getHttpDateFormat();
+        return format.format(date);
+    }
 }



Mime
View raw message