Package play.mvc

Examples of play.mvc.SimpleResult


      if (tempResult == null)
        tempResult = delegate.call(ctx);
    }

    WrapResponse wr = new WrapResponse();
    SimpleResult result = wr.wrap(ctx, tempResult);
    if (Logger.isDebugEnabled()) Logger.debug(result.toString());
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
    return F.Promise.<SimpleResult>pure(result);
  }
View Full Code Here


   
    //executes the request
    F.Promise<SimpleResult>  tempResult = delegate.call(ctx);

    WrapResponse wr = new WrapResponse();
    SimpleResult result=wr.wrap(ctx, tempResult);
       
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
      return F.Promise.<SimpleResult>pure(result);
  }
View Full Code Here

        if (tempResult==null) tempResult = delegate.call(ctx);
    }
   
   
    WrapResponse wr = new WrapResponse();
    SimpleResult result=wr.wrap(ctx, tempResult);
       
    if (Logger.isDebugEnabled()) Logger.debug(result.toString());
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
      return F.Promise.<SimpleResult>pure(result);
  }
View Full Code Here

    if (tempResult==null){
      tempResult = delegate.call(ctx);
    }

    WrapResponse wr = new WrapResponse();
    SimpleResult result=wr.wrap(ctx, tempResult);
   
   
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
      return F.Promise.<SimpleResult>pure(result);
  }
View Full Code Here

   
    //executes the request
    F.Promise<SimpleResult> tempResult = delegate.call(ctx);

    WrapResponse wr = new WrapResponse();
    SimpleResult result=wr.wrap(ctx, tempResult);
       
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
      return F.Promise.<SimpleResult>pure(result);
  }
View Full Code Here

  }

  public SimpleResult wrap(Context ctx, F.Promise<SimpleResult> simpleResult) throws Throwable {
    if (Logger.isTraceEnabled()) Logger.trace("Method Start");
   
    SimpleResult result=simpleResult.get(10000);
    ctx.response().setHeader("Access-Control-Allow-Origin", "*");
    ctx.response().setHeader("Access-Control-Allow-Headers", "X-Requested-With");
    //this is an hack because scala can't access to the http context, and we need this information for the access log
    String username=(String) ctx.args.get("username");
    if (username!=null) ctx.response().setHeader("BB-USERNAME", username);
   
      byte[] resultContent=null;
    if (BBConfiguration.getWrapResponse()){
      if (Logger.isDebugEnabled()) Logger.debug("Wrapping the response");
      final int statusCode = result.getWrappedSimpleResult().header().status();
      if (Logger.isDebugEnabled()) Logger.debug("Executed API: "  + ctx.request() + " , return code " + statusCode);
      if (Logger.isDebugEnabled()) Logger.debug("Result type:"+result.getWrappedResult().getClass().getName() + " Response Content-Type:" +ctx.response().getHeaders().get("Content-Type"));
      if (ctx.response().getHeaders().get("Content-Type")!=null
            &&
          !ctx.response().getHeaders().get("Content-Type").contains("json")){
          if (Logger.isDebugEnabled()) Logger.debug("The response is a file, no wrap will be applied");
          return result;
        }
       
        if(result.getWrappedResult() instanceof ChunkedResult<?>){
          return result;
        }
         
      final byte[] body = JavaResultExtractor.getBody(result);
      String stringBody = new String(body, "UTF-8");
        if (Logger.isTraceEnabled()) if (Logger.isTraceEnabled()) Logger.trace ("stringBody: " +stringBody);
      if (statusCode>399){  //an error has occured
            switch (statusCode) {
              case 400:   result =onBadRequest(ctx.request(),stringBody);
                    break;
              case 401:   result =onUnauthorized(ctx.request(),stringBody);
                    break;
              case 403:   result =onForbidden(ctx.request(),stringBody);
                    break;
              case 404:   result =onResourceNotFound(ctx.request(),stringBody);
                    break;
              default:   
                if (CustomHttpCode.getFromBbCode(statusCode)!=null){
                      result = onCustomCode(statusCode,ctx.request(),stringBody);   
                }else result =onDefaultError(statusCode,ctx.request(),stringBody);
              break;
            }
        }else{ //status is not an error
          result=onOk(statusCode,ctx.request(),stringBody);
        } //if (statusCode>399)
      if (statusCode==204) result = Results.noContent();
      try {
        if (Logger.isDebugEnabled()) Logger.debug("WrapperResponse:\n  + result: \n" + result.toString() + "\n  --> Body:\n" + new String(JavaResultExtractor.getBody(result),"UTF-8"));
      }catch (Throwable e){}
    }else{ //if (BBConfiguration.getWrapResponse())
      if (Logger.isDebugEnabled()) Logger.debug("The response will not be wrapped due configuration parameter");
      try {
        if (Logger.isDebugEnabled()) Logger.debug("WrapperResponse:\n  + result: \n" + result.toString() + "\n  --> Body:\n" + new String(JavaResultExtractor.getBody(result),"UTF-8"));
      }catch (Throwable e){}
      if (Logger.isDebugEnabled()) Logger.debug("WrapperResponse:\n  + result: \n" + result.toString() + "\n  --> Body:\n" + new String(JavaResultExtractor.getBody(result),"UTF-8"));
    }
    ctx.response().setHeader("Content-Length", Long.toString(JavaResultExtractor.getBody(result).length));
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
    return result;
  }//wrap
View Full Code Here

    }
     


    WrapResponse wr = new WrapResponse();
    SimpleResult result=wr.wrap(ctx, tempResult);
   
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
      return F.Promise.<SimpleResult>pure(result)
  }
View Full Code Here

    return new Action<Cached>() {
      public Promise<SimpleResult> call(Context ctx) {
        try {
          beforeActionInvocation(ctx, actionMethod);

          SimpleResult result = null;
          Request req = ctx.request();
          String method = req.method();
          int duration = 0;
          String key = null;
          Cached cachAnno = actionMethod.getAnnotation(Cached.class);
View Full Code Here

              Object obj = global.getControllerInstance(cl);
              if (obj == null && (m.getModifiers() & Modifier.STATIC) != Modifier.STATIC) {
                throw new RuntimeException("the action method is not static while the target object is null: " + targetRouterClass.clz + "#" + m.getName());
              }
              Object[] args = methodWithArgs._2;
              SimpleResult result = (SimpleResult)m.invoke(obj, args);
              Produces produces = methodWithArgs._1.getAnnotation(Produces.class);
              return produces != null ? new WrapProducer(produces.value()[0], result) : result;
            } catch (InvocationTargetException cause) {
              System.err.println("Exception occured while trying to invoke: " + targetRouterClass.clz.getName()
                  + "#" + methodWithArgs._1.getName() + " with " + methodWithArgs._2 + " for uri:" + r.path());
View Full Code Here

TOP

Related Classes of play.mvc.SimpleResult

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.