Package com.google.web.bindery.requestfactory.shared

Examples of com.google.web.bindery.requestfactory.shared.ServerFailure


      @SuppressWarnings("unchecked")
      Receiver<Object> callback = (Receiver<Object>) state.invocations.get(0).getReceiver();

      if (!raw.isNull("error")) {
        Splittable error = raw.get("error");
        ServerFailure failure =
            new ServerFailure(error.get("message").asString(), error.get("code").asString(),
                payload, true);
        fail(receiver, failure);
        return;
      }
View Full Code Here


    public void processPayload(final Receiver<Void> receiver, String payload) {
      ResponseMessage response =
          AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, ResponseMessage.class, payload).as();
      if (response.getGeneralFailure() != null) {
        ServerFailureMessage failure = response.getGeneralFailure();
        ServerFailure fail =
            new ServerFailure(failure.getMessage(), failure.getExceptionType(), failure
                .getStackTrace(), failure.isFatal());

        fail(receiver, fail);
        return;
      }

      // Process violations and then stop
      if (response.getViolations() != null) {
        Set<ConstraintViolation<?>> errors = new HashSet<ConstraintViolation<?>>();
        for (ViolationMessage message : response.getViolations()) {
          errors.add(new MyConstraintViolation(message));
        }

        violation(receiver, errors);
        return;
      }

      // Process operations
      processReturnOperations(response);

      // Send return values
      Set<Throwable> causes = null;
      for (int i = 0, j = state.invocations.size(); i < j; i++) {
        try {
          if (response.getStatusCodes().get(i)) {
            state.invocations.get(i).onSuccess(response.getInvocationResults().get(i));
          } else {
            ServerFailureMessage failure =
                AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, ServerFailureMessage.class,
                    response.getInvocationResults().get(i)).as();
            state.invocations.get(i).onFail(
                new ServerFailure(failure.getMessage(), failure.getExceptionType(), failure
                    .getStackTrace(), failure.isFatal()));
          }
        } catch (Throwable t) {
          if (causes == null) {
            causes = new HashSet<Throwable>();
View Full Code Here

            /*
             * Hand the receiver a non-fatal callback, so that
             * com.google.web.bindery.requestfactory.shared.Receiver will not post a
             * runtime exception.
             */
            receiver.onTransportFailure(new ServerFailure("Unauthenticated user", null, null, false /* not fatal */));
            eventBus.fireEvent(new GaeAuthenticationFailureEvent(loginUrl));
            return;
          }
        }
        if (statusCode == 0) {
          /*
           * A response with no status follows the SC_UNAUTHORIZED.
           * Report it as non-fatal, so that
           * com.google.web.bindery.requestfactory.shared.Receiver will not post a
           * runtime exception
           */
          receiver.onTransportFailure(new ServerFailure("Status zero response, probably after auth failure", null, null, false /* not fatal */));
          return;
        }
        superCallback.onResponseReceived(request, response);
      }

View Full Code Here

* Default implementation for handling exceptions thrown while processing a
* request. Suppresses stack traces and the exception class name.
*/
public class DefaultExceptionHandler implements ExceptionHandler {
  public ServerFailure createServerFailure(Throwable throwable) {
    return new ServerFailure("Server Error: "
        + (throwable == null ? null : throwable.getMessage()), null, null, true);
  }
View Full Code Here

      @SuppressWarnings("unchecked")
      Receiver<Object> callback = (Receiver<Object>) invocations.get(0).getReceiver();

      if (!raw.isNull("error")) {
        Splittable error = raw.get("error");
        ServerFailure failure =
            new ServerFailure(error.get("message").asString(), error.get("code").asString(),
                payload, true);
        fail(receiver, failure);
        return;
      }
View Full Code Here

    public void processPayload(final Receiver<Void> receiver, String payload) {
      ResponseMessage response =
          AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, ResponseMessage.class, payload).as();
      if (response.getGeneralFailure() != null) {
        ServerFailureMessage failure = response.getGeneralFailure();
        ServerFailure fail =
            new ServerFailure(failure.getMessage(), failure.getExceptionType(), failure
                .getStackTrace(), failure.isFatal());

        fail(receiver, fail);
        return;
      }

      // Process violations and then stop
      if (response.getViolations() != null) {
        Set<Violation> errors = new HashSet<Violation>();
        for (ViolationMessage message : response.getViolations()) {
          errors.add(new MyViolation(message));
        }

        violation(receiver, errors);
        return;
      }

      // Process operations
      processReturnOperations(response);

      // Send return values
      Set<Throwable> causes = null;
      for (int i = 0, j = invocations.size(); i < j; i++) {
        try {
          if (response.getStatusCodes().get(i)) {
            invocations.get(i).onSuccess(response.getInvocationResults().get(i));
          } else {
            ServerFailureMessage failure =
                AutoBeanCodex.decode(MessageFactoryHolder.FACTORY, ServerFailureMessage.class,
                    response.getInvocationResults().get(i)).as();
            invocations.get(i).onFail(
                new ServerFailure(failure.getMessage(), failure.getExceptionType(), failure
                    .getStackTrace(), failure.isFatal()));
          }
        } catch (Throwable t) {
          if (causes == null) {
            causes = new HashSet<Throwable>();
View Full Code Here

      final TransportReceiver receiver) {
    return new RequestCallback() {

      public void onError(Request request, Throwable exception) {
        wireLogger.log(Level.SEVERE, SERVER_ERROR, exception);
        receiver.onTransportFailure(new ServerFailure(exception.getMessage()));
      }

      public void onResponseReceived(Request request, Response response) {
        wireLogger.finest("Response received");
        if (Response.SC_OK == response.getStatusCode()) {
          String text = response.getText();
          receiver.onTransportSuccess(text);
        } else {
          String message = SERVER_ERROR + " " + response.getStatusCode() + " "
              + response.getText();
          wireLogger.severe(message);
          receiver.onTransportFailure(new ServerFailure(message));
        }
      }
    };
  }
View Full Code Here

    }
  }

  private AutoBean<ServerFailureMessage> createFailureMessage(
      ReportableException e) {
    ServerFailure failure = exceptionHandler.createServerFailure(e.getCause() == null
        ? e : e.getCause());
    AutoBean<ServerFailureMessage> bean = FACTORY.failure();
    ServerFailureMessage msg = bean.as();
    msg.setExceptionType(failure.getExceptionType());
    msg.setMessage(failure.getMessage());
    msg.setStackTrace(failure.getStackTraceString());
    msg.setFatal(failure.isFatal());
    return bean;
  }
View Full Code Here

            /*
             * Hand the receiver a non-fatal callback, so that
             * com.google.web.bindery.requestfactory.shared.Receiver will not post a
             * runtime exception.
             */
            receiver.onTransportFailure(new ServerFailure(
                "Unauthenticated user", null, null, false /* not fatal */));
            eventBus.fireEvent(new GaeAuthenticationFailureEvent(loginUrl));
            return;
          }
        }
View Full Code Here

      @SuppressWarnings("unchecked")
      Receiver<Object> callback = (Receiver<Object>) state.invocations.get(0).getReceiver();

      if (!raw.isNull("error")) {
        Splittable error = raw.get("error");
        ServerFailure failure =
            new ServerFailure(error.get("message").asString(), error.get("code").asString(),
                payload, true);
        fail(receiver, failure);
        return;
      }
View Full Code Here

TOP

Related Classes of com.google.web.bindery.requestfactory.shared.ServerFailure

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.