cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: [CXF-6015] Providing a workaround, a better solution will need to be provided in due time, also removing some redundant code to do with creating Context resolvers
Date Mon, 22 Sep 2014 13:16:12 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 9f5b54ed7 -> 8d6ec66ff


[CXF-6015] Providing a workaround, a better solution will need to be provided in due time,
also removing some redundant code to do with creating Context resolvers


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/8d6ec66f
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/8d6ec66f
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/8d6ec66f

Branch: refs/heads/master
Commit: 8d6ec66fffcc11c49c314277d56b1ebcf5b90ec7
Parents: 9f5b54e
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Mon Sep 22 14:15:54 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Mon Sep 22 14:15:54 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/provider/ProviderFactory.java     | 23 +++++---------------
 .../org/apache/cxf/jaxrs/utils/HttpUtils.java   |  3 +++
 .../cxf/jaxrs/provider/ProviderFactoryTest.java | 13 +----------
 .../jose/jaxrs/JweWriterInterceptor.java        |  5 ++---
 .../jose/jaxrs/JwsWriterInterceptor.java        |  7 +++---
 .../org/apache/cxf/transport/http/Headers.java  |  6 ++---
 .../jaxrs/JAXRS20ClientServerBookTest.java      |  1 +
 7 files changed, 20 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/8d6ec66f/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
index 43f7be3..e86f93b 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/ProviderFactory.java
@@ -42,7 +42,6 @@ import java.util.logging.Logger;
 import javax.ws.rs.Produces;
 import javax.ws.rs.core.Application;
 import javax.ws.rs.core.Configuration;
-import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.ext.ContextResolver;
@@ -61,7 +60,6 @@ import org.apache.cxf.common.util.ClassHelper;
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.ext.ContextProvider;
-import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
 import org.apache.cxf.jaxrs.impl.MetadataMap;
 import org.apache.cxf.jaxrs.impl.ReaderInterceptorMBR;
 import org.apache.cxf.jaxrs.impl.WriterInterceptorMBW;
@@ -169,27 +167,18 @@ public abstract class ProviderFactory {
         boolean isRequestor = MessageUtils.isRequestor(m);
         Message requestMessage = isRequestor ? m.getExchange().getOutMessage() 
                                              : m.getExchange().getInMessage();
-        HttpHeaders requestHeaders = new HttpHeadersImpl(requestMessage);
-        MediaType mt = null;
         
         Message responseMessage = isRequestor ? m.getExchange().getInMessage() 
                                               : m.getExchange().getOutMessage();
+        Object ctProperty = null;
         if (responseMessage != null) {
-            Object ctProperty = responseMessage.get(Message.CONTENT_TYPE);
-            if (ctProperty == null) {
-                List<MediaType> accepts = requestHeaders.getAcceptableMediaTypes();
-                if (accepts.size() > 0) {
-                    mt = accepts.get(0);
-                }
-            } else {
-                mt = JAXRSUtils.toMediaType(ctProperty.toString());
-            }
+            ctProperty = responseMessage.get(Message.CONTENT_TYPE);
         } else {
-            mt = requestHeaders.getMediaType();
+            ctProperty = requestMessage.get(Message.CONTENT_TYPE);
         }
-        
-        return createContextResolver(contextType, m,
-               mt == null ? MediaType.WILDCARD_TYPE : mt);
+        MediaType mt = ctProperty != null ? JAXRSUtils.toMediaType(ctProperty.toString())
+            : MediaType.WILDCARD_TYPE;
+        return createContextResolver(contextType, m, mt);
         
     }
     

http://git-wip-us.apache.org/repos/asf/cxf/blob/8d6ec66f/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
index ac4dbca..f76cbf2 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
@@ -226,6 +226,9 @@ public final class HttpUtils {
     }
     
     public static void convertHeaderValuesToString(Map<String, List<Object>>
headers, boolean delegateOnly) {
+        if (headers == null) {
+            return;
+        }
         RuntimeDelegate rd = getOtherRuntimeDelegate();
         if (rd == null && delegateOnly) {
             return;

http://git-wip-us.apache.org/repos/asf/cxf/blob/8d6ec66f/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
----------------------------------------------------------------------
diff --git a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
index b95c2a8..b142814 100644
--- a/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
+++ b/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/provider/ProviderFactoryTest.java
@@ -420,18 +420,6 @@ public class ProviderFactoryTest extends Assert {
     }
     
     @Test
-    public void testCustomResolverOut() throws Exception {
-        ProviderFactory pf = ServerProviderFactory.getInstance();
-        pf.registerUserProvider(new JAXBContextProvider());
-        pf.registerUserProvider(new JAXBContextProvider2());
-        Message message = prepareMessage("text/xml+c", "text/xml+a");
-        ContextResolver<JAXBContext> cr = pf.createContextResolver(JAXBContext.class,
message);
-        assertFalse(cr instanceof ProviderFactory.ContextResolverProxy);
-        assertTrue("JAXBContext ContextProvider can not be found", 
-                   cr instanceof JAXBContextProvider);
-    }
-    
-    @Test
     public void testCustomResolverProxy() throws Exception {
         ProviderFactory pf = ServerProviderFactory.getInstance();
         pf.registerUserProvider(new JAXBContextProvider());
@@ -457,6 +445,7 @@ public class ProviderFactoryTest extends Assert {
         } else {
             headers.put("Content-Type", Collections.singletonList(contentType));
         }
+        message.put("Content-Type", contentType);
         message.setExchange(exchange);
         return message;
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/8d6ec66f/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JweWriterInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JweWriterInterceptor.java
b/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JweWriterInterceptor.java
index 9d5fc9c..fc03d1a 100644
--- a/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JweWriterInterceptor.java
+++ b/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JweWriterInterceptor.java
@@ -52,6 +52,7 @@ import org.apache.cxf.rs.security.jose.jwe.RSAOaepKeyEncryptionAlgorithm;
 import org.apache.cxf.rs.security.jose.jwe.WrappedKeyJweEncryption;
 import org.apache.cxf.rs.security.jose.jwk.JsonWebKey;
 import org.apache.cxf.rs.security.jose.jwk.JwkUtils;
+import org.apache.cxf.rs.security.jose.jwt.JwtConstants;
 import org.apache.cxf.rs.security.jose.jwt.JwtHeadersWriter;
 import org.apache.cxf.rs.security.jose.jwt.JwtTokenReaderWriter;
 import org.apache.cxf.rs.security.oauth2.utils.crypto.CryptoUtils;
@@ -70,8 +71,6 @@ public class JweWriterInterceptor implements WriterInterceptor {
     @Override
     public void aroundWriteTo(WriterInterceptorContext ctx) throws IOException, WebApplicationException
{
         
-        //ctx.setMediaType(JAXRSUtils.toMediaType(JwtConstants.MEDIA_TYPE_JOSE_JSON));
-        
         OutputStream actualOs = ctx.getOutputStream();
         
         JweEncryptionProvider theEncryptionProvider = getInitializedEncryptionProvider();
@@ -88,7 +87,7 @@ public class JweWriterInterceptor implements WriterInterceptor {
             }
         }
         
-        
+        ctx.setMediaType(JAXRSUtils.toMediaType(JwtConstants.MEDIA_TYPE_JOSE_JSON));
         if (useJweOutputStream) {
             JweEncryptionState encryption = theEncryptionProvider.createJweEncryptionState(ctString);
             try {

http://git-wip-us.apache.org/repos/asf/cxf/blob/8d6ec66f/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JwsWriterInterceptor.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JwsWriterInterceptor.java
b/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JwsWriterInterceptor.java
index c99ec15..5c38928 100644
--- a/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JwsWriterInterceptor.java
+++ b/rt/rs/security/oauth-parent/oauth2-jose/src/main/java/org/apache/cxf/rs/security/jose/jaxrs/JwsWriterInterceptor.java
@@ -33,6 +33,7 @@ import org.apache.cxf.rs.security.jose.jws.JwsCompactProducer;
 import org.apache.cxf.rs.security.jose.jws.JwsOutputStream;
 import org.apache.cxf.rs.security.jose.jws.JwsSignature;
 import org.apache.cxf.rs.security.jose.jws.JwsSignatureProvider;
+import org.apache.cxf.rs.security.jose.jwt.JwtConstants;
 import org.apache.cxf.rs.security.jose.jwt.JwtHeaders;
 import org.apache.cxf.rs.security.jose.jwt.JwtHeadersWriter;
 import org.apache.cxf.rs.security.jose.jwt.JwtTokenReaderWriter;
@@ -46,11 +47,10 @@ public class JwsWriterInterceptor extends AbstractJwsWriterProvider implements
W
     private JwtHeadersWriter writer = new JwtTokenReaderWriter();
     @Override
     public void aroundWriteTo(WriterInterceptorContext ctx) throws IOException, WebApplicationException
{
-        //ctx.setMediaType(JAXRSUtils.toMediaType(JwtConstants.MEDIA_TYPE_JOSE_JSON));
         JwtHeaders headers = new JwtHeaders();
         JwsSignatureProvider sigProvider = getInitializedSigProvider(headers);
         setContentTypeIfNeeded(headers, ctx);
-        
+        ctx.setMediaType(JAXRSUtils.toMediaType(JwtConstants.MEDIA_TYPE_JOSE_JSON));
         OutputStream actualOs = ctx.getOutputStream();
         if (useJwsOutputStream) {
             JwsSignature jwsSignature = sigProvider.createJwsSignature(headers);
@@ -86,7 +86,8 @@ public class JwsWriterInterceptor extends AbstractJwsWriterProvider implements
W
     private void setContentTypeIfNeeded(JwtHeaders headers, WriterInterceptorContext ctx)
{    
         if (contentTypeRequired) {
             MediaType mt = ctx.getMediaType();
-            if (mt != null) {
+            if (mt != null 
+                && !JAXRSUtils.mediaTypeToString(mt).equals(JwtConstants.MEDIA_TYPE_JOSE_JSON))
{
                 if ("application".equals(mt.getType())) {
                     headers.setContentType(mt.getSubtype());
                 } else {

http://git-wip-us.apache.org/repos/asf/cxf/blob/8d6ec66f/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
----------------------------------------------------------------------
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
index cf5f0ed..46267ed 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/Headers.java
@@ -275,9 +275,9 @@ public class Headers {
      */
     void logProtocolHeaders(Level level) {
         for (String header : headers.keySet()) {
-            List<String> headerList = headers.get(header);
-            for (String value : headerList) {
-                LOG.log(level, header + ": " + value);
+            List<?> headerList = headers.get(header);
+            for (Object value : headerList) {
+                LOG.log(level, header + ": " + value.toString());
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/8d6ec66f/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
----------------------------------------------------------------------
diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
index 01feee0..497b31a 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRS20ClientServerBookTest.java
@@ -700,6 +700,7 @@ public class JAXRS20ClientServerBookTest extends AbstractBusClientServerTestBase
         @Override
         public void filter(ClientRequestContext context) throws IOException {
             context.getHeaders().putSingle("Simple", "simple");
+            context.getHeaders().putSingle("Content-Type", MediaType.APPLICATION_XML_TYPE);
         }
     }
     


Mime
View raw message