cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1494624 - in /cxf/branches/2.6.x-fixes: ./ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/ rt/frontend/jaxr...
Date Wed, 19 Jun 2013 13:50:50 GMT
Author: sergeyb
Date: Wed Jun 19 13:50:49 2013
New Revision: 1494624

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

................
  r1494592 | sergeyb | 2013-06-19 13:50:31 +0100 (Wed, 19 Jun 2013) | 13 lines
  
  Merged revisions 1494587-1494588 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1494587 | sergeyb | 2013-06-19 13:31:37 +0100 (Wed, 19 Jun 2013) | 1 line
    
    Not encoding comma in queries, trying to encode non-encoded URLs when constructing WebClients
  ........
    r1494588 | sergeyb | 2013-06-19 13:33:31 +0100 (Wed, 19 Jun 2013) | 1 line
    
    Minor update to get it simpler to register a single custom grant handler
  ........
................
  r1494596 | sergeyb | 2013-06-19 13:54:27 +0100 (Wed, 19 Jun 2013) | 9 lines
  
  Merged revisions 1489766 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1489766 | sergeyb | 2013-06-05 10:22:56 +0100 (Wed, 05 Jun 2013) | 1 line
    
    [CXF-5007] Some updates to Request implementation
  ........
................

Modified:
    cxf/branches/2.6.x-fixes/   (props changed)
    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/WebClient.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
    cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
    cxf/branches/2.6.x-fixes/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java

Propchange: cxf/branches/2.6.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/branches/2.7.x-fixes:r1494592-1494596
  Merged /cxf/trunk:r1489766,1494587-1494588

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

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=1494624&r1=1494623&r2=1494624&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
Wed Jun 19 13:50:49 2013
@@ -87,8 +87,8 @@ public abstract class AbstractClient imp
     protected static final String REQUEST_CONTEXT = "RequestContext";
     protected static final String RESPONSE_CONTEXT = "ResponseContext";
     protected static final String KEEP_CONDUIT_ALIVE = "KeepConduitAlive";
-    
-    private static final String HTTP_SCHEME = "http";
+    protected static final String HTTP_SCHEME = "http";
+
     private static final String PROXY_PROPERTY = "jaxrs.proxy";
     private static final Logger LOG = LogUtils.getL7dLogger(AbstractClient.class);
     private static final ResourceBundle BUNDLE = BundleUtils.getBundle(AbstractClient.class);

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=1494624&r1=1494623&r2=1494624&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
Wed Jun 19 13:50:49 2013
@@ -48,6 +48,7 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxrs.ext.form.Form;
+import org.apache.cxf.jaxrs.impl.UriBuilderImpl;
 import org.apache.cxf.jaxrs.model.ParameterType;
 import org.apache.cxf.jaxrs.model.URITemplate;
 import org.apache.cxf.jaxrs.provider.ProviderFactory;
@@ -71,7 +72,7 @@ public class WebClient extends AbstractC
     private static final String RESPONSE_TYPE = "response.type";
     
     protected WebClient(String baseAddress) {
-        this(URI.create(baseAddress));
+        this(convertStringToURI(baseAddress));
     }
     
     protected WebClient(URI baseAddress) {
@@ -976,4 +977,19 @@ public class WebClient extends AbstractC
         }
         return clientState;
     }
+    
+    static URI convertStringToURI(String baseAddress) {
+        try {
+            return URI.create(baseAddress);
+        } catch (RuntimeException ex) {
+            // no need to check "https" scheme or indeed ':' 
+            // as the relative address will not work as the base address
+            if (baseAddress.startsWith(HTTP_SCHEME)) {
+                return new UriBuilderImpl().uriAsTemplate(baseAddress).build();
+            } else {
+                throw ex;
+            }
+        }
+    }
+
 }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java?rev=1494624&r1=1494623&r2=1494624&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/RequestImpl.java
Wed Jun 19 13:50:49 2013
@@ -40,6 +40,7 @@ import org.apache.cxf.common.util.String
 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;
 
 /**
  * TODO : deal with InvalidStateExceptions
@@ -67,6 +68,8 @@ public class RequestImpl implements Requ
         List<String> acceptEncs = parseAcceptEnc(
             headers.getRequestHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING));
         
+        List<Object> varyValues = new LinkedList<Object>();
+        
         List<Variant> matchingVars = new LinkedList<Variant>();
         for (Variant var : vars) {
             MediaType mt = var.getMediaType();
@@ -75,23 +78,63 @@ public class RequestImpl implements Requ
                         
             boolean mtMatched = mt == null || acceptMediaTypes.isEmpty()
                 || JAXRSUtils.intersectMimeTypes(acceptMediaTypes, mt).size() != 0;
-            
-            boolean encMatched = acceptEncs.isEmpty() || enc == null 
-                || acceptEncs.contains(enc);
+            if (mtMatched) {
+                handleVaryValues(varyValues, HttpHeaders.ACCEPT);
+            }
             
             boolean langMatched = lang == null || acceptLangs.isEmpty()
                 || isLanguageMatched(acceptLangs, lang);
+            if (langMatched) {
+                handleVaryValues(varyValues, HttpHeaders.ACCEPT_LANGUAGE);
+            }
+            
+            boolean encMatched = acceptEncs.isEmpty() || enc == null 
+                || acceptEncs.contains(enc);
+            if (encMatched) {
+                handleVaryValues(varyValues, HttpHeaders.ACCEPT_ENCODING);
+            }
             
             if (mtMatched && encMatched && langMatched) {
                 matchingVars.add(var);
             }
         }
-        if (matchingVars.size() > 1) {
-            Collections.sort(matchingVars, new VariantComparator());       
-        }
-        return matchingVars.isEmpty() ? null : matchingVars.get(0);
+        if (matchingVars.size() > 0) {
+            addVaryHeader(varyValues);
+            Collections.sort(matchingVars, new VariantComparator());
+            return matchingVars.get(0);
+        } 
+        return null;
     }
 
+    private static void handleVaryValues(List<Object> varyValues, String ...values)
{
+        for (String v : values) {
+            if (v != null && !varyValues.contains(v)) {
+                varyValues.add(v);
+            }
+        }
+    }
+    
+    private static void addVaryHeader(List<Object> varyValues) {
+        // at this point we still have no out-bound message so lets
+        // use HttpServletResponse. If needed we can save the header on the exchange
+        // and then copy it into the out-bound message's headers
+        Message message = PhaseInterceptorChain.getCurrentMessage();
+        if (message != null) {
+            Object httpResponse = message.get("HTTP.RESPONSE");
+            if (httpResponse != null) {
+                StringBuilder sb = new StringBuilder();
+                for (int i = 0; i < varyValues.size(); i++) {
+                    if (i > 0) {
+                        sb.append(',');
+                    }
+                    sb.append(varyValues.get(i).toString());
+                }
+                ((javax.servlet.http.HttpServletResponse)httpResponse)
+                    .setHeader(HttpHeaders.VARY, sb.toString());
+            }
+        }
+    }
+    
     private static boolean isLanguageMatched(List<Locale> locales, Locale l) {
         for (Locale locale : locales) {
             if (locale.getLanguage().equalsIgnoreCase(l.getLanguage())) {
@@ -116,6 +159,9 @@ public class RequestImpl implements Requ
     }
     
     public ResponseBuilder evaluatePreconditions(EntityTag eTag) {
+        if (eTag == null) {
+            throw new IllegalArgumentException("ETag is null");
+        }
         ResponseBuilder rb = evaluateIfMatch(eTag);
         if (rb == null) {
             rb = evaluateIfNonMatch(eTag);
@@ -177,6 +223,9 @@ public class RequestImpl implements Requ
     }
     
     public ResponseBuilder evaluatePreconditions(Date lastModified) {
+        if (lastModified == null) {
+            throw new IllegalArgumentException("Date is null");
+        }
         List<String> ifModifiedSince = headers.getRequestHeader(HttpHeaders.IF_MODIFIED_SINCE);
         
         if (ifModifiedSince == null || ifModifiedSince.size() == 0) {
@@ -231,13 +280,13 @@ public class RequestImpl implements Requ
 
     public ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag) {
         final ResponseBuilder rb = evaluatePreconditions(eTag);
-        if (rb != null) {
+        if (rb == null) {
             // the ETag conditions match; so now conditions for last modified must match
             return evaluatePreconditions(lastModified);
         } else {
             // the ETag conditions do not match, so last modified should be ignored
             // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html (section 14.26
for
-            // "If-None-Match", behavior not specified for "If-Match", section 14.24)
+            // "If-None-Match", behaviour not specified for "If-Match", section 14.24)
             return null;
         }
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java?rev=1494624&r1=1494623&r2=1494624&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/UriBuilderImpl.java
Wed Jun 19 13:50:49 2013
@@ -739,4 +739,30 @@ public class UriBuilderImpl extends UriB
         buildMatrix(sb, matrix);
         return new PathSegmentImpl(sb.toString());
     }
+
+    public UriBuilder uriAsTemplate(String uri) {
+        // This can be a start of replacing URI class Parser completely
+        // but it can be too complicated, the following code is needed for now 
+        // to deal with URIs containing template variables. 
+        int index = uri.indexOf(":");
+        if (index != -1) {
+            this.scheme = uri.substring(0, index);
+            uri = uri.substring(index + 1);
+            if (uri.indexOf("//") == 0) {
+                uri = uri.substring(2);
+                index = uri.indexOf("/");
+                if (index != -1) {
+                    String[] schemePair = uri.substring(0, index).split(":");
+                    this.host = schemePair[0];
+                    this.port = schemePair.length == 2 ? Integer.valueOf(schemePair[1]) :
-1;
+                    
+                }
+                uri = uri.substring(index);
+            }
+            
+        }
+        setPathAndMatrix(uri);
+        return this;
+    }
+    
 }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java?rev=1494624&r1=1494623&r2=1494624&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/HttpUtils.java
Wed Jun 19 13:50:49 2013
@@ -70,7 +70,7 @@ public final class HttpUtils {
     
     // there are more of such characters, ex, '*' but '*' is not affected by UrlEncode
     private static final String PATH_RESERVED_CHARACTERS = "=@/:!$&\'(),;~";
-    private static final String QUERY_RESERVED_CHARACTERS = "?/";
+    private static final String QUERY_RESERVED_CHARACTERS = "?/,";
     
     private HttpUtils() {
     }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java?rev=1494624&r1=1494623&r2=1494624&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/impl/RequestImplTest.java
Wed Jun 19 13:50:49 2013
@@ -274,14 +274,11 @@ public class RequestImplTest extends Ass
         metadata.putSingle("If-Modified-Since", "Tue, 21 Oct 2008 14:00:00 GMT");
         
         Date lastModified = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.ENGLISH)
-            .parse("Mon, 20 Oct 2008 14:00:00 GMT");
+            .parse("Mon, 22 Oct 2008 14:00:00 GMT");
         
         ResponseBuilder rb = 
-            new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("123"));
-        assertNotNull("Precondition is not met", rb);
-        
-        Response r = rb.build();
-        assertEquals("If-Modified-Since precondition was not met", 304, r.getStatus());
+            new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("\"123\""));
+        assertNull("Precondition is not met", rb);
     }
     
     @Test
@@ -294,7 +291,7 @@ public class RequestImplTest extends Ass
         
         ResponseBuilder rb = 
             new RequestImpl(m).evaluatePreconditions(lastModified, new EntityTag("124"));
-        assertNull("Dates must not be checked if tags do not match", rb);
+        assertNotNull("Dates must not be checked if tags do not match", rb);
     }
    
 }

Modified: cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java?rev=1494624&r1=1494623&r2=1494624&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/utils/HttpUtilsTest.java
Wed Jun 19 13:50:49 2013
@@ -45,6 +45,11 @@ public class HttpUtilsTest extends Asser
     }
     
     @Test
+    public void testCommaInQuery() {
+        assertEquals("a+,b", HttpUtils.queryEncode("a ,b"));
+    }
+    
+    @Test
     public void testIsDateHeader() {
         assertFalse(HttpUtils.isDateRelatedHeader(HttpHeaders.ETAG));
         assertTrue(HttpUtils.isDateRelatedHeader(HttpHeaders.EXPIRES));

Modified: cxf/branches/2.6.x-fixes/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.6.x-fixes/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java?rev=1494624&r1=1494623&r2=1494624&view=diff
==============================================================================
--- cxf/branches/2.6.x-fixes/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java
(original)
+++ cxf/branches/2.6.x-fixes/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/services/AccessTokenService.java
Wed Jun 19 13:50:49 2013
@@ -20,7 +20,7 @@
 package org.apache.cxf.rs.security.oauth2.services;
 
 import java.security.Principal;
-import java.util.Collections;
+import java.util.LinkedList;
 import java.util.List;
 
 import javax.ws.rs.Consumes;
@@ -51,7 +51,7 @@ import org.apache.cxf.rs.security.oauth2
  */
 @Path("/token")
 public class AccessTokenService extends AbstractOAuthService {
-    private List<AccessTokenGrantHandler> grantHandlers = Collections.emptyList();
+    private List<AccessTokenGrantHandler> grantHandlers = new LinkedList<AccessTokenGrantHandler>();
     private boolean writeCustomErrors;
     private boolean canSupportPublicClients;
     
@@ -68,6 +68,14 @@ public class AccessTokenService extends 
     }
     
     /**
+     * Sets a grant handler
+     * @param handler the grant handler
+     */
+    public void setGrantHandler(AccessTokenGrantHandler handler) {
+        grantHandlers.add(handler);
+    }
+    
+    /**
      * Processes an access token request
      * @param params the form parameters representing the access token grant 
      * @return Access Token or the error 



Mime
View raw message