Search in sources :

Example 91 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project netxms by netxms.

the class AccessIntegrationTools method onPost.

/* (non-Javadoc)
    * @see org.netxms.websvc.handlers.AbstractHandler#onPost(org.restlet.representation.Representation)
    */
@Override
@Post
public Representation onPost(Representation entity) throws Exception {
    int rc = RCC.ACCESS_DENIED;
    if (entity != null) {
        JSONObject request = new JsonRepresentation(entity).getJsonObject();
        String login = request.getString("login");
        String password = request.getString("password");
        if ((login != null) || (password != null)) {
            NXCSession session = new NXCSession(properties.getServerAddress(), properties.getServerPort());
            session.connect();
            session.login(login, (password == null) ? "" : password);
            if ((session.getUserSystemRights() & UserAccessRights.SYSTEM_ACCESS_EXTERNAL_INTEGRATION) != 0)
                rc = RCC.SUCCESS;
            session.disconnect();
        } else {
            log.debug("Login or password not specified in login call");
            rc = RCC.INVALID_REQUEST;
        }
    } else {
        log.debug("No POST data in login call");
        rc = RCC.INVALID_REQUEST;
    }
    return new StringRepresentation(createErrorResponse(rc).toString(), MediaType.APPLICATION_JSON);
}
Also used : NXCSession(org.netxms.client.NXCSession) JSONObject(org.json.JSONObject) StringRepresentation(org.restlet.representation.StringRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) Post(org.restlet.resource.Post)

Example 92 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project vcell by virtualcell.

the class BiomodelBNGLServerResource method get_xml.

@Override
@Get(BiomodelBNGLResource.APPLICATION_BNGL_XML)
public StringRepresentation get_xml() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
    String vcml = getBiomodelBNGL(vcellUser);
    if (vcml != null) {
        String bioModelID = (String) getRequestAttributes().get(VCellApiApplication.BIOMODELID);
        setAttribute("Content-Disposition", "attachment; filename=\"VCBioModel_" + bioModelID + ".vcml\"");
        return new StringRepresentation(vcml, BiomodelBNGLResource.VCDOC_MEDIATYPE);
    }
    throw new RuntimeException("biomodel not found");
}
Also used : User(org.vcell.util.document.User) StringRepresentation(org.restlet.representation.StringRepresentation) VCellApiApplication(org.vcell.rest.VCellApiApplication) Get(org.restlet.resource.Get)

Example 93 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project vcell by virtualcell.

the class BiomodelSimulationStartServerResource method start.

@Override
public Representation start() {
    VCellApiApplication application = ((VCellApiApplication) getApplication());
    User vcellUser = application.getVCellUser(getChallengeResponse(), AuthenticationPolicy.prohibitInvalidCredentials);
    RestDatabaseService restDatabaseService = application.getRestDatabaseService();
    try {
        SimulationRep simRep = restDatabaseService.startSimulation(this, vcellUser);
        Representation representation = new StringRepresentation("simulation started", MediaType.TEXT_PLAIN);
        redirectSeeOther("/" + VCellApiApplication.SIMTASK + "?" + SimulationTasksServerResource.PARAM_SIM_ID + "=" + simRep.getKey().toString() + "&" + SimulationTasksServerResource.PARAM_STATUS_COMPLETED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_DISPATCHED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_FAILED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_QUEUED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_RUNNING + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_STOPPED + "=on" + "&" + SimulationTasksServerResource.PARAM_STATUS_WAITING + "=on" + "&" + SimulationTasksServerResource.PARAM_START_ROW + "=1" + "&" + SimulationTasksServerResource.PARAM_MAX_ROWS + "=" + Integer.toString(simRep.getScanCount() * 4));
        return representation;
    } catch (PermissionException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized to start simulation");
    } catch (ObjectNotFoundException e) {
        e.printStackTrace();
        throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation not found");
    } catch (Exception e) {
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : PermissionException(org.vcell.util.PermissionException) User(org.vcell.util.document.User) StringRepresentation(org.restlet.representation.StringRepresentation) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) VCellApiApplication(org.vcell.rest.VCellApiApplication) StringRepresentation(org.restlet.representation.StringRepresentation) Representation(org.restlet.representation.Representation) ResourceException(org.restlet.resource.ResourceException) SimulationRep(cbit.vcell.modeldb.SimulationRep) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException)

Example 94 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project vcell by virtualcell.

the class BiomodelVCMLModelInfoResource method get_html.

@Get("text/html")
public StringRepresentation get_html() {
    try {
        // VCellApiApplication application = ((VCellApiApplication)getApplication());
        // User vcellUser = application.getVCellUser(getChallengeResponse(),AuthenticationPolicy.ignoreInvalidCredentials);
        String biomodelid = getQueryValue(VCellApiApplication.BIOMODELID);
        String modelName = getQueryValue(VCellApiApplication.MODELNAME);
        // Create User so we don't need authentication for ModelBricks
        User modelBrickUser = new User("ModelBrick", new KeyValue("101222366"));
        BioModel bm = null;
        if (biomodelid != null) {
            bm = getBiomodel(new KeyValue(biomodelid), modelBrickUser);
        } else if (modelName != null) {
            bm = getBiomodel(modelName, modelBrickUser);
        } else {
            throw new Exception("expecting '" + VCellApiApplication.BIOMODELID + "' or '" + VCellApiApplication.MODELNAME + "' in query parameters, " + getRequest().getResourceRef().getQuery());
        }
        StringBuffer sb = createHtml(bm);
        return new StringRepresentation(sb.toString(), MediaType.TEXT_HTML);
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof ResourceException) {
            throw (ResourceException) e;
        }
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
    }
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) StringRepresentation(org.restlet.representation.StringRepresentation) BioModel(cbit.vcell.biomodel.BioModel) ResourceException(org.restlet.resource.ResourceException) BigString(org.vcell.util.BigString) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) ResourceException(org.restlet.resource.ResourceException) Get(org.restlet.resource.Get)

Example 95 with StringRepresentation

use of org.restlet.representation.StringRepresentation in project vcell by virtualcell.

the class OptimizationRunServerResource method run.

@Override
@Post
public Representation run(Representation optProblemJson) {
    OptSocketStreams optSocketStreams = (OptSocketStreams) doOP(optProblemJson, this);
    getResponse().setStatus(Status.SUCCESS_OK);
    Representation representation = new StringRepresentation(optSocketStreams.optID, MediaType.TEXT_PLAIN);
    return representation;
}
Also used : StringRepresentation(org.restlet.representation.StringRepresentation) JsonRepresentation(org.restlet.ext.json.JsonRepresentation) StringRepresentation(org.restlet.representation.StringRepresentation) Representation(org.restlet.representation.Representation) Post(org.restlet.resource.Post)

Aggregations

StringRepresentation (org.restlet.representation.StringRepresentation)130 HttpVerb (com.linkedin.pinot.common.restlet.swagger.HttpVerb)30 Paths (com.linkedin.pinot.common.restlet.swagger.Paths)30 Summary (com.linkedin.pinot.common.restlet.swagger.Summary)30 IOException (java.io.IOException)30 Tags (com.linkedin.pinot.common.restlet.swagger.Tags)29 ZkClient (org.apache.helix.manager.zk.ZkClient)29 JSONObject (org.json.JSONObject)23 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)19 ZNRecord (org.apache.helix.ZNRecord)17 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)17 JSONException (org.json.JSONException)17 Representation (org.restlet.representation.Representation)15 Responses (com.linkedin.pinot.common.restlet.swagger.Responses)14 HelixException (org.apache.helix.HelixException)12 JSONArray (org.json.JSONArray)12 Builder (org.apache.helix.PropertyKey.Builder)11 Get (org.restlet.resource.Get)10 Post (org.restlet.resource.Post)9 ResourceException (org.restlet.resource.ResourceException)9