Package org.restlet.routing

Examples of org.restlet.routing.VirtualHost


            getServers().add(Protocol.HTTP, iface.getAddress().equals("*") ? null : iface.getAddress(), iface.getPort());           
         }
        
         for (String name : iface.getHosts().keySet()) {
            final Configuration.Host host = iface.getHosts().get(name);
            VirtualHost vhost = new VirtualHost(getContext());
            getContext().getLogger().info("Adding host "+host.getName());
            if ("*".equals(iface.getAddress())) {
               vhost.setServerAddress(".*");
            } else {
               try {
                  InetAddress addr = InetAddress.getByName(iface.getAddress());
                  String saddr = addr.toString();
                  saddr = saddr.substring(saddr.indexOf('/')+1);
                  getLogger().info("Restricting "+host.getName()+" to address "+saddr);
                  vhost.setServerAddress(saddr);
               } catch (UnknownHostException ex) {
                  getLogger().severe("Cannot resolve host name "+iface.getAddress());
               }
            }
            if (host.getPort()==null) {
               vhost.setHostPort(Integer.toString(iface.getPort()));
            } else {
               vhost.setHostPort(host.getPort());
            }
            if (!"*".equals(name)) {
               if (name!=null) {
                  vhost.setHostDomain(name);
               }
            }
            configure(vhost,host);

            getHosts().add(vhost);
View Full Code Here


         }
      }
      ServerAdminApplication admin = new ServerAdminApplication(childContext,dbConfList,autodbList,storageFactory);
      for (ServerConfiguration.AdminHost adminHost : serverConf.getAdminHosts().values()) {
        
         VirtualHost vhost =  createVirtualHost(adminHost);
         getHosts().add(vhost);
         adminRouters.add(vhost);
         String authName = adminHost.getAuthName();
         if (authName==null) {
            getLogger().severe("The admin interface is missing a named auth service.");
            continue;
         }
         AuthService service = services.get(authName);
         if (service==null) {
            getLogger().severe("Cannot find auth service "+authName+" for admin interface.");
            continue;
         }
         UserGuard adminGuard = new UserGuard(childContext,ChallengeScheme.HTTP_BASIC,"Atom Administrator",service);
         adminGuard.getRequiredGroups().add(AuthService.ADMIN_GROUP);
         adminGuard.setNext(admin);
        
         vhost.attach("/admin",adminGuard);
        
      }
     
      admins = new HashMap<String,Restlet>();
      Restlet lastAdmin = null;
      for (final DB adminDB : dbList.values()) {
         getLogger().info("Configuring database "+adminDB.getName()+" for administration");
         ServerConfiguration.Database databaseConf = serverConf.getDatabases().get(adminDB.getName());
         AuthService service = null;
         if (databaseConf==null || databaseConf.getAuthName()==null) {
            service = new DBAuthService();
            Properties props = new Properties();
            props.setProperty("database",adminDB.getName());
            props.setProperty("dir", adminDB.getDatabaseDir().getAbsolutePath());
            try {
               service.init(props);
            } catch (AuthException ex) {
               getLogger().log(Level.SEVERE,"Cannot instantiate auth service for database "+adminDB.getName(),ex);
               continue;
            }
         } else {
            service = services.get(databaseConf.getAuthName());
            if (service==null) {
               getLogger().severe("Cannot find auth service "+databaseConf.getAuthName()+" for database "+adminDB.getName());
               continue;
            }
         }
         DBInfo dbinfo = new DBInfo(adminDB.getName(),adminDB,service,databaseConf==null ? null : databaseConf.getGroup(),databaseConf==null ? null : databaseConf.getGroupAlias());
         dbConfList.put(dbinfo.getName(),dbinfo);
         UserGuard adminGuard = new UserGuard(childContext,ChallengeScheme.HTTP_BASIC,"Atom Administrator",service);
         adminGuard.getRequiredGroups().add(AuthService.ADMIN_GROUP);

         try {
            adminGuard.setNext(new AdminApplication(childContext,adminDB,storageFactory.getStorage(adminDB),AtomApplication.RESOURCE_BASE));
            admins.put(adminDB.getName(),adminGuard);
            for (Router router : adminRouters) {
               router.attach("/admin/database/"+adminDB.getName(),adminGuard).getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
            }
            lastAdmin = adminGuard;
         } catch (Exception ex) {
            getLogger().log(Level.SEVERE,"Cannot add admin due to exception.",ex);
         }
      }
     
      // Add the configured hosts
      for (ServerConfiguration.Host hostConf : serverConf.getHosts().values()) {
        
         VirtualHost vhost =  createVirtualHost(hostConf);
         getHosts().add(vhost);
         try {
            configure(vhost,hostConf);
         } catch (Exception ex) {
            getLogger().log(Level.SEVERE,"Cannot configure host "+hostConf.getName()+" due to exception.",ex);
         }
      }
     
      // Add the configured hosts
      for (ServerConfiguration.ResourceHost resourceConf : serverConf.getResourceHosts().values()) {

         VirtualHost vhost =  createVirtualHost(resourceConf);
         getHosts().add(vhost);
         try {
            configureResource(vhost,resourceConf);
         } catch (Exception ex) {
            getLogger().log(Level.SEVERE,"Cannot configure host "+resourceConf.getName()+" due to exception.",ex);
View Full Code Here

     
   }
  
   protected VirtualHost createVirtualHost(ServerConfiguration.Host host)
   {
      VirtualHost vhost = new VirtualHost(childContext);
      getLogger().info("Creating virtual route for "+host.getName()+":"+host.getPort());
      if (host.getAddress()!=null) {
         getLogger().info("Restricting to address "+host.getAddress());
         vhost.setServerAddress(host.getAddress());
      }
      if (host.getPort()>0) {
         getLogger().info("Restricting to port "+host.getPort());
         vhost.setHostPort(Integer.toString(host.getPort()));
      } else {
         vhost.setHostPort(".*");
      }
      if (host.getName()!=null && !host.getName().equals("*")) {
         vhost.setHostDomain(host.getName());
      }
      return vhost;
     
   }
View Full Code Here

               ServerConfiguration.Host host = config.createHost(hostE);

               // Configure host
               getLogger().info("Adding host "+host.getName());
               VirtualHost vhost = createVirtualHost(host);

               WebComponent.this.configure(vhost,host);

               if (autoHost==null) {
                  hosts.put(entry.getId(),new AutoConfiguredHost(vhost,host,edited));
View Full Code Here

      this.edited = edited;
      this.docLoader = new SAXDocumentLoader();
      this.isStatic = isStatic;
      context.getAttributes().put(WebComponent.LINKS_ATTR, hostConf.getLinks());
      getLogger().info("Adding host "+hostConf.getName()+":"+iface.getPort());
      this.vhost = new VirtualHost(context) {
         public void handle(Request request, Response response) {
            long startTime = System.currentTimeMillis();
            super.handle(request,response);
            if (hostLog!=null) {
               int duration = (int) (System.currentTimeMillis() - startTime);
View Full Code Here

    // override the default error pages
    c.setStatusService(new ErrorStatusService(c.getContext()));

    // get the default virtual host
    VirtualHost host = c.getDefaultHost();   

    MoxieProxy app = new MoxieProxy(config);

    // Guard Moxie Proxy with BASIC authentication.
    Authenticator guard = new Authenticator(app);
    host.attachDefault(guard);
    guard.setNext(app);
   
    // start the shutdown monitor
    if (config.getShutdownPort() > 0) {
      Thread shutdownMonitor = new ShutdownMonitorThread(c, app, config);
View Full Code Here

TOP

Related Classes of org.restlet.routing.VirtualHost

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.