本文整理汇总了Java中javax.ws.rs.core.Response.ResponseBuilder.entity方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseBuilder.entity方法的具体用法?Java ResponseBuilder.entity怎么用?Java ResponseBuilder.entity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Response.ResponseBuilder
的用法示例。
在下文中一共展示了ResponseBuilder.entity方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAirConditioningById
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Return all lmin by air
*
* @return Response
*/
@PermitAll
@GET
@Path("/byair/{id}")
@Produces("application/json")
public Response getAirConditioningById(@PathParam("id") Long idAir) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
List<LitersMinute> lmin = LitersMinuteDao.getInstance().getByAirId(idAir);
if (lmin != null) {
builder.status(Response.Status.OK);
builder.entity(lmin);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例2: getAirConditioningById
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Return air by id
*
* @param id
* @return Response
*/
@PermitAll
@GET
@Path("/{id}")
@Produces("application/json")
public Response getAirConditioningById(@PathParam("id") Long idAirConditioning) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
AirConditioning air = AirConditioningDao.getInstance().getById(idAirConditioning);
if (air != null) {
builder.status(Response.Status.OK);
builder.entity(air);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例3: toResponse
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
@Override
public Response toResponse(@NonNull Exception exception) {
ResponseBuilder builder;
StatusType statusInfo;
if (exception instanceof WebApplicationException) {
Response response = ((WebApplicationException) exception).getResponse();
builder = Response.fromResponse(response);
statusInfo = response.getStatusInfo();
} else {
builder = Response.serverError();
statusInfo = Status.INTERNAL_SERVER_ERROR;
}
SimpleExceptionJson simpleExceptionJson = new SimpleExceptionJson(statusInfo.getReasonPhrase(),
statusInfo.getStatusCode(), exception.getMessage());
builder.entity(simpleExceptionJson);
builder.type("application/problem+json");
if (statusInfo.getFamily() == Family.CLIENT_ERROR) {
log.debug("Got client Exception", exception);
} else {
log.error("Sending error to client", exception);
}
return builder.build();
}
示例4: getGardenById
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Get Garden by Id
*
* @param idGarden
* @return Response
*/
@PermitAll
@GET
@Path("/{id}")
@Produces("application/json")
public Response getGardenById(@PathParam("id") Long idGarden) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
Garden garden = GardenDao.getInstance().getById(idGarden);
if (garden != null) {
builder.status(Response.Status.OK);
builder.entity(garden);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例5: getGardensByUsername
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Get garden by username's user
*
* @param username
* @return Response
*/
@PermitAll
@GET
@Path("/username/{username}")
@Produces("application/json")
public Response getGardensByUsername(@PathParam("username") String username) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
List<Garden> gardens = GardenDao.getInstance().getByUsername(username);
if (gardens != null) {
builder.status(Response.Status.OK);
builder.entity(gardens);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例6: getGardensByUserId
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Get gardens by user id
*
* @param userId
* @return
*/
@PermitAll
@GET
@Path("/user/{id}")
@Produces("application/json")
public Response getGardensByUserId(@PathParam("id") Long userId) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
List<Garden> gardens = GardenDao.getInstance().getByUserId(userId);
if (gardens != null) {
builder.status(Response.Status.OK);
builder.entity(gardens);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例7: getUserByEmail
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
@PermitAll
@GET
@Path("/email/{email}")
@Produces("application/json")
public Response getUserByEmail(@PathParam("email") String email) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
User user = UserDao.getInstance().getByEmail(email);
if (user != null) {
builder.status(Response.Status.OK);
builder.entity(user);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例8: getUserByUsername
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Get user by username
*
* @param username
* @return
*/
@PermitAll
@GET
@Path("/username/{username}")
@Produces("application/json")
public Response getUserByUsername(@PathParam("username") String username) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
User user = UserDao.getInstance().getByUsername(username);
if (user != null) {
builder.status(Response.Status.OK);
builder.entity(user);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例9: getWateringByGardenId
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Get watering by garden's id
*
* @param gardenId
* @return
*/
@PermitAll
@GET
@Path("/garden/{gardenId}")
@Produces("application/json")
public Response getWateringByGardenId(@PathParam("gardenId") Long gardenId) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
List<Watering> waterings = WateringDao.getInstance().getByGardenId(gardenId);
if (waterings != null) {
builder.status(Response.Status.OK);
builder.entity(waterings);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例10: getGardensByGardenId
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Get garden status by garden's id
*
* @param gardenId
* @return
*/
@PermitAll
@GET
@Path("/garden/{gardenId}")
@Produces("application/json")
public Response getGardensByGardenId(@PathParam("gardenId") Long gardenId) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
List<GardenStatus> gardenStatus = GardenStatusDao.getInstance().getByGardenId(gardenId);
if (gardenStatus != null) {
builder.status(Response.Status.OK);
builder.entity(gardenStatus);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例11: createResponse
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
private Response createResponse(final InputStream isInvariable) {
// ステータスコードを追加
ResponseBuilder res = Response.status(HttpStatus.SC_OK);
res.header(HttpHeaders.CONTENT_TYPE, EventUtils.TEXT_CSV);
res.entity(isInvariable);
return res.build();
}
示例12: getEmptyResponse
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* イベントログが存在しない場合に返却する空レスポンスを取得する.
* @return 空レスポンス
*/
private Response getEmptyResponse() {
// レスポンスの返却
ResponseBuilder res = Response.status(HttpStatus.SC_OK);
res.header(HttpHeaders.CONTENT_TYPE, EventUtils.TEXT_CSV);
res.entity("");
log.debug("main thread end.");
return res.build();
}
示例13: getLdpRs
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
private ResponseBuilder getLdpRs(final String identifier, final Resource res, final ResponseBuilder builder,
final RDFSyntax syntax, final IRI profile) {
// Check for a cache hit
final EntityTag etag = new EntityTag(md5Hex(res.getModified() + identifier), true);
checkCache(req.getRequest(), res.getModified(), etag);
builder.tag(etag);
if (res.isMemento()) {
builder.header(ALLOW, join(",", GET, HEAD, OPTIONS));
} else if (ACL.equals(req.getExt())) {
builder.header(ALLOW, join(",", GET, HEAD, OPTIONS, PATCH));
} else if (res.getInteractionModel().equals(LDP.RDFSource)) {
builder.header(ALLOW, join(",", GET, HEAD, OPTIONS, PATCH, PUT, DELETE));
} else {
builder.header(ALLOW, join(",", GET, HEAD, OPTIONS, PATCH, PUT, DELETE, POST));
}
// URI Templates
builder.header(LINK_TEMPLATE, "<" + identifier + "{?subject,predicate,object}>; rel=\""
+ LDP.Resource.getIRIString() + "\"");
final Prefer prefer = ACL.equals(req.getExt()) ?
new Prefer(PREFER_REPRESENTATION, singletonList(PreferAccessControl.getIRIString()),
of(PreferUserManaged, LDP.PreferContainment, LDP.PreferMembership).map(IRI::getIRIString)
.collect(toList()), null, null, null) : req.getPrefer();
ofNullable(prefer).ifPresent(p -> builder.header(PREFERENCE_APPLIED, PREFER_RETURN + "=" + p.getPreference()
.orElse(PREFER_REPRESENTATION)));
if (ofNullable(prefer).flatMap(Prefer::getPreference).filter(PREFER_MINIMAL::equals).isPresent()) {
return builder.status(NO_CONTENT);
}
// Short circuit HEAD requests
if (HEAD.equals(req.getRequest().getMethod())) {
return builder;
}
// Stream the rdf content
final StreamingOutput stream = new StreamingOutput() {
@Override
public void write(final OutputStream out) throws IOException {
try (final Stream<? extends Quad> stream = res.stream()) {
ioService.write(stream.filter(filterWithPrefer(prefer))
.map(unskolemizeQuads(resourceService, getBaseUrl()))
.filter(filterWithLDF(req.getSubject(), req.getPredicate(), req.getObject()))
.map(Quad::asTriple), out, syntax,
ofNullable(profile).orElseGet(() -> getDefaultProfile(syntax, identifier)));
}
}
};
return builder.entity(stream);
}
示例14: getUserById
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Retorna usuario atraves do Id
*
* @param idUser
* @return Response
*/
@PermitAll
@GET
@Path("/{id}")
@Produces("application/json")
public Response getUserById(@PathParam("id") Long idUser) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
User user = UserDao.getInstance().getById(idUser);
if (user != null) {
builder.status(Response.Status.OK);
builder.entity(user);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}
示例15: getWateringById
import javax.ws.rs.core.Response.ResponseBuilder; //导入方法依赖的package包/类
/**
* Retorna watering atraves do Id
*
* @param idWatering
* @return Response
*/
@PermitAll
@GET
@Path("/{id}")
@Produces("application/json")
public Response getWateringById(@PathParam("id") Long idWatering) {
ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
builder.expires(new Date());
try {
Watering watering = WateringDao.getInstance().getById(idWatering);
if (watering != null) {
builder.status(Response.Status.OK);
builder.entity(watering);
} else {
builder.status(Response.Status.NOT_FOUND);
}
} catch (SQLException exception) {
builder.status(Response.Status.INTERNAL_SERVER_ERROR);
}
return builder.build();
}