Search in sources :

Example 16 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlerImplementer method makeHandleRequestMethodContent.

protected String makeHandleRequestMethodContent() {
    EzyMethod method = getHandleRequestMethod();
    EzyFunction function = new EzyFunction(method).throwsException();
    EzyBody body = function.body();
    int paramCount = prepareHandleMethodArguments(body);
    EzyInstruction instruction = new EzyInstruction("\t", "\n");
    StringBuilder answerExpression = new StringBuilder();
    if (handlerMethod.getReturnType() != void.class) {
        answerExpression.append(Object.class.getName()).append(" data = ");
    }
    answerExpression.append("this.controller.").append(handlerMethod.getName()).append("(");
    for (int i = 0; i < paramCount; ++i) {
        answerExpression.append(PARAMETER_PREFIX).append(i);
        if (i < paramCount - 1) {
            answerExpression.append(", ");
        }
    }
    answerExpression.append(")");
    instruction.append(answerExpression);
    body.append(instruction);
    if (handlerMethod.getReturnType() != void.class) {
        EzyInstruction responseInstruction = new EzyInstruction("\t", "\n").invoke("this", "responseToSession", "arg1", "data");
        body.append(responseInstruction);
    }
    return function.toString();
}
Also used : EzyBody(com.tvd12.ezyfox.asm.EzyFunction.EzyBody) EzyInstruction(com.tvd12.ezyfox.asm.EzyInstruction) EzyFunction(com.tvd12.ezyfox.asm.EzyFunction) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod)

Example 17 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyfox-server by youngmonkeys.

the class EzyExceptionHandlerImplementerTest method testFailedCase.

@Test(expectedExceptions = IllegalStateException.class)
public void testFailedCase() throws Exception {
    EzyExceptionHandlerProxy handlerProxy = new EzyExceptionHandlerProxy(new ExceptionHandlerFail());
    EzyExceptionHandlerMethod method = new EzyExceptionHandlerMethod(new EzyMethod(ExceptionHandlerFail.class.getDeclaredMethod("handle", Exception.class, int.class)));
    new EzyExceptionHandlerImplementer(handlerProxy, method) {

        @SuppressWarnings("rawtypes")
        @Override
        protected EzyUncaughtExceptionHandler doImplement() {
            throw new IllegalStateException("test");
        }
    }.implement();
}
Also used : EzyExceptionHandlerImplementer(com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer) EzyExceptionHandlerProxy(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy) EzyExceptionHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod) EzyUncaughtExceptionHandler(com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) Test(org.testng.annotations.Test)

Example 18 with EzyMethod

use of com.tvd12.ezyfox.reflect.EzyMethod in project ezyfox-server by youngmonkeys.

the class EzyRequestHandlerMethodTest method test.

@Test
public void test() throws Exception {
    EzyMethod method = new EzyMethod(AppClientHelloRequestController.class.getDeclaredMethod("handleHello5", EzyContext.class));
    EzyRequestHandlerMethod handlerMethod = new EzyRequestHandlerMethod("c_hello5", method);
    assert handlerMethod.getMethod() == method;
    System.out.println(handlerMethod);
    // noinspection ConstantConditions
    assert handlerMethod.getParameterTypes().length >= 0;
}
Also used : AppClientHelloRequestController(com.tvd12.ezyfoxserver.support.test.controller.app.AppClientHelloRequestController) EzyMethod(com.tvd12.ezyfox.reflect.EzyMethod) EzyContext(com.tvd12.ezyfoxserver.context.EzyContext) EzyRequestHandlerMethod(com.tvd12.ezyfoxserver.support.reflect.EzyRequestHandlerMethod) Test(org.testng.annotations.Test)

Aggregations

EzyMethod (com.tvd12.ezyfox.reflect.EzyMethod)18 EzyFunction (com.tvd12.ezyfox.asm.EzyFunction)6 EzyBody (com.tvd12.ezyfox.asm.EzyFunction.EzyBody)6 EzyInstruction (com.tvd12.ezyfox.asm.EzyInstruction)6 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 EzyClass (com.tvd12.ezyfox.reflect.EzyClass)4 EzyClassTree (com.tvd12.ezyfox.reflect.EzyClassTree)4 CtClass (javassist.CtClass)4 RequestHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.RequestHandlerMethod)3 EzyTryCatch (com.tvd12.ezyfox.core.annotation.EzyTryCatch)2 EzyExceptionHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerMethod)2 TryCatch (com.tvd12.ezyhttp.server.core.annotation.TryCatch)2 ExceptionHandlerMethod (com.tvd12.ezyhttp.server.core.reflect.ExceptionHandlerMethod)2 BaseTest (com.tvd12.test.base.BaseTest)2 EzyContext (com.tvd12.ezyfoxserver.context.EzyContext)1 EzyExceptionHandlerImplementer (com.tvd12.ezyfoxserver.support.asm.EzyExceptionHandlerImplementer)1 EzyUncaughtExceptionHandler (com.tvd12.ezyfoxserver.support.handler.EzyUncaughtExceptionHandler)1 EzyExceptionHandlerProxy (com.tvd12.ezyfoxserver.support.reflect.EzyExceptionHandlerProxy)1 EzyRequestHandlerMethod (com.tvd12.ezyfoxserver.support.reflect.EzyRequestHandlerMethod)1