Search in sources :

Example 11 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.

the class EzySimpleDataHandler method handleRequest.

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void handleRequest(EzyConstant cmd, EzyArray data) {
    try {
        EzyRequest request = newRequest(cmd, data);
        try {
            EzyInterceptor interceptor = controllers.getInterceptor(cmd);
            interceptor.intercept(context, request);
            EzyController controller = controllers.getController(cmd);
            controller.handle(context, request);
        } finally {
            request.release();
        }
    } catch (Exception e) {
        if (context != null) {
            Throwable throwable = requestHandleException(session, cmd, data, e);
            context.handleException(Thread.currentThread(), throwable);
        } else {
            if (active) {
                logger.warn("fatal error, please add an issue to ezyfox-server github " + "with log: {}\nand stacktrace: ", this, e);
            } else {
                logger.warn("can't handle command: {} and data: {}, this session " + "maybe destroyed (session: {}), error message: {}", cmd, data, session, e.getMessage());
            }
        }
    }
}
Also used : EzyController(com.tvd12.ezyfoxserver.controller.EzyController) EzyRequest(com.tvd12.ezyfoxserver.request.EzyRequest) EzyInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyInterceptor) EzyRequestHandleException.requestHandleException(com.tvd12.ezyfoxserver.exception.EzyRequestHandleException.requestHandleException)

Example 12 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.

the class EzySocketRequestHandler method handleEvent.

@Override
public void handleEvent() {
    EzySocketRequest request = null;
    try {
        EzySession session = sessionTicketsQueue.take();
        EzyRequestQueue requestQueue = getRequestQueue(session);
        // noinspection SynchronizationOnLocalVariableOrMethodParameter
        synchronized (requestQueue) {
            request = requestQueue.take();
            if (requestQueue.size() > 0) {
                sessionTicketsQueue.add(session);
            }
        }
        processRequest(request);
    } catch (InterruptedException e) {
        logger.info("{}-request-handler thread interrupted", getRequestType());
    } catch (Throwable throwable) {
        logger.warn("problems in {}-request-handler", getRequestType(), throwable);
    } finally {
        if (request != null) {
            request.release();
        }
    }
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 13 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.

the class EzySessionTicketsRequestQueues method addRequest.

public boolean addRequest(EzySocketRequest request) {
    EzyRequestQueue queue;
    EzySessionTicketsQueue ticketsQueue;
    EzySession session = request.getSession();
    if (request.isSystemRequest()) {
        ticketsQueue = systemQueue;
        queue = session.getSystemRequestQueue();
    } else {
        ticketsQueue = extensionQueue;
        queue = session.getExtensionRequestQueue();
    }
    boolean success;
    // noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (queue) {
        boolean empty = queue.isEmpty();
        success = queue.add(request);
        if (empty && success) {
            ticketsQueue.add(session);
        }
    }
    return success;
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 14 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.

the class EzyRawBytesInterceptorTest method test2.

@Test(expectedExceptions = EzyNotAuthorizedException.class)
public void test2() throws Exception {
    EzyRawBytesInterceptor interceptor = new EzyRawBytesInterceptor();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzyStreamingRequest request = new EzySimpleStreamingRequest();
    interceptor.intercept(serverContext, request);
}
Also used : EzySimpleStreamingRequest(com.tvd12.ezyfoxserver.request.EzySimpleStreamingRequest) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyRawBytesInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyRawBytesInterceptor) EzyStreamingRequest(com.tvd12.ezyfoxserver.request.EzyStreamingRequest) Test(org.testng.annotations.Test)

Example 15 with Request

use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-server by youngmonkeys.

the class EzyRawBytesInterceptorTest method test.

@Test
public void test() throws Exception {
    EzyRawBytesInterceptor interceptor = new EzyRawBytesInterceptor();
    EzyServerContext serverContext = mock(EzyServerContext.class);
    EzySimpleStreamingRequest request = new EzySimpleStreamingRequest();
    request.setUser(new EzySimpleUser());
    interceptor.intercept(serverContext, request);
}
Also used : EzySimpleStreamingRequest(com.tvd12.ezyfoxserver.request.EzySimpleStreamingRequest) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyRawBytesInterceptor(com.tvd12.ezyfoxserver.interceptor.EzyRawBytesInterceptor) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)128 HttpServletResponse (javax.servlet.http.HttpServletResponse)48 HttpServletRequest (javax.servlet.http.HttpServletRequest)45 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)37 BeforeTest (org.testng.annotations.BeforeTest)36 BaseTest (com.tvd12.test.base.BaseTest)31 EzyArray (com.tvd12.ezyfox.entity.EzyArray)30 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)29 BlockingServlet (com.tvd12.ezyhttp.server.core.servlet.BlockingServlet)29 ToString (lombok.ToString)29 RequestURI (com.tvd12.ezyhttp.server.core.request.RequestURI)27 ServletOutputStream (javax.servlet.ServletOutputStream)25 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)24 RequestHandlerManager (com.tvd12.ezyhttp.server.core.manager.RequestHandlerManager)24 Cookie (javax.servlet.http.Cookie)24 HttpClientProxy (com.tvd12.ezyhttp.client.HttpClientProxy)22 RequestCookie (com.tvd12.ezyhttp.server.core.annotation.RequestCookie)22 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)21 HttpClient (com.tvd12.ezyhttp.client.HttpClient)21 PostRequest (com.tvd12.ezyhttp.client.request.PostRequest)21