Java Reference
In-Depth Information
}
else
else if ( element . getTagName (). equals ( "last-name" )) {
cust . setLastName ( element . getTextContent ());
}
else
else if ( element . getTagName (). equals ( "street" )) {
cust . setStreet ( element . getTextContent ());
}
else
else if ( element . getTagName (). equals ( "city" )) {
cust . setCity ( element . getTextContent ());
}
else
else if ( element . getTagName (). equals ( "state" )) {
cust . setState ( element . getTextContent ());
}
else
else if ( element . getTagName (). equals ( "zip" )) {
cust . setZip ( element . getTextContent ());
}
else
else if ( element . getTagName (). equals ( "country" )) {
cust . setCountry ( element . getTextContent ());
}
}
return
return cust ;
}
catch
catch ( Exception e ) {
throw
throw new
new WebApplicationException ( e ,
Response . Status . BAD_REQUEST );
}
}
}
I'll admit, this example was a bit contrived. In a real system, we would not manually output
XML or write all this boilerplate code to read in an XML document and convert it to a busi-
ness object, but I don't want to distract you from learning JAX-RS basics by introducing an-
other API. In Chapter 6 , I will show how you can use JAXB to map your Customer object to
XML and have JAX-RS automatically transform your HTTP message body to and from
XML.
JAX-RS and Java Interfaces
In our example so far, we've applied JAX-RS annotations directly on the Java class that im-
plements our service. In JAX-RS, you are also allowed to define a Java interface that con-
tains all your JAX-RS annotation metadata instead of applying all your annotations to your
implementation class.
Search WWH ::




Custom Search