use of org.restlet.resource.Post in project pinot by linkedin.
the class PinotTenantRestletResource method post.
/*
* For tenant creation
*/
@Override
@Post("json")
public Representation post(Representation entity) {
StringRepresentation presentation;
try {
final Tenant tenant = _objectMapper.readValue(entity.getText(), Tenant.class);
presentation = createTenant(tenant);
} catch (final Exception e) {
presentation = exceptionToStringRepresentation(e);
LOGGER.error("Caught exception while creating tenant ", e);
ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_CREATE_ERROR, 1L);
setStatus(Status.SERVER_ERROR_INTERNAL);
}
return presentation;
}
use of org.restlet.resource.Post in project Xponents by OpenSextant.
the class TaggerResource method processForm.
/**
* Contract:
* docid optional; 'text' | 'doc-list' required.
* command: cmd=ping sends back a simple response
*
* text = UTF-8 encoded text
* docid = user's provided document ID
* doc-list = An array of text
*
* cmd=ping = report status.
*
* Where json-array contains { docs=[ {docid='A', text='...'}, {docid='B', text='...',...] }
* The entire array must be parsable in memory as a single, traversible JSON object.
* We make no assumption about one-JSON object per line or anything about line-endings as separators.
*
*
* @param params
* the params
* @return the representation
* @throws JSONException
* the JSON exception
*/
@Post("application/json;charset=utf-8")
public Representation processForm(JsonRepresentation params) throws JSONException {
org.json.JSONObject json = params.getJsonObject();
String input = json.optString("text", null);
String docid = json.optString("docid", null);
if (input != null) {
String lang = json.optString("lang", null);
TextInput item = new TextInput(docid, input);
item.langid = lang;
RequestParameters job = fromRequest(json);
return process(item, job);
}
// }
return status("FAIL", "Invalid API use text+docid pair or doc-list was not found");
}
use of org.restlet.resource.Post in project OpenAM by OpenRock.
the class XacmlService method importXACML.
/**
* Expects to receive XACML formatted XML which will be read and imported.
*/
@Post
public Representation importXACML(Representation entity) {
boolean dryRun = "true".equalsIgnoreCase(getQuery().getFirstValue("dryrun"));
List<ImportStep> steps;
try {
if (!checkPermission("MODIFY")) {
// not allowed
throw new ResourceException(new Status(FORBIDDEN));
}
String realm = RestletRealmRouter.getRealmFromRequest(getRequest());
steps = importExport.importXacml(realm, entity.getStream(), getAdminToken(), dryRun);
if (steps.isEmpty()) {
throw new ResourceException(new Status(BAD_REQUEST, "No policies found in XACML document", null, null));
}
List<Map<String, String>> result = new ArrayList<Map<String, String>>();
for (XACMLExportImport.ImportStep step : steps) {
Map<String, String> stepResult = new HashMap<String, String>();
stepResult.put("status", String.valueOf(step.getDiffStatus().getCode()));
stepResult.put("name", step.getPrivilege().getName());
result.add(stepResult);
}
getResponse().setStatus(Status.SUCCESS_OK);
return jacksonRepresentationFactory.create(result);
} catch (EntitlementException e) {
debug.warning("Importing XACML to policies failed", e);
throw new ResourceException(new Status(BAD_REQUEST, e, e.getLocalizedMessage(getRequestLocale()), null, null));
} catch (IOException e) {
debug.warning("Reading XACML import failed", e);
throw new ResourceException(new Status(BAD_REQUEST, e, e.getLocalizedMessage(), null, null));
}
}
use of org.restlet.resource.Post in project OpenAM by OpenRock.
the class ConnectClientRegistration method createClient.
/**
* Handles POST requests to the OpenId Connect client registration endpoint for creating OpenId Connect client
* registrations.
*
* @param entity The representation of the client registration details.
* @return The representation of the client registration details as created in the store.
* @throws OAuth2RestletException If an error occurs whilst processing the client registration.
*/
@Post
public Representation createClient(Representation entity) throws OAuth2RestletException {
final OAuth2Request request = requestFactory.create(getRequest());
final ChallengeResponse authHeader = getRequest().getChallengeResponse();
final String accessToken = authHeader != null ? authHeader.getRawValue() : null;
try {
final String deploymentUrl = getRequest().getHostRef().toString() + "/" + getRequest().getResourceRef().getSegments().get(0);
final JsonValue registration = clientRegistrationService.createRegistration(accessToken, deploymentUrl, request);
setStatus(Status.SUCCESS_CREATED);
return jacksonRepresentationFactory.create(registration.asMap());
} catch (OAuth2Exception e) {
throw new OAuth2RestletException(e.getStatusCode(), e.getError(), e.getMessage(), null);
}
}
use of org.restlet.resource.Post in project netxms by netxms.
the class Sessions method onPost.
/* (non-Javadoc)
* @see org.netxms.websvc.handlers.AbstractHandler#onPost(org.restlet.representation.Representation)
*/
@Override
@Post
public Representation onPost(Representation entity) throws Exception {
String login = null;
String password = null;
if (entity != null) {
JSONObject request = new JsonRepresentation(entity).getJsonObject();
login = request.getString("login");
password = request.getString("password");
} else {
log.warn("No POST data in login call, looking for authentication data instead...");
String authHeader = getHeader("Authorization");
if ((authHeader != null) && !authHeader.isEmpty()) {
String[] values = decodeBase64(authHeader).split(":", 2);
if (values.length == 2) {
login = values[0];
password = values[1];
}
}
}
if ((login == null) || (password == null)) {
log.warn("Login or password not specified in login call");
return new StringRepresentation(createErrorResponse(RCC.INVALID_REQUEST).toString(), MediaType.APPLICATION_JSON);
}
SessionToken token = login(login, password);
log.info("Logged in to NetXMS server, assigned session id " + token.getGuid());
getCookieSettings().add(new CookieSetting(0, "session_handle", token.getGuid().toString(), "/", null));
getResponse().getHeaders().add(new Header("Session-Id", token.getGuid().toString()));
JSONObject response = new JSONObject();
response.put("session", token.getGuid().toString());
response.put("serverVersion", getSession().getServerVersion());
return new StringRepresentation(response.toString(), MediaType.APPLICATION_JSON);
}
Aggregations