
package app.tests;

import org.neogroup.httpserver.HttpRequest;
import org.neogroup.httpserver.HttpResponse;
import org.neogroup.sparks.web.processors.WebProcessor;
import org.neogroup.sparks.web.routing.After;
import org.neogroup.sparks.web.routing.Before;
import org.neogroup.sparks.web.routing.Get;

import java.util.Locale;

public class TestProcessor extends WebProcessor {

    @Get("/test/")
    public HttpResponse indexAction (HttpRequest request) {
        return createResponse("TEST CONTROLLER !!");
    }

    @Get("/test/template")
    public HttpResponse templateAction (HttpRequest request) {
        ViewHttpResponse response  = createViewResponse("templates.helloworld");
        response.setParameter("name", request.getParameter("name"));
        return response;
    }

    @Get("/test/properties")
    public HttpResponse propertiesAction (HttpRequest request) {
        String property = request.getParameter("property");
        String value = (String)getProperty(property);
        return createResponse("El valor de la propiedad \"" + property + "\" es: " + value);
    }

    @Get("/test/bundles")
    public HttpResponse bundlesAction (HttpRequest request) {
        return createResponse(getString(Locale.ENGLISH, "welcome_phrase", "Luis"));
    }

    @Get("/test/vars/:name/:lastname")
    public HttpResponse varsAction (HttpRequest request) {
        return createResponse ("Name: " + request.getParameter("name") + "; LastName: " + request.getParameter("lastname") + " !!");
    }

    @Get("/dimpler/*")
    public HttpResponse dimplerAction (HttpRequest request) {
        return createResponse ("Dimpler generic !!");
    }

    @Get("test/*")
    public HttpResponse testAction (HttpRequest request) {
        return createResponse ("Test generic !!");
    }

    @Get("*")
    public HttpResponse defaultAction (HttpRequest request) {
        return createResponse ("Testing default response !!");
    }

    @Before("/dimpler/*")
    public HttpResponse beforeAction (HttpRequest request) {
        System.out.println ("before action");
        return null;
    }

    @After("/dimpler/*")
    public HttpResponse afterAction (HttpRequest request, HttpResponse response) {
        System.out.println ("after action");
        return response;
    }
}

@@ -198,21 +198,17 @@
 routing.
-After
+*
 ;%0Aimport
@@ -244,58 +244,13 @@
 ing.
-Before;%0Aimport org.neogroup.sparks.web.routing.Get
+Error
 ;%0A%0Ai
@@ -1453,32 +1453,185 @@
  %22 !!%22);%0A    %7D%0A%0A
+    @Get(%22error%22)%0A    public HttpResponse errorAction (HttpRequest request) %7B%0A        int a = 10 / 0;%0A        return createResponse (%22Error !!%22);%0A    %7D%0A%0A
     @Get(%22/dimpl
@@ -2386,11 +2386,211 @@
 e;%0A    %7D
+%0A%0A    @Error(%22*%22)%0A    public HttpResponse afterAction (HttpRequest request, Throwable throwable) %7B%0A        return createResponse(%22sipi, estamos en un error %22 + throwable.getMessage() +  %22 !!!%22);%0A    %7D
 %0A%7D%0A

Add error and not found routes