Package org.restlet

Examples of org.restlet.Application


               proxy.getTunnelService().setEnabled(false);
               router.attach(content.getMatch(),proxy);
            } else {
               // hope the directory resource can handle it
               getLogger().info("  Directory: "+content.getSource()+" at "+content.getMatch());
               Application app = new Application(context) {
                  public Restlet createRoot() {
                     Directory directory = new Directory(getContext(),uri);
                     directory.setIndexName("index.html");
                     return directory;
                  }
View Full Code Here


            try {
               getLogger().info("  Application: "+appConf.getApplicationDef().getName()+" at "+appConf.getMatch());
               LinkSet set = new LinkSet();
               set.addLinkSet(hostConf.getLinks());
               set.addLinkSet(appConf.getLinks());
               Application app = appConf.getApplication(this.context,set);
               router.attach(appConf.getMatch(),app);
               if (internalName!=null) {
                  String route = "/"+internalName+appConf.getMatch();
                  getLogger().info("   adding internal route: "+route);
                  internalRouter.attach(route,app).getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
View Full Code Here

                     }
                  } else {
                     appContext.getParameters().add(key,"true");
                  }
               }
               Application app = null;
               if (proxyTerm!=null) {
                  String value = proxyTerm.getFirstValue();
                  List<Link> links = entry.getLinks().get(value);
                  Link target = null;
                  if (links!=null && links.size()>0) {
View Full Code Here

      //String path = packageName+request.getResourceRef().getRemainingPart();
      String path = request.getResourceRef().getRemainingPart();
      URL script = null;
      URI resource = (URI)request.getAttributes().get(RESOURCE_ATTR);
      int extPos = path.lastIndexOf('.');
      Application app = this.getApplication();
      Properties resourceProperties = resourceConfig.match(path);
      String stype = resourceProperties.getProperty("content-type");
      MediaType type = stype==null ? null : MediaType.valueOf(stype);
      String defaultExtension = resourceProperties.getProperty("extension");
      if (defaultExtension==null) {
         defaultExtension = ".ats";
      }
      String agentsValue = resourceProperties.getProperty("agents");
     
      String resourceTemplate = resourceProperties.getProperty("resource");
      getLogger().info("resource template: "+resourceTemplate);
      if (resource==null && resourceTemplate!=null) {
         String href = null;
         String uri = null;
         try {
            Template t = new Template(resourceTemplate);
            href = t.format(request.getAttributes());
            String baseURISpec = resourceProperties.getProperty("base-uri");
            URI baseURI = null;
            if (baseURISpec!=null) {
               Template tbase = new Template(baseURISpec);
               uri = tbase.format(request.getAttributes());
               baseURI = new URI(uri);
            }

            resource = baseURI==null ? new URI(href) : baseURI.resolve(href);
         } catch (URISyntaxException ex) {
            getLogger().log(Level.SEVERE,"Cannot construct resource URI, href="+href+", base="+uri,ex);
            return null;
         }
      }
     
      String [] agents = null;
      if (agentsValue!=null) {
         agents = agentsValue.split(",");
      }
     
      MediaType forceType = null;

      if (type==null && extPos>=0) {
         String ext = path.substring(extPos+1);
         Metadata mdata = this.getApplication().getMetadataService().getMetadata(ext);
         if (mdata!=null) {
            type = MediaType.valueOf(mdata.getName());
         }
      } else if (path.length()==0 || path.charAt(path.length()-1)=='/') {
         // no extension and is a directory path, default to index.xml template
         script = baseClass.getResource(packageName+path+"index.ats");
         if (script==null) {
            script = baseClass.getResource(packageName+path+"index.xsl");
         }
         if (resource==null) {
            try {
               URL url = baseClass.getResource(packageName+path + "index.xml");
               /*
               if (url==null) {
                  getLogger().warning("Canot find resource via class path: "+path+"index.xml");
                  return null;
               }
               resource = url.toURI();
                */
               if (url!=null) {
                  resource = url.toURI();
               }
            } catch (URISyntaxException ex) {
               getLogger().log(Level.SEVERE,"Cannot convert URL to URI: "+path,ex);
               return null;
            }
         }
         if (type==null && agents!=null) {
            String agent = request.getClientInfo().getAgent();
            for (int i=0; i<agents.length; i++) {
               String exp = resourceProperties.getProperty(agents[i]+".match");
               if (agent.matches(exp)) {
                  if (getLogger().isLoggable(Level.FINE)) {
                     getLogger().fine("Matched agent "+agent+" with "+agents[i]);
                  }
                  stype = resourceProperties.getProperty(agents[i]+".content-type");
                  forceType = stype==null ? null : MediaType.valueOf(stype);
                  break;
               }
            }
         }
         if (type==null) {
            type = MediaType.APPLICATION_XHTML_XML;
         }
      } else {
         // no extension, so lookup based on xml file
         script = baseClass.getResource(packageName+path+defaultExtension);
         if (script==null) {
            script = baseClass.getResource(packageName+path+".xsl");
         }
         if (resource==null) {
            try {
               URL url = baseClass.getResource(packageName+path + ".xml");
               /*
               if (url==null) {
                  getLogger().warning("Canot find resource via class path: "+path+".xml");
                  return null;
               }
               resource = url.toURI();
                */
               if (url!=null) {
                  resource = url.toURI();
               }
            } catch (URISyntaxException ex) {
               getLogger().log(Level.SEVERE,"Cannot convert URL to URI: "+path);
               return null;
            }
         }
         if (type==null && agents!=null) {
            String agent = request.getClientInfo().getAgent();
            for (int i=0; i<agents.length; i++) {
               String exp = resourceProperties.getProperty(agents[i]+".match");
               if (agent.matches(exp)) {
                  stype = resourceProperties.getProperty(agents[i]+".content-type");
                  forceType = stype==null ? null : MediaType.valueOf(stype);
                  break;
               }
            }
         }
         if (type==null) {
            type = MediaType.APPLICATION_XHTML_XML;
         }
      }
      if (type==null) {
         type = app.getMetadataService().getDefaultMediaType();
      }
      boolean isResource = (type.getMainType().equals("image") || (script==null && type.getMainType().equals("text")) || (type.getMainType().equals("application") && !type.getName().equals("application/xml") && !type.getName().endsWith("+xml")));
      String sflag = resourceProperties.getProperty("force-resource");
      if (sflag!=null && sflag.equals("true")) {
         isResource = true;
View Full Code Here

   {
      setNegotiated(false);
      this.baseClass = baseClass;
      this.path = path;
      int extPos = path.lastIndexOf('.');
      Application app = this.getApplication();
      type = app.getMetadataService().getDefaultMediaType();
      if (extPos>=0) {
         String ext = path.substring(extPos+1);
         Metadata mdata = this.getApplication().getMetadataService().getMetadata(ext);
         if (mdata!=null) {
            type = MediaType.valueOf(mdata.getName());
View Full Code Here

      xmldb.stop();
      getLogger().info("XMLDB "+dbName+" stopped.");
   }

   public Application getAdministration() {
      return new Application(context.createChildContext()) {
         public Restlet createRoot() {
            getContext().getAttributes().put(XMLDBResource.DBNAME_NAME, dbName);
            Router router = new Router(getContext());
            Restlet reindexer = new Restlet(getContext()) {
               public void handle(Request request,Response response) {
View Full Code Here

    super.destroy();
  }

  public Application createApplication(Context context) {
    Application application = null;

    final String applicationRole = getInitParameter("role", Application.class.getName());

    final String applicationRoleHint = getInitParameter("roleHint", null);

    // Load the application class using the given class name
    try {
      if (applicationRoleHint != null) {
        application = (Application) lookup(applicationRole, applicationRoleHint);
      }
      else {
        application = (Application) lookup(applicationRole);
      }
    }
    catch (Exception e) {
      throw new IllegalStateException("The PlexusServerServlet couldn't lookup the target component (role='"
          + applicationRole + "', hint='" + applicationRoleHint + "')", e);
    }

    // mimic constructor
    application.setName(getServletConfig().getServletName());

    application.setContext(new ServletContextAdapter(this, context));

    // setting logger explicitly, to override the stupid logger put there by ServletContextAdapter
    application.getContext().setLogger(application.getClass().getName());

    // --- FROM SUPERCLASS (as is) -- BEGIN
    // Copy all the servlet parameters into the context
    final Context applicationContext = application.getContext();

    String initParam;

    // Copy all the Servlet component initialization parameters
    final javax.servlet.ServletConfig servletConfig = getServletConfig();
View Full Code Here

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

        if (application != null) {
            result = application.getMetadataService();
        } else {
            result = new MetadataService();
        }

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

        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

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.