Examples of SimpleHttpResponse


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

Examples of javango.http.SimpleHttpResponse

  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

Examples of javango.http.SimpleHttpResponse

          // 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

Examples of javango.http.SimpleHttpResponse

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

Examples of javango.http.SimpleHttpResponse

  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

Examples of javango.http.SimpleHttpResponse

 
  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

Examples of javango.http.SimpleHttpResponse

 
  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

Examples of javango.http.SimpleHttpResponse

      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

Examples of javango.http.SimpleHttpResponse

 
  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

Examples of net.sf.sahi.response.SimpleHttpResponse

 
  public HttpResponse read(final HttpRequest request) {
    final String name = request.getParameter("name");
    String cookieValue = readCookie(name, request);
    cookieValue = cookieValue == null ? "null" : Utils.makeString(cookieValue);
    return new SimpleHttpResponse(cookieValue);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.