Update:添加日志实现,增加String类型的返回结果处理
This commit is contained in:
parent
99dc6a5b10
commit
4b185511d0
7
pom.xml
7
pom.xml
@ -41,6 +41,13 @@
|
||||
<version>1.5.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.25</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -79,7 +79,7 @@ public interface Aria2Client {
|
||||
String getServers(String gid);
|
||||
|
||||
@Aria2Method(Aria2MethodName.TELL_ACTIVE)
|
||||
String tellActive(List<String> keys);
|
||||
String tellActive(String... keys);
|
||||
|
||||
@Aria2Method(Aria2MethodName.TELL_WAITING)
|
||||
String tellWaiting(int offset, int num, String... keys);
|
||||
|
||||
@ -97,7 +97,9 @@ public class Aria2WebSocketProxy implements InvocationHandler {
|
||||
|
||||
private <T> T sendRequest(Aria2WebSocketRequest request, Type resultType) {
|
||||
String id = request.getId();
|
||||
webSocket.send(serializeRequest(request));
|
||||
String body = serializeRequest(request);
|
||||
log.debug("send body:{}", body);
|
||||
webSocket.send(body);
|
||||
JsonObject returnResult = null;
|
||||
while ((returnResult = this.webSocket.getResponse(id)) == null) {
|
||||
Aria2WebSocketClientException exception = this.webSocket.getException(id);
|
||||
@ -106,6 +108,9 @@ public class Aria2WebSocketProxy implements InvocationHandler {
|
||||
}
|
||||
}
|
||||
JsonElement result = returnResult.get("result");
|
||||
if (resultType.equals(String.class)) {
|
||||
return (T) result.toString();
|
||||
}
|
||||
return gson.fromJson(result, resultType);
|
||||
}
|
||||
|
||||
@ -145,8 +150,8 @@ public class Aria2WebSocketProxy implements InvocationHandler {
|
||||
|
||||
@Override
|
||||
public void onMessage(String message) {
|
||||
JsonElement jsonElement = JsonParser.parseString(message);
|
||||
JsonObject jsonObject = jsonElement.getAsJsonObject();
|
||||
log.debug("receive message:{}", message);
|
||||
JsonObject jsonObject = JsonParser.parseString(message).getAsJsonObject();
|
||||
String id = jsonObject.get("id").getAsString();
|
||||
if (id == null) {
|
||||
return;
|
||||
|
||||
1
src/main/resources/simplelogger.properties
Normal file
1
src/main/resources/simplelogger.properties
Normal file
@ -0,0 +1 @@
|
||||
org.slf4j.simpleLogger.defaultLogLevel=DEBUG
|
||||
@ -2,8 +2,11 @@ import cn.montaro.aria2.Aria2Client;
|
||||
import cn.montaro.aria2.Aria2ClientFactory;
|
||||
import cn.montaro.aria2.client.websocket.Aria2WebSocketConfig;
|
||||
import cn.montaro.aria2.client.websocket.Aria2WebSocketClient;
|
||||
import com.sun.org.apache.xpath.internal.SourceTree;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import java.sql.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -16,11 +19,32 @@ import java.util.Map;
|
||||
*/
|
||||
public class Aria2WebSocketClientTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Aria2WebSocketConfig config = new Aria2WebSocketConfig().setSecret("123456");
|
||||
Aria2Client client = Aria2ClientFactory.webSocketClient(config);
|
||||
String version = client.getVersion();
|
||||
System.out.println(version);
|
||||
|
||||
@Test
|
||||
public void tellActive() {
|
||||
String s = client.tellActive();
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tellWaiting() {
|
||||
String s = client.tellWaiting(0, 1000, null);
|
||||
System.out.println(s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getGlobalStat(){
|
||||
String globalStat = client.getGlobalStat();
|
||||
System.out.println(globalStat);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void changeUri() {
|
||||
List<String> addUris = new ArrayList<String>();
|
||||
addUris.add("https://mirrors.tuna.tsinghua.edu.cn/centos/8.5.2111/isos/x86_64/CentOS-8.5.2111-x86_64-dvd1.iso");
|
||||
String result = client.changeUri("97d4d126a7263df8", 1, new ArrayList<String>(), addUris);
|
||||
System.out.println(result);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user