Exemplo n.º 1
0
 @Override
 public CompletableFuture<Connection> connect(Address address) {
   if (this.address.equals(address)) {
     return local.connect(address);
   }
   return remote.connect(address);
 }
Exemplo n.º 2
0
  @GET
  @Path("/getclient")
  @Produces("application/json; charset=utf-8")
  // http://localhost:8080/ProjetRestFull/eources/getjson
  public JResponse getEtudiant(@QueryParam("numcli") int numCli) throws ParseException {
    try {
      EntityManager em = HibUtil.getEntityManager();
      em.getTransaction().begin();
      Client c = em.find(Client.class, numCli);
      Hibernate.initialize(c);

      // On met le séjour à null, sinon il y a des références circulaires.
      em.detach(c);
      c.setSejours(null);

      GenericEntity<Client> entity = new GenericEntity<Client>(c) {};
      JResponse r = JResponse.ok(entity).build();
      em.getTransaction().commit();
      HibUtil.closeEntityManager();
      return r;
    } catch (Exception e) {
      // em.getTransaction().commit();
      HibUtil.closeEntityManager();
      return null;
    }
  }
Exemplo n.º 3
0
  @RequestMapping(value = "/user", method = RequestMethod.PUT)
  @Transactional
  public ResponseEntity<Client> doIt(@RequestBody Client client, Authentication authentication) {

    List<String> errors = DomainValidator.checkForErrors(client);
    if (!errors.isEmpty()) {
      return new ResponseEntity<Client>(new Client(client, errors), HttpStatus.BAD_REQUEST);
    }
    HttpStatus status = null;

    List<GrantedAuthority> authorities = new ArrayList<>();
    authorities.add(new SimpleGrantedAuthority("USER"));

    if (ApplicationSecurity.isRoot(authentication)) {
      if (ApplicationSecurity.isRoot(client.getUsername())) {
        return new ResponseEntity<Client>(
            new Client(client, cannotChangeRootPassword), HttpStatus.BAD_REQUEST);
      }
      status = upsert(client, authorities);

    } else if (StringUtils.equals(client.getUsername(), authentication.getName())) {
      if (!userDetailsManager.userExists(client.getUsername())) {
        return new ResponseEntity<Client>(new Client(client, mustBeRoot), HttpStatus.BAD_REQUEST);
      }
      User user = new User(client.getUsername(), client.getPassword(), authorities);
      userDetailsManager.updateUser(user);
      status = HttpStatus.OK;

    } else {
      return new ResponseEntity<Client>(HttpStatus.FORBIDDEN);
    }

    return new ResponseEntity<Client>(new Client(client), status);
  }
Exemplo n.º 4
0
  public static void main(String[] args) {

    stat.addDescription("ejb-ejb30-hello-dcode");
    Client client = new Client(args);
    client.doTest();
    stat.printSummary("ejb-ejb30-hello-dcodeID");
  }
Exemplo n.º 5
0
 public static void eraseIndex(User user, String indexName)
     throws SearchLibException, NamingException, IOException {
   if (user != null && !user.isAdmin()) throw new SearchLibException("Operation not permitted");
   File indexDir = getIndexDirectory(indexName);
   Client client = null;
   synchronized (ClientCatalog.class) {
     clientsLock.r.lock();
     try {
       client = CLIENTS.get(indexDir);
     } finally {
       clientsLock.r.unlock();
     }
     if (client != null) {
       client.close();
       client.delete();
     } else FileUtils.deleteDirectory(indexDir);
     if (client != null) {
       clientsLock.w.lock();
       try {
         CLIENTS.remove(client.getDirectory());
       } finally {
         clientsLock.w.unlock();
       }
       PushEvent.eventClientSwitch.publish(client);
     }
   }
 }
 private double getRemainingRequireMents(List<Vehicle> vehicles) {
   List<Client> clients1 = getRemainingClient(vehicles);
   double result = 0;
   for (Client client : clients1) {
     result += client.getRequirement();
   }
   return result;
 }
 private Client getClientByIp(String ip) {
   for (Client client : clients) {
     if (client.getIp().equals(ip)) {
       return client;
     }
   }
   Client newClient = new Client(ip);
   clients.add(newClient);
   return newClient;
 }
Exemplo n.º 8
0
  public static void main(String arg[]) {
    Customer customer = new Customer();

    Vector allAccounts = new Vector();

    allAccounts.addElement(new Account("ckc", 120, customer));
    customer.setAllAccounts(allAccounts);
    Client cle = new ClientAdapter(customer);
    for (InternationalAccount a : cle.getAccountsAdapter())
      System.out.println(a.getAccountnumber());
  }
Exemplo n.º 9
0
  public void updateDependency(DependencyAttribute dependencyAttribute) {
    Client client = getClient();
    synchronized (client) {
      if (!client.isDone()) {
        queuedMeemProxy.updateDependency(dependencyAttribute);
        return;
      }
    }

    doUpdateDependency(meem, dependencyAttribute);
  }
Exemplo n.º 10
0
  public void addDependency(
      Facet facet, DependencyAttribute dependencyAttribute, LifeTime lifeTime) {
    Client client = getClient();
    synchronized (client) {
      if (!client.isDone()) {
        queuedMeemProxy.addDependency(facet, dependencyAttribute, lifeTime);
        return;
      }
    }

    doAddDependency(meem, facet, dependencyAttribute, lifeTime);
  }
Exemplo n.º 11
0
 public static String checkLogin(Userinfo ui) {
   Client client = ClientBuilder.newClient(config);
   WebTarget target = client.target(getBaseUri());
   return target
       .path("users")
       .path("role=" + ui.getUsertype())
       .path("email=" + ui.getUsername())
       .path("password=" + ui.getPassword())
       .request()
       .accept(MediaType.TEXT_HTML)
       .get(String.class);
 }
 public void addRequestInfo(String ip, HTTPRequest request) {
   Client client = getClientByIp(ip);
   client.addRequest(request);
   request.setClient(client);
   request.fixTimeSpent();
   requests.add(request);
   boolean isNewRequest = uniqueRequests.add(request);
   if (request.existsRedirect()) {
     Integer count = isNewRequest ? 1 : uniqueRedirects.get(request) + 1;
     uniqueRedirects.put(request, count);
   }
 }
Exemplo n.º 13
0
  private HttpStatus upsert(Client client, List<GrantedAuthority> authorities) {
    HttpStatus status;

    User user = new User(client.getUsername(), client.getPassword(), authorities);
    if (userDetailsManager.userExists(client.getUsername())) {
      userDetailsManager.updateUser(user);
      status = HttpStatus.OK;
    } else {
      userDetailsManager.createUser(user);
      status = HttpStatus.CREATED;
    }
    return status;
  }
Exemplo n.º 14
0
 public static final long countAllDocuments() throws IOException, SearchLibException {
   long count = 0;
   clientsLock.r.lock();
   try {
     for (Client client : CLIENTS.values()) {
       if (client.isTrueReplicate()) continue;
       count += client.getStatistics().getNumDocs();
     }
   } finally {
     clientsLock.r.unlock();
   }
   return count;
 }
Exemplo n.º 15
0
  /** Main client entry point for stand-alone operation. */
  public static void main(String[] args) {
    BasicConfigurator.configure(new ConsoleAppender(new PatternLayout("%d [%-25t] %-5p: %m%n")));

    CmdLineParser parser = new CmdLineParser();
    CmdLineParser.Option help = parser.addBooleanOption('h', "help");
    CmdLineParser.Option output = parser.addStringOption('o', "output");
    CmdLineParser.Option iface = parser.addStringOption('i', "iface");

    try {
      parser.parse(args);
    } catch (CmdLineParser.OptionException oe) {
      System.err.println(oe.getMessage());
      usage(System.err);
      System.exit(1);
    }

    // Display help and exit if requested
    if (Boolean.TRUE.equals(parser.getOptionValue(help))) {
      usage(System.out);
      System.exit(0);
    }

    String outputValue = (String) parser.getOptionValue(output, DEFAULT_OUTPUT_DIRECTORY);
    String ifaceValue = (String) parser.getOptionValue(iface);

    String[] otherArgs = parser.getRemainingArgs();
    if (otherArgs.length != 1) {
      usage(System.err);
      System.exit(1);
    }

    try {
      Client c = new Client(getIPv4Address(ifaceValue));
      SharedTorrent torrent =
          SharedTorrent.fromFile(new File(otherArgs[0]), new File(outputValue), false);
      c.addTorrent(torrent);

      // Set a shutdown hook that will stop the sharing/seeding and send
      // a STOPPED announce request.
      Runtime.getRuntime().addShutdownHook(new Thread(new ClientShutdown(c, null)));

      c.share();
      if (ClientState.ERROR.equals(torrent.getClientState())) {
        System.exit(1);
      }
    } catch (Exception e) {
      logger.error("Fatal error: {}", e.getMessage(), e);
      System.exit(2);
    }
  }
Exemplo n.º 16
0
  /**
   * Runs the stress test.
   *
   * @param clients number of clients
   * @param runs number of runs per client
   * @throws Exception exception
   */
  private static void run(final int clients, final int runs) throws Exception {
    // Create test database
    Command cmd = new CreateDB(NAME, INPUT);
    cmd.execute(context);

    // Start clients
    final Client[] cl = new Client[clients];
    for (int i = 0; i < clients; ++i) cl[i] = new Client(runs);
    for (final Client c : cl) c.start();
    for (final Client c : cl) c.join();
    // Drop database
    cmd = new DropDB(NAME);
    cmd.execute(context);
  }
Exemplo n.º 17
0
 public static final void closeAll() {
   synchronized (ClientCatalog.class) {
     clientsLock.r.lock();
     try {
       for (Client client : CLIENTS.values()) {
         if (client == null) continue;
         Logging.info("OSS unloads index " + client.getIndexName());
         client.close();
       }
     } finally {
       clientsLock.r.unlock();
     }
     rendererResults.release();
   }
 }
Exemplo n.º 18
0
 public static final void closeIndex(String indexName) throws SearchLibException {
   Client client = null;
   clientsLock.w.lock();
   try {
     File indexDirectory = getIndexDirectory(indexName);
     client = CLIENTS.get(indexDirectory);
     if (client == null) return;
     Logging.info("Closing client " + indexName);
     client.close();
     CLIENTS.remove(indexDirectory);
   } finally {
     clientsLock.w.unlock();
   }
   if (client != null) PushEvent.eventClientSwitch.publish(client);
 }
Exemplo n.º 19
0
 private static List<Client> findDepends(String indexName) {
   clientsLock.r.lock();
   try {
     ArrayList<Client> list = new ArrayList<Client>();
     for (Client client : CLIENTS.values()) {
       IndexConfig indexConfig = client.getIndex().getIndexConfig();
       if (indexConfig.isMulti())
         if (indexConfig.isIndexMulti(indexName)) {
           list.add(client);
         }
     }
     return list;
   } finally {
     clientsLock.r.unlock();
   }
 }
Exemplo n.º 20
0
 /**
  * Runs the stress test.
  *
  * @param clients number of clients
  * @param runs number of runs per client
  * @throws Exception exception
  */
 private void run(final int clients, final int runs) throws Exception {
   // run server instance
   server = createServer();
   // create test database
   try (final ClientSession cs = createClient()) {
     cs.execute("create db test " + INPUT);
     // run clients
     final Client[] cl = new Client[clients];
     for (int i = 0; i < clients; ++i) cl[i] = new Client(runs);
     for (final Client c : cl) c.start();
     for (final Client c : cl) c.join();
     // drop database and stop server
     cs.execute("drop db test");
   }
   stopServer(server);
 }
Exemplo n.º 21
0
 /**
  * @see
  *     org.openmaji.system.manager.registry.MeemRegistryClient#meemDeregistered(org.openmaji.meem.Meem)
  */
 public void meemDeregistered(Meem meem) {
   if (hasContentSent) {
     parent.bind(null);
   } else {
     this.meem = null;
   }
 }
Exemplo n.º 22
0
 public String getEmailAddressAsString() {
   String result = null;
   if (client != null) {
     result = client.getEmailAddress().asString();
   }
   return result;
 }
Exemplo n.º 23
0
 public void setEmailAddress(EmailAddress emailAddress) {
   if (client != null) {
     client.setEmailAddress(emailAddress);
   } else {
     SysLog.logError("attempted to set email address to null client");
   }
 }
  @Test
  public void testCopyHeadersClusterAdminRequest() {
    Map<String, String> transportHeaders = randomHeaders(randomIntBetween(0, 10));
    Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
    Map<String, String> copiedHeaders = randomHeadersFrom(restHeaders);
    Set<String> usefulRestHeaders = new HashSet<>(copiedHeaders.keySet());
    usefulRestHeaders.addAll(randomMap(randomIntBetween(0, 10), "useful-").keySet());
    Map<String, String> restContext = randomContext(randomIntBetween(0, 10));
    Map<String, String> transportContext =
        Maps.difference(randomContext(randomIntBetween(0, 10)), restContext).entriesOnlyOnLeft();

    HashMap<String, String> expectedHeaders = new HashMap<>();
    expectedHeaders.putAll(transportHeaders);
    expectedHeaders.putAll(copiedHeaders);

    Map<String, String> expectedContext = new HashMap<>();
    expectedContext.putAll(transportContext);
    expectedContext.putAll(restContext);

    Client client =
        client(
            new NoOpClient(), new FakeRestRequest(restHeaders, expectedContext), usefulRestHeaders);

    ClusterHealthRequest clusterHealthRequest = Requests.clusterHealthRequest();
    putHeaders(clusterHealthRequest, transportHeaders);
    putContext(clusterHealthRequest, transportContext);
    assertHeaders(clusterHealthRequest, transportHeaders);
    client.admin().cluster().health(clusterHealthRequest);
    assertHeaders(clusterHealthRequest, expectedHeaders);
    assertContext(clusterHealthRequest, expectedContext);

    ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest();
    putHeaders(clusterStateRequest, transportHeaders);
    putContext(clusterStateRequest, transportContext);
    assertHeaders(clusterStateRequest, transportHeaders);
    client.admin().cluster().state(clusterStateRequest);
    assertHeaders(clusterStateRequest, expectedHeaders);
    assertContext(clusterStateRequest, expectedContext);

    ClusterStatsRequest clusterStatsRequest = Requests.clusterStatsRequest();
    putHeaders(clusterStatsRequest, transportHeaders);
    putContext(clusterStatsRequest, transportContext);
    assertHeaders(clusterStatsRequest, transportHeaders);
    client.admin().cluster().clusterStats(clusterStatsRequest);
    assertHeaders(clusterStatsRequest, expectedHeaders);
    assertContext(clusterStatsRequest, expectedContext);
  }
  @Test
  public void testCopyHeadersRequest() {
    Map<String, String> transportHeaders = randomHeaders(randomIntBetween(0, 10));
    Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
    Map<String, String> copiedHeaders = randomHeadersFrom(restHeaders);
    Set<String> usefulRestHeaders = new HashSet<>(copiedHeaders.keySet());
    usefulRestHeaders.addAll(randomMap(randomIntBetween(0, 10), "useful-").keySet());
    Map<String, String> restContext = randomContext(randomIntBetween(0, 10));
    Map<String, String> transportContext =
        Maps.difference(randomContext(randomIntBetween(0, 10)), restContext).entriesOnlyOnLeft();

    Map<String, String> expectedHeaders = new HashMap<>();
    expectedHeaders.putAll(transportHeaders);
    expectedHeaders.putAll(copiedHeaders);

    Map<String, String> expectedContext = new HashMap<>();
    expectedContext.putAll(transportContext);
    expectedContext.putAll(restContext);

    Client client =
        client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders);

    SearchRequest searchRequest = Requests.searchRequest();
    putHeaders(searchRequest, transportHeaders);
    putContext(searchRequest, transportContext);
    assertHeaders(searchRequest, transportHeaders);
    client.search(searchRequest);
    assertHeaders(searchRequest, expectedHeaders);
    assertContext(searchRequest, expectedContext);

    GetRequest getRequest = Requests.getRequest("index");
    putHeaders(getRequest, transportHeaders);
    putContext(getRequest, transportContext);
    assertHeaders(getRequest, transportHeaders);
    client.get(getRequest);
    assertHeaders(getRequest, expectedHeaders);
    assertContext(getRequest, expectedContext);

    IndexRequest indexRequest = Requests.indexRequest();
    putHeaders(indexRequest, transportHeaders);
    putContext(indexRequest, transportContext);
    assertHeaders(indexRequest, transportHeaders);
    client.index(indexRequest);
    assertHeaders(indexRequest, expectedHeaders);
    assertContext(indexRequest, expectedContext);
  }
  @Test
  public void testCopyHeadersIndicesAdminRequest() {
    Map<String, String> transportHeaders = randomHeaders(randomIntBetween(0, 10));
    Map<String, String> restHeaders = randomHeaders(randomIntBetween(0, 10));
    Map<String, String> copiedHeaders = randomHeadersFrom(restHeaders);
    Set<String> usefulRestHeaders = new HashSet<>(copiedHeaders.keySet());
    usefulRestHeaders.addAll(randomMap(randomIntBetween(0, 10), "useful-").keySet());
    Map<String, String> restContext = randomContext(randomIntBetween(0, 10));
    Map<String, String> transportContext =
        Maps.difference(randomContext(randomIntBetween(0, 10)), restContext).entriesOnlyOnLeft();

    HashMap<String, String> expectedHeaders = new HashMap<>();
    expectedHeaders.putAll(transportHeaders);
    expectedHeaders.putAll(copiedHeaders);

    Map<String, String> expectedContext = new HashMap<>();
    expectedContext.putAll(transportContext);
    expectedContext.putAll(restContext);

    Client client =
        client(new NoOpClient(), new FakeRestRequest(restHeaders, restContext), usefulRestHeaders);

    CreateIndexRequest createIndexRequest = Requests.createIndexRequest("test");
    putHeaders(createIndexRequest, transportHeaders);
    putContext(createIndexRequest, transportContext);
    assertHeaders(createIndexRequest, transportHeaders);
    client.admin().indices().create(createIndexRequest);
    assertHeaders(createIndexRequest, expectedHeaders);
    assertContext(createIndexRequest, expectedContext);

    CloseIndexRequest closeIndexRequest = Requests.closeIndexRequest("test");
    putHeaders(closeIndexRequest, transportHeaders);
    putContext(closeIndexRequest, transportContext);
    assertHeaders(closeIndexRequest, transportHeaders);
    client.admin().indices().close(closeIndexRequest);
    assertHeaders(closeIndexRequest, expectedHeaders);
    assertContext(closeIndexRequest, expectedContext);

    FlushRequest flushRequest = Requests.flushRequest();
    putHeaders(flushRequest, transportHeaders);
    putContext(flushRequest, transportContext);
    assertHeaders(flushRequest, transportHeaders);
    client.admin().indices().flush(flushRequest);
    assertHeaders(flushRequest, expectedHeaders);
    assertContext(flushRequest, expectedContext);
  }
Exemplo n.º 27
0
 @GET
 @Path("/deleteclient")
 @Produces("text/plain")
 public String deleteClient(@QueryParam("numCli") int numCli) throws ParseException {
   EntityManager em = HibUtil.getEntityManager();
   em.getTransaction().begin();
   Client cli = em.find(Client.class, numCli);
   List<Sejour> sejs = cli.getSejours();
   for (Sejour s : sejs) {
     s.removeAllActivites();
     em.remove(s);
   }
   em.remove(cli);
   em.getTransaction().commit();
   HibUtil.closeEntityManager();
   return "ok";
 }
Exemplo n.º 28
0
 Client createClient(final ClientId clientId, final VerificationKey verificationKey) {
   final Client client = new Client();
   client.setComparisonIdentities(new ArrayList<>());
   client.setDeviceToken(clientId.getClient());
   final PublicKeys publicKeys = new PublicKeys();
   publicKeys.setVerification(verificationKey);
   final EncryptionKey encryptionKey = new EncryptionKey();
   encryptionKey.setAlgorithm(EncryptionAlgorithm.RSA2048);
   final ByteBuffer b = ByteBuffer.wrap("".getBytes());
   b.mark();
   encryptionKey.setBuffer(b);
   publicKeys.setEncryption(encryptionKey);
   client.setKeys(publicKeys);
   final UserAgent userAgent = new UserAgent();
   userAgent.setPlatform("");
   userAgent.setVersion("");
   client.setUserAgent(userAgent);
   return client;
 }
Exemplo n.º 29
0
 public static void receive_merge(WebApp webapp, Client client)
     throws SearchLibException, IOException {
   File tempDir = getTempReceiveDir(client);
   File clientDir = client.getDirectory();
   Client newClient = null;
   lockClientDir(clientDir);
   try {
     client.close();
     new ReplicationMerge(tempDir, clientDir);
     newClient =
         ClientFactory.INSTANCE.newClient(
             clientDir, true, true, ClientFactory.INSTANCE.properties.getSilentBackupUrl());
     newClient.writeReplCheck();
   } finally {
     unlockClientDir(clientDir, newClient);
   }
   PushEvent.eventClientSwitch.publish(client);
   FileUtils.deleteDirectory(tempDir);
 }
Exemplo n.º 30
0
 public static final boolean receive_file_exists(
     Client client, String filePath, long lastModified, long length) throws IOException {
   File existsFile = new File(client.getDirectory(), filePath);
   if (!existsFile.exists()) return false;
   if (existsFile.lastModified() != lastModified) return false;
   if (existsFile.length() != length) return false;
   File rootDir = getTempReceiveDir(client);
   IOUtils.appendLines(new File(rootDir, PATH_TO_MOVE), filePath);
   return true;
 }