예제 #1
0
 public static void main(String[] args) throws Exception {
   Component component = new Component();
   Server server = new Server(Protocol.HTTP, 8312);
   component.getServers().add(server);
   server.getContext().getParameters().set("maxTotalConnections", Defaults.MAX_CONNECTIONS);
   server.getContext().getParameters().set("maxThreads", Defaults.MAX_THREADS);
   component.getDefaultHost().attach(new SubscriberTest());
   component.start();
 }
예제 #2
0
  public DiscoveryRestServer(int port, IDiscoveryController controller) {
    this.port = port;

    this.component = new Component();
    final Server server = new Server(Protocol.HTTP, this.port);
    server.setContext(OtsoRestletUtils.createContext());
    this.component.getServers().add(server);

    this.application = new OtsopackHttpDiscoveryApplication();
    this.application.setController(controller);
    this.component.getDefaultHost().attach(this.application);
  }
  protected String start() throws Exception {
    this.component = new Component();

    final Server server = this.component.getServers().add(Protocol.HTTPS, 0);
    configureSslServerParameters(server.getContext());
    final Application application = createApplication(this.component);

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

    return "https://localhost:" + server.getEphemeralPort() + "/test";
  }
  /**
   * Constructor.
   *
   * @throws Exception
   */
  public MailServerComponent() throws Exception {
    // Set basic properties
    setName("RESTful Mail Server component");
    setDescription("Example for 'Restlet in Action' book");
    setOwner("Restlet S.A.S.");
    setAuthor("The Restlet Team");

    // Adds a HTTP server connector
    Server server = getServers().add(Protocol.HTTP, 8111);
    server.getContext().getParameters().set("tracing", "false");

    // Attach the application to the default virtual host
    getDefaultHost().attachDefault(new MailServerApplication());
  }
예제 #5
0
  public void activate() throws RESTException {
    /*
     * server opstarten
     */
    servicesByID = new HashMap<String, Object>();
    methodsByString = new HashMap<String, Method>();
    clientsByString = new HashMap<String, ClientResource>();

    component = new Component();
    Server server = component.getServers().add(Protocol.HTTP, 8080);
    try {
      server.start();
    } catch (Exception e1) {
      throw new RESTException("Error starting the server", e1);
    }

    /*
     * ServiceListener that automatically exports services with exported interfaces
     * as defined by the Remote Services specification
     */
    try {
      ServiceTracker serviceTracker =
          new ServiceTracker(
              context,
              context.createFilter("(service.exported.interfaces=*)"),
              new ServiceTrackerCustomizer() {

                @Override
                public Object addingService(ServiceReference ref) {
                  Collection<ExportRegistration> regs = exportService(ref, null);
                  return regs;
                }

                @Override
                public void modifiedService(ServiceReference ref, Object regs) {}

                @Override
                public void removedService(ServiceReference ref, Object regs) {
                  for (ExportRegistration r : (Collection<ExportRegistration>) regs) {
                    r.close();
                  }
                }
              });
      serviceTracker.open();
    } catch (InvalidSyntaxException e) {
    }
  }
예제 #6
0
파일: Engine.java 프로젝트: florhaf/ravent
  /**
   * Creates a new helper for a given server connector.
   *
   * @param server The server to help.
   * @param helperClass Optional helper class name.
   * @return The new helper.
   */
  @SuppressWarnings("unchecked")
  public ConnectorHelper<org.restlet.Server> createHelper(
      org.restlet.Server server, String helperClass) {
    ConnectorHelper<org.restlet.Server> result = null;

    if (server.getProtocols().size() > 0) {
      ConnectorHelper<org.restlet.Server> connector = null;
      for (final Iterator<ConnectorHelper<org.restlet.Server>> iter =
              getRegisteredServers().iterator();
          (result == null) && iter.hasNext(); ) {
        connector = iter.next();

        if ((helperClass == null) || connector.getClass().getCanonicalName().equals(helperClass)) {
          if (connector.getProtocols().containsAll(server.getProtocols())) {
            try {
              result =
                  connector.getClass().getConstructor(org.restlet.Server.class).newInstance(server);
            } catch (Exception e) {
              Context.getCurrentLogger()
                  .log(Level.SEVERE, "Exception while instantiation the server connector.", e);
            }
          }
        }
      }

      if (result == null) {
        // Couldn't find a matching connector
        final StringBuilder sb = new StringBuilder();
        sb.append("No available server connector supports the required protocols: ");

        for (final Protocol p : server.getProtocols()) {
          sb.append("'").append(p.getName()).append("' ");
        }

        sb.append(". Please add the JAR of a matching connector to your classpath.");

        if (Edition.CURRENT == Edition.ANDROID) {
          sb.append(" Then, register this connector helper manually.");
        }

        Context.getCurrentLogger().log(Level.WARNING, sb.toString());
      }
    }

    return result;
  }
예제 #7
0
 @Override
 public ServerHelper createHelper(Server server, String helperClass) {
   if (server.getProtocols().contains(Protocol.HTTPS)) return new HttpsServerHelper(server);
   else return new HttpServerHelper(server);
 }
 /**
  * Launches the application with an HTTP server.
  *
  * @param args The arguments.
  * @throws Exception
  */
 public static void main(String[] args) throws Exception {
   Server mailServer = new Server(Protocol.HTTP, 8111);
   mailServer.setNext(new MailServerApplication());
   mailServer.start();
 }