Java Reference
In-Depth Information
injected by the JAX-RS runtime. We then use this input stream to create a LineNumberRead-
er and output the posted data to the console.
byte[]
A raw array of bytes can be used for the input and output of any media type. Here's an ex-
ample:
@Path ( "/" )
public
public class
class MyService
MyService {
@GET
@Produces ( "text/plain" )
public
public byte
byte [] get () {
return
return "hello world" . getBytes ();
}
@POST
@Consumes ( "text/plain" )
public
public void
byte [] bytes ) {
System . out . println ( new
void post ( byte
new String ( bytes ));
}
}
For JAX-RS resource methods that return an array of bytes, you must specify the @Produces
annotation so that JAX-RS knows what media to use to set the Content-Type header.
String, char[]
Most of the data formats on the Internet are text based. JAX-RS can convert any text-based
format to and from either a String or an array of characters. For example:
@Path ( "/" )
public
public class
class MyService
MyService {
@GET
@Produces ( "application/xml" )
public
public String get () {
return
return "<customer><name>Bill Burke</name></customer>" ;
}
@POST
@Consumes ( "text/plain" )
public
public void
void post ( String str ) {
System . out . println ( str );
Search WWH ::




Custom Search