jsonrpc4j client 사용 실례
3722 단어 자바
package com.jiepu.Jsonrpc4j.client;
import java.net.URL;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import com.googlecode.jsonrpc4j.ProxyUtil;
public class App {
public static void main(String[] args) throws Throwable {
test001();
test002();
}
private static void test001() throws Throwable {
// JsonRpcHttpClient client = new JsonRpcHttpClient(new
// URL("http://10.0.0.107/json_server/index.php"));
JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(
"http://10.0.0.107/json_server/index.php"));
Student student = client.invoke("getstudent", new Object[] {new Student(2, "fuck", 65)}, Student.class);
System.out.println(student);
System.out.println(client.invoke("add", new Object[] {14,16}, Integer.class));
System.out.println(client.invoke("fuck", new Object[] {"java",14,16}, String.class));
}
private static void test002() throws Exception {
JsonRpcHttpClient client = new JsonRpcHttpClient(new URL(
"http://10.0.0.107/json_server/index.php"));
IMyService service = ProxyUtil.createClientProxy(new App().getClass()
.getClassLoader(), IMyService.class, client);
Student student = service.getstudent(new Student(12, "name", 63));
System.out.println(student);
System.out.println(service.add(15, 65));
System.out.println(service.fuck("xx wen",45,6));
}
}
package com.jiepu.Jsonrpc4j.client;
public interface IMyService {
public Integer add(Integer a, Integer b) throws Exception ;
public String fuck(String str,Integer a, Integer b) throws Exception;
public Student getstudent(Student b) throws Exception;
}
package com.jiepu.Jsonrpc4j.client;
public class Student {
private Integer id;
private String name;
private Integer age;
public Student(){}
public Student(Integer id, String name, Integer age) {
super();
this.id = id;
this.name = name;
this.age = age;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
@Override
public String toString() {
return "Student [age=" + age + ", id=" + id + ", name=" + name + "]";
}
}
다운로드:
https://github.com/briandilley/jsonrpc4j
4.0.0
com.jiepu
Jsonrpc4j
0.0.1-SNAPSHOT
jar
Jsonrpc4j
http://maven.apache.org
UTF-8
junit
junit
3.8.1
test
com.github.briandilley.jsonrpc4j
jsonrpc4j
1.1
com.alibaba
fastjson
1.2.2
javax.servlet
javax.servlet-api
3.1-b06
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.