6.10.94-stable

GreyCat Java

If you want to explore the Java SDK capabilities for GreyCat we would highly recommend starting from Java SDK 101 tutorial

In addition, there is a Java SDK Advanced tutorial which demonstrates how you can integrate Kafka with GreyCat in a small project.

These tutorials will show you how to use Java SDK, call GreyCat functions and how to work with real-time data through Kafka.

You can access java SDK versions at https://get.greycat.io/files/sdk/java/testing/

How to login to GreyCat

Once you have followed Java SDK 101 tutorial and have your Java SDK working, you can start accessing GreyCat

Start the GreyCat server

use runtime;
use util;
fn main() {
  var user: User = User {
    id: 0,
    name: "admin",
    activated: true,
    external: false,
    role: "user",
  };
  SecurityEntity::set(user);
  // Logging
  info(Crypto::sha256hex("password"));
  User::setPassword(user.name, Crypto::sha256hex("password"));
}

fn main() { var user: User = User { id: 0, name: “admin”, activated: true, external: false, role: “user”, }; SecurityEntity::set(user); // Logging info(Crypto::sha256hex(“password”)); User::setPassword(user.name, Crypto::sha256hex(“password”)); }


Run the command to start the server in the same directory as the ```project.gcl```

```bash
greycat serve

It will start the server in your local host at port 8080.

Access the GreyCat server in your Java package

In any of your Java package you can call the running server with your credentials and play with it.

package com.example;

import java.util.ArrayList;
import java.util.List;

import ai.greycat.GreyCat.Library;

public class Sandbox {

    public static void main(String... args) throws Exception {
        String url = "http://localhost:8080";
        String username = "admin";
        String password = "password";

        // This will send POST request to login into the server
        GreyCat greycat = new GreyCat(url, username, password, null);

        // Another POST request to get the currently user
        System.out.println(greycat.call("runtime::User::me"));
    }
}