Package org.apache.abdera.protocol.client

Examples of org.apache.abdera.protocol.client.AbderaClient


    return options;
  }
 
  private void _methodInvalidates(int type) throws Exception {
   
    AbderaClient abderaClient = new AbderaClient();
    RequestOptions options = getRequestOptions(abderaClient,1);
    ClientResponse response = abderaClient.get(CHECK_CACHE_INVALIDATE, options);
 
    String resp1 = getResponse(response);
   
    response.release();
    assertEquals(resp1, "1");
   
    // calling a method that could change state on the server should invalidate the cache
    options = getRequestOptions(abderaClient,2);
    switch(type) {
      case POST: 
        response = abderaClient.post(
          CHECK_CACHE_INVALIDATE,
          new ByteArrayInputStream("".getBytes()),
          options);
        break;
      case PUT:
        response = abderaClient.put(
          CHECK_CACHE_INVALIDATE,
          new ByteArrayInputStream("".getBytes()),
          options);
        break;
      case DELETE:
        response = abderaClient.delete(
          CHECK_CACHE_INVALIDATE,
          options);
        break;
    }
    response.release();
   
    options = getRequestOptions(abderaClient,3);
    response = abderaClient.get(CHECK_CACHE_INVALIDATE, options);
 
    resp1 = getResponse(response);
    response.release();
    assertEquals(resp1, "3");
  }
View Full Code Here


    assertEquals(resp1, "3");
  }
 
  private void _requestCacheInvalidation(int type) throws Exception {
   
    AbderaClient abderaClient = new AbderaClient();
    RequestOptions options = getRequestOptions(abderaClient,1);
    ClientResponse response = abderaClient.get(CHECK_CACHE_INVALIDATE, options)
    String resp1 = getResponse(response);
    assertEquals(resp1, "1");
   
    // Should not use the cache
    options = getRequestOptions(abderaClient,2);
    switch(type) {
      case NOCACHE: options.setNoCache(true); break;
      case NOSTORE: options.setNoStore(true); break;
      case MAXAGE0: options.setMaxAge(0); break;
    }
    response = abderaClient.get(CHECK_CACHE_INVALIDATE, options);
 
    String resp2 = getResponse(response);
    assertEquals(resp2, "2");
   
    // Should use the cache
    options =getRequestOptions(abderaClient,3);
    switch(type) {
      case NOCACHE: options.setNoCache(false); break;
      case NOSTORE: options.setNoStore(false); break;
      case MAXAGE0: options.setMaxAge(60); break;
    }
    response = abderaClient.get(CHECK_CACHE_INVALIDATE, options);
 
    String resp3 = getResponse(response);
    assertEquals(resp3, "2");
  }
View Full Code Here

    assertEquals(resp3, "2");
  }
 
  private void _responseNoCache(int type) throws Exception {
   
    AbderaClient abderaClient = new AbderaClient();
    RequestOptions options = getRequestOptions(abderaClient,1);
    options.setHeader("x-reqtest", String.valueOf(type));
    ClientResponse response = abderaClient.get(CHECK_NO_CACHE, options);
 
    String resp1 = getResponse(response);
    assertEquals(resp1, "1");
   
    // Should not use the cache
   
    options = getRequestOptions(abderaClient,2);
    options.setHeader("x-reqtest", String.valueOf(type));
    response = abderaClient.get(CHECK_NO_CACHE, options);
 
    String resp2 = getResponse(response);
    assertEquals(resp2, "2");
   
    // Should use the cache
    options = getRequestOptions(abderaClient,3);
    options.setHeader("x-reqtest", String.valueOf(type));
    response = abderaClient.get(CHECK_NO_CACHE, options);
 
    String resp3 = getResponse(response);
    assertEquals(resp3, "3");
  }
View Full Code Here

    return resp.trim();
  }
 
  @Test
  public void testInitCache() {   
    AbderaClient client = new AbderaClient();   
    assertNotNull(client.getCache());
  }
View Full Code Here

  }
 
  @Test
  public void testServiceDocument() throws Exception {
    initializeJetty("/");   
    AbderaClient client = new AbderaClient(new Abdera());
   
    ClientResponse res = client.get("http://localhost:9002/");
    assertEquals(200, res.getStatus());
    StringWriter sw = new StringWriter();
    res.getDocument().writeTo(sw)
       
    assertTrue(sw.toString().contains("accept alternate=\"multipart-related\">image/png"));
View Full Code Here

    initializeJetty("/");

    Abdera abdera = new Abdera();
    Factory factory = abdera.getFactory();

    AbderaClient client = new AbderaClient(abdera);

    Entry entry = factory.newEntry();

    entry.setTitle("my image");
    entry.addAuthor("david");
    entry.setId("tag:apache.org,2008:234534344");
    entry.setSummary("multipart test");   
    entry.setContent(new IRI("cid:234234@example.com"), contentType);

    ClientResponse res = client.post("http://localhost:9002/media", entry,
        this.getClass().getResourceAsStream("info.png"));
    assertEquals(status, res.getStatus());
  }
View Full Code Here

        }
        try {
            System.out.println(">>>FeedAggregatorTest.init");
            scaProviderDomain = SCADomain.newInstance("FeedAggregator.composite");
            abdera = new Abdera();
            client = new AbderaClient(abdera);
            abderaParser = Abdera.getNewParser();
        } catch (Throwable e) {
            System.out.println(e);
            e.printStackTrace();
        }
View Full Code Here

   * and accepts all server certificates and issuers.
   */
  public static void defaultTrustManager() throws Exception {
   
    Abdera abdera = new Abdera();
    AbderaClient client = new AbderaClient(abdera);
   
    // Default trust manager provider registered for port 443
    AbderaClient.registerTrustManager();
   
    client.get("https://localhost:9080/foo");
   
  }
View Full Code Here

   * The default trust manager can be registered for additional ports
   */
  public static void defaultTrustManager2() throws Exception {
   
    Abdera abdera = new Abdera();
    AbderaClient client = new AbderaClient(abdera);
   
    // Default trust manager provider registered for port 9443
    AbderaClient.registerTrustManager(9443);
   
    client.get("https://localhost:9080/foo");
   
  }
View Full Code Here

   * You can provide your own X509TrustManager implementation
   */
  public static void customTrustManager() throws Exception {
   
    Abdera abdera = new Abdera();
    AbderaClient client = new AbderaClient(abdera);
   
    // Default trust manager provider registered for port 9443
    AbderaClient.registerTrustManager(
      new X509TrustManager() {
        public void checkClientTrusted(
          X509Certificate[] certs,
          String arg1)
            throws CertificateException {
          // ignore this one for now
        }

        public void checkServerTrusted(
          X509Certificate[] certs,
          String arg1)
            throws CertificateException {
          // logic to determine if the cert is acceptable
          // throw a CertificateException if it's not
        }

        public X509Certificate[] getAcceptedIssuers() {
          List<X509Certificate> certs = new ArrayList<X509Certificate>();
          // prepare list of accepted issuer certs
          return certs.toArray(new X509Certificate[certs.size()]);
        }
       
      }
    );
   
    client.get("https://localhost:9080/foo");
   
  }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.client.AbderaClient

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.