-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuth.java
More file actions
38 lines (28 loc) · 1.15 KB
/
Auth.java
File metadata and controls
38 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package city.makeour.moc.examples;
import java.util.UUID;
import org.springframework.web.client.RestClientResponseException;
import city.makeour.moc.MocClient;
import city.makeour.ngsi.v2.model.CreateEntityRequest;
public class Auth {
public static void main(String[] args) {
// Create a new MocClient instance
MocClient mocClient = new MocClient("https://orion.sandbox.makeour.city");
// Set the Cognito auth info
mocClient.setMocAuthInfo("your_cognito_user_pool_id", "your_cognito_client_id");
// Authenticate with username and password
try {
mocClient.auth("your_username", "your_password");
} catch (Exception e) {
e.printStackTrace();
}
String uuid = UUID.randomUUID().toString();
CreateEntityRequest entity = new CreateEntityRequest();
entity.setType("TestEntity");
entity.setId("urn:ngsi-ld:TestEntity:" + uuid);
try {
mocClient.createEntity("application/json", entity);
} catch (RestClientResponseException e) {
System.err.println("Error creating entity: " + e.getMessage());
}
}
}