You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2013/09/09 17:49:50 UTC
svn commit: r1521164 - in /cxf/branches/2.7.x-fixes: ./
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/
Author: sergeyb
Date: Mon Sep 9 15:49:50 2013
New Revision: 1521164
URL: http://svn.apache.org/r1521164
Log:
Merged revisions 1521160 via svnmerge from
https://svn.apache.org/repos/asf/cxf/trunk
........
r1521160 | sergeyb | 2013-09-09 16:30:52 +0100 (Mon, 09 Sep 2013) | 1 line
[CXF-5262] Updating Reader and Writer contexts to select new providers if needed
........
Modified:
cxf/branches/2.7.x-fixes/ (props changed)
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Merged /cxf/trunk:r1521160
Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java?rev=1521164&r1=1521163&r2=1521164&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/AbstractInterceptorContextImpl.java Mon Sep 9 15:49:50 2013
@@ -21,6 +21,7 @@ package org.apache.cxf.jaxrs.impl;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.message.Message;
public class AbstractInterceptorContextImpl extends AbstractPropertiesImpl {
@@ -60,8 +61,14 @@ public class AbstractInterceptorContextI
}
public void setType(Class<?> ctype) {
+ if (cls != null && !cls.isAssignableFrom(ctype)) {
+ providerSelectionPropertyChanged();
+ }
cls = ctype;
}
-
+ protected void providerSelectionPropertyChanged() {
+ m.put(ProviderFactory.PROVIDER_SELECTION_PROPERTY_CHANGED, Boolean.TRUE);
+ }
+
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java?rev=1521164&r1=1521163&r2=1521164&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorContextImpl.java Mon Sep 9 15:49:50 2013
@@ -85,6 +85,9 @@ public class ReaderInterceptorContextImp
@Override
public void setMediaType(MediaType mt) {
+ if (!getMediaType().isCompatible(mt)) {
+ providerSelectionPropertyChanged();
+ }
getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, JAXRSUtils.mediaTypeToString(mt));
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java?rev=1521164&r1=1521163&r2=1521164&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ReaderInterceptorMBR.java Mon Sep 9 15:49:50 2013
@@ -19,12 +19,16 @@
package org.apache.cxf.jaxrs.impl;
import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.MessageBodyReader;
import javax.ws.rs.ext.ReaderInterceptor;
import javax.ws.rs.ext.ReaderInterceptorContext;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.message.Message;
public class ReaderInterceptorMBR implements ReaderInterceptor {
@@ -47,8 +51,22 @@ public class ReaderInterceptorMBR implem
})
@Override
public Object aroundReadFrom(ReaderInterceptorContext c) throws IOException, WebApplicationException {
- return reader.readFrom((Class)c.getType(), c.getGenericType(),
- c.getAnnotations(), c.getMediaType(),
+ Class entityCls = (Class)c.getType();
+ Type entityType = c.getGenericType();
+ MediaType entityMt = c.getMediaType();
+ Annotation[] entityAnns = c.getAnnotations();
+
+ if (m.get(ProviderFactory.PROVIDER_SELECTION_PROPERTY_CHANGED) == Boolean.TRUE
+ && !reader.isReadable(entityCls, entityType, entityAnns, entityMt)) {
+ reader = ProviderFactory.getInstance(m)
+ .createMessageBodyReader(entityCls, entityType, entityAnns, entityMt, m);
+ if (reader == null) {
+ throw new RuntimeException("No reader available");
+ }
+ }
+
+
+ return reader.readFrom(entityCls, entityType, entityAnns, entityMt,
new HttpHeadersImpl(m).getRequestHeaders(),
c.getInputStream());
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java?rev=1521164&r1=1521163&r2=1521164&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorContextImpl.java Mon Sep 9 15:49:50 2013
@@ -85,7 +85,7 @@ public class WriterInterceptorContextImp
@Override
public void setEntity(Object object) {
entity = object;
-
+ super.setType(entity != null ? entity.getClass() : null);
}
@Override
@@ -105,6 +105,9 @@ public class WriterInterceptorContextImp
@Override
public void setMediaType(MediaType mt) {
+ if (!getMediaType().isCompatible(mt)) {
+ providerSelectionPropertyChanged();
+ }
getHeaders().putSingle(HttpHeaders.CONTENT_TYPE, mt);
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java?rev=1521164&r1=1521163&r2=1521164&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/WriterInterceptorMBW.java Mon Sep 9 15:49:50 2013
@@ -19,6 +19,8 @@
package org.apache.cxf.jaxrs.impl;
import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -31,6 +33,7 @@ import javax.ws.rs.ext.WriterInterceptor
import javax.ws.rs.ext.WriterInterceptorContext;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.message.Message;
@@ -49,21 +52,38 @@ public class WriterInterceptorMBW implem
return writer;
}
+ @SuppressWarnings("unchecked")
@Override
public void aroundWriteTo(WriterInterceptorContext c) throws IOException, WebApplicationException {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine("Response EntityProvider is: " + writer.getClass().getName());
}
+
MultivaluedMap<String, Object> headers = c.getHeaders();
Object mtObject = headers.getFirst(HttpHeaders.CONTENT_TYPE);
- MediaType mt = mtObject == null ? c.getMediaType() : JAXRSUtils.toMediaType(mtObject.toString());
+ MediaType entityMt = mtObject == null ? c.getMediaType() : JAXRSUtils.toMediaType(mtObject.toString());
m.put(Message.CONTENT_TYPE, mtObject.toString());
+
+ Class<?> entityCls = c.getType();
+ Type entityType = c.getGenericType();
+ Annotation[] entityAnns = c.getAnnotations();
+
+ if (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");
+ }
+ }
+
writer.writeTo(c.getEntity(),
c.getType(),
c.getGenericType(),
c.getAnnotations(),
- mt,
+ entityMt,
headers,
c.getOutputStream());
}
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java?rev=1521164&r1=1521163&r2=1521164&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java Mon Sep 9 15:49:50 2013
@@ -92,8 +92,9 @@ import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
public final class ProviderFactory {
+ public static final String PROVIDER_SELECTION_PROPERTY_CHANGED = "provider.selection.property.changed";
static final String IGNORE_TYPE_VARIABLES = "org.apache.cxf.jaxrs.providers.ignore.typevars";
-
+
private static final Class<?>[] FILTER_INTERCEPTOR_CLASSES =
new Class<?>[] {ContainerRequestFilter.class,
ContainerResponseFilter.class,