All Projects → yale8848 → Summer

yale8848 / Summer

Licence: mit
Vertx router with JAX-RS

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Summer

Falco
A functional-first toolkit for building brilliant ASP.NET Core applications using F#.
Stars: ✭ 214 (+296.3%)
Mutual labels:  asynchronous, router
Jax Rs Performance Comparison
⚡️ Performance Comparison of Jax-RS implementations and embedded containers
Stars: ✭ 181 (+235.19%)
Mutual labels:  jax-rs, vertx
Vertx Blueprint Todo Backend
Vert.x Blueprint Project - A reactive todo-backend implementation using Vert.x and various persistence
Stars: ✭ 169 (+212.96%)
Mutual labels:  asynchronous, vertx
spring-webflux-research
spring webflux research
Stars: ✭ 42 (-22.22%)
Mutual labels:  vertx, reactor
Jetlinks
JetLinks Core
Stars: ✭ 380 (+603.7%)
Mutual labels:  reactor, vertx
Vertx Blueprint Microservice
Vert.x Blueprint Project - Micro-Shop microservice application
Stars: ✭ 663 (+1127.78%)
Mutual labels:  asynchronous, vertx
Pac4j
Security engine for Java (authentication, authorization, multi frameworks): OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 2,097 (+3783.33%)
Mutual labels:  jax-rs, vertx
rest.vertx
A JAX-RS like annotation processor for vert.x verticals and more
Stars: ✭ 138 (+155.56%)
Mutual labels:  jax-rs, vertx
Atmosphere
Realtime Client Server Framework for the JVM, supporting WebSockets with Cross-Browser Fallbacks
Stars: ✭ 3,552 (+6477.78%)
Mutual labels:  asynchronous, vertx
Elle
The Elle coroutine-based asynchronous C++ development framework.
Stars: ✭ 459 (+750%)
Mutual labels:  asynchronous, reactor
Recoil
Asynchronous coroutines for PHP 7.
Stars: ✭ 765 (+1316.67%)
Mutual labels:  asynchronous, reactor
Vertx Lang Clojure
Vert.x Clojure support
Stars: ✭ 50 (-7.41%)
Mutual labels:  vertx
Halive
A fast http and https prober, to check which URLs are alive
Stars: ✭ 47 (-12.96%)
Mutual labels:  asynchronous
Ios Nd Gcd
Resources for Udacity's Grand Central Dispatch course.
Stars: ✭ 46 (-14.81%)
Mutual labels:  asynchronous
Restify Router
A router interface for restify that lets you aggregate route definitions and apply to a restify server
Stars: ✭ 45 (-16.67%)
Mutual labels:  router
Hyper Router
Simple routing middleware for rust HTTP library hyper.
Stars: ✭ 51 (-5.56%)
Mutual labels:  router
React Async Fetcher
React component for asynchronous loading/fetch online data
Stars: ✭ 50 (-7.41%)
Mutual labels:  asynchronous
Tackle
💯 percent reliable microservice communication
Stars: ✭ 44 (-18.52%)
Mutual labels:  asynchronous
Async Deeprl
Playing Atari games with TensorFlow implementation of Asynchronous Deep Q-Learning
Stars: ✭ 44 (-18.52%)
Mutual labels:  asynchronous
React Redux Antdesign Webpack Starter
react + redux + ant design + react-router 4 + webpack 4 starter
Stars: ✭ 44 (-18.52%)
Mutual labels:  router

Summer

Vertx router with JAX-RS

Add to pom

<dependency>
 <groupId>ren.yale.java</groupId>
 <artifactId>summer</artifactId>
 <version>1.1.9</version>
</dependency>

wrapper io.vertx.vertx-core:3.5.4

How to use

Use SummerRouter:

  public class WebServer extends AbstractVerticle {

   @Override
   public void start() throws Exception {
        Router router = Router.router(vertx);
        SummerRouter summerRouter =  new SummerRouter(router,vertx);
        summerRouter.registerResource(Hello.class);
        vertx.createHttpServer()
             .requestHandler(router::accept)
                 .listen(port,host,httpServerAsyncResult -> {
                      if (httpServerAsyncResult.succeeded()){
                            System.out.println("listen at: http://"+host+":"+port);
                      }else{
                            System.out.println(httpServerAsyncResult.cause().getCause());
                      }
                    });
        }
    }

Use simple SummerServer(use io.vertx.core.AbstractVerticle):

  SummerServer summerServer =SummerServer.create(8080);

  summerServer.getSummerRouter().registerResource(Hello.class);

  summerServer.start();

or further:

   VertxOptions options = new VertxOptions();
   options.setBlockedThreadCheckInterval(20000);
   options.setMaxEventLoopExecuteTime(20000);
   
   SummerServer summerServer =SummerServer.create("localhost",8080,options);

   summerServer.getVertx().
                deployVerticle(MyVerticle.class.getName());
   
   summerServer.getSummerRouter().registerResource(Hello.class);
    
   DeploymentOptions deploymentOptions = new DeploymentOptions();
   deploymentOptions.setWorker(true);
   summerServer.start(deploymentOptions);


Hello.java with JAX-RS

@Path("/hello")
@Before(LogInterceptor.class)
public class Hello {

    @GET
    @Path("/html/{name}")
    @Produces({MediaType.TEXT_HTML})
    public String h1(@Context RoutingContext routingContext,
                     @PathParam("name") String name,
                     @DefaultValue("18") @QueryParam("age") int age, String text){
        return String.format("<html><body>name:%s,age:%d</body></html>",name,age);
    }

    @POST
    @Path("/name/bob")
    @Produces({MediaType.APPLICATION_JSON})
    public User h2(@QueryParam("age") int age,@FormParam("name") String name) {
        User u = new User();
        u.setName(name);
        u.setAge(age);
        return u;
    }

    @GET
    @Path("/async")
    public void h3(@Context HttpServerResponse response, @Context Vertx vertx){

        vertx.eventBus().send("user",EventMessage.message("bob").setKey("name"),message->{
            EventMessage eventMessage = (EventMessage) message.result().body();
           if (eventMessage.isSuccess()){
               String ret= String.format("name:%s,age:%d",eventMessage.getMessage(),18);
               response.end(ret);
          }else{
               response.end("error");
           }
        });

    }

    @GET
    @Path("/xml")
    @Produces({MediaType.TEXT_XML})
    public User xml(){
        return new User();
    }

    @GET
    @Path("/aop")
    @Produces({MediaType.APPLICATION_JSON})
    @After(ChangeUserInterceptor.class)
    public User getInter(){
        User u = new User();
        u.setName("bob");
        u.setAge(18);
        return u;
    }
   
    @HEAD
    @Path("/head")
    public void head(@Context RoutingContext routingContext){
        routingContext.response().setStatusCode(200).end();
    }
    
    @PUT
    @Path("/put/bob/{age}")
    @Produces({MediaType.APPLICATION_JSON})
    public User put(@Context RoutingContext routingContext,@PathParam("age") int age){

        User u = new User();
        u.setName("bob");
        u.setAge(age);
        return u;
    }

    @DELETE
    @Path("/delete/{name}")
    public String delete(@Context RoutingContext routingContext, @PathParam("name") String name){
        return "delete "+name+" success";
    }
}

Add resource

Like Hello.java, you can create your own resource and then call summerServer.getSummerRouter().registerResource(Hello.class);

AOP

  • Create a intercepter implements Interceptor. @After interceptor only work in sync mode
public class LogInterceptor implements Interceptor {
    @Override
    public boolean handle(RoutingContext routingContext, Object obj) {
        System.out.println(routingContext.request().absoluteURI());
        return false;
    }
}

public class ChangeUserInterceptor implements Interceptor {
    @Override
    public boolean handle(RoutingContext routingContext,Object obj) {
        User user = (User) obj;
        user.setName("Alice");
        routingContext.response()
                .end(JsonObject.mapFrom(user).encodePrettily());
        return true;
    }
}

if handle return true will interrupt the chain, the method interceptor work before class interceptor

@Path("/hello")
@Before(LogInterceptor.class)
public class Hello {}

@After(ChangeUserInterceptor.class)
public User getInter(){}

Inject object

    @GET
    @Path("/test")
    public void test(@Context RoutingContext routingContext,
                     @Context HttpServerRequest request,
                     @Context HttpServerResponse response,
                     @Context Session session,
                     @Context Vertx vertx
                       ){

    }

Return json

By default each method will return Object will return json;

    @GET
    @Path("/h2")
    public Test h2(){
        return new Test();
    }

this will return Test json object

SQL builder

SummerSQL same as mybatis3 sqlbuilder

// With conditionals (note the final parameters, required for the anonymous inner class to access them)
public String selectPersonLike(final String id, final String firstName, final String lastName) {
  return new SummerSQL() {{
    SELECT("P.ID, P.USERNAME, P.PASSWORD, P.FIRST_NAME, P.LAST_NAME");
    FROM("PERSON P");
    if (id != null) {
      WHERE("P.ID like #{id}");
    }
    if (firstName != null) {
      WHERE("P.FIRST_NAME like #{firstName}");
    }
    if (lastName != null) {
      WHERE("P.LAST_NAME like #{lastName}");
    }
    ORDER_BY("P.LAST_NAME");
  }}.toString();
}


SQL ResultMapper

   sqlConnection.query(new SummerSQL().SELECT("*")
                                .FROM("db_test.tb_test").toString(), resultSetAsyncResult -> {
                            if (resultSetAsyncResult.succeeded()){

                               List<DBTest> tests =  ResultSetMapper.create().camelName()
                                        .mapperList(resultSetAsyncResult.result(), DBTest.class);
                            }
                            sqlConnection.close();
                 });


License

MIT License

Copyright (c) 2018 Yale

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].