Hi,

I have a problem with virtualHost.

The following code works :

    public static void main(String[] args) {
        try {

            final ConfigFile conf = new ConfigFile();


            // Create a new Component.
            Component component = new Component();

            // Add a new HTTP server listening on port 8182.
            component.getServers().add(Protocol.HTTP, conf.getPort());
            component.getClients().add(Protocol.FILE);

            Application application = new Application() {

                @Override
                public Restlet createRoot() {
                    Directory directory = new Directory(getContext(),
conf.getRoot_uri());
                    directory.setListingAllowed(true);
                    directory.setModifiable(false);
                    directory.setDeeplyAccessible(true);
                    return directory;
                }
            };

            // Attach the application.
            component.getDefaultHost().attach(application);

            // Start the component.
            component.start();
        } catch (Exception e) {
            // Something is wrong.
            e.printStackTrace();
        }
    }



but the following code does not work :


    public static void main(String[] args) {
        try {

            final ConfigFile conf = new ConfigFile();


            // Create a new Component.
            Component component = new Component();

            // Add a new HTTP server listening on port 8182.
            component.getServers().add(Protocol.HTTP, conf.getPort());
            component.getClients().add(Protocol.FILE);

            Application application = new Application() {

                @Override
                public Restlet createRoot() {
                    Directory directory = new Directory(getContext(),
conf.getRoot_uri());
                    directory.setListingAllowed(true);
                    directory.setModifiable(false);
                    directory.setDeeplyAccessible(true);
                    return directory;
                }
            };

            // Attach the application.
            VirtualHost host = new VirtualHost();
            host.setHostDomain(conf.getHostname());
            host.setHostPort(String.valueOf(conf.getPort()));
            host.attach(application);

            // Attach the host to the component.
            component.getHosts().add(host); //host = localhost|<my IP>
            component.updateHosts();

            // Start the component.
            component.start();
        } catch (Exception e) {
            // Something is wrong.
            e.printStackTrace();
        }
    }

I do not understand why the second code does not work. Anyone can explain me
please ?

Thanks,
J-Christophe

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2428263

Reply via email to