diff --git a/build.gradle b/build.gradle index 08197df51..56c09ffa5 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,6 @@ ext { 'org.hamcrest:hamcrest:2.2', 'org.glassfish:jakarta.json:2.0.1', 'org.eclipse:yasson:2.0.4', - //'org.apache.johnzon:johnzon-jsonb:1.2.21', 'org.slf4j:slf4j-simple:2.0.9', 'com.google.code.gson:gson:2.10.1', 'org.hamcrest:hamcrest:2.2', diff --git a/json-path-web-test/build.gradle b/json-path-web-test/build.gradle deleted file mode 100644 index a708daf64..000000000 --- a/json-path-web-test/build.gradle +++ /dev/null @@ -1,46 +0,0 @@ -apply plugin: 'com.github.johnrengelman.shadow' -apply plugin: 'application' - -description = "Web app that compares different JsonPath implementations." - -mainClassName = 'com.jayway.jsonpath.web.boot.Main' - -task createBuildInfoFile { - dependsOn compileJava - doLast { - def buildInfoFile = new File("$buildDir/classes/java/main/build-info.properties") - Properties props = new Properties() - props.setProperty('version', project.version.toString()) - props.setProperty('timestamp', project.buildTimestamp) - props.store(buildInfoFile.newWriter(), null) - } -} - -jar { - dependsOn createBuildInfoFile - baseName 'json-path-web-test' - bnd ( - 'Implementation-Title': 'json-path-web-test', - 'Implementation-Version': version, - 'Main-Class': mainClassName - ) -} - - -dependencies { - implementation project(':json-path') - implementation 'commons-io:commons-io:2.4' - implementation libs.slf4jApi - implementation libs.jacksonDatabind - implementation libs.jsonSmart - implementation 'io.fastjson:boon:0.33' - implementation 'com.nebhale.jsonpath:jsonpath:1.2' - implementation 'io.gatling:jsonpath_2.10:0.6.4' - implementation 'org.eclipse.jetty:jetty-server:9.3.0.M1' - implementation 'org.eclipse.jetty:jetty-webapp:9.3.0.M1' - implementation 'org.glassfish.jersey.containers:jersey-container-servlet:2.20' - implementation('org.glassfish.jersey.media:jersey-media-json-jackson:2.20'){ - exclude module: 'jackson-annotations:com.fasterxml.jackson.core' - exclude module: 'jackson-core:com.fasterxml.jackson.core' - } -} diff --git a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Bench.java b/json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Bench.java deleted file mode 100644 index 8d51620bf..000000000 --- a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Bench.java +++ /dev/null @@ -1,156 +0,0 @@ -package com.jayway.jsonpath.web.bench; - -import com.jayway.jsonpath.Configuration; -import com.jayway.jsonpath.JsonPath; -import com.jayway.jsonpath.Option; -import com.jayway.jsonpath.spi.json.JacksonJsonProvider; -import io.gatling.jsonpath.JsonPath$; -import org.boon.json.JsonParser; -import org.boon.json.ObjectMapper; -import org.boon.json.implementation.JsonParserCharArray; -import org.boon.json.implementation.ObjectMapperImpl; -import scala.collection.Iterator; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class Bench { - - protected final String json; - protected final String path; - private final boolean optionAsValues; - private final boolean flagWrap; - private final boolean flagSuppress; - private final boolean flagNullLeaf; - private final boolean flagRequireProps; - - public Bench(String json, String path, boolean optionAsValues, boolean flagWrap, boolean flagSuppress, boolean flagNullLeaf, boolean flagRequireProps) { - this.json = json; - this.path = path; - this.optionAsValues = optionAsValues; - this.flagWrap = flagWrap; - this.flagSuppress = flagSuppress; - this.flagNullLeaf = flagNullLeaf; - this.flagRequireProps = flagRequireProps; - } - - public Result runJayway() { - String result = null; - String error = null; - long time; - Object res = null; - - - Configuration configuration = Configuration.defaultConfiguration(); - if(flagWrap){ - configuration = configuration.addOptions(Option.ALWAYS_RETURN_LIST); - } - if(flagSuppress){ - configuration = configuration.addOptions(Option.SUPPRESS_EXCEPTIONS); - } - if (!optionAsValues) { - configuration = configuration.addOptions(Option.AS_PATH_LIST); - } - if(flagNullLeaf){ - configuration = configuration.addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL); - } - if(flagRequireProps){ - configuration = configuration.addOptions(Option.REQUIRE_PROPERTIES); - } - - long now = System.currentTimeMillis(); - try { - res = JsonPath.using(configuration).parse(json).read(path); - } catch (Exception e) { - error = getError(e); - } finally { - time = System.currentTimeMillis() - now; - - if (res instanceof String) { - result = "\"" + res + "\""; - } else if (res instanceof Number) { - result = res.toString(); - } else if (res instanceof Boolean) { - result = res.toString(); - } else { - result = res != null ? Configuration.defaultConfiguration().jsonProvider().toJson(res) : "null"; - } - return new Result("jayway", time, result, error); - } - } - - public Result runBoon() { - String result = null; - String error = null; - long time; - - Iterator query = null; - long now = System.currentTimeMillis(); - try { - if (!optionAsValues) { - throw new UnsupportedOperationException("Not supported!"); - } - io.gatling.jsonpath.JsonPath jsonPath = JsonPath$.MODULE$.compile(path).right().get(); - - JsonParser jsonParser = new JsonParserCharArray(); - Object jsonModel = jsonParser.parse(json); - query = jsonPath.query(jsonModel); - - } catch (Exception e) { - error = getError(e); - } finally { - time = System.currentTimeMillis() - now; - - if (query != null) { - List res = new ArrayList(); - while (query.hasNext()) { - res.add(query.next()); - } - ObjectMapper mapper = new ObjectMapperImpl(); - result = mapper.toJson(res); - } - return new Result("boon", time, result, error); - } - } - - public Result runNebhale() { - String result = null; - String error = null; - long time; - Object res = null; - JacksonJsonProvider jacksonProvider = new JacksonJsonProvider(); - - long now = System.currentTimeMillis(); - try { - if (!optionAsValues) { - throw new UnsupportedOperationException("Not supported!"); - } - com.nebhale.jsonpath.JsonPath compiled = com.nebhale.jsonpath.JsonPath.compile(path); - res = compiled.read(json, Object.class); - } catch (Exception e) { - error = getError(e); - } finally { - time = System.currentTimeMillis() - now; - result = res != null ? jacksonProvider.toJson(res) : null; - return new Result("nebhale", time, result, error); - } - } - - public Map runAll() { - Map res = new HashMap(); - res.put("jayway", runJayway()); - res.put("boon", runBoon()); - res.put("nebhale", runNebhale()); - return res; - } - - private String getError(Exception e) { - String ex = e.getMessage(); - if (ex == null || ex.trim().isEmpty()) { - ex = "Undefined error"; - } - return ex; - } -} diff --git a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Result.java b/json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Result.java deleted file mode 100644 index 3aa8bebe3..000000000 --- a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/bench/Result.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.jayway.jsonpath.web.bench; - -import com.jayway.jsonpath.internal.JsonFormatter; - -public class Result { - - public final String provider; - public final long time; - public final String result; - public final String error; - - public Result(String provider, long time, String result, String error) { - this.provider = provider; - this.time = time; - this.result = result != null ? JsonFormatter.prettyPrint(result) : result; - this.error = error; - } -} \ No newline at end of file diff --git a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/boot/Main.java b/json-path-web-test/src/main/java/com/jayway/jsonpath/web/boot/Main.java deleted file mode 100644 index 9bd72f4c8..000000000 --- a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/boot/Main.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.jayway.jsonpath.web.boot; - -import com.jayway.jsonpath.web.resource.ApiResource; -import org.eclipse.jetty.server.Connector; -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.ServerConnector; -import org.eclipse.jetty.server.handler.HandlerList; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; -import org.eclipse.jetty.webapp.WebAppContext; -import org.glassfish.jersey.jackson.JacksonFeature; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.servlet.ServletContainer; - -import java.io.IOException; - - - -public class Main { - - public static void main(String[] args) throws Exception { - String configPort = "8080"; - if(args.length > 0){ - configPort = args[0]; - } - - String port = System.getProperty("server.http.port", configPort); - System.out.println("Server started on port: " + port); - - Server server = new Server(); - - server.setConnectors(new Connector[]{createConnector(server, Integer.parseInt(port))}); - - ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); - context.setContextPath("/api"); - ServletHolder servletHolder = new ServletHolder(createJerseyServlet()); - servletHolder.setInitOrder(1); - context.addServlet(servletHolder, "/*"); - - WebAppContext webAppContext = new WebAppContext(); - webAppContext.setServer(server); - webAppContext.setContextPath("/"); - - String resourceBase = System.getProperty("resourceBase"); - if(resourceBase != null){ - webAppContext.setResourceBase(resourceBase); - } else { - webAppContext.setResourceBase(Main.class.getResource("/webapp").toExternalForm()); - } - - HandlerList handlers = new HandlerList(); - handlers.setHandlers(new Handler[]{context, webAppContext}); - server.setHandler(handlers); - - server.start(); - server.join(); - } - - private static ServerConnector createConnector(Server s, int port){ - ServerConnector connector = new ServerConnector(s); - connector.setHost("0.0.0.0"); - connector.setPort(port); - return connector; - } - - private static ServletContainer createJerseyServlet() throws IOException { - ResourceConfig resourceConfig = new ResourceConfig(); - resourceConfig.register(JacksonFeature.class); - - resourceConfig.register(new ApiResource()); - - return new ServletContainer(resourceConfig); - } -} diff --git a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java b/json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java deleted file mode 100644 index 69aa43586..000000000 --- a/json-path-web-test/src/main/java/com/jayway/jsonpath/web/resource/ApiResource.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.jayway.jsonpath.web.resource; - -import com.jayway.jsonpath.JsonPath; -import com.jayway.jsonpath.web.bench.Bench; -import com.jayway.jsonpath.web.bench.Result; -import net.minidev.json.JSONStyle; -import net.minidev.json.JSONValue; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.ResourceBundle; - -@Path("/") -@Produces(MediaType.TEXT_HTML) -public class ApiResource { - - private static final Logger logger = LoggerFactory.getLogger(ApiResource.class); - - static { - JSONValue.COMPRESSION = JSONStyle.LT_COMPRESS; - } - - @GET - @Path("/info") - @Produces(MediaType.APPLICATION_JSON) - public Response info() { - Map result = new HashMap(); - try { - ResourceBundle resource = ResourceBundle.getBundle("build-info"); - result.put("version", resource.getString("version")); - result.put("timestamp", resource.getString("timestamp")); - } catch (Exception e){ - result.put("version", "LOCAL"); - result.put("timestamp", "NOW"); - } - return Response.ok(result).build(); - } - - @GET - @Path("/validate") - @Produces(MediaType.APPLICATION_JSON) - public Response validate(@QueryParam("path") String path) { - int result = -1; - try { - JsonPath compiled = JsonPath.compile(path); - result = compiled.isDefinite() ? 0 : 1; - } catch (Exception e) { - } - return Response.ok(Collections.singletonMap("result", result)).build(); - } - - - @POST - @Path("/eval") - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) - @Produces(MediaType.APPLICATION_JSON) - public Response getTemplate(@FormParam("json") String json, - @FormParam("path") String path, - @FormParam("type") String type, - @FormParam("flagWrap") boolean flagWrap, - @FormParam("flagNullLeaf") boolean flagNullLeaf, - @FormParam("flagSuppress") boolean flagSuppress, - @FormParam("flagRequireProps") boolean flagRequireProps) { - - boolean value = "VALUE".equalsIgnoreCase(type); - - Map resultMap = new Bench(json, path, value, flagWrap, flagSuppress, flagNullLeaf, flagRequireProps).runAll(); - - return Response.ok(resultMap).build(); - } - - -} diff --git a/json-path-web-test/src/main/resources/simplelogger.properties b/json-path-web-test/src/main/resources/simplelogger.properties deleted file mode 100644 index 16dec9a81..000000000 --- a/json-path-web-test/src/main/resources/simplelogger.properties +++ /dev/null @@ -1,2 +0,0 @@ -org.slf4j.simpleLogger.defaultLogLevel=warn -org.slf4j.simpleLogger.log.com.jayway=debug \ No newline at end of file diff --git a/json-path-web-test/src/main/resources/webapp/index.html b/json-path-web-test/src/main/resources/webapp/index.html deleted file mode 100644 index dc8fa4b7a..000000000 --- a/json-path-web-test/src/main/resources/webapp/index.html +++ /dev/null @@ -1,361 +0,0 @@ - - - - - - Jayway JsonPath evaluator - - - - - - - - - - - -
-

Jayway JsonPath Evaluator

-
-  -  -
-
-
-
- -
- -
- -
- -
- - - - - -
- -
- -
-
-
- JSONPath options -
- -
-
- -
-
-
- -
-
- Jayway options -
- -
-
- -
-
- -
-
- -
-
-
-
-
-
- - - -
- -
-
- About implementation... -  millis -
-
-
-

-                                
-
-

-
- -
-
- About implementation... -  millis -
-
-
-

-                                
-
-

-
- -
-
- About implementation... -  millis -
-
-
-

-                                
-
-

-
- -
-
- About implementation... -  millis -
-
-
-

-                                
-
-
- -
-
-
-
- - - - \ No newline at end of file diff --git a/json-path-web-test/src/main/resources/webapp/js/jsonpath-0.8.0.js b/json-path-web-test/src/main/resources/webapp/js/jsonpath-0.8.0.js deleted file mode 100644 index fc8d2d601..000000000 --- a/json-path-web-test/src/main/resources/webapp/js/jsonpath-0.8.0.js +++ /dev/null @@ -1,87 +0,0 @@ -/* JSONPath 0.8.0 - XPath for JSON - * - * Copyright (c) 2007 Stefan Goessner (goessner.net) - * Licensed under the MIT (MIT-LICENSE.txt) licence. - */ -function jsonPath(obj, expr, arg) { - var P = { - resultType: arg && arg.resultType || "VALUE", - result: [], - normalize: function(expr) { - var subx = []; - return expr.replace(/[\['](\??\(.*?\))[\]']/g, function($0,$1){return "[#"+(subx.push($1)-1)+"]";}) - .replace(/'?\.'?|\['?/g, ";") - .replace(/;;;|;;/g, ";..;") - .replace(/;$|'?\]|'$/g, "") - .replace(/#([0-9]+)/g, function($0,$1){return subx[$1];}); - }, - asPath: function(path) { - var x = path.split(";"), p = "$"; - for (var i=1,n=x.length; i