Search in sources :

Example 1 with DoGet

use of com.tvd12.ezyhttp.server.core.annotation.DoGet in project ezyhttp by youngmonkeys.

the class RequestHandlerMethod method fetchHttpMethod.

protected HttpMethod fetchHttpMethod() {
    DoGet doGet = method.getAnnotation(DoGet.class);
    if (doGet != null) {
        return HttpMethod.GET;
    }
    DoPost doPost = method.getAnnotation(DoPost.class);
    if (doPost != null) {
        return HttpMethod.POST;
    }
    DoPut doPut = method.getAnnotation(DoPut.class);
    if (doPut != null) {
        return HttpMethod.PUT;
    }
    return HttpMethod.DELETE;
}
Also used : DoPost(com.tvd12.ezyhttp.server.core.annotation.DoPost) DoPut(com.tvd12.ezyhttp.server.core.annotation.DoPut) DoGet(com.tvd12.ezyhttp.server.core.annotation.DoGet)

Example 2 with DoGet

use of com.tvd12.ezyhttp.server.core.annotation.DoGet in project ezyhttp by youngmonkeys.

the class RequestHandlerImplementerTest method implementOneFailed.

@Test
public void implementOneFailed() throws Exception {
    // given
    ControllerProxy controller = new ControllerProxy(new Controller());
    RequestHandlerMethod handlerMethod = new RequestHandlerMethod("/", new EzyMethod(Controller.class.getDeclaredMethod("doGet")));
    RequestHandlerImplementer sut = new RequestHandlerImplementer(controller, handlerMethod);
    // when
    Throwable e = Asserts.assertThrows(sut::implement);
    // then
    Asserts.assertEquals(0, handlerMethod.getParameterTypes().length);
    Asserts.assertThat(e).isEqualsType(IllegalStateException.class);
}
Also used : RequestHandlerMethod(com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod) RequestHandlerImplementer(com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer) ControllerProxy(com.tvd12.ezyhttp.server.core.reflect.ControllerProxy) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) Test(org.testng.annotations.Test)

Example 3 with DoGet

use of com.tvd12.ezyhttp.server.core.annotation.DoGet in project ezyhttp by youngmonkeys.

the class MetricsController method threadsGet.

@EzyFeature(DEFAULT_FEATURE_NAME)
@DoGet("/management/thread-count")
public ThreadCountPoint threadsGet() {
    EzyThreadsMonitor threadsMonitor = SystemMonitor.getInstance().getThreadsMonitor();
    int threadCount = threadsMonitor.getThreadCount();
    int daemonThreadCount = threadsMonitor.getDaemonThreadCount();
    return ThreadCountPoint.builder().threadCount(threadCount).daemonThreadCount(daemonThreadCount).build();
}
Also used : EzyThreadsMonitor(com.tvd12.ezyfox.monitor.EzyThreadsMonitor) ThreadCountPoint(com.tvd12.ezyhttp.server.management.data.ThreadCountPoint) MemoryPoint(com.tvd12.ezyhttp.server.management.data.MemoryPoint) CpuPoint(com.tvd12.ezyhttp.server.management.data.CpuPoint) EzyFeature(com.tvd12.ezyfox.annotation.EzyFeature) DoGet(com.tvd12.ezyhttp.server.core.annotation.DoGet)

Example 4 with DoGet

use of com.tvd12.ezyhttp.server.core.annotation.DoGet in project ezyfox-examples by tvd12.

the class BookController method getBook.

@DoGet("/books/{bookId}")
public BookResponse getBook(@PathVariable Long bookId) {
    Book book = bookRepository.findById(bookId);
    if (book == null) {
        throw new HttpNotFoundException("not found book with id: " + bookId);
    }
    Author author = authorRepository.findById(book.getAuthorId());
    Category category = categoryRepository.findById(book.getCategoryId());
    return entityToResponseConverter.toBookResponse(book, author, category);
}
Also used : HttpNotFoundException(com.tvd12.ezyhttp.core.exception.HttpNotFoundException) Category(com.tvd12.ezydata.example.mongo.entity.Category) Book(com.tvd12.ezydata.example.mongo.entity.Book) Author(com.tvd12.ezydata.example.mongo.entity.Author)

Example 5 with DoGet

use of com.tvd12.ezyhttp.server.core.annotation.DoGet in project ezyfox-examples by tvd12.

the class BookController method getBook.

@DoGet("/books/{bookId}")
public BookResponse getBook(@PathVariable Long bookId) {
    Book book = bookMap.get(bookId);
    if (book == null) {
        throw new HttpNotFoundException("not found book with id: " + bookId);
    }
    Author author = authorMap.get(book.getAuthorId());
    Category category = categoryMap.get(book.getCategoryId());
    return entityToResponseConverter.toBookResponse(book, author, category);
}
Also used : HttpNotFoundException(com.tvd12.ezyhttp.core.exception.HttpNotFoundException) Category(com.tvd12.ezydata.example.redis.entity.Category) Book(com.tvd12.ezydata.example.redis.entity.Book) Author(com.tvd12.ezydata.example.redis.entity.Author)

Aggregations

DoGet (com.tvd12.ezyhttp.server.core.annotation.DoGet)6 DoPost (com.tvd12.ezyhttp.server.core.annotation.DoPost)3 DoPut (com.tvd12.ezyhttp.server.core.annotation.DoPut)3 EzyFeature (com.tvd12.ezyfox.annotation.EzyFeature)2 HttpNotFoundException (com.tvd12.ezyhttp.core.exception.HttpNotFoundException)2 DoDelete (com.tvd12.ezyhttp.server.core.annotation.DoDelete)2 Test (org.testng.annotations.Test)2 Author (com.tvd12.ezydata.example.mongo.entity.Author)1 Book (com.tvd12.ezydata.example.mongo.entity.Book)1 Category (com.tvd12.ezydata.example.mongo.entity.Category)1 Author (com.tvd12.ezydata.example.redis.entity.Author)1 Book (com.tvd12.ezydata.example.redis.entity.Book)1 Category (com.tvd12.ezydata.example.redis.entity.Category)1 EzyCpuMonitor (com.tvd12.ezyfox.monitor.EzyCpuMonitor)1 EzyGcMonitor (com.tvd12.ezyfox.monitor.EzyGcMonitor)1 EzyThreadsMonitor (com.tvd12.ezyfox.monitor.EzyThreadsMonitor)1 EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)1 HealthCheckServlet (com.tvd12.ezyfoxserver.nio.builder.impl.EzyWebSocketServerCreator.HealthCheckServlet)1 RequestHandlerImplementer (com.tvd12.ezyhttp.server.core.asm.RequestHandlerImplementer)1 ControllerProxy (com.tvd12.ezyhttp.server.core.reflect.ControllerProxy)1