18 Eylül 2017 Pazartesi

JAX-RS Response Sınıfı

Şu satırı dahil ederiz.
import javax.ws.rs.core.Response;
Açıklaması şöyle
Results in an entity body mapped from the entity property of the Response with the status code specified by the status property of the Response. A null return value results in a 204 status code. If the status property of the Response is not set: a 200 status code is used for a non-null entity property and a 204 status code is used if the entity property is null.
Methods that need to provide additional metadata with a response should return an instance of Response, the ResponseBuilder class provides a convenient way to create a Response instance using a builder pattern.
Response nesnesi static metodlar ile ResponseBuilder nesnesi döner. Açıklaması şöyle
Response objects cannot be created directly; instead, they are created from javax.ws.rs.core.Response.ResponseBuilder instances returned by one of the static helper methods of Response
build metodu
Şöyle yaparız.
Response r = r.build ();
entity metodu
Şöyle yaparız.
String data= "...";
Response r = r.entity (data);
Şöyle yaparız.
return Response.status(200).entity("OK").build();
ok metodu
ResponseBuilder nesnesi döner. Şöyle yaparız
StreamingOutput stream = ...;
return Response.ok(stream).build();
seeOther metodu
Şöyle yaparız.
return Response.seeOther("/")
               .cookie(new NewCookie("name", "Hello, world!"))
status metodu
Şöyle yaparız.
Response r = Response.status (200);

Hiç yorum yok:

Yorum Gönder