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

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


    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


      resp.setOperations(operations);
    }
  }

  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

      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) {
          try {
            JSONObject cookie = Cookie.toJSONObject(header);
            String name = cookie.getString("name");
            String value = cookie.getString("value");
            String domain = cookie.optString("Domain");
            if (domain == null || url.getHost().endsWith(domain)) {
              String path = cookie.optString("Path");
              if (path == null || url.getPath().startsWith(path)) {
                cookies.put(name, value);
              }
            }
          } catch (JSONException ignored) {
          }
        }
      }

      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

           * Hand the receiver a non-fatal callback, so that
           * com.google.gwt.requestfactory.shared.Receiver will not post a
           * runtime exception.
           */
          receiver.onTransportFailure(
            new ServerFailure("Unauthenticated user", null, null, false /* non-fatal */));
          boolean responseWasUnauthorized = AuthAwareRequestTransport.this.lastResponseWasUnauthorized;
          AuthAwareRequestTransport.this.lastResponseWasUnauthorized = true;
          if (!responseWasUnauthorized) {
            // TODO: Maybe fire an event on the EventBus instead...
            Window.alert("You've been disconnected. Reload the page to authenticate back.");
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.