Search in sources :

Example 1 with Post

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;
}
Also used : Tenant(com.linkedin.pinot.common.config.Tenant) StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) Post(org.restlet.resource.Post)

Example 2 with Post

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");
}
Also used : JSONObject(org.json.JSONObject) TextInput(org.opensextant.data.TextInput) Post(org.restlet.resource.Post)

Example 3 with Post

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));
    }
}
Also used : Status(org.restlet.data.Status) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) XACMLExportImport(com.sun.identity.entitlement.xacml3.XACMLExportImport) IOException(java.io.IOException) ImportStep(com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep) EntitlementException(com.sun.identity.entitlement.EntitlementException) ResourceException(org.restlet.resource.ResourceException) ResourceException(org.forgerock.json.resource.ResourceException) Map(java.util.Map) HashMap(java.util.HashMap) ImportStep(com.sun.identity.entitlement.xacml3.XACMLExportImport.ImportStep) Post(org.restlet.resource.Post)

Example 4 with Post

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);
    }
}
Also used : OAuth2Request(org.forgerock.oauth2.core.OAuth2Request) OAuth2RestletException(org.forgerock.oauth2.restlet.OAuth2RestletException) JsonValue(org.forgerock.json.JsonValue) OAuth2Exception(org.forgerock.oauth2.core.exceptions.OAuth2Exception) ChallengeResponse(org.restlet.data.ChallengeResponse) Post(org.restlet.resource.Post)

Example 5 with Post

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);
}
Also used : CookieSetting(org.restlet.data.CookieSetting) JSONObject(org.json.JSONObject) Header(org.restlet.data.Header) StringRepresentation(org.restlet.representation.StringRepresentation) SessionToken(org.netxms.websvc.SessionToken) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Post(org.restlet.resource.Post)

Aggregations

Post (org.restlet.resource.Post)20 StringRepresentation (org.restlet.representation.StringRepresentation)9 OAuth2Request (org.forgerock.oauth2.core.OAuth2Request)7 IOException (java.io.IOException)5 JsonRepresentation (org.restlet.ext.json.JsonRepresentation)5 HashMap (java.util.HashMap)4 JsonValue (org.forgerock.json.JsonValue)4 OAuth2Exception (org.forgerock.oauth2.core.exceptions.OAuth2Exception)4 JSONException (org.json.JSONException)4 JSONObject (org.json.JSONObject)4 Representation (org.restlet.representation.Representation)4 OAuth2ProviderSettings (org.forgerock.oauth2.core.OAuth2ProviderSettings)3 Request (org.restlet.Request)3 DeviceCode (org.forgerock.oauth2.core.DeviceCode)2 InvalidClientException (org.forgerock.oauth2.core.exceptions.InvalidClientException)2 RedirectUriMismatchException (org.forgerock.oauth2.core.exceptions.RedirectUriMismatchException)2 ResourceOwnerAuthenticationRequired (org.forgerock.oauth2.core.exceptions.ResourceOwnerAuthenticationRequired)2 ResourceSetDescription (org.forgerock.oauth2.resources.ResourceSetDescription)2 ISwitchManager (org.openkilda.floodlight.switchmanager.ISwitchManager)2 MessageError (org.openkilda.messaging.error.MessageError)2