Package org.restlet

Examples of org.restlet.Server


        }
    }

    protected String start() throws Exception {
        this.component = new Component();
        final Server server = this.component.getServers().add(Protocol.HTTP, 0);
        // server.getContext().getParameters().add("tracing", "true");
        final Application application = createApplication(this.component);

        this.component.getDefaultHost().attach(application);
        this.component.start();

        return "http://localhost:" + server.getEphemeralPort() + "/test";
    }
View Full Code Here


                        headers);
            }
        };

        // Create the HTTP server and listen on port 8111
        final Server server = new Server(Protocol.HTTP, 8111, restlet);
        server.start();
    }
View Full Code Here

    private static boolean TRACE;

    public static void main(String[] args) throws Exception {
        Engine.setLogLevel(Level.FINE);
        Server server = null;

        if (args.length == 1) {
            server = new Server(new Context(), Protocol.SIP,
                    Integer.parseInt(args[0]), UacServerResource.class);
        } else {
            server = new Server(new Context(), Protocol.SIP,
                    UacServerResource.class);
        }

        ClassLoader cl = UacServerResource.class.getClassLoader();
        InputStream is = cl.getResourceAsStream("UacServerResource.properties");

        if (is == null) {
            is = cl.getResourceAsStream("org/restlet/example/ext/sip/UacServerResource.properties");
        }

        if (is != null) {
            Properties p = new Properties();
            p.load(is);

            for (Map.Entry<Object, Object> entry : p.entrySet()) {
                server.getContext()
                        .getParameters()
                        .add((String) entry.getKey(), (String) entry.getValue());
            }

            // Sets the sleep time of this resource
            String str = p.getProperty("sleepTime", "100");

            try {
                SLEEP_TIME = Integer.parseInt(str);
            } catch (Throwable e) {
            }

            str = p.getProperty("trace", "false");

            try {
                TRACE = Boolean.parseBoolean(str);
            } catch (Throwable e) {
            }
        }

        server.start();
    }
View Full Code Here

public class ExampleServer {

    public static void main(String[] args) throws Exception {
        // create Component (as ever for Restlet)
        final Component comp = new Component();
        final Server server = comp.getServers().add(Protocol.HTTP, 80);

        // create JAX-RS runtime environment
        final JaxRsApplication application = new JaxRsApplication(comp
                .getContext().createChildContext());

        // attach ApplicationConfig
        application.add(new ExampleApplication());

        // Attach the application to the component and start it
        comp.getDefaultHost().attach(application);
        comp.start();

        System.out.println("Server started on port " + server.getPort());
        System.out.println("Press key to stop server");
        System.in.read();
        System.out.println("Stopping server");
        comp.stop();
        System.out.println("Server stopped");
View Full Code Here

public class RestartTestCase extends RestletTestCase {

    public void testRestart() throws Exception {
        final int waitTime = 100;

        final Server connector = new Server(Protocol.HTTP, TEST_PORT,
                (Restlet) null);

        System.out.print("Starting connector... ");
        connector.start();
        System.out.println("done");
        Thread.sleep(waitTime);

        System.out.print("Stopping connector... ");
        connector.stop();
        System.out.println("done");
        Thread.sleep(waitTime);

        System.out.print("Restarting connector... ");
        connector.start();
        System.out.println("done");
        Thread.sleep(waitTime);
        connector.stop();
    }
View Full Code Here

         getLogger().info("Script Engines: " + w.toString());
      }*/

      for (Configuration.Server serverConf : config.getServers()) {
         getContext().getLogger().info(serverConf.getProtocol().getName()+" listening on " + serverConf.getAddress() + ":" + serverConf.getPort());
         Server server = getServers().add(serverConf.getProtocol(), serverConf.getAddress().equals("*") ? null : serverConf.getAddress(), serverConf.getPort());
         if (serverConf.getProtocol().isConfidential()) {
            if (config.getKeyStorePath() != null) {
               server.getContext().getParameters().add("keystorePath", config.getKeyStorePath().getAbsolutePath());
               server.getContext().getParameters().add("keystorePassword", config.getKeyStorePassword());
               server.getContext().getParameters().add("keyPassword", config.getKeyStorePassword());
            }
         }

         Map<String, ConfiguredHost> confHosts = ifaceHosts.get(serverConf.getKey());
         if (confHosts == null) {
            confHosts = new TreeMap<String, ConfiguredHost>();
            ifaceHosts.put(serverConf.getKey(), confHosts);
         }
         // Configure static hosts
         for (String name : serverConf.getHosts().keySet()) {
            final Configuration.Host host = serverConf.getHosts().get(name);
            if (confHosts.get(host.getName()) != null) {
               getLogger().warning("Ignoring duplicate host name " + host.getName());
            } else {
               Context hostContext = getContext().createChildContext();
              
               ConfiguredHost confHost = new ConfiguredHost(hostContext, getInternalRouter(), serverConf, host, new Date(), true);
               confHosts.put(host.getName(), confHost);
               if (host.getLinks().get("autoconf") != null) {
                  hasStaticAutoConf = true;
               }

               getHosts().add(confHost.getVirtualHost());
            }

         }

         // Configure autoconf
         List<Link> autoFeeds = serverConf.getLinks().get("autoconf");
         if (autoFeeds != null) {
            for (Link link : autoFeeds) {
               addAutoConfiguration(serverConf, link);
            }
         }

      }
      this.getDefaultHost().attach(new Restlet() {

         public void handle(Request request, Response response) {
            response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         }
      });

      // Add the clients
      for (Protocol client : config.getClients()) {
         getClients().add(client);
      }

      for (Server server : getServers()) {
         try {
            server.start();
         } catch (Exception ex) {
            getLogger().log(Level.SEVERE,"Cannot start server.",ex);
         }
      }

View Full Code Here

        // Register the selected connector
        Engine.getInstance().getRegisteredServers().add(0, helper);
        // Engine.setLogLevel(Level.FINEST);

        // Create and start a connector instance
        Server server = new Server(Protocol.HTTP, 8554, new Restlet() {
            @Override
            public void handle(Request request, Response response) {
                try {
                    FileRepresentation fr = new FileRepresentation(
                            "file:///c:/TEST/restlet-jse-2.0.5-ff.zip",
                            MediaType.APPLICATION_ZIP);
                    System.out.println("Size sent: " + fr.getSize());
                    InputRepresentation ir = new InputRepresentation(
                            fr.getStream(), fr.getMediaType());
                    response.setEntity(ir);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

        server.getContext().getParameters().add("tracing", "false");
        server.getContext().getParameters().add("minThreads", "1");
        server.getContext().getParameters().add("lowThreads", "30");
        server.getContext().getParameters().add("maxThreads", "40");
        server.getContext().getParameters().add("maxQueued", "0");
        server.getContext().getParameters().add("directBuffers", "false");
        server.getContext().getParameters().add("workerThreads", "true");
        server.getContext().getParameters().add("pooledConnections", "true");
        server.getContext().getParameters().add("maxIoIdleTimeMs", "3000000");

        server.start();
    }
View Full Code Here

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        component = new Component();
        Server server = component.getServers().add(Protocol.HTTP, 0);
        Application application = new MyApplication();
        component.getDefaultHost().attach(application);
        component.start();
        port = server.getEphemeralPort();
    }
View Full Code Here

        ConnectorHelper<Server> helper;
        helper = new org.restlet.engine.connector.HttpServerHelper(null);
        Engine.getInstance().getRegisteredServers().add(0, helper);
        Engine.setLogLevel(Level.FINE);

        Server server = new Server(new Context(), Protocol.HTTP, 8554,
                new Restlet() {
                    @Override
                    public void handle(Request request, Response response) {
                        FileRepresentation fr = new FileRepresentation(
                                "file:///c:/TEST/restlet-jse-2.0.5-ff.zip",
                                MediaType.APPLICATION_ZIP);
                        System.out.println("Size sent: " + fr.getSize());
                        response.setEntity(fr);
                    }
                });

        server.start();
    }
View Full Code Here

public class TestPostServer {

    public static void main(String[] args) throws Exception {

        Server server = new Server(Protocol.HTTP, 8554, new Restlet() {
            int count = 0;

            @Override
            public void handle(Request request, Response response) {
                try {
                    System.out.println("Request received (" + (++count) + ")");
                    long expectedSize = request.getEntity().getSize();
                    long receivedSize = request.getEntity().exhaust();

                    System.out.println("Size expected: " + expectedSize);
                    System.out.println("Size consumed: " + receivedSize);

                    if ((expectedSize != -1) && (expectedSize != receivedSize)) {
                        System.out.println("ERROR: SOME BYTES WERE LOST!");
                    }
                    System.out
                            .println("--------------------------------------");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

        server.start();
    }
View Full Code Here

TOP

Related Classes of org.restlet.Server

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.