Example #1
0
 public WebApp(
     String id,
     Set<String> owners,
     Set<String> hostnames,
     Set<String> uriContexts,
     AppMode mode,
     Router router,
     PojoDispatcher dispatcher,
     Classes classes,
     Config config) {
   this.id = id;
   this.router = U.or(router, new HttpRouter());
   this.dispatcher = U.or(dispatcher, new WebPojoDispatcher(classes));
   this.owners = U.safe(owners);
   this.hostnames = U.safe(hostnames);
   this.uriContexts = U.safe(uriContexts);
   this.mode = U.or(mode, AppMode.DEVELOPMENT);
   this.classes = U.or(classes, new Classes());
   this.config = U.or(config, new Config());
 }
Example #2
0
  private boolean processNext(RapidoidConnection conn) {
    int pos = conn.input().position();
    int limit = conn.input().limit();

    try {
      protocol.process(conn);
      return true;
    } catch (IncompleteReadException e) {
      // input not ready, so recover
      conn.input().position(pos);
      conn.input().limit(limit);
      // FIXME recover output position
    } catch (ProtocolException e) {
      conn.write(U.or(e.getMessage(), "Protocol error!"));
      conn.error();
      conn.close(true);
    } catch (Throwable e) {
      U.error("Failed to process message!", e);
      conn.close(true);
    }

    return false;
  }
Example #3
0
  private void update_(long id, Object record, boolean reflectRelChanges, boolean checkSecurity) {

    failIfReadonlyTx();
    validateId(id);

    Rec old = data.data.get(id);
    Object entity = obj(old);

    if (checkSecurity) {
      secureUpdate(entity);
    }

    // Optimistic concurrency control through the "version" property
    Long oldVersion = U.or(Beany.getPropValueOfType(entity, VERSION, Long.class, null), 0L);
    Long recordVersion = U.or(Beany.getPropValueOfType(record, VERSION, Long.class, null), 0L);

    occErrorIf(
        !U.eq(oldVersion, recordVersion),
        "Concurrent modification occured while updating the object with ID=%s!",
        id);

    Beany.setId(record, id);

    if (!sudo && checkSecurity) {
      boolean canUpdate = false;
      for (Prop prop : Beany.propertiesOf(record)) {
        if (!Secure.getPropertyPermissions(username(), entity.getClass(), entity, prop.getName())
            .change) {
          prop.set(record, prop.get(entity));
        } else {
          canUpdate = true;
        }
      }
      U.secure(
          canUpdate,
          "Not enough privileges to update any column of %s!",
          entity.getClass().getSimpleName());
    }

    // Optimistic concurrency control through the "version" property
    if (Beany.hasProperty(record, VERSION)) {
      Beany.setPropValue(record, VERSION, oldVersion + 1);
    }

    if (checkSecurity) {
      secureUpdate(record);
    }

    if (Beany.hasProperty(record, LAST_UPDATED_BY)) {
      Beany.setPropValue(record, LAST_UPDATED_BY, username());
    }

    if (Beany.hasProperty(record, LAST_UPDATED_ON)) {
      Beany.setPropValue(record, LAST_UPDATED_ON, new Date());
    }

    boolean updated = data.data.replace(id, old, rec(record));

    occErrorIf(
        !updated, "Concurrent modification occured while updating the object with ID=%s!", id);

    if (data.insideTx.get()) {
      data.txChanges.putIfAbsent(id, old);
    }

    if (old == null) {
      throw new IllegalStateException("Cannot update non-existing record with ID=" + id);
    }

    if (reflectRelChanges) {
      updateChangesFromRels(record);
    }

    data.lastChangedOn.set(System.currentTimeMillis());

    Log.audit("Updated DB record", "id", id);
  }