forked from Authing/authing-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
package cn.authing.sdk.java.client; | ||
|
||
import cn.authing.sdk.java.model.Receiver; | ||
import cn.authing.sdk.java.model.AuthingClientOptions; | ||
import cn.authing.sdk.java.model.AuthingRequestConfig; | ||
import cn.authing.sdk.java.util.JsonUtils; | ||
|
||
|
||
/** | ||
* @author luojielin | ||
*/ | ||
public class BaseClient { | ||
|
||
protected AuthingClientOptions options; | ||
|
||
public BaseClient(AuthingClientOptions options) { | ||
this.options = options; | ||
} | ||
|
||
public static <T> T deserialize(String content, Class<T> valueType) { | ||
return JsonUtils.deserialize(content, valueType); | ||
} | ||
|
||
public static String serialize(Object value) { | ||
return JsonUtils.serialize(value); | ||
} | ||
|
||
public String request(AuthingRequestConfig config) { | ||
return options.doRequest(config.getUrl(), config.getMethod(), config.getHeaders(), config.getBody()); | ||
} | ||
|
||
|
||
|
||
public void subEvent(String eventCode, Receiver receiver){ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/main/java/cn/authing/sdk/java/model/AuthingWebsocketClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package cn.authing.sdk.java.model; | ||
|
||
import org.java_websocket.client.WebSocketClient; | ||
import org.java_websocket.handshake.ServerHandshake; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author songxueyan | ||
* @date 2023/2/21 | ||
**/ | ||
public class AuthingWebsocketClient extends WebSocketClient { | ||
|
||
private final Receiver receiver; | ||
|
||
public AuthingWebsocketClient(URI serverUri, Map<String, String> httpHeaders, Receiver receiver) { | ||
super(serverUri, httpHeaders); | ||
this.receiver = receiver; | ||
} | ||
|
||
@Override | ||
public void onOpen(ServerHandshake serverHandshake) { | ||
// System.out.println("onOpen"); | ||
} | ||
|
||
@Override | ||
public void onMessage(String s) { | ||
// System.out.println("onMessage:"+s); | ||
this.receiver.onReceiverMessage(s); | ||
} | ||
|
||
@Override | ||
public void onClose(int i, String s, boolean b) { | ||
System.out.println("onClose,i="+i+",s="+s+",b="+b); | ||
} | ||
|
||
@Override | ||
public void onError(Exception e) { | ||
System.out.println(e); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package cn.authing.sdk.java.model; | ||
|
||
public interface Receiver { | ||
void onReceiverMessage(String msg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package test.management; | ||
|
||
import cn.authing.sdk.java.client.ManagementClient; | ||
import cn.authing.sdk.java.model.ManagementClientOptions; | ||
import cn.authing.sdk.java.model.Receiver; | ||
|
||
/** | ||
* @author songxueyan | ||
* @date 2023/2/21 | ||
**/ | ||
public class SubEventTest { | ||
public static void main(String[] args) { | ||
ManagementClientOptions clientOptions = new ManagementClientOptions(); | ||
clientOptions.setAccessKeyId("ACCESS_KEY_ID"); | ||
clientOptions.setAccessKeySecret("ACCESS_KEY_SECRET"); | ||
// clientOptions.setHost("http://core.authing.cn"); | ||
// clientOptions.setEventEndpoint("/events"); | ||
|
||
ManagementClient client = new ManagementClient(clientOptions); | ||
|
||
client.subEvent("authing.user.created", msg -> System.out.println(msg)); | ||
} | ||
} |