Package org.restlet

Examples of org.restlet.Context


        // helper = new org.restlet.ext.httpclient.HttpClientHelper(null);
        // helper = new org.restlet.ext.net.HttpClientHelper(null);
        Engine.getInstance().getRegisteredClients().add(0, helper);
        Engine.setLogLevel(Level.FINE);

        Client client = new Client(new Context(), Protocol.HTTP);
        // client.getContext().getParameters().add("persistingConnections",
        // "false");
        client.getContext().getParameters().add("tracing", "false");
        client.getContext().getParameters().add("minThreads", "1");
        client.getContext().getParameters().add("lowThreads", "30");
View Full Code Here


            }
        };

        component.getDefaultHost().attach(application);

        Client client = new Client(new Context(), Protocol.HTTP);
        Request request = new Request(Method.GET, uri);
        Response response = client.handle(request);
        Representation entity = response.getEntity();

        assertEquals(Status.SUCCESS_OK, response.getStatus());
View Full Code Here

            }
            for (Server server : conf.getServers()) {
               LOG.info("Server: "+server.getProtocol()+" at "+server.getAddress()+":"+server.getPort());
               for (Host host : server.getHosts().values()) {
                  LOG.info("Host: "+host.getName());
                  Context context = new Context();
                  Router router = new Router(context);
                  host.attach(router);
               }
            }
         } catch (Exception ex) {
View Full Code Here

      public void attach(Router router,Element child,boolean defaultRoute) {
         attach(router,null,child,defaultRoute);
      }
      protected void attach(Router router,Filter filter,Element child,boolean defaultRoute) {
         Name name = child.getName();
         Context parentContext = router==null ? filter.getContext() : router.getContext();
         if (name.equals(ROUTER)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The router element does not have the required match attribute.");
               return;
            }
            if (defaultRoute) {
               router.attachDefault(createRouter(parentContext,child));
            } else if (router!=null) {
               router.attach(match,createRouter(parentContext,child));
            } else {
               filter.setNext(createRouter(parentContext,child));
            }
         } else if (name.equals(ROUTE)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The route element does not have the required match attribute.");
               return;
            }
            Class def = getTargetClass(child);
            if (def==null) {
               return;
            }
            if (isServerResource(def)) {
               Restlet finder = Finder.createFinder(def, Finder.class, hasParametersOrAttributes(child) ? createContext(parentContext,child) : parentContext,parentContext.getLogger());
               if (defaultRoute) {
                  LOG.fine("Mapping default -> "+def.getName());
                  router.attachDefault(finder);
               } else if (router!=null) {
                  LOG.fine("Mapping "+match+" -> "+def.getName());
View Full Code Here

         }

      }
     
      public Router createRouter(Context parentContext,Element routerConf) {
         Context routerContext = hasParametersOrAttributes(routerConf) ? createContext(parentContext,routerConf) : parentContext;
         Router router = new Router(routerContext);
         router.setDefaultMatchingMode(Template.MODE_STARTS_WITH);
         String method = routerConf.getAttributeValue("method");
         if ("best".equals(method)) {
            router.setRoutingMode(Router.MODE_BEST_MATCH);
View Full Code Here

         return createRestlet(parentContext,targetClass,useConf);
      }
     
      protected Context createContext(Context parentContext, Element useConf)
      {
         Context appContext = parentContext.createChildContext();
         LinkSet confLinks = linkSet;
         boolean hasLinks = false;
         Iterator<Element> appLinks = useConf.getElementsByName(LINK);
         while (appLinks.hasNext()) {
            if (!hasLinks) {
               LinkSet set = new LinkSet();
               set.addLinkSet(linkSet);
               confLinks = set;
            }
            Element linkE = appLinks.next();
            String href = linkE.getAttributeValue("href");
            if (href!=null) {
               URI tlocation = linkE.getBaseURI().resolve(href);
               String mtype = linkE.getAttributeValue("type");
               Link l = new Link(linkE.getAttributeValue("rel"),mtype==null ? null : MediaType.valueOf(mtype),tlocation);
               l.setIdentity(linkE.getAttributeValue("username"),linkE.getAttributeValue("password"));
               if (l.getRelation()!=null) {
                  confLinks.put(l.getRelation(),l);
               }
            }
         }
        
         loadContext(appContext,useConf);
         String copy = useConf.getAttributeValue("copy");
         if (copy==null || "parameters".equals(copy) || "all".equals(copy)) {
            for (Parameter param : parentContext.getParameters()) {
               appContext.getParameters().add(param);
            }
         }
        
         if (copy==null || "attributes".equals(copy) || "all".equals(copy)) {
            for (String key : parentContext.getAttributes().keySet()) {
               appContext.getAttributes().put(key,parentContext.getAttributes().get(key));
            }
         }
         return appContext;
      }
View Full Code Here

     
      public Restlet createRestlet(Context parentContext,Class targetClass,Element useConf)
         throws InstantiationException,IllegalAccessException,NoSuchMethodException,InvocationTargetException
      {
         LOG.fine("Creating restlet: "+targetClass);
         Context appContext = createContext(parentContext,useConf);
         return getRestletInstance(appContext,targetClass);
      }
View Full Code Here

         for (String name : serverConf.getHosts().keySet()) {
            final Configuration.Host host = serverConf.getHosts().get(name);
            if (confHosts.get(host.getName()) != null) {
               getLogger().warning("Ignoring duplicate host name " + host.getName());
            } else {
               Context hostContext = getContext().createChildContext();
              
               ConfiguredHost confHost = new ConfiguredHost(hostContext, getInternalRouter(), serverConf, host, new Date(), true);
               confHosts.put(host.getName(), confHost);
               if (host.getLinks().get("autoconf") != null) {
                  hasStaticAutoConf = true;
View Full Code Here

* @author Jerome Louvel
*/
public class SaasComponent extends Component {

    public SaasComponent() {
        Context context = getContext().createChildContext();
        SaasApplication app = new SaasApplication(context);

        MemoryRealm realm = new MemoryRealm();
        context.setDefaultEnroler(realm.getEnroler());
        context.setDefaultVerifier(realm.getVerifier());

        // Add users
        User stiger = new User("stiger", "pwd", "Scott", "Tiger",
                "scott.tiger@foobar.com");
        realm.getUsers().add(stiger);
View Full Code Here

    @Override
    protected void call(String uri) throws Exception {
        final Request request = new Request(Method.GET, uri);
        final Client client = new Client(Protocol.HTTPS);
        client.setContext(new Context());
        configureSslClientParameters(client.getContext());
        final Response r = client.handle(request);

        assertEquals(r.getStatus().getDescription(), Status.SUCCESS_OK,
                r.getStatus());
View Full Code Here

TOP

Related Classes of org.restlet.Context

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.