Package org.restlet

Examples of org.restlet.Application


    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 Context for the Application
     *
     * @return The newly created Application or null if unable to create
     */
    public Application createApplication(Context context) {
        Application application = null;
        // Try to instantiate a new target application
        // First, find the application class name
        String applicationClassName = getInitParameter(Application.KEY, null);

        // Load the application class using the given class name
        if (applicationClassName != null) {
            try {
                // According to
                // http://www.caucho.com/resin-3.0/webapp/faq.xtp#Class.forName()-doesn't-seem-to-work-right
                // this approach may need to used when loading classes.
                Class<?> targetClass;
                ClassLoader loader = Thread.currentThread()
                        .getContextClassLoader();

                if (loader != null)
                    targetClass = Class.forName(applicationClassName, false,
                            loader);
                else
                    targetClass = Class.forName(applicationClassName);

                try {
                    // Create a new instance of the application class by
                    // invoking the constructor with the Context parameter.
                    application = (Application) targetClass.getConstructor(
                            Context.class).newInstance(context);
                } 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. The empty constructor and the context setter wille used instead. "
                                    + applicationClassName, e);
                    // The constructor with the Context parameter does not
                    // exist. Instantiate an application with the default
                    // constructor then invoke the setContext method.
                    application = (Application) targetClass.getConstructor()
                            .newInstance();
                }
            } 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) {
                // Set the context based on the Servlet's context
                application.setContext(new ServletContextAdapter(this,
                        application, context));
            }
        }

        return application;
View Full Code Here

     * @return The new HTTP server handling calls.
     */
    public HttpServerHelper createServer(HttpServletRequest request) {
        HttpServerHelper result = null;
        Component component = getComponent();
        Application application = getApplication();

        if ((component != null) && (application != null)) {
            // First, let's locate the closest component
            Server server = new Server(component.getContext(),
                    (List<Protocol>) null, request.getLocalAddr(), request
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) {
                // Find the attribute name to use to store the application
                String applicationAttributeName = getInitParameter(
View Full Code Here

    }

    static void startServer(String repo) throws Exception {
        GeoGIG geogig = loadGeoGIG(repo);
        org.restlet.Context context = new org.restlet.Context();
        Application application = new Main(geogig);
        application.setContext(context);
        Component comp = new Component();
        comp.getDefaultHost().attach(application);
        comp.getServers().add(Protocol.HTTP, 8182);
        comp.start();
    }
View Full Code Here

            CommandFailedException, IOException {

        String loc = repo != null && repo.size() > 0 ? repo.get(0) : ".";

        GeoGIG geogig = loadGeoGIG(loc, cli);
        Application application = new Main(geogig);

        Component comp = new Component();

        comp.getDefaultHost().attach(application);
        comp.getServers().add(Protocol.HTTP, port);
View Full Code Here

   *            The Context for the Application
   *
   * @return The newly created Application or null if unable to create
   */
  public Application createApplication(Context context) {
    Application application = null;
    // Try to instantiate a new target application
    // First, find the application class name
    String applicationClassName = getInitParameter(Application.KEY, null);

    // Load the application class using the given class name
    if (applicationClassName != null) {
      try {
        // According to
        // http://www.caucho.com/resin-3.0/webapp/faq.xtp#Class.forName()-doesn't-seem-to-work-right
        // this approach may need to used when loading classes.
        Class<?> targetClass;
        ClassLoader loader = Thread.currentThread()
            .getContextClassLoader();

        if (loader != null)
          targetClass = Class.forName(applicationClassName, false,
              loader);
        else
          targetClass = Class.forName(applicationClassName);

        try {
          // Create a new instance of the application class by
          // invoking the constructor with the Context parameter.
          application = (Application) targetClass.getConstructor(
              Context.class).newInstance(context);
        } 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. The empty constructor and the context setter wille used instead. "
                  + applicationClassName, e);
          // The constructor with the Context parameter does not
          // exist. Instantiate an application with the default
          // constructor then invoke the setContext method.
          application = (Application) targetClass.getConstructor()
              .newInstance();
        }
      } 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) {
        // Set the context based on the Servlet's context
        application.setContext(new ServletContextAdapter(this,
            application, context));
      }
    }

    return application;
View Full Code Here

   * @return The new HTTP server handling calls.
   */
  public HttpServerHelper createServer(HttpServletRequest request) {
    HttpServerHelper result = null;
    Component component = getComponent();
    Application application = getApplication();

    if ((component != null) && (application != null)) {
      // First, let's locate the closest component
      Server server = new Server(component.getContext(),
          (List<Protocol>) null, request.getLocalAddr(), request
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) {
        // Find the attribute name to use to store the application
        String applicationAttributeName = getInitParameter(
View Full Code Here

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

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

        return result;
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.