cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject git commit: Minor updates to the search parser to beter control the encoding/decoding process
Date Wed, 09 Jul 2014 10:00:59 GMT
Repository: cxf
Updated Branches:
  refs/heads/master f55a02f15 -> 9fc73f516


Minor updates to the search parser to beter control the encoding/decoding process


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

Branch: refs/heads/master
Commit: 9fc73f516f215d640b144f13088bb8c73cce8406
Parents: f55a02f
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Jul 9 11:00:26 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Jul 9 11:00:26 2014 +0100

----------------------------------------------------------------------
 .../cxf/jaxrs/ext/search/AbstractSearchConditionParser.java | 5 +++++
 .../org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java  | 9 ++++++++-
 .../java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java   | 2 +-
 .../org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java    | 4 ++++
 .../org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java  | 7 ++++++-
 5 files changed, 24 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/9fc73f51/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
index 0278d53..94eb45f 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractSearchConditionParser.java
@@ -32,6 +32,7 @@ import java.util.Set;
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
 
+import org.apache.cxf.common.util.PropertyUtils;
 import org.apache.cxf.jaxrs.ext.search.Beanspector.TypeInfo;
 import org.apache.cxf.jaxrs.ext.search.collections.CollectionCheck;
 import org.apache.cxf.jaxrs.ext.search.collections.CollectionCheckInfo;
@@ -68,6 +69,10 @@ public abstract class AbstractSearchConditionParser<T> implements
SearchConditio
         return beanPropertyName != null ? beanPropertyName : setter;
     }
     
+    protected Boolean isDecodeQueryValues() {
+        return PropertyUtils.isTrue(contextProperties.get(SearchUtils.DECODE_QUERY_VALUES));
+    }
+    
     protected TypeInfo getTypeInfo(String setter, String value) 
         throws SearchParseException, PropertyNotFoundException {
         

http://git-wip-us.apache.org/repos/asf/cxf/blob/9fc73f51/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
index d783d50..be1e4d9 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
@@ -47,6 +47,7 @@ public class SearchContextImpl implements SearchContext {
     private static final String USE_PLAIN_QUERY_PARAMETERS = "search.use.plain.queries";
     private static final String USE_ALL_QUERY_COMPONENT = "search.use.all.query.component";
     private static final String BLOCK_SEARCH_EXCEPTION = "search.block.search.exception";
+    private static final String KEEP_QUERY_ENCODED = "search.keep.query.encoded";
     private static final Logger LOG = LogUtils.getL7dLogger(SearchContextImpl.class);
     private Message message;
     
@@ -115,8 +116,10 @@ public class SearchContextImpl implements SearchContext {
             if (MessageUtils.isTrue(message.getContextualProperty(USE_ALL_QUERY_COMPONENT)))
{
                 return queryStr;
             }
+            boolean encoded = PropertyUtils.isTrue(getKeepEncodedProperty());
+            
             MultivaluedMap<String, String> params = 
-                JAXRSUtils.getStructuredParams(queryStr, "&", true, false);
+                JAXRSUtils.getStructuredParams(queryStr, "&", !encoded, false);
             String customQueryParamName = (String)message.getContextualProperty(CUSTOM_SEARCH_QUERY_PARAM_NAME);
             if (customQueryParamName != null) {
                 return params.getFirst(customQueryParamName);
@@ -145,6 +148,10 @@ public class SearchContextImpl implements SearchContext {
         return builder.and(list).query();
     }
     
+    private String getKeepEncodedProperty() {
+        return (String)message.getContextualProperty(KEEP_QUERY_ENCODED);
+    }
+    
     private CompleteCondition getOrCondition(SearchConditionBuilder builder,
                                              Map.Entry<String, List<String>>
entry) {
         String key = entry.getKey();

http://git-wip-us.apache.org/repos/asf/cxf/blob/9fc73f51/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
index 4051d33..2565cbb 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchUtils.java
@@ -40,6 +40,7 @@ public final class SearchUtils {
     public static final String LAX_PROPERTY_MATCH = "search.lax.property.match";
     public static final String BEAN_PROPERTY_MAP = "search.bean.property.map";
     public static final String SEARCH_VISITOR_PROPERTY = "search.visitor";
+    public static final String DECODE_QUERY_VALUES = "search.decode.values";
     
     private static final Logger LOG = LogUtils.getL7dLogger(SearchUtils.class);
     
@@ -63,7 +64,6 @@ public final class SearchUtils {
     }
 
     
-    //new SimpleDateFormat(DEFAULT_DATE_FORMAT);
     public static Date dateFromStringWithContextProperties(String value) {
         try {            
             final SimpleDateFormat format = getContextualDateFormat();

http://git-wip-us.apache.org/repos/asf/cxf/blob/9fc73f51/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
index 0bab949..ef97c97 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParser.java
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionParser;
 import org.apache.cxf.jaxrs.ext.search.AndSearchCondition;
 import org.apache.cxf.jaxrs.ext.search.Beanspector.TypeInfo;
@@ -272,6 +273,9 @@ public class FiqlParser<T> extends AbstractSearchConditionParser<T>
{
     
     private TypeInfoObject parseType(String originalName, String setter, String value) throws
SearchParseException {
         TypeInfo typeInfo = getTypeInfo(setter, value);
+        if (isDecodeQueryValues()) {
+            value = UrlUtils.urlDecode(value);
+        }
         Object object = parseType(originalName, null, null, setter, typeInfo, value);
         return new TypeInfoObject(object, typeInfo);
     }

http://git-wip-us.apache.org/repos/asf/cxf/blob/9fc73f51/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
----------------------------------------------------------------------
diff --git a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
index 5227ebe..a51cc6d 100644
--- a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
+++ b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/odata/ODataParser.java
@@ -23,6 +23,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
+import org.apache.cxf.common.util.UrlUtils;
 import org.apache.cxf.jaxrs.ext.search.AbstractSearchConditionParser;
 import org.apache.cxf.jaxrs.ext.search.AndSearchCondition;
 import org.apache.cxf.jaxrs.ext.search.Beanspector.TypeInfo;
@@ -165,8 +166,12 @@ public class ODataParser<T> extends AbstractSearchConditionParser<T>
{
             if (property.typeInfo.getWrappedTypeClass().isAssignableFrom(value.typeClass))
{
                 typedValue = value.value;
             } else { // Property type and value type are not compatible and convert / cast
are required
+                String valueStr = value.literal;
+                if (isDecodeQueryValues()) {
+                    valueStr = UrlUtils.urlDecode(valueStr);
+                }
                 typedValue = parseType(property.propertyName, null, null, property.propertyName,

-                    property.typeInfo, value.literal);
+                    property.typeInfo, valueStr);
             }
             
             final CollectionCheckInfo checkInfo = property.typeInfo.getCollectionCheckInfo();


Mime
View raw message