Package org.restlet

Examples of org.restlet.Client


            Protocol protocol = (rProtocol != null) ? rProtocol
                    : (rReference != null) ? rReference.getSchemeProtocol()
                            : null;

            if (protocol != null) {
                result = new Client(protocol);
            }
        }

        return result;
    }
View Full Code Here


                Protocol protocol = (rProtocol != null) ? rProtocol
                        : (rReference != null) ? rReference.getSchemeProtocol()
                                : null;

                if (protocol != null) {
                    this.clientConnector = new Client(protocol);
                    // Set the next handler for reuse
                    cr.setNext(this.clientConnector);
                }
            }
View Full Code Here

   {
      config.stopServer();
   }

   public void testUsers() {
      Client client = new Client(new Context(),adminUserLoc.getSchemeProtocol()) {
         public void handle(Request request,Response response) {
            request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,"admin","admin"));
            super.handle(request,response);
         }
      };
     
      Response response = client.handle(makePost(adminUserLoc,new StringRepresentation("<user xmlns='http://www.atomojo.org/Vocabulary/Admin/2007/1/0' alias='testuser.1' password='mypassword.1'/>",MediaType.APPLICATION_XML)));
      assertTrue(response.getStatus().isSuccess());
     
      Reference testUser1Loc = new Reference(adminUserLoc.toString()+"testuser.1");
      response = client.handle(makeGet(testUser1Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("testuser.1".equals(top.getAttributeValue("alias")));
      } catch (Exception ex) {
         fail("Exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makePost(adminUserLoc,new StringRepresentation("<user xmlns='http://www.atomojo.org/Vocabulary/Admin/2007/1/0' alias='testuser.2' password='mypassword.2'/>",MediaType.APPLICATION_XML)));
      assertTrue(response.getStatus().isSuccess());
     
      Reference testUser2Loc = new Reference(adminUserLoc.toString()+"testuser.2");
      response = client.handle(makeGet(testUser2Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("testuser.2".equals(top.getAttributeValue("alias")));
      } catch (Exception ex) {
         fail("I/O exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makePost(testUser1Loc,new StringRepresentation("<user xmlns='http://www.atomojo.org/Vocabulary/Admin/2007/1/0' alias='testuser.1' password='mypassword.1.changed'><name>Test User</name></user>",MediaType.APPLICATION_XML)));
      assertTrue(response.getStatus().isSuccess());
     
      response = client.handle(makeGet(testUser1Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("Test User".equals(top.getFirstElementNamed(Name.create("{http://www.atomojo.org/Vocabulary/Admin/2007/1/0}name")).getText()));
      } catch (Exception ex) {
         fail("Exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makeDelete(testUser2Loc));
      assertTrue(response.getStatus().isSuccess());
   }
View Full Code Here

      // Make sure we start clean
      System.out.println("Using database directory: "+config.getDatabaseDirectory());
     
      config.startServer();
     
      Client client = new Client(new Context(),config.getServerLocation().getSchemeProtocol()) {
         public void handle(Request request,Response response) {
            request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,"admin","admin"));
            super.handle(request,response);
         }
      };
     
      Reference rootFeed = new Reference(config.getServerLocation()+"R/");
     
      Response response;
      Form headers;
      String entryLocation;
      Reference entryRef;

      response = client.handle(makeHead(rootFeed));
      System.out.println("Status: "+response.getStatus());
      switch (response.getStatus().getCode()) {
         case 404:
         {
            System.out.println("Creating feed.");
            response = client.handle(makePost(rootFeed,new StringRepresentation("<feed xmlns='http://www.w3.org/2005/Atom'><title>Root</title></feed>",MediaType.APPLICATION_ATOM)));
            System.out.println("Status: "+response.getStatus());
            response.getEntity().release();
            assertTrue(response.getStatus().isSuccess());
            break;
         }
         default:
            assertTrue(response.getStatus().isSuccess());
      }
     
      response = client.handle(makePost(rootFeed,new StringRepresentation("<entry xmlns='http://www.w3.org/2005/Atom'><title>Entry 1</title></entry>",MediaType.APPLICATION_ATOM)));
      System.out.println("Status: "+response.getStatus());
      assertTrue(response.getStatus().isSuccess());
      headers = (Form)response.getAttributes().get("org.restlet.http.headers");
      entryLocation = headers.getValues("Location");
      System.out.println("Entry: "+entryLocation);
      //System.out.println("Entry: "+response.getEntity().getText());
      response.getEntity().release();
     
      entryRef = new Reference(entryLocation);
      response = client.handle(makeGet(entryRef));
      System.out.println("Status: "+response.getStatus());
      response.getEntity().release();
      assertTrue(response.getStatus().isSuccess());
     
      response = client.handle(makePost(rootFeed,new StringRepresentation("<entry xmlns='http://www.w3.org/2005/Atom'><title>Entry 2</title></entry>",MediaType.APPLICATION_ATOM)));
      System.out.println("Status: "+response.getStatus());
      response.getEntity().release();
      assertTrue(response.getStatus().isSuccess());
      entryLocation = headers.getValues("Location");
      System.out.println("Entry: "+entryLocation);
      response.getEntity().release();
     
      entryRef = new Reference(entryLocation);
      response = client.handle(makeGet(entryRef));
      System.out.println("Status: "+response.getStatus());
      assertTrue(response.getStatus().isSuccess());
      response.getEntity().release();
     
      response = client.handle(makePut(rootFeed,new StringRepresentation("<feed xmlns='http://www.w3.org/2005/Atom'><title>Root</title><category term='test'/><category term='bingo'/></feed>",MediaType.APPLICATION_ATOM)));
      System.out.println("Status: "+response.getStatus());
      assertTrue(response.getStatus().isSuccess());
      response.getEntity().release();
     
      config.stopServer();
View Full Code Here

      }
      serviceBase = baseURI==null ? URI.create(href) : baseURI.resolve(href);
      authURL = serviceBase.resolve("./auth?session=false").toString();
      sessionURL = serviceBase.resolve("./auth/").toString();
      Protocol protocol = Protocol.valueOf(serviceBase.getScheme());
      client = new Client(new Context(LOG),protocol);
      client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      parser = new XMLRepresentationParser();
      passwords = new TreeMap<String,String>();
      userCache = new Cache<String,User>(100,2*60*1000) {
         public User fetch(AuthCredentials cred,String alias)
View Full Code Here

      // Make sure we start clean
      log.info("Using database directory: "+config.getDatabaseDirectory());
     
      config.startServer();
     
      Client client = new Client(new Context(),config.getServerLocation().getSchemeProtocol());

      loop(log,client);

      loop(log,client);
     
View Full Code Here

      // Make sure we start clean
      log.info("Using database directory: "+config.getDatabaseDirectory());
     
      config.startServer();
     
      Client client = new Client(new Context(),config.getServerLocation().getSchemeProtocol());

      long start = System.currentTimeMillis();

      loop(log,client);
View Full Code Here

   }
  
   public void introspect(ServiceListener listener)
      throws IOException,XMLException
   {
      Client client = new Client(new Context(Logger.getLogger(IntrospectionClient.class.getName())),Protocol.valueOf(location.getScheme()));
      client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      Request request = new Request(Method.GET,location.toString());
      if (identity!=null) {
         request.setChallengeResponse(new ChallengeResponse(ChallengeScheme.HTTP_BASIC,identity.getName(),identity.getPassword()));
      }
      if (cookie!=null) {
         request.getCookies().add(cookie);
      }
      Response response = client.handle(request);
      if (response.getStatus().isSuccess()) {
         Representation rep = response.getEntity();
         String mediaTypeName = rep.getMediaType().getName();
         if (!mediaTypeName.equals(ATOM_SERVICE_XML.getName())) {
            if (mediaTypeName.equals(MediaType.APPLICATION_XML.getName()) || mediaTypeName.equals(MediaType.TEXT_XML.getName()) || mediaTypeName.equals("application/atomserv+xml")) {
View Full Code Here

   {
      this.context = new Context(Logger.getLogger(EntryClient.class.getName()));
      this.feed = null;
      this.location = location;
      this.editURI = editURI;
      this.locClient = client==null ? new Client(context,Protocol.valueOf(location.getScheme())) : client;
      locClient.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      this.editClient = client==null ? new Client(context,Protocol.valueOf(editURI.getScheme())) : client;
      editClient.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
   }
View Full Code Here

      super(identity);
      this.context = new Context(Logger.getLogger(EntryClient.class.getName()));
      this.feed = null;
      this.location = location;
      this.editURI = editURI;
      this.locClient = client==null ? new Client(context,Protocol.valueOf(location.getScheme())) : client;
      locClient.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      this.editClient = client==null ? new Client(context,Protocol.valueOf(editURI.getScheme())) : client;
      editClient.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
   }
View Full Code Here

TOP

Related Classes of org.restlet.Client

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.