This is an automated email from the ASF dual-hosted git repository.
coheigea pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new afe3c500127 Removing SQLPrinterVisitor due to security concerns (#3092)
afe3c500127 is described below
commit afe3c50012795a9cad0475f3b61d477e8361694d
Author: Colm O hEigeartaigh <[email protected]>
AuthorDate: Mon May 11 13:24:42 2026 +0100
Removing SQLPrinterVisitor due to security concerns (#3092)
---
.../jaxrs/ext/search/AbstractComplexCondition.java | 4 -
.../jaxrs/ext/search/PrimitiveSearchCondition.java | 6 +-
.../apache/cxf/jaxrs/ext/search/SearchUtils.java | 7 -
.../jaxrs/ext/search/SimpleSearchCondition.java | 4 -
.../jaxrs/ext/search/jpa/JPALanguageVisitor.java | 56 ------
.../jaxrs/ext/search/sql/SQLPrinterVisitor.java | 154 ---------------
.../cxf/jaxrs/ext/search/fiql/FiqlParserTest.java | 43 -----
.../ext/search/jpa/JPALanguageVisitorTest.java | 39 ----
.../ext/search/sql/SQLHierarchicalQueryTest.java | 75 --------
.../ext/search/sql/SQLPrinterVisitorTest.java | 211 ---------------------
.../org/apache/cxf/systest/jaxrs/BookServer.java | 3 -
.../systest/jaxrs/JAXRSClientServerBookTest.java | 22 ---
12 files changed, 1 insertion(+), 623 deletions(-)
diff --git
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
index f81198f80c9..1512b451c12 100644
---
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
+++
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/AbstractComplexCondition.java
@@ -67,10 +67,6 @@ public abstract class AbstractComplexCondition<T> implements
SearchCondition<T>
return null;
}
- public String toSQL(String table, String... columns) {
- return SearchUtils.toSQL(this, table, columns);
- }
-
public void accept(SearchConditionVisitor<T, ?> visitor) {
visitor.visit(this);
}
diff --git
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
index d9e604864cf..ad3b6fd1965 100644
---
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
+++
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/PrimitiveSearchCondition.java
@@ -127,11 +127,7 @@ public class PrimitiveSearchCondition<T> implements
SearchCondition<T> {
return null;
}
}
-
- public String toSQL(String table, String... columns) {
- return SearchUtils.toSQL(this, table, columns);
- }
-
+
public void accept(SearchConditionVisitor<T, ?> visitor) {
visitor.visit(this);
}
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 c2a6cda13c2..3527c2c9735 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
@@ -29,7 +29,6 @@ import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.cxf.common.logging.LogUtils;
-import org.apache.cxf.jaxrs.ext.search.sql.SQLPrinterVisitor;
import org.apache.cxf.message.Message;
import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.phase.PhaseInterceptorChain;
@@ -117,12 +116,6 @@ public final class SearchUtils {
return tzProperty == null ? defaultValue : Boolean.valueOf(tzProperty);
}
- public static <T> String toSQL(SearchCondition<T> sc, String table,
String... columns) {
- SQLPrinterVisitor<T> visitor = new SQLPrinterVisitor<>(table, columns);
- sc.accept(visitor);
- return visitor.getQuery();
- }
-
public static String toSqlWildcardString(String value, boolean
alwaysWildcard) {
if (value.contains("\\")) {
value = value.replaceAll("\\\\", "\\\\\\\\");
diff --git
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
index 683473b4e3c..bf0e44cf71d 100644
---
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
+++
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/SimpleSearchCondition.java
@@ -308,10 +308,6 @@ public class SimpleSearchCondition<T> implements
SearchCondition<T> {
return result;
}
- public String toSQL(String table, String... columns) {
- return SearchUtils.toSQL(this, table, columns);
- }
-
@Override
public PrimitiveStatement getStatement() {
if (scts.size() == 1) {
diff --git
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPALanguageVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPALanguageVisitor.java
deleted file mode 100644
index 6bd21472456..00000000000
---
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/JPALanguageVisitor.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/**
- * 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.jpa;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.cxf.jaxrs.ext.search.SearchCondition;
-import org.apache.cxf.jaxrs.ext.search.sql.SQLPrinterVisitor;
-
-public class JPALanguageVisitor<T> extends SQLPrinterVisitor<T> {
-
-
- public JPALanguageVisitor(Class<T> tClass) {
- this(tClass, "t", null);
- }
-
- public JPALanguageVisitor(Class<T> tClass, String tableAlias) {
- this(tClass, tableAlias, null);
- }
-
- public JPALanguageVisitor(Class<T> tClass,
- Map<String, String> fieldMap) {
- this(tClass, "t", fieldMap);
- }
-
- public JPALanguageVisitor(Class<T> tClass,
- String tableAlias,
- Map<String, String> fieldMap) {
- super(fieldMap,
- tClass.getSimpleName(),
- tableAlias,
- tableAlias != null ? Collections.singletonList(tableAlias) :
null);
- }
-
- public void visit(SearchCondition<T> sc) {
- // provide more customizations as needed
- super.visit(sc);
- }
-}
diff --git
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
b/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
deleted file mode 100644
index 77ef992043b..00000000000
---
a/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * 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.sql;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.cxf.jaxrs.ext.search.PrimitiveStatement;
-import org.apache.cxf.jaxrs.ext.search.SearchCondition;
-import org.apache.cxf.jaxrs.ext.search.SearchParseException;
-import org.apache.cxf.jaxrs.ext.search.SearchUtils;
-import
org.apache.cxf.jaxrs.ext.search.visitor.AbstractUntypedSearchConditionVisitor;
-
-
-public class SQLPrinterVisitor<T> extends
AbstractUntypedSearchConditionVisitor<T, String> {
-
- private String primaryTable;
- private String tableAlias;
- private List<String> columns;
- private StringBuilder topBuilder = new StringBuilder();
- private volatile boolean joinDone;
- // Can be useful when some other code will build Select and From clauses.
- public SQLPrinterVisitor() {
- this(null, null, Collections.<String>emptyList());
- }
-
- public SQLPrinterVisitor(String table, String... columns) {
- this(null, table, Arrays.asList(columns));
- }
-
- public SQLPrinterVisitor(Map<String, String> fieldMap,
- String table,
- List<String> columns) {
- this(fieldMap, table, null, columns);
- }
-
- public SQLPrinterVisitor(Map<String, String> fieldMap,
- String table,
- String tableAlias,
- List<String> columns) {
- super(fieldMap);
-
- this.columns = columns;
- this.primaryTable = table;
- this.tableAlias = tableAlias;
- prepareTopStringBuilder();
- }
-
- public void visit(SearchCondition<T> sc) {
- StringBuilder sb = getStringBuilder();
-
- PrimitiveStatement statement = sc.getStatement();
- if (statement != null) {
- if (statement.getProperty() != null) {
-
- String property = statement.getProperty();
- String[] properties = property.split("\\.");
- if (properties.length > 2) {
- throw new SearchParseException("SQL Visitor supports only
a single JOIN");
- } else if (properties.length == 2) {
- if (joinDone) {
- throw new SearchParseException("SQL Visitor has
already created JOIN");
- }
- joinDone = true;
- String joinTable = getRealPropertyName(properties[0]);
- // Joining key can be pre-configured
- String joiningKey = primaryTable;
- if (joiningKey.endsWith("s")) {
- joiningKey = joiningKey.substring(0,
joiningKey.length() - 1);
- }
- joiningKey += "_id";
-
- topBuilder.append(" left join ").append(joinTable);
- topBuilder.append(" on
").append(primaryTable).append(".id").append(" = ")
- .append(joinTable).append('.').append(joiningKey);
-
- property = joinTable + "." +
getRealPropertyName(properties[1]);
- }
-
- String name = getRealPropertyName(property);
- String originalValue = getPropertyValue(name,
statement.getValue());
- validatePropertyValue(name, originalValue);
-
- String value = SearchUtils.toSqlWildcardString(originalValue,
isWildcardStringMatch());
- value = SearchUtils.duplicateSingleQuoteIfNeeded(value);
-
- if (tableAlias != null) {
- name = tableAlias + "." + name;
- }
-
- sb.append(name).append(' ').append(
-
SearchUtils.conditionTypeToSqlOperator(sc.getConditionType(), value,
-
originalValue))
- .append('
').append("'").append(value).append("'"); //NOPMD
- }
- } else {
- boolean first = true;
- for (SearchCondition<T> condition : sc.getSearchConditions()) {
- if (!first) {
- sb.append('
').append(sc.getConditionType().toString()).append(' ');
- } else {
- first = false;
- }
- sb.append('(');
- saveStringBuilder(sb);
- condition.accept(this);
- sb = getStringBuilder();
- sb.append(')');
- }
- }
-
- saveStringBuilder(sb);
- }
-
- protected StringBuilder getStringBuilder() {
- StringBuilder sb = super.getStringBuilder();
- if (sb == null) {
- sb = new StringBuilder();
- }
- return sb;
- }
-
-
- @Override
- public String getQuery() {
- StringBuilder sb = removeStringBuilder();
- return sb == null ? null : topBuilder.toString() + " WHERE " +
sb.toString();
- }
-
- private void prepareTopStringBuilder() {
- if (primaryTable != null) {
- SearchUtils.startSqlQuery(topBuilder, primaryTable, tableAlias,
columns);
- }
- }
-
-}
diff --git
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
index c46913a49d9..db406954c95 100644
---
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
+++
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/fiql/FiqlParserTest.java
@@ -389,14 +389,6 @@ public class FiqlParserTest {
assertFalse(filter.isMet(new Condition("am", 20, null)));
}
- @Test
- public void testSQL1() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("name==ami*;level=gt=10");
- String sql = SearchUtils.toSQL(filter, "table");
- assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') AND (level >
'10')".equals(sql)
- || "SELECT * FROM table WHERE (level > '10') AND (name LIKE
'ami%')".equals(sql));
- }
-
@Test
public void testParseComplex2() throws SearchParseException {
SearchCondition<Condition> filter =
parser.parse("name==ami*,level=gt=10");
@@ -417,14 +409,6 @@ public class FiqlParserTest {
assertFalse(filter.isMet(new Condition("foo", 0, null)));
}
- @Test
- public void testSQL2() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("name==ami*,level=gt=10");
- String sql = SearchUtils.toSQL(filter, "table");
- assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') OR (level >
'10')".equals(sql)
- || "SELECT * FROM table WHERE (level > '10') OR (name LIKE
'ami%')".equals(sql));
- }
-
@Test
public void testParseComplex3() throws SearchParseException {
SearchCondition<Condition> filter =
parser.parse("name==foo*;(name!=*bar,level=gt=10)");
@@ -434,33 +418,6 @@ public class FiqlParserTest {
assertFalse(filter.isMet(new Condition("bar", 20, null)));
}
- @Test
- public void testSQL3() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("name==foo*;(name!=*bar,level=gt=10)");
- String sql = SearchUtils.toSQL(filter, "table");
- assertTrue(("SELECT * FROM table WHERE (name LIKE 'foo%') AND ((name
NOT LIKE '%bar') "
- + "OR (level > '10'))").equals(sql)
- || ("SELECT * FROM table WHERE (name LIKE 'foo%') AND "
- + "((level > '10') OR (name NOT LIKE
'%bar'))").equals(sql));
- }
-
- @Test
- public void testSQL4() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("(name==test,level==18);(name==test1,level!=19)");
- String sql = SearchUtils.toSQL(filter, "table");
- assertTrue(("SELECT * FROM table WHERE ((name = 'test') OR (level =
'18'))"
- + " AND ((name = 'test1') OR (level <> '19'))").equals(sql)
- || ("SELECT * FROM table WHERE ((name = 'test1') OR (level
<> '19'))"
- + " AND ((name = 'test') OR (level =
'18'))").equals(sql));
- }
-
- @Test
- public void testSQL5() throws SearchParseException {
- SearchCondition<Condition> filter = parser.parse("name==test");
- String sql = SearchUtils.toSQL(filter, "table");
- assertEquals("SELECT * FROM table WHERE name = 'test'", sql);
- }
-
@Test
public void testParseComplex4() throws SearchParseException {
SearchCondition<Condition> filter =
parser.parse("name==foo*;name!=*bar,level=gt=10");
diff --git
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPALanguageVisitorTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPALanguageVisitorTest.java
deleted file mode 100644
index 84c58ec9e65..00000000000
---
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/jpa/JPALanguageVisitorTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.jpa;
-
-import org.apache.cxf.jaxrs.ext.search.SearchCondition;
-import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class JPALanguageVisitorTest {
-
- @Test
- public void testSimpleQuery() throws Exception {
-
- SearchCondition<Book> filter = new
FiqlParser<>(Book.class).parse("id=lt=10");
- JPALanguageVisitor<Book> jpa = new JPALanguageVisitor<>(Book.class);
- filter.accept(jpa);
- assertEquals("SELECT t FROM Book t WHERE t.id < '10'", jpa.getQuery());
-
- }
-}
\ No newline at end of file
diff --git
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLHierarchicalQueryTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLHierarchicalQueryTest.java
deleted file mode 100644
index 737140e6e02..00000000000
---
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLHierarchicalQueryTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * 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.sql;
-
-import org.apache.cxf.jaxrs.ext.search.SearchBean;
-import org.apache.cxf.jaxrs.ext.search.SearchCondition;
-import org.apache.cxf.jaxrs.ext.search.SearchParseException;
-import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-//userName eq "[email protected]" and entitlements sw "TDP_"
-
-public class SQLHierarchicalQueryTest {
- @Test
- public void testSimpleHierarchicalQuery() throws SearchParseException {
- FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class);
- SearchCondition<SearchBean> filter =
parser.parse("cartridges.colour==blue");
- SQLPrinterVisitor<SearchBean> visitor = new
SQLPrinterVisitor<>("printers");
- filter.accept(visitor.visitor());
- String sql = visitor.getQuery();
-
- assertEquals("SELECT * FROM printers left join cartridges"
- + " on printers.id = cartridges.printer_id"
- + " WHERE cartridges.colour = 'blue'",
- sql);
- }
-
- @Test
- public void testAndHierarchicalQuery() throws SearchParseException {
- FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class);
- SearchCondition<SearchBean> filter =
parser.parse("name==Epson;cartridges.colour==blue");
- SQLPrinterVisitor<SearchBean> visitor = new
SQLPrinterVisitor<>("printers");
- filter.accept(visitor.visitor());
- String sql = visitor.getQuery();
-
- assertEquals("SELECT * FROM printers left join cartridges"
- + " on printers.id = cartridges.printer_id"
- + " WHERE (name = 'Epson') AND (cartridges.colour =
'blue')",
- sql);
- }
-
- @Test(expected = SearchParseException.class)
- public void testLongHierarchicalQuery() {
- FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class);
- SearchCondition<SearchBean> filter =
parser.parse("cartridges.producer.location==Japan");
- SQLPrinterVisitor<SearchBean> visitor = new
SQLPrinterVisitor<>("printers");
- filter.accept(visitor.visitor());
- }
-
- @Test(expected = SearchParseException.class)
- public void testTooManyJoins() {
- FiqlParser<SearchBean> parser = new FiqlParser<>(SearchBean.class);
- SearchCondition<SearchBean> filter =
parser.parse("cartridges.colour==blue;cartridges.location==Japan");
- SQLPrinterVisitor<SearchBean> visitor = new
SQLPrinterVisitor<>("printers");
- filter.accept(visitor.visitor());
- }
-}
\ No newline at end of file
diff --git
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
b/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
deleted file mode 100644
index 50b75a8fb2d..00000000000
---
a/rt/rs/extensions/search/src/test/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitorTest.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/**
- * 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.sql;
-
-import java.util.Collections;
-import java.util.Date;
-
-import org.apache.cxf.jaxrs.ext.search.SearchBean;
-import org.apache.cxf.jaxrs.ext.search.SearchCondition;
-import org.apache.cxf.jaxrs.ext.search.SearchParseException;
-import org.apache.cxf.jaxrs.ext.search.fiql.FiqlParser;
-import org.apache.cxf.jaxrs.ext.search.visitor.SBThreadLocalVisitorState;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-
-public class SQLPrinterVisitorTest {
- private FiqlParser<Condition> parser = new FiqlParser<>(Condition.class);
-
- @Test
- public void testSQL1() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("name==ami%*;level=gt=10");
- SQLPrinterVisitor<Condition> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor.visitor());
- String sql = visitor.getQuery();
-
- assertTrue("SELECT * FROM table WHERE (name LIKE 'ami\\%%') AND (level
> '10')".equals(sql)
- || "SELECT * FROM table WHERE (level > '10') AND (name LIKE
'ami\\%%')".equals(sql));
- }
-
- @Test
- public void testSQL1WithSearchBean() throws SearchParseException {
- FiqlParser<SearchBean> beanParser = new FiqlParser<>(SearchBean.class);
- SearchCondition<SearchBean> filter =
beanParser.parse("name==ami*;level=gt=10");
- SQLPrinterVisitor<SearchBean> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor);
- String sql = visitor.getQuery();
-
- assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') AND (level >
'10')".equals(sql)
- || "SELECT * FROM table WHERE (level > '10') AND (name LIKE
'ami%')".equals(sql));
- }
-
- @Test
- public void testSQLCamelNameSearchBean() throws SearchParseException {
- FiqlParser<SearchBean> beanParser = new FiqlParser<>(SearchBean.class);
- SearchCondition<SearchBean> filter =
beanParser.parse("theName==ami*;theLevel=gt=10");
- SQLPrinterVisitor<SearchBean> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor);
- String sql = visitor.getQuery();
-
- assertTrue("SELECT * FROM table WHERE (theName LIKE 'ami%') AND
(theLevel > '10')".equals(sql)
- || "SELECT * FROM table WHERE (theLevel > '10') AND
(theName LIKE 'ami%')".equals(sql));
- }
-
- @Test
- public void testSQL2() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("name==ami*,level=gt=10");
- SQLPrinterVisitor<Condition> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertTrue("SELECT * FROM table WHERE (name LIKE 'ami%') OR (level >
'10')".equals(sql)
- || "SELECT * FROM table WHERE (level > '10') OR (name LIKE
'ami%')".equals(sql));
- }
-
- @Test
- public void testSQL3() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("name==foo*;(name!=*bar,level=gt=10)");
- SQLPrinterVisitor<Condition> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertTrue(("SELECT * FROM table WHERE (name LIKE 'foo%') AND ((name
NOT LIKE '%bar') "
- + "OR (level > '10'))").equals(sql)
- || ("SELECT * FROM table WHERE (name LIKE 'foo%') AND "
- + "((level > '10') OR (name NOT LIKE
'%bar'))").equals(sql));
- }
-
- @Test
- public void testSQL3WithSearchBean() throws SearchParseException {
- FiqlParser<SearchBean> beanParser = new FiqlParser<>(SearchBean.class);
- SearchCondition<SearchBean> filter =
beanParser.parse("name==foo*;(name!=*bar,level=gt=10)");
- SQLPrinterVisitor<SearchBean> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertTrue(("SELECT * FROM table WHERE (name LIKE 'foo%') AND ((name
NOT LIKE '%bar') "
- + "OR (level > '10'))").equals(sql)
- || ("SELECT * FROM table WHERE (name LIKE 'foo%') AND "
- + "((level > '10') OR (name NOT LIKE
'%bar'))").equals(sql));
- }
-
- @Test
- public void testSQL4() throws SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("(name==test,level==18);(name==test1,level!=19)");
- SQLPrinterVisitor<Condition> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertTrue(("SELECT * FROM table WHERE ((name = 'test') OR (level =
'18'))"
- + " AND ((name = 'test1') OR (level <> '19'))").equals(sql)
- || ("SELECT * FROM table WHERE ((name = 'test1') OR (level
<> '19'))"
- + " AND ((name = 'test') OR (level = '18'))").equals(sql));
- }
-
- @Test
- public void testSQL4WithTLStateAndSingleThread() throws
SearchParseException {
- SearchCondition<Condition> filter =
parser.parse("(name==test,level==18);(name==test1,level!=19)");
- SQLPrinterVisitor<Condition> visitor = new
SQLPrinterVisitor<>("table");
- visitor.setVisitorState(new SBThreadLocalVisitorState());
-
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertTrue(("SELECT * FROM table WHERE ((name = 'test') OR (level =
'18'))"
- + " AND ((name = 'test1') OR (level <> '19'))").equals(sql)
- || ("SELECT * FROM table WHERE ((name = 'test1') OR (level
<> '19'))"
- + " AND ((name = 'test') OR (level = '18'))").equals(sql));
- }
-
- @Test
- public void testSQL5() throws SearchParseException {
- SearchCondition<Condition> filter = parser.parse("name==test");
- SQLPrinterVisitor<Condition> visitor = new
SQLPrinterVisitor<>("table");
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertEquals("SELECT * FROM table WHERE name = 'test'", sql);
- }
-
- @Test
- public void testSQL5WithColumns() throws SearchParseException {
- SearchCondition<Condition> filter = parser.parse("name==test");
- SQLPrinterVisitor<Condition> visitor =
- new SQLPrinterVisitor<>("table", "NAMES");
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertEquals("SELECT NAMES FROM table WHERE name = 'test'", sql);
- }
-
- @Test
- public void testSQL5WithFieldMap() throws SearchParseException {
- SearchCondition<Condition> filter = parser.parse("name==test");
- SQLPrinterVisitor<Condition> visitor =
- new SQLPrinterVisitor<Condition>(
- Collections.singletonMap("name", "NAMES"),
- "table", Collections.singletonList("NAMES"));
- filter.accept(visitor);
- String sql = visitor.getQuery();
- assertEquals("SELECT NAMES FROM table WHERE NAMES = 'test'", sql);
- }
-
- @Ignore
- public static class Condition {
- private String name;
- private Integer level;
- private Date time;
-
- public Condition() {
- }
-
- public Condition(String name, Integer level, Date time) {
- this.name = name;
- this.level = level;
- this.time = time;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public Integer getLevel() {
- return level;
- }
-
- public void setLevel(Integer level) {
- this.level = level;
- }
-
- public Date getTime() {
- return time;
- }
-
- public void setTime(Date time) {
- this.time = time;
- }
-
- public void setException(Exception ex) {
- // do nothing
- }
-
- }
-}
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
index da035006c11..80a16e1080d 100644
--- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
+++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/BookServer.java
@@ -57,9 +57,7 @@ import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
import org.apache.cxf.jaxrs.client.ResponseExceptionMapper;
import org.apache.cxf.jaxrs.ext.search.QueryContextProvider;
-import org.apache.cxf.jaxrs.ext.search.SearchBean;
import org.apache.cxf.jaxrs.ext.search.SearchContextProvider;
-import org.apache.cxf.jaxrs.ext.search.sql.SQLPrinterVisitor;
import org.apache.cxf.jaxrs.impl.MetadataMap;
import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;
import org.apache.cxf.jaxrs.provider.BinaryDataProvider;
@@ -140,7 +138,6 @@ public class BookServer extends
AbstractServerTestServerBase {
sf.setAddress("http://localhost:" + PORT + "/");
sf.getProperties(true).put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", true);
- sf.getProperties().put("search.visitor", new
SQLPrinterVisitor<SearchBean>("books"));
sf.getProperties().put("org.apache.cxf.http.header.split", true);
sf.getProperties().put("default.content.type", "*/*");
sf.getProperties().putAll(properties);
diff --git
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
index 8c3460e6768..64cc125d07f 100644
---
a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
+++
b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
@@ -40,7 +40,6 @@ import java.util.zip.GZIPInputStream;
import javax.xml.namespace.QName;
-import jakarta.ws.rs.InternalServerErrorException;
import jakarta.ws.rs.NotAcceptableException;
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.ServerErrorException;
@@ -1969,27 +1968,6 @@ public class JAXRSClientServerBookTest extends
AbstractBusClientServerTestBase {
assertEquals(b.getId(), 123L);
}
- @Test
- public void testGetSearchBookSQL() throws Exception {
- String address = "http://localhost:" + PORT
- + "/bookstore/books/querycontext/id=ge=123";
-
- WebClient client = WebClient.create(address);
- client.accept("text/plain");
- String sql = client.get(String.class);
- assertEquals("SELECT * FROM books WHERE id >= '123'", sql);
- }
-
- @Test (expected = InternalServerErrorException.class)
- public void testSearchUnknownParameter() throws Exception {
- String address = "http://localhost:" + PORT
- + "/bookstore/books/querycontext/id=ge=123%2C1==1";
-
- WebClient client = WebClient.create(address);
- client.accept("text/plain");
- client.get(String.class);
- }
-
@Test
public void testGetBook123CGLIB() throws Exception {
getAndCompareAsStrings("http://localhost:" + PORT +
"/bookstore/books/123/cglib",