use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class PinotTenantRestletResource method getAllTenants.
@HttpVerb("get")
@Summary("Gets information about all tenants")
@Tags({ "tenant" })
@Paths({ "/tenants", "/tenants/" })
private StringRepresentation getAllTenants(@Parameter(name = "type", in = "query", description = "The type of tenant, either SERVER or BROKER") String type) throws JSONException {
// Return all the tags.
StringRepresentation presentation;
final JSONObject ret = new JSONObject();
if (type == null || type.equalsIgnoreCase("server")) {
ret.put("SERVER_TENANTS", _pinotHelixResourceManager.getAllServerTenantNames());
}
if (type == null || type.equalsIgnoreCase("broker")) {
ret.put("BROKER_TENANTS", _pinotHelixResourceManager.getAllBrokerTenantNames());
}
presentation = new StringRepresentation(ret.toString(), MediaType.APPLICATION_JSON);
return presentation;
}
use of org.restlet.representation.StringRepresentation in project pinot by linkedin.
the class SwaggerResource method get.
@Get
@Override
public Representation get() {
try {
// Info
JSONObject info = new JSONObject();
info.put("title", "Pinot Controller");
info.put("version", "0.1");
// Paths
JSONObject paths = new JSONObject();
Router router = PinotRestletApplication.getRouter();
RouteList routeList = router.getRoutes();
for (Route route : routeList) {
if (route instanceof TemplateRoute) {
TemplateRoute templateRoute = (TemplateRoute) route;
JSONObject pathObject = new JSONObject();
String routePath = templateRoute.getTemplate().getPattern();
// Check which methods are present
Restlet routeTarget = templateRoute.getNext();
if (routeTarget instanceof Finder) {
Finder finder = (Finder) routeTarget;
generateSwaggerForFinder(pathObject, routePath, finder);
} else if (routeTarget instanceof Filter) {
do {
Filter filter = (Filter) routeTarget;
routeTarget = filter.getNext();
} while (routeTarget instanceof Filter);
if (routeTarget instanceof Finder) {
Finder finder = (Finder) routeTarget;
generateSwaggerForFinder(pathObject, routePath, finder);
}
}
if (pathObject.keys().hasNext()) {
paths.put(routePath, pathObject);
}
}
}
// Tags
JSONArray tags = new JSONArray();
addTag(tags, "tenant", "Tenant-related operations");
addTag(tags, "instance", "Instance-related operations");
addTag(tags, "table", "Table-related operations");
addTag(tags, "segment", "Segment-related operations");
addTag(tags, "schema", "Schema-related operations");
addTag(tags, "version", "Version-related operations");
// Swagger
JSONObject swagger = new JSONObject();
swagger.put("swagger", "2.0");
swagger.put("info", info);
swagger.put("paths", paths);
swagger.put("tags", tags);
StringRepresentation representation = new StringRepresentation(swagger.toString());
// Set up CORS
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add(new Header("Access-Control-Allow-Origin", "*"));
return representation;
} catch (JSONException e) {
return new StringRepresentation(e.toString());
}
}
use of org.restlet.representation.StringRepresentation in project camel by apache.
the class DefaultRestletBinding method createRepresentationFromBody.
protected Representation createRepresentationFromBody(Exchange exchange, MediaType mediaType) {
Object body = exchange.getIn().getBody();
if (body == null) {
return new EmptyRepresentation();
}
// unwrap file
if (body instanceof WrappedFile) {
body = ((WrappedFile) body).getFile();
}
if (body instanceof InputStream) {
return new InputRepresentation((InputStream) body, mediaType);
} else if (body instanceof File) {
return new FileRepresentation((File) body, mediaType);
} else if (body instanceof byte[]) {
return new ByteArrayRepresentation((byte[]) body, mediaType);
} else if (body instanceof String) {
return new StringRepresentation((CharSequence) body, mediaType);
}
// fallback as string
body = exchange.getIn().getBody(String.class);
if (body != null) {
return new StringRepresentation((CharSequence) body, mediaType);
} else {
return new EmptyRepresentation();
}
}
use of org.restlet.representation.StringRepresentation in project camel by apache.
the class RestletSetBodyTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("restlet:http://localhost:" + portNum + "/stock/{symbol}?restletMethods=get").to("http://localhost:" + portNum2 + "/test?bridgeEndpoint=true").setBody().constant("110");
from("jetty:http://localhost:" + portNum2 + "/test").setBody().constant("response is back");
// create ByteArrayRepresentation for response
from("restlet:http://localhost:" + portNum + "/images/{symbol}?restletMethods=get").setBody().constant(new InputRepresentation(new ByteArrayInputStream(getAllBytes()), MediaType.IMAGE_PNG, 256));
from("restlet:http://localhost:" + portNum + "/music/{symbol}?restletMethods=get").setHeader(Exchange.CONTENT_TYPE).constant("audio/mpeg").setBody().constant(getAllBytes());
from("restlet:http://localhost:" + portNum + "/video/{symbol}?restletMethods=get").setHeader(Exchange.CONTENT_TYPE).constant("video/mp4").setBody().constant(new ByteArrayInputStream(getAllBytes()));
from("restlet:http://localhost:" + portNum + "/gzip/data?restletMethods=get").setBody().constant(new EncodeRepresentation(Encoding.GZIP, new StringRepresentation("Hello World!", MediaType.TEXT_XML)));
}
};
}
use of org.restlet.representation.StringRepresentation in project netxms by netxms.
the class AbstractHandler method onPost.
/**
* Process POST requests
*
* @param entity
* @return
*/
@Post
public Representation onPost(Representation entity) throws Exception {
if (entity == null) {
log.warn("No POST data in call");
return new StringRepresentation(createErrorResponse(RCC.ACCESS_DENIED).toString(), MediaType.APPLICATION_JSON);
}
JSONObject data = new JsonRepresentation(entity).getJsonObject();
log.debug("POST: data = " + data);
if (attachToSession()) {
return new StringRepresentation(JsonTools.jsonFromObject(create(data), null), MediaType.APPLICATION_JSON);
} else {
return new StringRepresentation(createErrorResponse(RCC.ACCESS_DENIED).toString(), MediaType.APPLICATION_JSON);
}
}
Aggregations