Skip to content
Permalink
Browse files
Set Content-Type for String based response (#12295)
  • Loading branch information
FrankChen021 committed Mar 4, 2022
1 parent 58d05d7 commit 36bc41855d4d368ab6fbe0d5019bb27ba9c48440
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 0 deletions.
@@ -31,6 +31,7 @@
import org.apache.druid.server.security.ResourceType;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

public class BasicSecurityResourceFilter extends AbstractResourceFilter
@@ -62,6 +63,7 @@ public ContainerRequest filter(ContainerRequest request)
if (!authResult.isAllowed()) {
throw new WebApplicationException(
Response.status(Response.Status.FORBIDDEN)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format("Access-Check-Result: %s", authResult.toString()))
.build()
);
@@ -639,6 +639,7 @@ public Response getTasks(
if (state != null) {
if (!API_TASK_STATES.contains(StringUtils.toLowerCase(state))) {
return Response.status(Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format("Invalid state : %s, valid values are: %s", state, API_TASK_STATES))
.build();
}
@@ -658,6 +659,7 @@ public Response getTasks(
if (!authResult.isAllowed()) {
throw new WebApplicationException(
Response.status(Response.Status.FORBIDDEN)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format("Access-Check-Result: %s", authResult.toString()))
.build()
);
@@ -38,6 +38,7 @@
import org.apache.druid.server.security.ResourceAction;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;

@@ -79,6 +80,7 @@ public boolean apply(PathSegment input)
if (!supervisorSpecOptional.isPresent()) {
throw new WebApplicationException(
Response.status(Response.Status.NOT_FOUND)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format("Cannot find any supervisor with id: [%s]", supervisorId))
.build()
);
@@ -38,6 +38,7 @@
import org.apache.druid.server.security.ResourceType;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
@@ -79,6 +80,7 @@ public ContainerRequest filter(ContainerRequest request)
if (!taskOptional.isPresent()) {
throw new WebApplicationException(
Response.status(Response.Status.NOT_FOUND)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format("Cannot find any task with id: [%s]", taskId))
.build()
);
@@ -1639,6 +1639,7 @@ public Response setEndOffsets(
return Response.ok(sequenceNumbers).build();
} else if (latestSequence.isCheckpointed()) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format(
"Sequence [%s] has already endOffsets set, cannot set to [%s]",
latestSequence,
@@ -1771,6 +1772,7 @@ public Response pause() throws InterruptedException
{
if (!(status == Status.PAUSED || status == Status.READING)) {
return Response.status(Response.Status.BAD_REQUEST)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format("Can't pause, task is not in a pausable state (state: [%s])", status))
.build();
}
@@ -206,6 +206,7 @@ public Response doGetLog(
IdUtils.validateId("taskId", taskId);
if (!(taskRunner instanceof TaskLogStreamer)) {
return Response.status(501)
.type(MediaType.TEXT_PLAIN)
.entity(StringUtils.format(
"Log streaming not supported by [%s]",
taskRunner.getClass().getName()

0 comments on commit 36bc418

Please sign in to comment.