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);
}
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");
}
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());
}
}
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());
}
}
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;
}
Aggregations