Package org.restlet

Examples of org.restlet.Application


     *
     * @return The newly created Application or null if unable to create
     */
    @SuppressWarnings("unchecked")
    protected Application createApplication(Context parentContext) {
        Application application = null;

        // Try to instantiate a new target application
        // First, find the application class name
        final String applicationClassName = getInitParameter(APPLICATION_KEY,
                null);

        // Load the application class using the given class name
        if (applicationClassName != null) {
            try {
                final Class<?> targetClass = loadClass(applicationClassName);

                try {
                    // Instantiate an application with the default constructor
                    // then invoke the setContext method.
                    application = (Application) targetClass.getConstructor()
                            .newInstance();

                    // Set the context based on the Servlet's context
                    application.setContext(new ServletContextAdapter(this,
                            parentContext));
                } catch (NoSuchMethodException e) {
                    log("[Noelios Restlet Engine] - The ServerServlet couldn't invoke the constructor of the target class. Please check this class has a constructor without parameter. The constructor with a parameter of type Context will be used instead.");
                    // The constructor with the Context parameter does not
                    // exist. Create a new instance of the application class by
                    // invoking the constructor with the Context parameter.
                    application = (Application) targetClass.getConstructor(
                            Context.class).newInstance(
                            new ServletContextAdapter(this, parentContext));
                }
            } catch (ClassNotFoundException e) {
                log(
                        "[Noelios Restlet Engine] - The ServerServlet couldn't find the target class. Please check that your classpath includes "
                                + applicationClassName, e);

            } catch (InstantiationException e) {
                log(
                        "[Noelios Restlet Engine] - The ServerServlet couldn't instantiate the target class. Please check this class has an empty constructor "
                                + applicationClassName, e);
            } catch (IllegalAccessException e) {
                log(
                        "[Noelios Restlet Engine] - The ServerServlet couldn't instantiate the target class. Please check that you have to proper access rights to "
                                + applicationClassName, e);
            } catch (NoSuchMethodException e) {
                log(
                        "[Noelios Restlet Engine] - The ServerServlet couldn't invoke the constructor of the target class. Please check this class has a constructor with a single parameter of Context "
                                + applicationClassName, e);
            } catch (InvocationTargetException e) {
                log(
                        "[Noelios Restlet Engine] - The ServerServlet couldn't instantiate the target class. An exception was thrown while creating "
                                + applicationClassName, e);
            }
        }

        if (application != null) {
            final Context applicationContext = application.getContext();

            // Copy all the servlet parameters into the context
            String initParam;

            // Copy all the Servlet component initialization parameters
View Full Code Here


     * Returns the application. It creates a new one if none exists.
     *
     * @return The application.
     */
    public Application getApplication() {
        Application result = this.application;

        if (result == null) {
            synchronized (ServerServlet.class) {
                if (result == null) {
                    // In case a component is explicitely defined, it cannot be
View Full Code Here

        if (host != null) {
            for (Route route : host.getRoutes()) {
                Restlet next = route.getNext();

                if (next instanceof Application) {
                    Application application = (Application) next;

                    for (Protocol clientProtocol : application
                            .getConnectorService().getClientProtocols()) {
                        boolean clientFound = false;

                        // Try to find a client connector matching the client
                        // protocol
                        Client client;
                        for (Iterator<Client> iter = getComponent()
                                .getClients().iterator(); !clientFound
                                && iter.hasNext();) {
                            client = iter.next();
                            clientFound = client.getProtocols().contains(
                                    clientProtocol);
                        }

                        if (!clientFound) {
                            getComponent()
                                    .getLogger()
                                    .severe(
                                            "Unable to start the application \""
                                                    + application.getName()
                                                    + "\". Client connector for protocol "
                                                    + clientProtocol.getName()
                                                    + " is missing.");
                            result = false;
                        }
                    }

                    for (Protocol serverProtocol : application
                            .getConnectorService().getServerProtocols()) {
                        boolean serverFound = false;

                        // Try to find a server connector matching the server
                        // protocol
                        Server server;
                        for (Iterator<Server> iter = getComponent()
                                .getServers().iterator(); !serverFound
                                && iter.hasNext();) {
                            server = iter.next();
                            serverFound = server.getProtocols().contains(
                                    serverProtocol);
                        }

                        if (!serverFound) {
                            getComponent()
                                    .getLogger()
                                    .severe(
                                            "Unable to start the application \""
                                                    + application.getName()
                                                    + "\". Server connector for protocol "
                                                    + serverProtocol.getName()
                                                    + " is missing.");
                            result = false;
                        }
                    }

                    if (result && application.isStopped()) {
                        application.start();
                    }
                }
            }
        }
View Full Code Here

    private void stopVirtualHostApplications(VirtualHost host) throws Exception {
        for (Route route : host.getRoutes()) {
            Restlet next = route.getNext();

            if (next instanceof Application) {
                Application application = (Application) next;

                if (application.isStarted()) {
                    application.stop();
                }
            }
        }
    }
View Full Code Here

     *            The request to lookup.
     * @return The connector service associated to a request.
     */
    public ConnectorService getConnectorService(Request request) {
        ConnectorService result = null;
        Application application = (Application) request.getAttributes().get(
                Application.KEY);

        if (application != null) {
            result = application.getConnectorService();
        } else {
            result = new ConnectorService();
        }

        return result;
View Full Code Here

    @Override
    public void init() throws ServletException
    {
        adapter = new ServletAdapter(getServletContext());
        Context context = adapter.getContext().createChildContext();
        Application application = new Application(context);
        application.setInboundRoot(createRouter(injector, context));
        adapter.setNext(application);
    }
View Full Code Here

    protected void initialize()
    {
        if (application == null)
        {
            application = new Application();
        }
        if (router == null)
        {
            router = new Router();
        }
View Full Code Here

    @Override
    protected void initialize()
    {
        if (application == null)
        {
            application = new Application();
        }
        if (router == null)
        {
            router = new SecureRouter(injector, application.getContext())
            {
View Full Code Here

     * @return The Restlet-Application to use.
     */
    @SuppressWarnings("unchecked")
    @Override
    public Application createApplication(Context parentContext) {
        Application application = null;

        final String applicationBeanName = getInitParameter(
                SpringServerServlet.APPLICATION_BEAN_PARAM_NAME, null);
        application = (Application) getWebApplicationContext().getBean(
                applicationBeanName);

        if (application != null) {
            // Set the context based on the Servlet's context
            application.setContext(new ChildContext(new ServletContextAdapter(
                    this, parentContext)));
            final ChildContext applicationContext = (ChildContext) application
                    .getContext();

            // Copy all the servlet parameters into the context
            String initParam;

View Full Code Here

        org.restlet.Application application;
        if (getTargetRestlet() instanceof Application) {
            application = (Application) getTargetRestlet();
        } else {
            application = new Application();
            application.setRoot(getTargetRestlet());
        }
        if (application.getContext() == null) {
            application.setContext(createContext());
        }
View Full Code Here

TOP

Related Classes of org.restlet.Application

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.