Package org.restlet

Examples of org.restlet.Restlet


    public void testRiap() throws Exception {
        final Component comp = new Component();
        final Application localOnly = new Application() {
            @Override
            public Restlet createInboundRoot() {
                return new Restlet(getContext()) {
                    @Override
                    public void handle(Request request, Response response) {
                        final String selfBase = "riap://application";
                        final Reference ref = request.getResourceRef();
                        final String remainder = ref.getRemainingPart();
View Full Code Here


        Application app = new Application() {
            @Override
            public Restlet createInboundRoot() {
                Router router = new Router(getContext());
                router.attach("/testA", new Restlet(getContext()) {

                    @Override
                    public void handle(Request request, Response response) {
                        response.setEntity("hello, world", MediaType.TEXT_PLAIN);
                    }

                });
                router.attach("/testB", new Restlet(getContext()) {
                    public void handle(Request request, Response response) {
                        ClientResource resource = new ClientResource(
                                "riap://component/app/testA");
                        try {
                            response.setEntity(resource.get().getText(),
View Full Code Here

               addAutoConfiguration(serverConf, link);
            }
         }

      }
      this.getDefaultHost().attach(new Restlet() {

         public void handle(Request request, Response response) {
            response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         }
      });
View Full Code Here

    @Override
    protected Application createApplication(final Component component) {
        Application application = new Application() {
            @Override
            public Restlet createInboundRoot() {
                final Restlet trace = new Restlet(getContext()) {
                    @Override
                    public void handle(Request request, Response response) {
                        Representation entity = request.getEntity();
                        if (entity != null) {
                            Form form = new Form(entity);
View Full Code Here

        // Register the selected connector
        Engine.getInstance().getRegisteredServers().add(0, helper);
        // Engine.setLogLevel(Level.FINEST);

        // Create and start a connector instance
        Server server = new Server(Protocol.HTTP, 8554, new Restlet() {
            @Override
            public void handle(Request request, Response response) {
                try {
                    FileRepresentation fr = new FileRepresentation(
                            "file:///c:/TEST/restlet-jse-2.0.5-ff.zip",
View Full Code Here

     */
    private static class TestDigestApplication extends Application {

        @Override
        public Restlet createInboundRoot() {
            Restlet restlet = new Restlet() {
                @Override
                public void handle(Request request, Response response) {
                    Representation rep = request.getEntity();
                    try {
                        // Such representation computes the digest while
View Full Code Here

        return everythingFine;
    }

    @Override
    public Restlet createInboundRoot() {
        Restlet restlet = this.jaxRsRestlet;

        if (this.guard != null) {
            this.guard.setNext(restlet);
            restlet = this.guard;
        }
View Full Code Here

    public void testFileName() throws Exception {
        Application application = new Application() {
            @Override
            public Restlet createInboundRoot() {
                return new Restlet() {
                    @Override
                    public void handle(Request request, Response response) {
                        response.setEntity(new FileRepresentation(file,
                                MediaType.TEXT_PLAIN));
                        response.getEntity().getDisposition().setType(
View Full Code Here

      try {
         Constructor<Restlet> makeit = targetClass.getConstructor(Context.class);
         return makeit.newInstance(context);
      } catch (NoSuchMethodException ex) {
         Constructor<Restlet> makeit = targetClass.getConstructor();
         Restlet r = makeit.newInstance();
         r.setContext(context);
         return r;
      }
   }
View Full Code Here

            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());
                  router.attach(match,finder);
               } else {
                  filter.setNext(finder);
               }
            } else {
               try {
                  Restlet restlet = createRestlet(parentContext,def,child);
                  if (defaultRoute) {
                     LOG.fine("Mapping default -> "+def.getName());
                     router.attachDefault(restlet);
                  } else if (router!=null) {
                     LOG.fine("Mapping "+match+" -> "+def.getName());
                     router.attach(match,restlet);
                  } else {
                     filter.setNext(restlet);
                  }
               } catch (Exception ex) {
                  LOG.log(Level.SEVERE,"Cannot instantiate class: "+def.getName(),ex);
               }
            }
         } else if (name.equals(FILTER)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The filter element does not have the required match attribute.");
               return;
            }
            Class def = getTargetClass(child);
            if (def==null) {
               return;
            }
            Filter childFilter = null;
            try {
               childFilter = createFilter(parentContext,def,child);
            } catch (Exception ex) {
               LOG.log(Level.SEVERE,"Cannot instantiate filter.",ex);
               return;
            }
            if (defaultRoute) {
               router.attachDefault(childFilter);
            } else if (router!=null) {
               router.attach(match,childFilter);
            } else {
               filter.setNext(childFilter);
            }
            Iterator<Element> elements = child.getElementChildren();
            while (elements.hasNext()) {
               Element nextChild = elements.next();
               if (nextChild.getName().equals(NEXT)) {
                  Iterator<Element> nextChildren = nextChild.getElementChildren();
                  while (nextChildren.hasNext()) {
                     attachNext(childFilter,nextChildren.next());
                  }
               }
            }
         } else if (name.equals(CONTENT)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The content element does not have the required match attribute.");
               return;
            }
            Restlet restlet = createContent(parentContext,child);
            if (defaultRoute) {
               router.attachDefault(restlet);
            } else if (router!=null) {
               router.attach(match,restlet);
            } else {
               filter.setNext(restlet);
            }
         } else if (name.equals(REDIRECT)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The content element does not have the required match attribute.");
               return;
            }
            String to = child.getAttributeValue("to");
            if (to==null) {
               LOG.severe("The redirect element is missing the required 'to' attribute.");
               return;
            }
           
            Reference targetRef = new Reference(to);
            Restlet restlet = null;
            if (targetRef.isAbsolute() && targetRef.getScheme().equals("riap")) {
               restlet = new Redirector(parentContext,to,Redirector.MODE_SERVER_INBOUND);
            } else {
               restlet = new Redirector(parentContext,to,Redirector.MODE_CLIENT_SEE_OTHER);
            }
View Full Code Here

TOP

Related Classes of org.restlet.Restlet

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.