Search in sources :

Example 1 with HealthRestlet

use of org.vcell.rest.health.HealthRestlet in project vcell by virtualcell.

the class VCellApiApplication method createInboundRoot.

@Override
public Restlet createInboundRoot() {
    System.setProperty("java.net.preferIPv4Stack", "true");
    /**
     * curl --insecure
     * "https://nrcamdev5.cam.uchc.edu:8080/access_token?user_id=schaff&user_password=056F4508E0DE1ED22D4D6F541E91460694A00E16&client_id=85133f8d-26f7-4247-8356-d175399fc2e6"
     *
     * {"token":"9002b7ba-004f-40aa-a639-9136364850a6","creationDateSeconds"
     * :1376586968,"expireDateSeconds":1376673368,"userId":"schaff",
     * "userKey":"17"}
     *
     * curl --verbose --insecure -H
     * "Authorization: CUSTOM access_token=9002b7ba-004f-40aa-a639-9136364850a6"
     * https://nrcamdev5.cam.uchc.edu:8080/simtask?running=on
     *
     * [{"simKey":"83642386","simName":"Simulation5","userName":"schaff",
     * "userKey"
     * :"17","htcJobId":"SGE:283488","status":"running","startdate":
     * 1375408007000
     * ,"jobIndex":0,"taskId":0,"message":"0.7202440000182919","site"
     * :"REL","computeHost"
     * :"compute-2-0.local","schedulerStatus":"running","hasData"
     * :true,"scanCount"
     * :1,"bioModelLink":{"bioModelKey":"83642503","bioModelBranchId"
     * :"83640470"
     * ,"bioModelName":"CSHL 2011 Exercise 6_Jim_2013","simContextKey"
     * :"83642357","simContextBranchId":"83642358","simContextName":
     * "smoldyn_repressor_activator_oscillations"
     * }},{"simKey":"38442198","simName"
     * :"Simulation0","userName":"schaff","userKey"
     * :"17","status":"running","startdate"
     * :1264828384000,"jobIndex":0,"taskId"
     * :0,"message":"processing geometry..."
     * ,"site":"SCHAFF_WSAD","computeHost"
     * :"\u003c\u003clocal\u003e\u003e","schedulerStatus"
     * :"running","hasData"
     * :false,"scanCount":1,"mathModelLink":{"mathModelKey"
     * :"38442201","mathModelBranchId"
     * :"38442202","mathModelName":"tempMath77"}}]
     */
    // Attach a guard to secure access to user parts of the api
    boolean bCookieOptional = true;
    final VCellCookieAuthenticator cookieAuthenticator = new VCellCookieAuthenticator(this, bCookieOptional, "My cookie realm", "MyExtraSecretKey".getBytes());
    cookieAuthenticator.setLoginPath("/" + LOGIN);
    cookieAuthenticator.setLogoutPath("/" + LOGOUT);
    cookieAuthenticator.setCookieName("org.vcell.auth");
    cookieAuthenticator.setLoginFormPath("/" + LOGINFORM);
    cookieAuthenticator.setIdentifierFormName(IDENTIFIER_FORMNAME);
    cookieAuthenticator.setSecretFormName(SECRET_FORMNAME);
    cookieAuthenticator.setRedirectQueryName(REDIRECTURL_FORMNAME);
    cookieAuthenticator.setVerifier(userVerifier);
    // 15 minutes (in units of seconds).
    cookieAuthenticator.setMaxCookieAge(15 * 60);
    String ROOT_URI = javascriptDir.toURI().toString();
    String WEBAPP_URI = new File(javascriptDir.getParentFile(), "webapp").toURI().toString();
    System.out.println("using uri=" + ROOT_URI + " for scripts directory");
    String SCRIPTS = "scripts";
    Router rootRouter = new Router(getContext());
    rootRouter.attach("/" + SCRIPTS, new Directory(getContext(), ROOT_URI));
    rootRouter.attach("/" + ACCESSTOKENRESOURCE, AccessTokenServerResource.class);
    rootRouter.attach("/" + WEBAPP, new Directory(getContext(), WEBAPP_URI));
    rootRouter.attach("/" + OPTIMIZATION, OptimizationRunServerResource.class);
    rootRouter.attach("/" + OPTIMIZATION + "/{" + OPTIMIZATIONID + "}", OptimizationServerResource.class);
    rootRouter.attach("/" + PUBLICATION, PublicationsServerResource.class);
    rootRouter.attach("/" + PUBLICATION + "/{" + PUBLICATIONID + "}", PublicationServerResource.class);
    rootRouter.attach("/" + BIOMODEL, BiomodelsServerResource.class);
    rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}", BiomodelServerResource.class);
    rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + VCML_DOWNLOAD, BiomodelVCMLServerResource.class);
    rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + DIAGRAM_DOWNLOAD, BiomodelDiagramServerResource.class);
    rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}", BiomodelSimulationServerResource.class);
    rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}/" + SAVESIMULATION, BiomodelSimulationSaveServerResource.class);
    rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}/" + STARTSIMULATION, BiomodelSimulationStartServerResource.class);
    rootRouter.attach("/" + BIOMODEL + "/{" + BIOMODELID + "}/" + SIMULATION + "/{" + SIMULATIONID + "}/" + STOPSIMULATION, BiomodelSimulationStopServerResource.class);
    rootRouter.attach("/" + SIMSTATUS, SimulationStatusServerResource.class);
    rootRouter.attach("/" + SIMTASK, SimulationTasksServerResource.class);
    rootRouter.attach("/" + SIMTASK + "/{" + SIMTASKID + "}", SimulationTaskServerResource.class);
    rootRouter.attach("/" + SIMDATA + "/{" + SIMDATAID + "}", SimDataServerResource.class);
    rootRouter.attach("/" + SIMDATA + "/{" + SIMDATAID + "}/jobindex/{" + JOBINDEX + "}", SimDataValuesServerResource.class);
    rootRouter.attach("/" + LOGIN, new LoginRestlet(getContext()));
    rootRouter.attach("/" + LOGINFORM, new LoginFormRestlet(getContext()));
    rootRouter.attach("/" + REGISTRATIONFORM, new RegistrationFormRestlet(getContext()));
    rootRouter.attach("/" + NEWUSER, new NewUserRestlet(getContext()));
    rootRouter.attach("/" + NEWUSER_VERIFY, new EmailTokenVerifyRestlet(getContext()));
    rootRouter.attach("/" + LOSTPASSWORD, new LostPasswordRestlet(getContext()));
    rootRouter.attach("/" + SWVERSION, new SWVersionRestlet(getContext()));
    rootRouter.attach("/" + RPC, new RpcRestlet(getContext()));
    rootRouter.attach("/" + EVENTS, new EventsRestlet(getContext()));
    rootRouter.attach("/" + HEALTH, new HealthRestlet(getContext()));
    rootRouter.attach("/" + ADMIN + "/" + ADMIN_JOBS, new AdminJobsRestlet(getContext()));
    rootRouter.attach("/auth/user", new Restlet(getContext()) {

        @Override
        public void handle(Request request, Response response) {
            if (request.getMethod().equals(Method.GET)) {
                VCellApiApplication application = ((VCellApiApplication) getApplication());
                User vcellUser = application.getVCellUser(request.getChallengeResponse(), AuthenticationPolicy.ignoreInvalidCredentials);
                String jsonString = "{}";
                if (vcellUser != null) {
                    jsonString = "{user: \"" + vcellUser.getName() + "\"}";
                }
                response.setEntity(new StringRepresentation(jsonString));
            }
        }
    });
    cookieAuthenticator.setNext(rootRouter);
    return cookieAuthenticator;
}
Also used : User(org.vcell.util.document.User) SWVersionRestlet(org.vcell.rest.users.SWVersionRestlet) RpcRestlet(org.vcell.rest.rpc.RpcRestlet) SWVersionRestlet(org.vcell.rest.users.SWVersionRestlet) RegistrationFormRestlet(org.vcell.rest.users.RegistrationFormRestlet) LoginRestlet(org.vcell.rest.users.LoginRestlet) HealthRestlet(org.vcell.rest.health.HealthRestlet) EventsRestlet(org.vcell.rest.events.EventsRestlet) NewUserRestlet(org.vcell.rest.users.NewUserRestlet) EmailTokenVerifyRestlet(org.vcell.rest.users.EmailTokenVerifyRestlet) LostPasswordRestlet(org.vcell.rest.users.LostPasswordRestlet) Restlet(org.restlet.Restlet) AdminJobsRestlet(org.vcell.rest.admin.AdminJobsRestlet) LoginFormRestlet(org.vcell.rest.users.LoginFormRestlet) EventsRestlet(org.vcell.rest.events.EventsRestlet) LoginFormRestlet(org.vcell.rest.users.LoginFormRestlet) Request(org.restlet.Request) Router(org.restlet.routing.Router) RegistrationFormRestlet(org.vcell.rest.users.RegistrationFormRestlet) RpcRestlet(org.vcell.rest.rpc.RpcRestlet) ChallengeResponse(org.restlet.data.ChallengeResponse) Response(org.restlet.Response) LostPasswordRestlet(org.vcell.rest.users.LostPasswordRestlet) NewUserRestlet(org.vcell.rest.users.NewUserRestlet) AdminJobsRestlet(org.vcell.rest.admin.AdminJobsRestlet) StringRepresentation(org.restlet.representation.StringRepresentation) EmailTokenVerifyRestlet(org.vcell.rest.users.EmailTokenVerifyRestlet) LoginRestlet(org.vcell.rest.users.LoginRestlet) HealthRestlet(org.vcell.rest.health.HealthRestlet) File(java.io.File) Directory(org.restlet.resource.Directory)

Aggregations

File (java.io.File)1 Request (org.restlet.Request)1 Response (org.restlet.Response)1 Restlet (org.restlet.Restlet)1 ChallengeResponse (org.restlet.data.ChallengeResponse)1 StringRepresentation (org.restlet.representation.StringRepresentation)1 Directory (org.restlet.resource.Directory)1 Router (org.restlet.routing.Router)1 AdminJobsRestlet (org.vcell.rest.admin.AdminJobsRestlet)1 EventsRestlet (org.vcell.rest.events.EventsRestlet)1 HealthRestlet (org.vcell.rest.health.HealthRestlet)1 RpcRestlet (org.vcell.rest.rpc.RpcRestlet)1 EmailTokenVerifyRestlet (org.vcell.rest.users.EmailTokenVerifyRestlet)1 LoginFormRestlet (org.vcell.rest.users.LoginFormRestlet)1 LoginRestlet (org.vcell.rest.users.LoginRestlet)1 LostPasswordRestlet (org.vcell.rest.users.LostPasswordRestlet)1 NewUserRestlet (org.vcell.rest.users.NewUserRestlet)1 RegistrationFormRestlet (org.vcell.rest.users.RegistrationFormRestlet)1 SWVersionRestlet (org.vcell.rest.users.SWVersionRestlet)1 User (org.vcell.util.document.User)1