Search in sources :

Example 1 with AdminClient

use of org.folio.rest.client.AdminClient in project raml-module-builder by folio-org.

the class DemoRamlRestTest method checkClientCode.

/**
 * @param context
 */
private void checkClientCode(TestContext context) {
    Async async = context.async(1);
    log.info("checkClientCode test");
    try {
        MimeMultipart mmp = new MimeMultipart();
        BodyPart bp = new MimeBodyPart(new InternetHeaders(), IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("job.json")));
        bp.setDisposition("form-data");
        bp.setFileName("abc.raml");
        BodyPart bp2 = new MimeBodyPart(new InternetHeaders(), IOUtils.toByteArray(getClass().getClassLoader().getResourceAsStream("job.json")));
        bp2.setDisposition("form-data");
        bp2.setFileName("abcd.raml");
        log.debug("--- bp content --- " + bp.getContent());
        mmp.addBodyPart(bp);
        mmp.addBodyPart(bp2);
        AdminClient aClient = new AdminClient("localhost", port, "abc", "abc", false);
        aClient.postUploadmultipart(PersistMethod.SAVE, null, "abc", mmp, reply -> {
            if (reply.statusCode() != 200) {
                context.fail();
            }
            log.debug("checkClientCode statusCode 1 " + reply.statusCode());
            String key;
            try {
                SecretKey sk = AES.generateSecretKey();
                key = AES.convertSecretKeyToString(sk);
                final String expected = AES.encryptPasswordAsBase64("abc", sk);
                aClient.postGetPassword(key, reply2 -> {
                    reply2.bodyHandler(bodyHandler -> {
                        if (!expected.equals(bodyHandler.toString())) {
                            context.fail("expected : " + expected + " got " + bodyHandler.toString());
                        } else {
                            log.info("received expected password: " + expected);
                            aClient.getModuleStats(r -> {
                                r.bodyHandler(br -> {
                                    log.info("received: " + br.toString());
                                });
                                async.countDown();
                            });
                        }
                    });
                });
            } catch (Exception e) {
                log.error(e.getMessage(), e);
            }
        });
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        context.fail();
    }
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) SecretKey(javax.crypto.SecretKey) InternetHeaders(javax.mail.internet.InternetHeaders) MimeMultipart(javax.mail.internet.MimeMultipart) Async(io.vertx.ext.unit.Async) MimeBodyPart(javax.mail.internet.MimeBodyPart) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) AdminClient(org.folio.rest.client.AdminClient)

Example 2 with AdminClient

use of org.folio.rest.client.AdminClient in project raml-module-builder by folio-org.

the class Test method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    MimeMultipart mmp = new MimeMultipart();
    BodyPart bp = new MimeBodyPart(new FileInputStream("C:\\Git\\mod-files\\ramls\\mod-files\\files.raml"));
    bp.setDisposition("form-data");
    bp.setFileName("abc.raml");
    BodyPart bp2 = new MimeBodyPart(new FileInputStream("C:\\Git\\mod-files\\ramls\\mod-files\\files.raml"));
    bp2.setDisposition("form-data");
    bp2.setFileName("abcd.raml");
    mmp.addBodyPart(bp);
    mmp.addBodyPart(bp2);
    AdminClient aClient = new AdminClient("localhost", 8888, null, null, false);
    aClient.postUploadmultipart(PersistMethod.SAVE, null, "abc", mmp, reply -> {
        reply.statusCode();
    });
    /*    aClient.postImportSQL(
      Test.class.getClassLoader().getResourceAsStream("create_config.sql"), reply -> {
      reply.statusCode();
    });*/
    aClient.getJstack(trace -> {
        trace.bodyHandler(content -> {
            System.out.println(content);
        });
    });
    TenantClient tc = new TenantClient("localhost", 8888, "harvard", "harvard");
    tc.post(null, response -> {
        response.bodyHandler(body -> {
            System.out.println(body.toString());
            tc.delete(reply -> {
                reply.bodyHandler(body2 -> {
                    System.out.println(body2.toString());
                });
            });
        });
    });
    aClient.getPostgresActiveSessions("postgres", reply -> {
        reply.bodyHandler(body -> {
            System.out.println(body.toString("UTF8"));
        });
    });
    aClient.getPostgresLoad("postgres", reply -> {
        reply.bodyHandler(body -> {
            System.out.println(body.toString("UTF8"));
        });
    });
    aClient.getPostgresTableAccessStats(reply -> {
        reply.bodyHandler(body -> {
            System.out.println(body.toString("UTF8"));
        });
    });
    aClient.getPostgresTableSize("postgres", reply -> {
        reply.bodyHandler(body -> {
            System.out.println(body.toString("UTF8"));
        });
    });
}
Also used : MimeBodyPart(javax.mail.internet.MimeBodyPart) BodyPart(javax.mail.BodyPart) MimeMultipart(javax.mail.internet.MimeMultipart) TenantClient(org.folio.rest.client.TenantClient) MimeBodyPart(javax.mail.internet.MimeBodyPart) FileInputStream(java.io.FileInputStream) AdminClient(org.folio.rest.client.AdminClient)

Aggregations

BodyPart (javax.mail.BodyPart)2 MimeBodyPart (javax.mail.internet.MimeBodyPart)2 MimeMultipart (javax.mail.internet.MimeMultipart)2 AdminClient (org.folio.rest.client.AdminClient)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Async (io.vertx.ext.unit.Async)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 SecretKey (javax.crypto.SecretKey)1 InternetHeaders (javax.mail.internet.InternetHeaders)1 TenantClient (org.folio.rest.client.TenantClient)1