cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1336734 - in /cxf/trunk/rt/rs/extensions/search/src: main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
Date Thu, 10 May 2012 15:02:22 GMT
Author: sergeyb
Date: Thu May 10 15:02:22 2012
New Revision: 1336734

URL: http://svn.apache.org/viewvc?rev=1336734&view=rev
Log:
[CXF-4305] Getting SearchContext to enforce that only non-primitive condition types are supported

Modified:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
    cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java?rev=1336734&r1=1336733&r2=1336734&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
Thu May 10 15:02:22 2012
@@ -21,9 +21,12 @@ package org.apache.cxf.jaxrs.ext.search;
 
 import java.util.LinkedHashMap;
 import java.util.Map;
+import java.util.logging.Logger;
 
 import javax.ws.rs.core.MultivaluedMap;
 
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
 import org.apache.cxf.jaxrs.utils.JAXRSUtils;
 import org.apache.cxf.message.Message;
 
@@ -31,6 +34,7 @@ public class SearchContextImpl implement
 
     public static final String SEARCH_QUERY = "_search";
     public static final String SHORT_SEARCH_QUERY = "_s";
+    private static final Logger LOG = LogUtils.getL7dLogger(SearchContextImpl.class);
     private Message message;
     
     public SearchContextImpl(Message message) {
@@ -38,6 +42,13 @@ public class SearchContextImpl implement
     }
     
     public <T> SearchCondition<T> getCondition(Class<T> cls) {
+        
+        if (InjectionUtils.isPrimitive(cls)) {
+            String errorMessage = "The condition type can not be a primitive type"; 
+            LOG.warning(errorMessage);
+            throw new IllegalArgumentException(errorMessage);
+        }
+        
         FiqlParser<T> parser = getParser(cls);
         
         String expression = getSearchExpression();
@@ -70,7 +81,6 @@ public class SearchContextImpl implement
     }
     
     private <T> FiqlParser<T> getParser(Class<T> cls) {
-        
         // we can use this method as a parser factory, ex
         // we can get parsers capable of parsing XQuery and other languages
         // depending on the properties set by a user

Modified: cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java?rev=1336734&r1=1336733&r2=1336734&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
Thu May 10 15:02:22 2012
@@ -35,6 +35,11 @@ public class SearchContextImplTest exten
             SearchContextImpl.SEARCH_QUERY + "=" + "name==CXF%20Rocks;id=gt=123");
     }
     
+    @Test(expected = IllegalArgumentException.class)
+    public void testIllegalConditionType() {
+        SearchContext context = new SearchContextImpl(new MessageImpl());
+        context.getCondition(String.class);
+    }
     @Test
     public void testFiqlSearchConditionWithShortQuery() {
         doTestFiqlSearchCondition(



Mime
View raw message