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

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


  protected RequestCallback createRequestCallback(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(), getExceptionName(exception), null, true));
      }

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


    $wnd.gapi.client.rpcRequest(payloadObject.method,
        payloadObject.apiVersion, params).execute(callback);
  }-*/;

  private static void handleError(int code, String message, TransportReceiver receiver) {
    receiver.onTransportFailure(new ServerFailure(code + " " + message));
  }
View Full Code Here

        makeRequest(payload, receiver);
      }

      @Override
      public void onFailure(Exception e) {
        receiver.onTransportFailure(new ServerFailure(e.getMessage()));
      }
    });
  }
View Full Code Here

  private void makeRequest(String payload, TransportReceiver receiver) {
    if (JsonUtils.safeToEval(payload)) {
      nativeSend(payload, receiver);
    } else {
      receiver.onTransportFailure(new ServerFailure("Request payload is invalid."));
    }
  }
View Full Code Here

  @Override
  public void create(@SuppressWarnings("rawtypes") Receiver<
      com.google.api.gwt.shared.GoogleApiRequestTransport> receiver) {
    if (this.transport != null) {
      // receiver.onSuccess(this);
      receiver.onFailure(new ServerFailure("Transport is already created."));
    }
    this.transport =
        new GoogleApiRequestTransport(applicationName, apiKey, baseUrl);
    receiver.onSuccess(this);
  }
View Full Code Here

  }

  @Override
  public void send(String payload, TransportReceiver receiver) {
    if (this.transport == null) {
      receiver.onTransportFailure(new ServerFailure("Must call create() before making requests."));
    }
    transport.send(payload, receiver);
  }
View Full Code Here

    extends RequestFactoryServlet {
  public RequestFactoryExceptionHandlerServlet() {
    super(new ExceptionHandler() {
      @Override
      public ServerFailure createServerFailure(Throwable throwable) {
        return new ServerFailure(throwable.getMessage(),
            throwable.getClass().getName(), "my stack trace", true);
      }
    });
  }
View Full Code Here

      out.write(payload.getBytes("UTF-8"));
      out.close();

      int status = connection.getResponseCode();
      if (status != HttpURLConnection.HTTP_OK) {
        ServerFailure failure = new ServerFailure(status + " " + connection.getResponseMessage());
        receiver.onTransportFailure(failure);
        return;
      }

      List<String> cookieHeaders = connection.getHeaderFields().get("Set-Cookie");
      if (cookieHeaders != null) {
        for (String header : cookieHeaders) {
          List<HttpCookie> headerCookies;
          try {
            headerCookies = HttpCookie.parse(header);
          } catch (IllegalArgumentException e) {
            // if we can't parse it, ignore it
            continue;
          }

          for (HttpCookie cookie : headerCookies) {
            String domain = cookie.getDomain();
            if (domain == null || url.getHost().endsWith(domain)) {
              String path = cookie.getPath();
              if (path == null || url.getPath().startsWith(path)) {
                cookies.put(cookie.getName(), cookie.getValue());
              }
            }
          }
        }
      }

      String encoding = connection.getContentEncoding();
      InputStream in = connection.getInputStream();
      if ("gzip".equalsIgnoreCase(encoding)) {
        in = new GZIPInputStream(in);
      } else if ("deflate".equalsIgnoreCase(encoding)) {
        in = new InflaterInputStream(in);
      } else if (encoding != null) {
        receiver.onTransportFailure(new ServerFailure("Unknown server encoding " + encoding));
        return;
      }

      ByteArrayOutputStream bytes = new ByteArrayOutputStream();
      byte[] buffer = new byte[4096];
      int read = in.read(buffer);
      while (read != -1) {
        bytes.write(buffer, 0, read);
        read = in.read(buffer);
      }
      in.close();

      String received = new String(bytes.toByteArray(), "UTF-8");
      receiver.onTransportSuccess(received);
    } catch (IOException e) {
      ServerFailure failure = new ServerFailure(e.getMessage(), e.getClass().getName(), null, true);
      receiver.onTransportFailure(failure);
    } finally {
      if (connection != null) {
        connection.disconnect();
      }
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

    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

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.