From bac28ed8a870d7f4118a775769af45abcfe162f7 Mon Sep 17 00:00:00 2001 From: Ignacio Baca Moreno-Torres Date: Sat, 18 Apr 2020 10:53:35 +0200 Subject: [PATCH] Remove example and upgrade rxjava to 2.2.10 Official example here: https://github.com/ibaca/autorest-nominatim-example --- README.md | 10 +-- example/pom.xml | 74 ------------------- .../gwt/autorest/example/Example.gwt.xml | 9 --- .../example/client/ExampleEntryPoint.java | 67 ----------------- .../example/client/ExampleService.java | 46 ------------ .../gwt/autorest/example/public/index.html | 8 -- .../example/server/GreetingServlet.java | 60 --------------- gwt/pom.xml | 1 - pom.xml | 5 +- 9 files changed, 7 insertions(+), 273 deletions(-) delete mode 100644 example/pom.xml delete mode 100644 example/src/main/java/com/intendia/gwt/autorest/example/Example.gwt.xml delete mode 100644 example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleEntryPoint.java delete mode 100644 example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleService.java delete mode 100644 example/src/main/java/com/intendia/gwt/autorest/example/public/index.html delete mode 100644 example/src/main/java/com/intendia/gwt/autorest/example/server/GreetingServlet.java diff --git a/README.md b/README.md index a06d36f..1b943a3 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ to build requests using any transport library.* It helps organize because AutoREST uses a simplified JSR311 RESTful API definition which is easy to write and read. You can use this API in the server side using any JAX-RS implementation like [jersey](https://jersey.github.io/) and AutoREST will make it trivial to create your clients (JRE, Android or GWT) using this same JAX-RS API definition. -The lib includes a JRE (android compatible) and GWT clients, but it is strongly recommended to see the source code +The lib includes a JRE (android compatible) and GWT clients, but it is strongly recommended seeing the source code and create your own request builder. To keep the project simple only part of the JSR311 is supported: @@ -20,10 +20,10 @@ To keep the project simple only part of the JSR311 is supported: to which segment the matrix param applies, @Encoded still not supported) * *@Consumer* and *@Producer* -All included implementations requires to use [RxJava][rxjava] types (Observable, Single or Completable) as return types. +All included implementations requires using [RxJava][rxjava] types (Observable, Single or Completable) as return types. This is mandatory to share the same interface between the client and the server, because the server requires a -synchronous return value but the client requires an asynchronous one. [RxJava][rxjava] types allows to get both -strategies using the same type. Also those containers describe perfectly all available JSON responses, empty, one and +synchronous return value, but the client requires an asynchronous one. [RxJava][rxjava] types allows to get both +strategies using the same type. Also, those containers describe perfectly all available JSON responses, empty, one and many objects (see response containers) which make client implementation and response parsing much easier. ## Download @@ -54,7 +54,7 @@ public class ExampleEntryPoint implements EntryPoint { public void onModuleLoad() { Nominatim nominatim = new Nominatim_RestServiceModel(() -> osm()); nominatim.search("Málaga,España", "json").subscribe(n -> { - GWT.log("[" + (int) (n.importance * 10.) + "] " + n.display_name + " (" + n.lon + "," + n.lat + ")"); + GWT.log("[" + (n.importance * 10.) + "] " + n.display_name + " (" + n.lon + "," + n.lat + ")"); }); } diff --git a/example/pom.xml b/example/pom.xml deleted file mode 100644 index f247096..0000000 --- a/example/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - - com.intendia.gwt.autorest - autorest-parent - HEAD-SNAPSHOT - - autorest-gwt-example - gwt-app - AutoREST :: Example - - - - - com.google.gwt - gwt - ${gwt.version} - pom - import - - - - - - - com.intendia.gwt.autorest - autorest-gwt - ${project.version} - gwt-lib - - - com.intendia.gwt.autorest - autorest-processor - ${project.version} - provided - true - - - com.fasterxml.jackson.core - jackson-databind - 2.9.10.3 - - - com.google.gwt - gwt-user - - - com.google.gwt - gwt-dev - - - - - - - net.ltgt.gwt.maven - gwt-maven-plugin - true - - com.intendia.gwt.autorest.example.Example - true - - - - org.apache.maven.plugins - maven-deploy-plugin - - true - - - - - diff --git a/example/src/main/java/com/intendia/gwt/autorest/example/Example.gwt.xml b/example/src/main/java/com/intendia/gwt/autorest/example/Example.gwt.xml deleted file mode 100644 index 5092bcc..0000000 --- a/example/src/main/java/com/intendia/gwt/autorest/example/Example.gwt.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleEntryPoint.java b/example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleEntryPoint.java deleted file mode 100644 index 347b2a2..0000000 --- a/example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleEntryPoint.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.intendia.gwt.autorest.example.client; - -import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.core.client.GWT; -import com.google.gwt.event.dom.client.HasKeyUpHandlers; -import com.google.gwt.event.dom.client.KeyUpEvent; -import com.google.gwt.event.logical.shared.HasValueChangeHandlers; -import com.google.gwt.event.logical.shared.ValueChangeEvent; -import com.google.gwt.user.client.ui.HTML; -import com.google.gwt.user.client.ui.IsWidget; -import com.google.gwt.user.client.ui.Label; -import com.google.gwt.user.client.ui.RootPanel; -import com.google.gwt.user.client.ui.TextBox; -import com.google.web.bindery.event.shared.HandlerRegistration; -import com.intendia.gwt.autorest.client.RequestResourceBuilder; -import com.intendia.gwt.autorest.client.ResourceVisitor; -import com.intendia.gwt.autorest.example.client.ExampleService.Greeting; -import io.reactivex.Observable; -import io.reactivex.ObservableEmitter; -import io.reactivex.functions.Consumer; - -public class ExampleEntryPoint implements EntryPoint { - private Consumer err = e -> GWT.log("exception: " + e, e); - - public void onModuleLoad() { - TextBox name = append(new TextBox()); - HTML out = append(new HTML()); - - ResourceVisitor.Supplier getApi = () -> new RequestResourceBuilder().path(GWT.getModuleBaseURL(), "api"); - ExampleService srv = new ExampleService_RestServiceModel(() -> getApi.get().header("auth", "ok")); - - Observable.merge(valueChange(name), keyUp(name)).map(e -> name.getValue()) - .switchMap(q -> { - Greeting greeting = new Greeting(); - greeting.greeting = q; - return srv.post(greeting) - .map(o -> o.greeting) - .onErrorReturn(Throwable::toString); - }) - .forEach(out::setHTML); - name.setValue("ping", true); - - append("-- Static tests --"); - srv.pingObservable().ignoreElements().subscribe(() -> append("observable pong"), err); - srv.pingMaybe().ignoreElement().subscribe(() -> append("maybe pong"), err); - srv.pingCompletable().subscribe(() -> append("completable pong"), err); - - srv.getFoo().subscribe(n -> append("observable.foo response: " + n.greeting), err); - srv.getFoo("FOO", "BAR", null).subscribe(n -> append("observable.foo response: " + n.greeting), err); - } - - private static void append(String text) { append(new Label(text)); } - - private static T append(T w) { RootPanel.get().add(w); return w; } - - private static Observable keyUp(HasKeyUpHandlers source) { - return Observable.create(s -> register(s, source.addKeyUpHandler(s::onNext))); - } - - public static Observable> valueChange(HasValueChangeHandlers source) { - return Observable.create(s -> register(s, source.addValueChangeHandler(s::onNext))); - } - - private static void register(ObservableEmitter s, HandlerRegistration handlerRegistration) { - s.setCancellable(handlerRegistration::removeHandler); - } -} diff --git a/example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleService.java b/example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleService.java deleted file mode 100644 index f0f9726..0000000 --- a/example/src/main/java/com/intendia/gwt/autorest/example/client/ExampleService.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.intendia.gwt.autorest.example.client; - -import static jsinterop.annotations.JsPackage.GLOBAL; - -import com.intendia.gwt.autorest.client.AutoRestGwt; -import io.reactivex.Completable; -import io.reactivex.Maybe; -import io.reactivex.Observable; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; -import jsinterop.annotations.JsType; - -@AutoRestGwt -@Path("observable") -public interface ExampleService { - - @PUT @Path("pingObservable") Observable pingObservable(); - - @PUT @Path("pingMaybe") Maybe pingMaybe(); - - @PUT @Path("pingCompletable") Completable pingCompletable(); - - @POST @Path("observable") Observable post(Greeting name); - - @GET @Path("observable/foo") Observable getFoo(); - - @GET @Path("observable/foo/{foo}") Observable getFoo( - @PathParam("foo") String foo, - @QueryParam("bar") String bar, - @QueryParam("unk") String oth); - - @JsType(namespace = GLOBAL, name = "Object", isNative = true) class Greeting { - public String greeting; - } - - // incompatible - - @com.google.gwt.core.shared.GwtIncompatible Response gwtIncompatible(); - - @com.google.common.annotations.GwtIncompatible("serverOnly") Response guavaIncompatible(); -} diff --git a/example/src/main/java/com/intendia/gwt/autorest/example/public/index.html b/example/src/main/java/com/intendia/gwt/autorest/example/public/index.html deleted file mode 100644 index f21acce..0000000 --- a/example/src/main/java/com/intendia/gwt/autorest/example/public/index.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - Auto RESTful GWT Example - - - diff --git a/example/src/main/java/com/intendia/gwt/autorest/example/server/GreetingServlet.java b/example/src/main/java/com/intendia/gwt/autorest/example/server/GreetingServlet.java deleted file mode 100644 index 6643bd1..0000000 --- a/example/src/main/java/com/intendia/gwt/autorest/example/server/GreetingServlet.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.intendia.gwt.autorest.example.server; - -import static com.fasterxml.jackson.databind.node.JsonNodeFactory.instance; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -// @WebServlet(name = "greeting-service", urlPatterns = "/example/api/*") -public class GreetingServlet extends HttpServlet { - private static final Logger L = Logger.getLogger(GreetingServlet.class.getName()); - private static final String helloWorldJson = "[{\"greeting\":\"Hello World\"}]"; - - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) { - String uri = req.getRequestURI(); - L.info("Sending 'Hello World' in response of " + uri); - try { - String FOO_URI = "/example/api/observable/foo"; - if (uri.equals(FOO_URI)) { - resp.getWriter().write("[{\"greeting\":\"/foo\"}]"); - } else if (uri.startsWith(FOO_URI)) { - String x = uri.substring(FOO_URI.length()) + "?" + req.getQueryString(); - resp.getWriter().write("[{\"greeting\":\"/foo" + x + "\"}]"); - } else { - ObjectMapper mapper = new ObjectMapper(); - JsonNode helloJsonNode = mapper.readTree(helloWorldJson); - mapper.writeValue(resp.getOutputStream(), helloJsonNode); - } - } catch (Throwable e) { - L.log(Level.SEVERE, "error sending 'Hello World'", e); - } - } - - @Override - protected void doPost(HttpServletRequest req, HttpServletResponse resp) { - String uri = req.getRequestURI(); - L.info("Creating custom greeting in response of " + uri); - try { - ObjectMapper mapper = new ObjectMapper(); - ObjectNode nameObject = mapper.readValue(req.getInputStream(), ObjectNode.class); - - final ObjectNode value = new ObjectNode(instance); - value.put("greeting", "Hello " + nameObject.get("greeting").asText()); - mapper.writeValue(resp.getOutputStream(), new ArrayNode(instance).add(value)); - } catch (Throwable e) { - L.log(Level.SEVERE, "error creating custom greeting", e); - } - } - - @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) { - L.info("Void pong response..."); - } -} diff --git a/gwt/pom.xml b/gwt/pom.xml index 628314b..2a3d9f1 100644 --- a/gwt/pom.xml +++ b/gwt/pom.xml @@ -72,7 +72,6 @@ com.intendia.gwt.autorest.AutoRest true - true diff --git a/pom.xml b/pom.xml index 8fd4dc6..7a6f99d 100644 --- a/pom.xml +++ b/pom.xml @@ -53,7 +53,6 @@ core - example gwt jre processor @@ -65,8 +64,8 @@ UTF-8 UTF-8 2.8.2-rx1 - 2.1.2 - 2.1.2-beta1 + 2.2.10 + ${rxjava.version}-gwt1