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 2010/03/13 17:40:31 UTC
svn commit: r922599 - in /cxf/trunk:
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/
rt/frontend/jaxrs/src/main...
Author: sergeyb
Date: Sat Mar 13 16:40:31 2010
New Revision: 922599
URL: http://svn.apache.org/viewvc?rev=922599&view=rev
Log:
JAXRS: implementing SearchContext (rt/management-web build failure will be fixed next for this merge to go into 2.2.x too)
Added:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSearchContext.java (with props)
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java (with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AndSearchCondition.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AndSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AndSearchCondition.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AndSearchCondition.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/AndSearchCondition.java Sat Mar 13 16:40:31 2010
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxrs.ext.search;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -62,7 +63,7 @@ public class AndSearchCondition<T> imple
return Collections.unmodifiableList(conditions);
}
- public List<T> findAll(List<T> pojos) {
+ public List<T> findAll(Collection<T> pojos) {
List<T> result = new ArrayList<T>();
for (T pojo : pojos) {
if (isMet(pojo)) {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/Beanspector.java Sat Mar 13 16:40:31 2010
@@ -138,7 +138,6 @@ class Beanspector<T> {
public Beanspector<T> setValue(Method setter, Object value) throws Throwable {
Class<?> paramType = setter.getParameterTypes()[0];
- value = narrowNumerics(paramType, value);
try {
setter.invoke(tobj, value);
return this;
@@ -153,40 +152,6 @@ class Beanspector<T> {
}
}
- // narrowing conversion is compile-time so in reflection is not supported
- // this is clunky workaround for numeric datatypes
- private Object narrowNumerics(Class<?> targetType, Object value) {
- Class<?> sourceType = value.getClass();
- if (sourceType == Double.class) {
- if (targetType == Integer.class || targetType == Integer.TYPE) {
- value = ((Double)value).intValue();
- } else if (targetType == Short.class || targetType == Short.TYPE) {
- value = ((Double)value).shortValue();
- } else if (targetType == Byte.class || targetType == Byte.TYPE) {
- value = ((Double)value).byteValue();
- }
- } else if (sourceType == Float.class) {
- if (targetType == Integer.class || targetType == Integer.TYPE) {
- value = ((Float)value).intValue();
- } else if (targetType == Short.class || targetType == Short.TYPE) {
- value = ((Float)value).shortValue();
- } else if (targetType == Byte.class || targetType == Byte.TYPE) {
- value = ((Float)value).byteValue();
- }
- } else if (sourceType == Integer.class) {
- if (targetType == Short.class || targetType == Short.TYPE) {
- value = ((Integer)value).shortValue();
- } else if (targetType == Byte.class || targetType == Byte.TYPE) {
- value = ((Integer)value).byteValue();
- }
- } else if (sourceType == Short.class
- && (targetType == Byte.class || targetType == Byte.TYPE)) {
- value = ((Integer)value).byteValue();
-
- }
- return value;
- }
-
public Object getValue(String getterName) throws Throwable {
return getValue(getters.get(getterName));
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/FiqlParser.java Sat Mar 13 16:40:31 2010
@@ -33,6 +33,8 @@ import java.util.regex.Pattern;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
+import org.apache.cxf.jaxrs.utils.InjectionUtils;
+
/**
* Parses <a href="http://tools.ietf.org/html/draft-nottingham-atompub-fiql-00">FIQL</a> expression to
* construct {@link SearchCondition} structure. Since this class operates on Java type T, not on XML
@@ -188,13 +190,7 @@ public class FiqlParser<T> {
} catch (Exception e) {
throw new FiqlParseException(e);
}
- if (Number.class.isAssignableFrom(valueType)) {
- try {
- castedValue = Float.parseFloat(value);
- } catch (NumberFormatException e) {
- throw new FiqlParseException("Cannot parse " + value + " as number", e);
- }
- } else if (Date.class.isAssignableFrom(valueType)) {
+ if (Date.class.isAssignableFrom(valueType)) {
DateFormat df;
try {
df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
@@ -218,6 +214,13 @@ public class FiqlParser<T> {
throw new FiqlParseException("Can parse " + value + " neither as date nor duration", e);
}
}
+ } else {
+ try {
+ castedValue = InjectionUtils.convertStringToPrimitive(value, valueType);
+ } catch (Exception e) {
+ throw new FiqlParseException("Cannot convert String value \"" + value
+ + "\" to a value of class " + valueType.getName(), e);
+ }
}
return castedValue;
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/OrSearchCondition.java Sat Mar 13 16:40:31 2010
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxrs.ext.search;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -62,7 +63,7 @@ public class OrSearchCondition<T> implem
return Collections.unmodifiableList(conditions);
}
- public List<T> findAll(List<T> pojos) {
+ public List<T> findAll(Collection<T> pojos) {
List<T> result = new ArrayList<T>();
for (T pojo : pojos) {
if (isMet(pojo)) {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchCondition.java Sat Mar 13 16:40:31 2010
@@ -18,6 +18,7 @@
*/
package org.apache.cxf.jaxrs.ext.search;
+import java.util.Collection;
import java.util.List;
//CHECKSTYLE:OFF
@@ -47,7 +48,7 @@ public interface SearchCondition<T> {
* @param pojos list of pojos
* @return list of the matching pojos or null if none have been found
*/
- List<T> findAll(List<T> pojos);
+ List<T> findAll(Collection<T> pojos);
/**
* Some SearchConditions may use instance of T to capture the actual search criteria
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java?rev=922599&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java Sat Mar 13 16:40:31 2010
@@ -0,0 +1,71 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxrs.ext.search;
+
+import org.apache.cxf.jaxrs.utils.HttpUtils;
+import org.apache.cxf.message.Message;
+
+public class SearchContextImpl implements SearchContext {
+
+ public static final String SEARCH_QUERY = "_search";
+ public static final String SHORT_SEARCH_QUERY = "_s";
+ private Message message;
+
+ public SearchContextImpl(Message message) {
+ this.message = message;
+ }
+
+ public <T> SearchCondition<T> getCondition(Class<T> cls) {
+ FiqlParser<T> parser = getParser(cls);
+
+ String expression = getExpression();
+ if (expression != null) {
+ try {
+ return parser.parse(expression);
+ } catch (FiqlParseException ex) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+
+ }
+
+ private String getExpression() {
+ String queryStr = (String)message.get(Message.QUERY_STRING);
+ if (queryStr != null
+ && (queryStr.startsWith(SEARCH_QUERY) || queryStr.startsWith(SHORT_SEARCH_QUERY))) {
+ int ind = queryStr.indexOf('=');
+ if (ind + 1 < queryStr.length()) {
+ return HttpUtils.urlDecode(queryStr.substring(ind + 1));
+ }
+ }
+ return null;
+ }
+
+ 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
+
+ return new FiqlParser<T>(cls);
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SearchContextImpl.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java Sat Mar 13 16:40:31 2010
@@ -19,6 +19,7 @@
package org.apache.cxf.jaxrs.ext.search;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -244,6 +245,8 @@ public class SimpleSearchCondition<T> im
if (cond == ConditionType.EQUALS || cond == ConditionType.NOT_EQUALS) {
if (rval == null) {
compares = true;
+ } else if (lval == null) {
+ compares = false;
} else {
if (lval instanceof String) {
compares = textCompare((String)lval, (String)rval);
@@ -307,7 +310,7 @@ public class SimpleSearchCondition<T> im
}
}
- public List<T> findAll(List<T> pojos) {
+ public List<T> findAll(Collection<T> pojos) {
List<T> result = new ArrayList<T>();
for (T pojo : pojos) {
if (isMet(pojo)) {
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ext/xml/XMLSource.java Sat Mar 13 16:40:31 2010
@@ -23,7 +23,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
-import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collections;
import java.util.Iterator;
@@ -50,7 +49,6 @@ import org.xml.sax.InputSource;
import org.apache.cxf.common.i18n.BundleUtils;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.common.util.PrimitiveUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.helpers.XMLUtils;
@@ -162,7 +160,7 @@ public class XMLSource {
public <T> T getValue(String expression, Map<String, String> namespaces, Class<T> cls) {
Object result = evaluate(expression, namespaces, XPathConstants.STRING);
- return result == null ? null : convertStringToPrimitive(result.toString(), cls);
+ return result == null ? null : InjectionUtils.convertStringToPrimitive(result.toString(), cls);
}
@@ -230,23 +228,7 @@ public class XMLSource {
}
}
- return convertStringToPrimitive(node.getNodeValue(), cls);
- }
-
- private <T> T convertStringToPrimitive(String value, Class<T> cls) {
- if (String.class == cls) {
- return cls.cast(value);
- }
- if (cls.isPrimitive()) {
- return cls.cast(PrimitiveUtils.read(value, cls));
- } else {
- try {
- Method m = cls.getMethod("valueOf", new Class[]{String.class});
- return cls.cast(m.invoke(null, value));
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
+ return InjectionUtils.convertStringToPrimitive(node.getNodeValue(), cls);
}
Added: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSearchContext.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSearchContext.java?rev=922599&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSearchContext.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSearchContext.java Sat Mar 13 16:40:31 2010
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+package org.apache.cxf.jaxrs.impl.tl;
+
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchContext;
+
+public class ThreadLocalSearchContext extends AbstractThreadLocalProxy<SearchContext>
+ implements SearchContext {
+
+ @SuppressWarnings("unchecked")
+ public SearchCondition getCondition(Class cls) {
+ return get().getCondition(cls);
+ }
+
+
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSearchContext.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/tl/ThreadLocalSearchContext.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java Sat Mar 13 16:40:31 2010
@@ -70,6 +70,7 @@ import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.jaxrs.ext.MessageContext;
import org.apache.cxf.jaxrs.ext.ParameterHandler;
import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
+import org.apache.cxf.jaxrs.ext.search.SearchContext;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.impl.PathSegmentImpl;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalContextResolver;
@@ -81,6 +82,7 @@ import org.apache.cxf.jaxrs.impl.tl.Thre
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProviders;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalProxy;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalRequest;
+import org.apache.cxf.jaxrs.impl.tl.ThreadLocalSearchContext;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalSecurityContext;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalServletConfig;
import org.apache.cxf.jaxrs.impl.tl.ThreadLocalServletContext;
@@ -720,8 +722,10 @@ public final class InjectionUtils {
proxy = new ThreadLocalHttpServletResponse();
} else if (MessageContext.class.isAssignableFrom(type)) {
proxy = new ThreadLocalMessageContext();
- } else if (ServletConfig.class.isAssignableFrom(type)) {
+ } else if (ServletConfig.class.isAssignableFrom(type)) {
proxy = new ThreadLocalServletConfig();
+ } else if (SearchContext.class.isAssignableFrom(type)) {
+ proxy = new ThreadLocalSearchContext();
}
return proxy;
}
@@ -908,4 +912,21 @@ public final class InjectionUtils {
}
}
}
+
+ @SuppressWarnings("unchecked")
+ public static <T> T convertStringToPrimitive(String value, Class<T> cls) {
+ if (String.class == cls) {
+ return cls.cast(value);
+ }
+ if (cls.isPrimitive()) {
+ return (T)PrimitiveUtils.read(value, cls);
+ } else {
+ try {
+ Method m = cls.getMethod("valueOf", new Class[]{String.class});
+ return cls.cast(m.invoke(null, value));
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
}
Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/JAXRSUtils.java Sat Mar 13 16:40:31 2010
@@ -75,6 +75,8 @@ import org.apache.cxf.jaxrs.ext.MessageC
import org.apache.cxf.jaxrs.ext.ProtocolHeaders;
import org.apache.cxf.jaxrs.ext.ProtocolHeadersImpl;
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody;
+import org.apache.cxf.jaxrs.ext.search.SearchContext;
+import org.apache.cxf.jaxrs.ext.search.SearchContextImpl;
import org.apache.cxf.jaxrs.impl.HttpHeadersImpl;
import org.apache.cxf.jaxrs.impl.HttpServletResponseFilter;
import org.apache.cxf.jaxrs.impl.MetadataMap;
@@ -784,6 +786,8 @@ public final class JAXRSUtils {
o = createContextResolver(genericType, contextMessage);
} else if (MessageContext.class.isAssignableFrom(clazz)) {
o = new MessageContextImpl(m);
+ } else if (SearchContext.class.isAssignableFrom(clazz)) {
+ o = new SearchContextImpl(m);
}
o = o == null ? createServletResourceValue(contextMessage, clazz) : o;
Modified: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java (original)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/FiqlParserTest.java Sat Mar 13 16:40:31 2010
@@ -205,11 +205,11 @@ public class FiqlParserTest {
this.name = name;
}
- public Integer getLevel() {
+ public int getLevel() {
return level;
}
- public void setLevel(Integer level) {
+ public void setLevel(int level) {
this.level = level;
}
Added: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java?rev=922599&view=auto
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java (added)
+++ cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java Sat Mar 13 16:40:31 2010
@@ -0,0 +1,60 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.jaxrs.ext.search;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.cxf.jaxrs.resources.Book;
+import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageImpl;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SearchContextImplTest extends Assert {
+
+ @Test
+ public void testFiqlSearchCondition() {
+ doTestFiqlSearchCondition(SearchContextImpl.SEARCH_QUERY,
+ "name==CXF%20Rocks;id=gt=123");
+ }
+
+ @Test
+ public void testFiqlSearchConditionWithShortQuery() {
+ doTestFiqlSearchCondition(SearchContextImpl.SHORT_SEARCH_QUERY,
+ "name==CXF%20Rocks;id=gt=123");
+ }
+
+ private void doTestFiqlSearchCondition(String queryName, String queryValue) {
+ Message m = new MessageImpl();
+ m.put(Message.QUERY_STRING, queryName + "=" + queryValue);
+ SearchContext context = new SearchContextImpl(m);
+ SearchCondition<Book> sc = context.getCondition(Book.class);
+ assertNotNull(sc);
+
+ List<Book> books = new ArrayList<Book>();
+ books.add(new Book("CXF is cool", 125L));
+ books.add(new Book("CXF Rocks", 125L));
+
+ List<Book> found = sc.findAll(books);
+ assertEquals(1, found.size());
+ assertEquals(new Book("CXF Rocks", 125L), found.get(0));
+ }
+}
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cxf/trunk/rt/frontend/jaxrs/src/test/java/org/apache/cxf/jaxrs/ext/search/SearchContextImplTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java Sat Mar 13 16:40:31 2010
@@ -66,6 +66,8 @@ import javax.xml.transform.dom.DOMSource
import org.apache.cxf.helpers.XMLUtils;
import org.apache.cxf.jaxrs.ext.Oneway;
+import org.apache.cxf.jaxrs.ext.search.SearchCondition;
+import org.apache.cxf.jaxrs.ext.search.SearchContext;
import org.apache.cxf.phase.PhaseInterceptorChain;
@Path("/bookstore")
@@ -336,6 +338,23 @@ public class BookStore {
}
@GET
+ @Path("/books/search")
+ @Produces("application/xml")
+ public Book getBook(@Context SearchContext searchContext)
+ throws BookNotFoundFault {
+
+ SearchCondition<Book> sc = searchContext.getCondition(Book.class);
+ if (sc == null) {
+ throw new BookNotFoundFault("Search exception");
+ }
+ List<Book> found = sc.findAll(books.values());
+ if (found.size() != 1) {
+ throw new BookNotFoundFault("Single book is expected");
+ }
+ return found.get(0);
+ }
+
+ @GET
@Path("/books/{bookId}/")
@Produces("text/xml")
public Book getBookTextXml(@PathParam("bookId") String id) throws BookNotFoundFault {
Modified: cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=922599&r1=922598&r2=922599&view=diff
==============================================================================
--- cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java (original)
+++ cxf/trunk/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java Sat Mar 13 16:40:31 2010
@@ -482,6 +482,13 @@ public class JAXRSClientServerBookTest e
"application/xml", 200);
}
+ @Test
+ public void testSearchBook123() throws Exception {
+ getAndCompareAsStrings("http://localhost:9080/bookstore/books/search"
+ + "?_s=name==CXF*;id=ge=123;id=lt=124",
+ "resources/expected_get_book123.txt",
+ "application/xml", 200);
+ }
@Test
public void testGetBook123() throws Exception {