Rest Services Method
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 (); revenue collection
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! ");
}
Modify fields by yourself
Android Client
Public void onclick (view ){
Try {
Textview tvresult = (textview) findviewbyid (R. Id. myview );
Httpclient client = new defaulthttpclient ();
Httpget = new httpget (
"Http: // 10.0.0.101: 8080/BS/books/1234 ");
Httpresponse response = client.exe cute (httpget );
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 ());
// Here we get a JSON Data Type
Tvresult. settext (buffer. tostring ());
// The conversion is omitted.
} 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> Sn 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>
The above two files are copied directly from the experiment.