Package javango.http

Examples of javango.http.SimpleHttpResponse


    String queryString = request.getParameter("term");

    String searchProperty = getSearchProperty(request.getUser(), pc);
    if (searchProperty == null) {
      return new SimpleHttpResponse("Unsupported class " + model + "|").setMimeType("text/plain");
    }
    Manager<Object> manager = managers.forClass(pc.getMappedClass());

    QuerySet<Object> qs = manager.filter(searchProperty + "__ilike", queryString + "%" )
        .limit(0,500);

    StringBuilder b = new StringBuilder("[");
    char comma = ' ';
    for (Object o : qs) {
      b.append(String.format("%s{ \"id\": \"%s\", \"label\": \"%s\", \"value\": \"%s\"}", comma, manager.getPk(o), o.toString(), o.toString()));
      comma = ',';
    }
    b.append("]");
    return new SimpleHttpResponse(b.toString()).setMimeType("application/json");
  }
View Full Code Here


  public HttpResponse processRequest(HttpRequest request) throws HttpException {

    String path = request.getPath();
    if (path.length() > 0 && !path.endsWith("/")) {
      if ("POST".equals(request.getMethod())) {
        return new SimpleHttpResponse("Cannot append trailing slash to POSTed you should update the form.");
      }
      path = request.getContext() + "/" + path + "/";
      return new HttpResponseRedirect(path);
    }
   
View Full Code Here

          // TODO Move somewhere else
          for (Annotation annotation : mop.getMethod().getAnnotations()) {
            // TODO Should this return the response,  or let it fall through to the middleware?
            if (annotation instanceof LoginRequired) {
              if (request.getUser() == null || request.getUser() instanceof AnonymousUser) {
                response = new SimpleHttpResponse("Login Required");
              }
            } else if (annotation instanceof RoleRequired) {
              RoleRequired rr = (RoleRequired)annotation;
              if (request.getUser() == null || request.getUser() instanceof AnonymousUser || !request.getUser().hasRole(rr.role())) {             
                response = new SimpleHttpResponse("Not Authorized");
              }
            }
          }
         
          if (response == null ) response = invoke(mop, injector);
View Full Code Here

import javango.http.SimpleHttpResponse;

public class BaseUrls implements Urls {
 
  public SimpleHttpResponse index(HttpRequest request) {
    return new SimpleHttpResponse("Javango is running, please configure your Urls.");
  }
View Full Code Here

  public void testSimpleHeaders() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
   
    HttpResponse resp = new SimpleHttpResponse("Hello World");
    resp.render(request, response);
   
    assertEquals(new Integer(200), new Integer(response.getStatus()));
    assertEquals("text/html", response.getContentType())
  }
View Full Code Here

 
  public void testAddCookie() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
   
    SimpleHttpResponse resp = new SimpleHttpResponse("Hello World");
    resp.setCookie(new Cookie("test", "value"));
    resp.render(request, response);
   
    assertEquals(new Integer(200), new Integer(response.getStatus()));
    assertEquals("text/html", response.getContentType());
    Cookie[] cookies = response.getCookies();
    assertTrue(cookies.length == 1);
View Full Code Here

 
  public void testOverrideHeaders() throws Exception {
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
   
    SimpleHttpResponse resp = new SimpleHttpResponse("Hello World");
    resp.setStatusCode(201);
    resp.setMimeType("somethingelse");
    resp.render(request, response);
   
    assertEquals(new Integer(201), new Integer(response.getStatus()));
    assertEquals("somethingelse", response.getContentType())
 
View Full Code Here

      Object object = null;

      if (object_id != null) {
        object = manager.get(object_id);
        if (object == null) {
          return new SimpleHttpResponse("Object not found");
        }
      }

      String[] property_list = ma.getFields();     
View Full Code Here

 
  public HttpResponse detail(HttpRequest request, Long poll_id) throws HttpException {
    try {
      Poll p = modelFactory.dao(Poll.class).get(poll_id);
      if (p == null) {
        return new SimpleHttpResponse("Unable to find poll with id = " + poll_id);
      }
     
      VoteForm form = (VoteForm)formFactory.newForm(VoteForm.class);
      form.updateChoices(p);
     
View Full Code Here

          log.fatal(e,e);
        }
      }
      if (!injector.getInstance(Settings.class).isDebug()) {
        // TODO ability to specify 404 handler
        SimpleHttpResponse response = new SimpleHttpResponse("Page not found");
        response.setStatusCode(404);
        try {
          response.render(servletRequest, servletResponse);
        } catch (HttpException e2) {
          log.error(e2,e2);
          throw new ServletException(e);
        }
      } else {
        throw new ServletException(e);
      }
    } catch (FileUploadException e) {
      log.error(e,e);
      try {
        request.close();
      } catch (HttpException e1) {
        log.error(e1,e1);
      }
      // TODO Pretty print the exception and stack trace,  request information, etc
      if (!injector.getInstance(Settings.class).isDebug()) {
        HttpResponse response = new SimpleHttpResponse("Unrecoverable error processing uploaded files, please contact support");
        try {
          response.render(servletRequest, servletResponse);
        } catch (HttpException e2) {
          log.error(e2,e2);
          throw new ServletException(e);
        }
      }
    } catch (HttpException e) {
      log.error(String.format("HttpException while processing for user '%s' %s:%s", request.getUser(), context, path));
      log.error(e,e);
      try {
        request.close();
      } catch (HttpException e1) {
        log.error(e1,e1);
      }
      // TODO Pretty print the exception and stack trace,  request information, etc
      // TODO can this exception be handled by middleware?  middleware is not really avaliable here as it is handled in the requestProcessor...
      if (!injector.getInstance(Settings.class).isDebug()) {
        HttpResponse response = new SimpleHttpResponse("Unrecoverable error, please contact support");
        try {
          response.render(servletRequest, servletResponse);
        } catch (HttpException e2) {
          log.error(e2,e2);
          throw new ServletException(e);
        }
      } else {
View Full Code Here

TOP

Related Classes of javango.http.SimpleHttpResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.