rest services 的services方法
public static void main(String[] args) throws Throwable {
// this can create JAX-RS server objects
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(BooksResource.class, BookResource.class,
BookSelectionsResource.class);
sf.setAddress("http://10.0.0.101:8080/bs");
sf.create();商賬追收
System.out.println("Started");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for (;;) {
System.out.println("Enter command: u--update. q--quit");
String cmd = br.readLine();
if (cmd.equals("u")) {
BookDB.instance.getBook("1234").setLastModified(new Date());
} else if (cmd.equals("q")) {
System.exit(0);
}
}
}
XJCFacade.main(new String[] { "-b", "src/main/resources/bindings.xml",
"-d", "src/main/java", "src/main/resources/BookService.xsd" });
System.out.println("Done!");
}
自己修改相應的欄位
android 用戶端
public void onClick(View view) {
try {
TextView tvResult = (TextView) findViewById(R.id.myView);
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(
"http://10.0.0.101:8080/bs/books/1234");
HttpResponse response = client.execute(httpGet);
InputStream inputStream = response.getEntity().getContent();
StringBuffer buffer = new StringBuffer();
BufferedReader bufferReader = new BufferedReader(
new InputStreamReader(inputStream));
String str = new String("");
while ((str = bufferReader.readLine()) != null) {
buffer.append(str);
}
bufferReader.close();
System.out.println(buffer.toString());
//這裡得到的是一個json資料類型的
tvResult.setText(buffer.toString());
//轉換就省略了
} catch (Throwable e) {
new RuntimeException(e);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://ttdev.com/bs"
xmlns:tns="http://ttdev.com/bs" elementFormDefault="qualified">
<element name="book">
<complexType>
<sequence>
<element name="isbn" type="string"></element>
<element name="title" type="string"></element>
</sequence>
</complexType>
</element>
<element name="books">
<complexType>
<sequence>
<element ref="tns:book" minOccurs="0" maxOccurs="unbounded"></element>
</sequence>
</complexType>
</element>
<element name="reviews">
<complexType>
<sequence>
<element ref="tns:reviewRef" minOccurs="0" maxOccurs="unbounded"></element>
</sequence>
</complexType>
</element>51賽爾號
<element name="reviewRef">
<complexType>
<sequence>
<element name="summary" type="string"></element>
<element name="url" type="anyURI"></element>
</sequence>
</complexType>
</element>
<element name="review">
<complexType>
<sequence>
<element name="by" type="string"></element>
<element name="text" type="string"></element>
</sequence>
</complexType>
</element>
</schema>
<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" schemaLocation="BookService.xsd"
jaxb:version="2.0">
<jaxb:bindings node="/xsd:schema/xsd:element[@name='book']">
<jaxb:class name="BookState"></jaxb:class>
</jaxb:bindings>
<jaxb:bindings node="/xsd:schema/xsd:element[@name='books']">
<jaxb:class name="BooksState"></jaxb:class>
</jaxb:bindings>
<jaxb:bindings node="/xsd:schema/xsd:element[@name='reviews']">
<jaxb:class name="ReviewsState"></jaxb:class>
</jaxb:bindings>
<jaxb:bindings node="/xsd:schema/xsd:element[@name='review']">
<jaxb:class name="ReviewState"></jaxb:class>
</jaxb:bindings>
</jaxb:bindings>
上面的2個檔案 都是直接從的實驗中複製的 呵呵 自行修改吧