cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1464503 - in /cxf/branches/2.6.x-fixes: ./ api/src/main/java/org/apache/cxf/common/util/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/ rt/frontend/jaxrs/src...
Date Thu, 04 Apr 2013 12:38:21 GMT
Author: sergeyb
Date: Thu Apr  4 12:38:20 2013
New Revision: 1464503

URL: http://svn.apache.org/r1464503
Log:
Merged revisions 1463595,1464389 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.7.x-fixes

................
  r1463595 | sergeyb | 2013-04-02 18:29:34 +0300 (Tue, 02 Apr 2013) | 9 lines
  
  Merged revisions 1463583 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1463583 | sergeyb | 2013-04-02 18:06:29 +0300 (Tue, 02 Apr 2013) | 1 line
    
    [CXF-4825] Trying to make sure JAX-RS Responses created by alternative implementations
are not used internally or replaced by the CXF implementation if needed
  ........
................
  r1464389 | sergeyb | 2013-04-04 12:24:20 +0300 (Thu, 04 Apr 2013) | 13 lines
  
  Merged revisions 1464337,1464355 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1464337 | sergeyb | 2013-04-04 10:56:46 +0300 (Thu, 04 Apr 2013) | 1 line
    
    [CXF-4825] Replacing MediaType.valueOf calls with the internal util calls
  ........
    r1464355 | sergeyb | 2013-04-04 11:42:42 +0300 (Thu, 04 Apr 2013) | 1 line
    
    [CXF-4825] Replacing MediaType.toString calls with the internal util calls
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
(original)
+++ cxf/branches/2.6.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
Thu Apr  4 12:38:20 2013
@@ -46,6 +46,23 @@ public final class ReflectionUtil {
         // intentionally empty
     }
     
+    public static <T> T accessDeclaredField(final Field f, final Object o, final Class<T>
responseClass) {
+        return AccessController.doPrivileged(new PrivilegedAction<T>() {
+            public T run() {
+                try {
+                    f.setAccessible(true);
+                    return responseClass.cast(f.get(o));
+                } catch (SecurityException e) {
+                    return null;
+                } catch (IllegalAccessException e) {
+                    return null;
+                } finally {
+                    f.setAccessible(false);
+                }
+            }
+        });
+    }
+    
     public static Field getDeclaredField(final Class<?> cls, final String name) {
         return AccessController.doPrivileged(new PrivilegedAction<Field>() {
             public Field run() {

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
Thu Apr  4 12:38:20 2013
@@ -66,6 +66,7 @@ import org.apache.cxf.jaxrs.model.URITem
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
 import org.apache.cxf.jaxrs.utils.HttpUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -137,7 +138,7 @@ public abstract class AbstractClient imp
      */
     public Client accept(MediaType... types) {
         for (MediaType mt : types) {
-            possiblyAddHeader(HttpHeaders.ACCEPT, mt.toString());
+            possiblyAddHeader(HttpHeaders.ACCEPT, JAXRSUtils.mediaTypeToString(mt));
         }
         return this;
     }
@@ -146,7 +147,7 @@ public abstract class AbstractClient imp
      * {@inheritDoc}
      */
     public Client type(MediaType ct) {
-        return type(ct.toString());
+        return type(JAXRSUtils.mediaTypeToString(ct));
     }
     
     /**
@@ -320,7 +321,7 @@ public abstract class AbstractClient imp
     
     protected ResponseBuilder setResponseBuilder(Message outMessage, Exchange exchange) throws
Exception {
         Integer status = getResponseCode(exchange);
-        ResponseBuilder currentResponseBuilder = Response.status(status);
+        ResponseBuilder currentResponseBuilder = JAXRSUtils.toResponseBuilder(status);
         
         Message responseMessage = exchange.getInMessage() != null 
             ? exchange.getInMessage() : exchange.getInFaultMessage();
@@ -383,7 +384,7 @@ public abstract class AbstractClient imp
         @SuppressWarnings("unchecked")
         Class<T> theClass = (Class<T>)cls;
         
-        MediaType contentType = MediaType.valueOf(headers.getFirst("Content-Type").toString());

+        MediaType contentType = JAXRSUtils.toMediaType(headers.getFirst("Content-Type").toString());

         
         MessageBodyWriter<T> mbw = ProviderFactory.getInstance(outMessage)
             .createMessageBodyWriter(theClass, type, anns, contentType, outMessage);
@@ -629,7 +630,7 @@ public abstract class AbstractClient imp
             new org.apache.cxf.common.i18n.Message(name, 
                                                    BUNDLE,
                                                    cls,
-                                                   ct.toString());
+                                                   JAXRSUtils.mediaTypeToString(ct));
         LOG.severe(errorMsg.toString());
         throw new ClientWebApplicationException(errorMsg.toString(), cause, response);
     }
@@ -637,7 +638,7 @@ public abstract class AbstractClient imp
     private static MediaType getResponseContentType(Response r) {
         MultivaluedMap<String, Object> map = r.getMetadata();
         if (map.containsKey(HttpHeaders.CONTENT_TYPE)) {
-            return MediaType.valueOf(map.getFirst(HttpHeaders.CONTENT_TYPE).toString());
+            return JAXRSUtils.toMediaType(map.getFirst(HttpHeaders.CONTENT_TYPE).toString());
         }
         return MediaType.WILDCARD_TYPE;
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ClientProxyImpl.java
Thu Apr  4 12:38:20 2013
@@ -62,6 +62,7 @@ import org.apache.cxf.jaxrs.provider.Pro
 import org.apache.cxf.jaxrs.utils.AnnotationUtils;
 import org.apache.cxf.jaxrs.utils.FormUtils;
 import org.apache.cxf.jaxrs.utils.InjectionUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageContentsList;
@@ -318,7 +319,7 @@ public class ClientProxyImpl extends Abs
             } else {
                 String cType = ori.getConsumeTypes().isEmpty() 
                     || ori.getConsumeTypes().get(0).equals(MediaType.WILDCARD_TYPE) 
-                    ? MediaType.APPLICATION_XML : ori.getConsumeTypes().get(0).toString();
  
+                    ? MediaType.APPLICATION_XML : JAXRSUtils.mediaTypeToString(ori.getConsumeTypes().get(0));
  
                 headers.putSingle(HttpHeaders.CONTENT_TYPE, cType);
             }
         }
@@ -338,7 +339,7 @@ public class ClientProxyImpl extends Abs
             }
             
             for (MediaType mt : accepts) {
-                headers.add(HttpHeaders.ACCEPT, mt.toString());
+                headers.add(HttpHeaders.ACCEPT, JAXRSUtils.mediaTypeToString(mt));
             }
         }
             
@@ -352,7 +353,7 @@ public class ClientProxyImpl extends Abs
         }
         List<MediaType> types = new ArrayList<MediaType>();
         for (String s : headers) {
-            types.add(MediaType.valueOf(s));
+            types.add(JAXRSUtils.toMediaType(s));
         }
         return types;
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Thu Apr  4 12:38:20 2013
@@ -762,7 +762,7 @@ public class WebClient extends AbstractC
         }
         if (responseClass != null && responseClass != Response.class 
             && headers.getFirst(HttpHeaders.ACCEPT) == null) {
-            headers.putSingle(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML_TYPE.toString());
+            headers.putSingle(HttpHeaders.ACCEPT, JAXRSUtils.mediaTypeToString(MediaType.APPLICATION_XML_TYPE));
         }
         resetResponse();
         Response r = doChainedInvocation(httpMethod, headers, body, requestClass, inGenericType,

@@ -863,6 +863,7 @@ public class WebClient extends AbstractC
                     entity = currentResponse.getEntity();
                 }
             }
+            rb = JAXRSUtils.fromResponse(currentResponse);
             rb.entity(entity instanceof Response 
                       ? ((Response)entity).getEntity() : entity);
             

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/Attachment.java
Thu Apr  4 12:38:20 2013
@@ -32,6 +32,7 @@ import javax.ws.rs.ext.MessageBodyReader
 import javax.ws.rs.ext.Providers;
 
 import org.apache.cxf.jaxrs.impl.MetadataMap;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 /**
  * This class represents an attachment; generally a multipart part. 
@@ -112,7 +113,7 @@ public class Attachment {
 
     public MediaType getContentType() {
         String value = handler != null ? handler.getContentType() : headers.getFirst("Content-Type");
-        return value == null ? MediaType.TEXT_PLAIN_TYPE : MediaType.valueOf(value);
+        return value == null ? MediaType.TEXT_PLAIN_TYPE : JAXRSUtils.toMediaType(value);
     }
 
     public DataHandler getDataHandler() {

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/multipart/MultipartBody.java
Thu Apr  4 12:38:20 2013
@@ -24,12 +24,14 @@ import java.util.List;
 
 import javax.ws.rs.core.MediaType;
 
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
+
 public class MultipartBody {
     
     public static final String INBOUND_MESSAGE_ATTACHMENTS = "org.apache.cxf.jaxrs.attachments.inbound";
     public static final String OUTBOUND_MESSAGE_ATTACHMENTS = "org.apache.cxf.jaxrs.attachments.outbound";
     
-    private static final MediaType MULTIPART_RELATED_TYPE = MediaType.valueOf("multipart/related");

+    private static final MediaType MULTIPART_RELATED_TYPE = JAXRSUtils.toMediaType("multipart/related");

     private boolean outbound;
     private List<Attachment> atts;
     private MediaType mt; 

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/HttpHeadersImpl.java
Thu Apr  4 12:38:20 2013
@@ -133,7 +133,7 @@ public class HttpHeadersImpl implements 
 
     public MediaType getMediaType() {
         List<String> values = getListValues(HttpHeaders.CONTENT_TYPE);
-        return values.size() == 0 ? null : MediaType.valueOf(values.get(0));
+        return values.size() == 0 ? null : JAXRSUtils.toMediaType(values.get(0));
     }
 
     public MultivaluedMap<String, String> getRequestHeaders() {

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/MediaTypeHeaderProvider.java
Thu Apr  4 12:38:20 2013
@@ -45,6 +45,11 @@ public class MediaTypeHeaderProvider imp
     
     public MediaType fromString(String mType) {
         
+        return valueOf(mType);
+    }
+
+    public static MediaType valueOf(String mType) {
+        
         if (mType == null) {
             throw new IllegalArgumentException("Media type value can not be null");
         }
@@ -84,7 +89,7 @@ public class MediaTypeHeaderProvider imp
                              subtype.trim().toLowerCase(), 
                              parameters);
     }
-
+    
     private static void addParameter(Map<String, String> parameters, String token)
{
         int equalSign = token.indexOf('=');
         if (equalSign == -1) {
@@ -95,6 +100,10 @@ public class MediaTypeHeaderProvider imp
     }
     
     public String toString(MediaType type) {
+        return typeToString(type);
+    }
+    
+    public static String typeToString(MediaType type) {
         StringBuilder sb = new StringBuilder();
         sb.append(type.getType()).append('/').append(type.getSubtype());
         
@@ -110,7 +119,7 @@ public class MediaTypeHeaderProvider imp
         return sb.toString();
     }
 
-    private MediaType handleMediaTypeWithoutSubtype(String mType) {
+    private static MediaType handleMediaTypeWithoutSubtype(String mType) {
         if (mType.startsWith(MediaType.MEDIA_TYPE_WILDCARD)) {
             char next = mType.length() == 1 ? ' ' : mType.charAt(1);
             if (next == ' ' || next == ';') {
@@ -128,7 +137,7 @@ public class MediaTypeHeaderProvider imp
             } else {
                 mt = MediaType.WILDCARD_TYPE;
             }
-            LOG.fine("Converting a malformed media type '" + mType + "' to '" + mt.toString()
+ "'");
+            LOG.fine("Converting a malformed media type '" + mType + "' to '" + typeToString(mt)
+ "'");
             return mt;
         } else {
             throw new IllegalArgumentException("Media type separator is missing");

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseBuilderImpl.java
Thu Apr  4 12:38:20 2013
@@ -37,6 +37,7 @@ 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;
 
@@ -77,7 +78,7 @@ public final class ResponseBuilderImpl e
     }
 
     public ResponseBuilder type(MediaType type) {
-        return type(type == null ? null : type.toString());
+        return type(type == null ? null : JAXRSUtils.mediaTypeToString(type));
     }
 
     public ResponseBuilder type(String type) {

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WebApplicationExceptionMapper.java
Thu Apr  4 12:38:20 2013
@@ -23,12 +23,14 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.ext.ExceptionMapper;
 
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.logging.FaultListener;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.phase.PhaseInterceptorChain;
@@ -72,7 +74,8 @@ public class WebApplicationExceptionMapp
         }
         
         if (doAddMessage) {
-            r = Response.fromResponse(r).entity(errorMessage).type(MediaType.TEXT_PLAIN).build();
+            r = JAXRSUtils.copyResponseIfNeeded(r);
+            r = JAXRSUtils.fromResponse(r).entity(errorMessage).type(MediaType.TEXT_PLAIN).build();
         }
         return r;
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/interceptor/JAXRSOutInterceptor.java
Thu Apr  4 12:38:20 2013
@@ -240,9 +240,9 @@ public class JAXRSOutInterceptor extends
         try {
             responseType = checkFinalContentType(responseType);
             if (LOG.isLoggable(Level.FINE)) {
-                LOG.fine("Response content type is: " + responseType.toString());
+                LOG.fine("Response content type is: " + JAXRSUtils.mediaTypeToString(responseType));
             }
-            message.put(Message.CONTENT_TYPE, responseType.toString());
+            message.put(Message.CONTENT_TYPE, JAXRSUtils.mediaTypeToString(responseType));
             
             long size = getSize(writer, entity, targetType, genericType, annotations, responseType);
             if (size > 0) {
@@ -464,7 +464,7 @@ public class JAXRSOutInterceptor extends
         if (mt.isWildcardType() || mt.isWildcardSubtype()) {
             return MediaType.APPLICATION_OCTET_STREAM_TYPE;
         } else if (mt.getParameters().containsKey("q")) {
-            return MediaType.valueOf(JAXRSUtils.removeMediaTypeParameter(mt, "q"));
+            return JAXRSUtils.toMediaType(JAXRSUtils.removeMediaTypeParameter(mt, "q"));
         } else {
             return mt;
         }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/wadl/WadlGenerator.java
Thu Apr  4 12:38:20 2013
@@ -113,7 +113,7 @@ import org.apache.ws.commons.schema.XmlS
 public class WadlGenerator implements RequestHandler {
 
     public static final String WADL_QUERY = "_wadl";
-    public static final MediaType WADL_TYPE = MediaType.valueOf("application/vnd.sun.wadl+xml");
+    public static final MediaType WADL_TYPE = JAXRSUtils.toMediaType("application/vnd.sun.wadl+xml");
     public static final String WADL_NS = "http://wadl.dev.java.net/2009/02";
     
     private static final MediaType DEFAULT_MEDIA_TYPE = MediaType.APPLICATION_XML_TYPE; 
@@ -721,7 +721,7 @@ public class WadlGenerator implements Re
         for (MediaType mt : types) {
             
             sb.append("<representation");
-            sb.append(" mediaType=\"").append(mt.toString()).append("\"");
+            sb.append(" mediaType=\"").append(JAXRSUtils.mediaTypeToString(mt)).append("\"");
             if (isJson && !mt.getSubtype().contains("json")) {
                 sb.append("/>");
                 continue;
@@ -1645,7 +1645,7 @@ public class WadlGenerator implements Re
     }
 
     public void setDefaultMediaType(String mt) {
-        this.defaultMediaType = MediaType.valueOf(mt);
+        this.defaultMediaType = JAXRSUtils.toMediaType(mt);
     }
 
     private static class SchemaConverter extends DelegatingXMLStreamWriter {

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/DataSourceProvider.java
Thu Apr  4 12:38:20 2013
@@ -36,6 +36,7 @@ import javax.ws.rs.ext.Provider;
 import org.apache.cxf.common.util.StringUtils;
 import org.apache.cxf.helpers.IOUtils;
 import org.apache.cxf.jaxrs.ext.multipart.InputStreamDataSource;
+import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 
 @Provider
 public class DataSourceProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<T>
{
@@ -82,7 +83,7 @@ public class DataSourceProvider<T> imple
     private void setContentTypeIfNeeded(MediaType type, 
         MultivaluedMap<String, Object> headers, String ct) {
 
-        if (!StringUtils.isEmpty(ct) && !type.equals(MediaType.valueOf(ct))) { 
+        if (!StringUtils.isEmpty(ct) && !type.equals(JAXRSUtils.toMediaType(ct)))
{ 
             headers.putSingle("Content-Type", ct);
         }
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/MultipartProvider.java
Thu Apr  4 12:38:20 2013
@@ -388,7 +388,7 @@ public class MultipartProvider extends A
                                             Class<T> cls, Type genericType,
                                             Annotation[] anns,
                                             String mimeType, int id) {
-        MediaType mt = MediaType.valueOf(mimeType);
+        MediaType mt = JAXRSUtils.toMediaType(mimeType);
         mc.put(ACTIVE_JAXRS_PROVIDER_KEY, this);
         
         MessageBodyWriter<T> r = null;

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Thu Apr  4 12:38:20 2013
@@ -190,7 +190,7 @@ public final class ProviderFactory {
                     mt = accepts.get(0);
                 }
             } else {
-                mt = MediaType.valueOf(ctProperty.toString());
+                mt = JAXRSUtils.toMediaType(ctProperty.toString());
             }
         } else {
             mt = requestHeaders.getMediaType();

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
Thu Apr  4 12:38:20 2013
@@ -80,10 +80,13 @@ import org.apache.cxf.jaxrs.ext.Protocol
 import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
 import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
+import org.apache.cxf.jaxrs.impl.MediaTypeHeaderProvider;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
 import org.apache.cxf.jaxrs.impl.ProvidersImpl;
 import org.apache.cxf.jaxrs.impl.RequestImpl;
+import org.apache.cxf.jaxrs.impl.ResponseBuilderImpl;
+import org.apache.cxf.jaxrs.impl.ResponseImpl;
 import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
 import org.apache.cxf.jaxrs.impl.UriInfoImpl;
 import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -180,7 +183,7 @@ public final class JAXRSUtils {
     public static List<MediaType> getMediaTypes(String[] values) {
         List<MediaType> supportedMimeTypes = new ArrayList<MediaType>(values.length);
         for (int i = 0; i < values.length; i++) {
-            supportedMimeTypes.add(MediaType.valueOf(values[i]));    
+            supportedMimeTypes.add(toMediaType(values[i]));    
         }
         return supportedMimeTypes;
     }
@@ -309,7 +312,7 @@ public final class JAXRSUtils {
         MediaType requestType;
         try {
             requestType = requestContentType == null
-                                ? ALL_TYPES : MediaType.valueOf(requestContentType);
+                                ? ALL_TYPES : toMediaType(requestContentType);
         } catch (IllegalArgumentException ex) {
             throw new WebApplicationException(ex, 415);
         }
@@ -404,7 +407,7 @@ public final class JAXRSUtils {
                                                    message.get(Message.REQUEST_URI),
                                                    path,
                                                    httpMethod,
-                                                   requestType.toString(),
+                                                   mediaTypeToString(requestType),
                                                    convertTypesToString(acceptContentTypes));
         if (!"OPTIONS".equalsIgnoreCase(httpMethod) && logNow) {
             LOG.warning(errorMsg.toString());
@@ -477,7 +480,7 @@ public final class JAXRSUtils {
     private static String convertTypesToString(List<MediaType> types) {
         StringBuilder sb = new StringBuilder();
         for (MediaType type : types) {
-            sb.append(type.toString()).append(',');
+            sb.append(mediaTypeToString(type)).append(',');
         }
         return sb.toString();
     }
@@ -616,7 +619,7 @@ public final class JAXRSUtils {
                                        parameterType,
                                        parameterAnns,
                                        is, 
-                                       MediaType.valueOf(contentType),
+                                       toMediaType(contentType),
                                        ori.getConsumeTypes(),
                                        message);
         } else if (parameter.getType() == ParameterType.CONTEXT) {
@@ -1048,7 +1051,7 @@ public final class JAXRSUtils {
                 String errorMessage = new org.apache.cxf.common.i18n.Message("NO_MSG_READER",
                                                        BUNDLE,
                                                        targetTypeClass.getSimpleName(),
-                                                       contentType).toString();
+                                                       mediaTypeToString(contentType)).toString();
                 LOG.warning(errorMessage);
                 throw new WebApplicationException(Response.Status.UNSUPPORTED_MEDIA_TYPE);
             }
@@ -1095,7 +1098,7 @@ public final class JAXRSUtils {
                 } else {
                     types = "";
                 }
-                acceptValues.add(MediaType.valueOf(tp));
+                acceptValues.add(toMediaType(tp));
             }
         } else {
             acceptValues.add(ALL_TYPES);
@@ -1270,4 +1273,48 @@ public final class JAXRSUtils {
         return XMLUtils.convertStringToQName(name, "");
     }
     
+    
+    public static String mediaTypeToString(MediaType mt) {
+        return MediaTypeHeaderProvider.typeToString(mt);
+    }
+    
+    public static MediaType toMediaType(String value) {
+        return MediaTypeHeaderProvider.valueOf(value);
+    }
+    
+    public static Response toResponse(int status) {
+        return toResponseBuilder(status).build();
+    }
+    
+    public static Response toResponse(Response.Status status) {
+        return toResponse(status.getStatusCode());
+    }
+    
+    public static ResponseBuilder toResponseBuilder(int status) {
+        return new ResponseBuilderImpl().status(status);
+    }
+    
+    public static ResponseBuilder toResponseBuilder(Response.Status status) {
+        return toResponseBuilder(status.getStatusCode());
+    }
+    
+    public static ResponseBuilder fromResponse(Response response) {
+        ResponseBuilder rb = toResponseBuilder(response.getStatus());
+        rb.entity(response.getEntity());
+        for (Map.Entry<String, List<Object>> entry : response.getMetadata().entrySet())
{
+            List<Object> values = entry.getValue();
+            for (Object value : values) {
+                rb.header(entry.getKey(), value);
+            }
+        }
+        return rb;
+    }
+
+    public static Response copyResponseIfNeeded(Response response) {
+        if (!(response instanceof ResponseImpl)) {
+            return fromResponse(response).build();
+        } else {
+            return response;
+        }
+    }
 }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java?rev=1464503&r1=1464502&r2=1464503&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/multipart/AttachmentUtils.java
Thu Apr  4 12:38:20 2013
@@ -174,7 +174,7 @@ public final class AttachmentUtils {
     }
     
     private static void checkMediaTypes(MediaType mt1, String mt2) {
-        if (!mt1.isCompatible(MediaType.valueOf(mt2))) {                                
           
+        if (!mt1.isCompatible(JAXRSUtils.toMediaType(mt2))) {                           
                
             throw new WebApplicationException(415);
         }
     }



Mime
View raw message