Search in sources :

Example 1 with Component

use of org.restlet.Component in project GeoGig by boundlessgeo.

the class Main method startServer.

static void startServer(String repo) throws Exception {
    GeoGIG geogig = loadGeoGIG(repo);
    org.restlet.Context context = new org.restlet.Context();
    Application application = new Main(geogig);
    application.setContext(context);
    Component comp = new Component();
    comp.getDefaultHost().attach(application);
    comp.getServers().add(Protocol.HTTP, 8182);
    comp.start();
}
Also used : Context(org.locationtech.geogig.api.Context) Component(org.restlet.Component) Application(org.restlet.Application) GeoGIG(org.locationtech.geogig.api.GeoGIG)

Example 2 with Component

use of org.restlet.Component in project AJSC by att.

the class RestletSpringServlet method getServer.

public HttpServerHelper getServer(HttpServletRequest request) {
    // Lazy initialization with double-check.
    HttpServerHelper result;
    // // Find the attribute name to use to store the server
    // // reference
    final String serverAttributeName = getInitParameter(NAME_SERVER_ATTRIBUTE, NAME_SERVER_ATTRIBUTE_DEFAULT + "." + getServletName());
    Component component = getComponent();
    // System.out.println("isFirstRequest:" +isFirstRequest);
    // if ((!isFirstRequest) && isNewRouteAdded(request, component)) {
    // result = createServer(request, component);
    // getServletContext().setAttribute(serverAttributeName, result);
    // } else {
    // System.out.println("Super getServer");
    result = super.getServer(request);
    // }
    isFirstRequest = false;
    return result;
}
Also used : HttpServerHelper(org.restlet.engine.adapter.HttpServerHelper) Component(org.restlet.Component)

Example 3 with Component

use of org.restlet.Component in project lobcder by skoulouzis.

the class RestletFileserver method main.

public static void main(String[] args) throws Exception {
    Component component = new Component();
    component.getServers().add(Protocol.HTTP, 8080);
    // Restlet logs requests by default
    // component.getLogService().setEnabled(false);
    component.getDefaultHost().attach(new Application() {

        @Override
        public Restlet createInboundRoot() {
            FileSystemResourceFactory factory = new FileSystemResourceFactory(new File(System.getProperty("user.home")), new NullSecurityManager());
            factory.setContentService(new SimpleFileContentService());
            factory.setLockManager(new FsMemoryLockManager());
            return new WebDavRestlet(factory);
        }
    });
    component.start();
    System.out.println("Restlet demo fileserver started, open http://localhost:8080 in your browser or WebDAV client...");
}
Also used : Restlet(org.restlet.Restlet) WebDavRestlet(io.milton.restlet.WebDavRestlet) NullSecurityManager(io.milton.http.fs.NullSecurityManager) FileSystemResourceFactory(io.milton.http.fs.FileSystemResourceFactory) FsMemoryLockManager(io.milton.http.fs.FsMemoryLockManager) WebDavRestlet(io.milton.restlet.WebDavRestlet) Component(org.restlet.Component) SimpleFileContentService(io.milton.http.fs.SimpleFileContentService) Application(org.restlet.Application) File(java.io.File)

Example 4 with Component

use of org.restlet.Component in project vcell by virtualcell.

the class TestRestServerBlinov method main.

public static void main(String[] args) {
    try {
        // The following mimics the the VCell server and database without having to connect to them
        // arg[0] (first argument) is directory path on local system where you have exported .vcml models from VCell client
        // that you want to use to test the biomodel web page generating code, these files are a proxy for the VCell database
        // Test biomodel vcml documents
        File biomodel_vcml_dir = new File(args[0]);
        File[] dirFiles = biomodel_vcml_dir.listFiles(new FileFilter() {

            @Override
            public boolean accept(File pathname) {
                return pathname.isFile();
            }
        });
        // final List<Element> parseOverrideElementsFromVCML = MathOverrides.parseOverrideElementsFromVCML(new CommentStringTokenizer(xmlString));
        for (int i = 0; i < dirFiles.length; i++) {
            try {
                // Read in each file found in the directory passed in args[0] check if it can be imported as a BioModel
                // If it fails just skip.
                // The imported BioModel is cached as BioModelRep info and are returned when the Resource objects make a 'query'
                final BioModel bm = XmlHelper.XMLToBioModel(new XMLSource(dirFiles[i]));
                mapBMidToFileName.put(bm.getVersion().getVersionKey().toString(), dirFiles[i]);
                final SimulationContext[] simulationContexts = bm.getSimulationContexts();
                SimContextRep[] scr = new SimContextRep[simulationContexts.length];
                KeyValue[] scrKeys = new KeyValue[simulationContexts.length];
                for (int j = 0; j < simulationContexts.length; j++) {
                    // KeyValue scKey, BigDecimal branchID, String name, User owner, KeyValue mathKey)
                    scrKeys[j] = simulationContexts[j].getVersion().getVersionKey();
                    scr[j] = new SimContextRep(scrKeys[j], simulationContexts[j].getVersion().getBranchID(), simulationContexts[j].getName(), simulationContexts[j].getVersion().getOwner(), simulationContexts[j].getModel().getKey());
                }
                final Simulation[] simulations = bm.getSimulations();
                SimulationRep[] sreps = new SimulationRep[simulations.length];
                KeyValue[] srepKeys = new KeyValue[simulations.length];
                for (int j = 0; j < simulations.length; j++) {
                    // KeyValue key, BigDecimal branchID, String name, User owner, KeyValue mathKey, SolverTaskDescription solverTaskDescription, Element[] mathOverrideElements
                    srepKeys[j] = simulations[j].getVersion().getVersionKey();
                    // public SimulationRep(KeyValue key, BigDecimal branchID, String name, User owner, KeyValue mathKey, SolverTaskDescription solverTaskDescription, MathOverrides.Element[] mathOverrideElements) {
                    // final MathOverrides mathOverrides = simulations[j].getSolverTaskDescription().getSimulation().getMathOverrides();
                    // for(int k=0;k<mathOverrides.getScanCount();k++) {
                    // MathOverrides.Element elem = new Element(mathOverrides.get, null);
                    // }
                    sreps[j] = new SimulationRep(srepKeys[j], simulations[j].getVersion().getBranchID(), simulations[j].getName(), simulations[j].getVersion().getOwner(), simulations[j].getMathDescription().getKey(), simulations[j].getSolverTaskDescription(), new MathOverrides.Element[] {});
                }
                // KeyValue bmKey, String name, int privacy, User[] groupUsers, Date date, String annot, BigDecimal branchID, KeyValue modelRef, User owner, KeyValue[] simKeyList, KeyValue[] simContextKeyList)
                BioModelRep bmrep = new BioModelRep(bm.getVersion().getVersionKey(), bm.getName(), bm.getVersion().getGroupAccess().getGroupid().intValue(), new User[] {}, bm.getVersion().getDate(), bm.getVersion().getAnnot(), bm.getVersion().getBranchID(), bm.getModel().getVersion().getVersionKey(), bm.getVersion().getOwner(), srepKeys, scrKeys);
                for (int j = 0; j < simulationContexts.length; j++) {
                    bmrep.addSimContextRep(scr[j]);
                }
                for (int j = 0; j < simulations.length; j++) {
                    bmrep.addSimulationRep(sreps[j]);
                }
                bioModelRepArr.add(bmrep);
                mapBMidToBiomodelRep.put(bm.getVersion().getVersionKey().toString(), bmrep);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        // Create a Restlet server on local machine that will accept queries from a regular web browser
        Component restletComponent = new Component();
        // So FreeMarker html formatting scripts work (.ftl files in {EclipseWorkspaceRootDir}/vcell/vcell-api/src/main/resources/(*.ftl}
        restletComponent.getClients().add(Protocol.CLAP);
        Server server = restletComponent.getServers().add(Protocol.HTTP, 8182);
        server.getContext().getParameters().add("useForwardedForHeader", "true");
        // restletComponent.getInternalRouter().setDefaultMatchingMode(Template.MODE_STARTS_WITH);
        final VirtualHost defaultHost = restletComponent.getDefaultHost();
        // getVcellApiApplication() actually makes the connections URL->ServerResource
        // e.g. http://{HostNameWhereThisProgramIsRunning}:8182/biomodel -> BiomodelServerResource
        // See getVCellApiApplication() for other mappings (router attachments)
        defaultHost.attach(getVCellApiApplication());
        // Start servlet which can be accessed with base URL http://{HostNameWhereThisProgramIsRunning}:8182
        restletComponent.start();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Server(org.restlet.Server) BioModelRep(cbit.vcell.modeldb.BioModelRep) SimulationContext(cbit.vcell.mapping.SimulationContext) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) VirtualHost(org.restlet.routing.VirtualHost) FileFilter(java.io.FileFilter) Component(org.restlet.Component) File(java.io.File) XMLSource(cbit.vcell.xml.XMLSource) SimContextRep(cbit.vcell.modeldb.SimContextRep) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 5 with Component

use of org.restlet.Component in project pinot by linkedin.

the class StarTreeJsonNode method startServer.

private void startServer(final File segmentDirectory, final String json) throws Exception {
    Component component = new Component();
    int port = 8090;
    component.getServers().add(Protocol.HTTP, port);
    component.getClients().add(Protocol.FILE);
    Application application = new Application() {

        @Override
        public Restlet createInboundRoot() {
            Router router = new Router(getContext());
            StarTreeViewRestResource.json = json;
            router.attach("/data", StarTreeViewRestResource.class);
            Directory directory = new Directory(getContext(), getClass().getClassLoader().getResource("star-tree.html").toString());
            router.attach(directory);
            return router;
        }
    };
    VirtualHost defaultHost = component.getDefaultHost();
    defaultHost.attach(application);
    component.start();
    LOGGER.info("Go to http://{}:{}/  to view the star tree", VirtualHost.getLocalHostName(), port);
}
Also used : Router(org.restlet.routing.Router) VirtualHost(org.restlet.routing.VirtualHost) Component(org.restlet.Component) Application(org.restlet.Application) Directory(org.restlet.resource.Directory)

Aggregations

Component (org.restlet.Component)10 Application (org.restlet.Application)4 File (java.io.File)2 IOException (java.io.IOException)2 GeoGIG (org.locationtech.geogig.api.GeoGIG)2 VirtualHost (org.restlet.routing.VirtualHost)2 BioModel (cbit.vcell.biomodel.BioModel)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 BioModelRep (cbit.vcell.modeldb.BioModelRep)1 SimContextRep (cbit.vcell.modeldb.SimContextRep)1 SimulationRep (cbit.vcell.modeldb.SimulationRep)1 Simulation (cbit.vcell.solver.Simulation)1 XMLSource (cbit.vcell.xml.XMLSource)1 FileSystemResourceFactory (io.milton.http.fs.FileSystemResourceFactory)1 FsMemoryLockManager (io.milton.http.fs.FsMemoryLockManager)1 NullSecurityManager (io.milton.http.fs.NullSecurityManager)1 SimpleFileContentService (io.milton.http.fs.SimpleFileContentService)1 WebDavRestlet (io.milton.restlet.WebDavRestlet)1 OpenemsException (io.openems.common.exceptions.OpenemsException)1 ConnectionConfig (io.restassured.config.ConnectionConfig)1