ph.com.nightowlstudios.service.Service Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of edge Show documentation
Show all versions of edge Show documentation
A simple library for building REST API using Vertx.
package ph.com.nightowlstudios.service;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Vertx;
import io.vertx.core.json.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Method;
import java.util.IllegalFormatException;
import java.util.NoSuchElementException;
/**
* @author Joseph Harvey Angeles - yev
* @since 4/4/21
**/
public abstract class Service extends AbstractVerticle {
protected final Logger log;
public Service() {
this.log = LoggerFactory.getLogger(this.getClass());
}
@SuppressWarnings("unchecked")
@Override
public void start() throws Exception {
setup(vertx);
vertx.eventBus()
.consumer(this.getClass().getName())
.handler(message -> {
String action = message.headers().get("action");
try {
JsonObject body = message.body();
Method method = this.getClass().getMethod(action, ServiceUtils.extractRequestPayloadParameterTypes(body));
Future