本文整理了Java中javax.ws.rs.core.Response.serverError
方法的一些代码示例,展示了Response.serverError
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.serverError
方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:serverError
[英]Create a new ResponseBuilder with an server error status.
[中]创建具有服务器错误状态的新ResponseBuilder。
代码示例来源:origin: dropwizard/dropwizard
@Override
public Response toResponse(WebApplicationException exception) {
LOGGER.error("Template Error", exception);
return Response.serverError()
.type(MediaType.TEXT_HTML_TYPE)
.entity(TEMPLATE_ERROR_MSG)
.build();
}
代码示例来源:origin: apache/incubator-druid
@POST
@Path("/assignTask")
@Consumes({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
public Response assignTask(Task task)
{
try {
workerTaskMonitor.assignTask(task);
return Response.ok().build();
}
catch (RuntimeException ex) {
return Response.serverError().entity(ex.getMessage()).build();
}
}
代码示例来源:origin: apache/incubator-druid
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("/{nodeType}")
public Response getClusterServers(@PathParam("nodeType") NodeType nodeType, @QueryParam("full") boolean full)
{
if (nodeType == null) {
return Response.serverError()
.status(Response.Status.BAD_REQUEST)
.entity("Invalid nodeType of null. Valid node types are " + Arrays.toString(NodeType.values()))
.build();
} else {
return Response.status(Response.Status.OK).entity(getNodes(nodeType, full)).build();
}
}
代码示例来源:origin: apache/incubator-druid
@POST
@Path("/task/{taskid}/shutdown")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(StateResourceFilter.class)
public Response doShutdown(@PathParam("taskid") String taskid)
{
try {
taskRunner.shutdown(taskid, "shut down request via HTTP endpoint");
}
catch (Exception e) {
log.error(e, "Failed to issue shutdown for task: %s", taskid);
return Response.serverError().build();
}
return Response.ok(ImmutableMap.of("task", taskid)).build();
}
代码示例来源:origin: apache/incubator-druid
@POST
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response doPost(
.ok(
(StreamingOutput) outputStream -> {
Exception e = null;
.build();
return Response.serverError()
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(jsonMapper.writeValueAsBytes(QueryInterruptedException.wrapIfNeeded(exceptionToReport)))
.build();
代码示例来源:origin: apache/incubator-druid
@GET
@Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
public Response getAll()
{
try {
return handler.handleGETAll();
}
catch (Exception e) {
LOG.error(e, "Exception in handling GETAll request");
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public Response apply(TaskRunner taskRunner)
{
if (taskRunner instanceof WorkerTaskRunner) {
return Response.ok(((WorkerTaskRunner) taskRunner).getWorkers()).build();
} else {
log.debug(
"Task runner [%s] of type [%s] does not support listing workers",
taskRunner,
taskRunner.getClass().getCanonicalName()
);
return Response.serverError()
.entity(ImmutableMap.of("error", "Task Runner does not support worker listing"))
.build();
}
}
}
代码示例来源:origin: javaee-samples/javaee7-samples
@POST
@Path("/upload2")
@Consumes({ MediaType.APPLICATION_OCTET_STREAM, "image/png" })
@Produces(MediaType.TEXT_PLAIN)
public Response postImageFile(File file) {
try (Reader reader = new FileReader(file)) {
int totalsize = 0;
int count = 0;
final char[] buffer = new char[256];
while ((count = reader.read(buffer)) != -1) {
totalsize += count;
}
return Response.ok(totalsize).build();
} catch (IOException e) {
e.printStackTrace();
return Response.serverError().build();
}
}
代码示例来源:origin: apache/incubator-druid
@POST
@Path("/updates")
@Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
@Consumes({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
public Response serviceAnnouncementHandleUpdates(
final InputStream inputStream,
final @Context HttpServletRequest req // used only to get request content-type
)
{
final String reqContentType = req.getContentType();
final boolean isSmile = SmileMediaTypes.APPLICATION_JACKSON_SMILE.equals(reqContentType);
final ObjectMapper mapper = isSmile ? smileMapper : jsonMapper;
try {
return handler.handleUpdates(inputStream, mapper);
}
catch (Exception e) {
LOG.error(e, "Exception in handling updates request");
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/is_replace_token")
public Response isReplaceToken() {
try {
return Response.ok(String.valueOf(priamServer.getInstanceIdentity().isReplace()))
.build();
} catch (Exception e) {
// TODO: can this ever happen? if so, what conditions would cause an exception here?
logger.error("Error while executing is_replace_token", e);
return Response.serverError().build();
}
}
代码示例来源:origin: apache/incubator-druid
@POST
@Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
@Consumes({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
public Response serviceAnnouncementPOSTAll(
final InputStream inputStream,
final @Context HttpServletRequest req // used only to get request content-type
)
{
final String reqContentType = req.getContentType();
final boolean isSmile = SmileMediaTypes.APPLICATION_JACKSON_SMILE.equals(reqContentType);
final ObjectMapper mapper = isSmile ? smileMapper : jsonMapper;
try {
return handler.handlePOSTAll(inputStream, mapper);
}
catch (Exception e) {
LOG.error(e, "Exception in handling POSTAll request");
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public final Response handleGET(String id)
{
try {
final Object returnObj = get(id);
if (returnObj == null) {
return Response.status(Response.Status.NOT_FOUND).build();
} else {
return Response.ok(returnObj).build();
}
}
catch (Exception e) {
LOG.error(e, "Error handling get request for [%s]", id);
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
代码示例来源:origin: Graylog2/graylog2-server
@Override
public Response toResponse(Exception exception) {
LOG.error("Unhandled exception in REST resource", exception);
final String message = nullToEmpty(exception.getMessage());
final ApiError apiError = ApiError.create(message);
return Response.serverError()
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(apiError)
.build();
}
}
代码示例来源:origin: javaee-samples/javaee7-samples
@POST
@Path("/upload")
@Consumes(MediaType.APPLICATION_OCTET_STREAM)
@Produces(MediaType.TEXT_PLAIN)
public Response postOctetStream(InputStream content) {
try (Reader reader = new InputStreamReader(content)) {
int totalsize = 0;
int count = 0;
final char[] buffer = new char[256];
while ((count = reader.read(buffer)) != -1) {
totalsize += count;
}
return Response.ok(totalsize).build();
} catch (IOException e) {
e.printStackTrace();
return Response.serverError().build();
}
}
代码示例来源:origin: apache/incubator-druid
@Path("/{id}")
@DELETE
@Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
public Response serviceAnnouncementDELETE(
final @PathParam("id") String id
)
{
if (Strings.isNullOrEmpty(id)) {
return makeNullIdResponse();
}
try {
return handler.handleDELETE(id);
}
catch (Exception e) {
LOG.error(e, "Exception in handling DELETE request for [%s]", id);
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
代码示例来源:origin: Netflix/Priam
@GET
@Path("/get_replaced_ip")
public Response getReplacedIp() {
try {
metrics.incGetReplacedIp();
return Response.ok(String.valueOf(priamServer.getInstanceIdentity().getReplacedIp()))
.build();
} catch (Exception e) {
logger.error("Error while executing get_replaced_ip", e);
return Response.serverError().build();
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public Response apply(TaskActionClient taskActionClient)
{
final Map<String, Object> retMap;
// It would be great to verify that this worker is actually supposed to be running the task before
// actually doing the action. Some ideas for how that could be done would be using some sort of attempt_id
// or token that gets passed around.
try {
final Object ret = taskActionClient.submit(holder.getAction());
retMap = new HashMap<>();
retMap.put("result", ret);
}
catch (Exception e) {
log.warn(e, "Failed to perform task action");
return Response.serverError().entity(ImmutableMap.of("error", e.getMessage())).build();
}
return Response.ok().entity(retMap).build();
}
}
代码示例来源:origin: prestodb/presto
@Override
public Response toResponse(Throwable throwable)
{
if (throwable instanceof WebApplicationException) {
return ((WebApplicationException) throwable).getResponse();
}
log.warn(throwable, "Request failed for %s", request.getRequestURI());
ResponseBuilder responseBuilder = Response.serverError()
.header(CONTENT_TYPE, TEXT_PLAIN);
if (includeExceptionInResponse) {
responseBuilder.entity(Throwables.getStackTraceAsString(throwable));
}
else {
responseBuilder.entity("Exception processing request");
}
return responseBuilder.build();
}
}
代码示例来源:origin: apache/incubator-druid
@GET
@Path("/enabled")
@Produces(MediaType.APPLICATION_JSON)
@ResourceFilters(StateResourceFilter.class)
public Response isEnabled()
{
try {
final Worker theWorker = curatorCoordinator.getWorker();
final boolean enabled = !theWorker.getVersion().equalsIgnoreCase(DISABLED_VERSION);
return Response.ok(ImmutableMap.of(theWorker.getHost(), enabled)).build();
}
catch (Exception e) {
return Response.serverError().build();
}
}
代码示例来源:origin: apache/incubator-druid
@Path("/{id}")
@GET
@Produces({MediaType.APPLICATION_JSON, SmileMediaTypes.APPLICATION_JACKSON_SMILE})
public Response serviceAnnouncementGET(
final @PathParam("id") String id
)
{
if (Strings.isNullOrEmpty(id)) {
return makeNullIdResponse();
}
try {
return handler.handleGET(id);
}
catch (Exception e) {
LOG.error(e, "Exception in handling GET request for [%s]", id);
return Response.serverError().entity(ServletResourceUtils.sanitizeException(e)).build();
}
}
内容来源于网络,如有侵权,请联系作者删除!