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


     *
     * @return The application.
     */
    @SuppressWarnings("null")
    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

  protected Application doCreateApplication(Context context)
  {
    // FIXME Workaround for a bug in Restlet 2.1M7 - the context should be passed to the Application
    // constructor.

    Application app = new Application();
    app.setContext(context);
    return app;
  }
View Full Code Here

  }

  @Override
  protected Application doCreateApplication(Context context)
  {
    Application application = new Application();
    application.setContext(context);
    return application;
  }
View Full Code Here

    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        Application.setCurrent(new Application());
        this.uriBuilder = ExtendedUriBuilder.newInstance();
        this.uriBuilder.host("localhost");
        this.uriBuilder.segment("path1", "path2");
        this.uriBuilder.scheme("http");
        this.uriBuilderWithVars = ExtendedUriBuilder.newInstance();
View Full Code Here

    /**
     * Constructor.
     */
    public ConverterProvider() {
        Application application = Application.getCurrent();

        if (application != null) {
            this.converterService = application.getConverterService();
        }

        if (this.converterService == null) {
            this.converterService = new ConverterService();
        }
View Full Code Here

        setPrefs();
        this.request.getClientInfo().setAgent(this.userAgent);
    }

    private void extensionTunnelOff() {
        final Application application = this.tunnelFilter.getApplication();
        application.getTunnelService().setExtensionsTunnel(false);
    }
View Full Code Here

            if (response.getStatus().isSuccess()
                    && response.isEntityAvailable()) {
                final Representation representation = response.getEntity();
                // Create a new instance of the application class by
                // invoking the constructor with the Context parameter.
                final Application target = (Application) targetClass
                        .getConstructor(Context.class, Representation.class)
                        .newInstance(
                                getComponent().getContext()
                                        .createChildContext(), representation);
                if (target != null) {
View Full Code Here

    }

    @Override
    public void setUp() throws Exception {
        super.setUp();
        Application app = new Application(new Context());
        Application.setCurrent(app);
        this.tunnelFilter = new TunnelFilter(app.getContext());
        this.tunnelFilter.getApplication().getTunnelService()
                .setExtensionsTunnel(true);
    }
View Full Code Here

                return executorService.awaitTermination(timeout, unit);
            }

            public void execute(final Runnable runnable) {
                // Save the thread local variables
                final Application currentApplication = Application.getCurrent();
                final Context currentContext = Context.getCurrent();
                final Integer currentVirtualHost = VirtualHost.getCurrent();
                final Response currentResponse = Response.getCurrent();

                executorService.execute(new Runnable() {
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.