https://github.com/ep2p/row-client
Java client for ROW
https://github.com/ep2p/row-client
java java-client websocket
Last synced: 9 months ago
JSON representation
Java client for ROW
- Host: GitHub
- URL: https://github.com/ep2p/row-client
- Owner: ep2p
- License: gpl-3.0
- Created: 2020-07-20T11:40:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-07-01T05:22:59.000Z (over 4 years ago)
- Last Synced: 2025-01-22T19:48:30.422Z (11 months ago)
- Topics: java, java-client, websocket
- Language: Java
- Homepage:
- Size: 156 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# java-row-client
[](https://jitpack.io/#idioglossia/java-row-client)
Java client for ROW (Rest Over Websocket)
---
## Setup
todo
## Usage
Create RowClient using `RowWebsocketClient` and pass configuration object.
```java
RowClient rowClient = new TyrusRowWebsocketClient(RowClientConfig.builder()
.address("ws://localhost:8080/ws")
.build());
```
Call `open()` method on client to start the connection:
```java
rowClient.open();
```
Create a request:
```java
RowRequest request = RowRequest.builder()
.address("/address")
.method(RowRequest.RowMethod.GET)
.body(...)
.query(...)
.headers(...)
.build();
```
Send request and pass response handler:
```java
rowClient.sendRequest(request, new ResponseCallback() {
@Override
public void onResponse(RowResponse rowResponse) {
System.out.println(rowResponse);
}
@Override
public void onError(Throwable throwable) {
throwable.printStackTrace();
}
});
```
If your request is subscribing to a channel, pass SubscriptionListener too:
```java
rowClient.subscribe(request, new ResponseCallback() {
@Override
public void onResponse(RowResponse rowResponse) {
//request response
System.out.println(rowResponse);
System.out.println(rowResponse.getSubscription());
}
@Override
public void onError(Throwable throwable) {
throwable.printStackTrace();
}
}, new SubscriptionListener() {
@Override
public void onMessage(Subscription subscription, PublishedMessage sampleDto) {
//subscription listener
System.out.println(sampleDto);
System.out.println(subscription);
}
});
```
Check `RowClientConfig` for more config parameters. For example you can pass handshake headers through configuration:
```java
RowClient rowClient = new RowWebsocketClient(RowClientConfig.builder()
.address("ws://localhost:8080/ws")
.handshakeHeadersProvider(new HandshakeHeadersProvider() {
@Override
public Map> getHeaders() {
Map> headers = new HashMap<>();
headers.put("X-Auth-Token", Collections.singletonList("adminToken"));
return headers;
}
})
.build());
```
You can make changes to websocket configuration by passing `WebsocketConfig` to `RowClientConfig`. Also, its possible to alter `SSLEngineConfigurator`. Follow [this documentation](https://eclipse-ee4j.github.io/tyrus-project.github.io/documentation/latest/index/tyrus-proprietary-config.html#d0e1129).
Then on server side the websocket can be validated.