abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r1173209 [6/49] - in /abdera/abdera2: ./ .settings/ activities/ activities/src/ activities/src/main/ activities/src/main/java/ activities/src/main/java/org/ activities/src/main/java/org/apache/ activities/src/main/java/org/apache/abdera2/ a...
Date Tue, 20 Sep 2011 15:57:20 GMT
Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,331 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.util.Date;
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.model.Base;
+import org.apache.abdera2.model.Document;
+import org.apache.abdera2.model.Element;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.protocol.EntityProvider;
+import org.apache.abdera2.protocol.error.Error;
+import org.apache.abdera2.protocol.error.AbderaProtocolException;
+import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.common.http.Method;
+import org.apache.abdera2.common.http.ResponseType;
+import org.apache.http.entity.mime.content.ContentBody;
+
+/**
+ * A client session. Session's MUST NOT be used by more
+ * than one Thread of execution as a time as multiple threads would stomp 
+ * all over the shared session context. It is critical to completely
+ * consume each ClientResponse before executing an additional request on 
+ * the same session.
+ */
+public class AbderaSession extends Session {
+
+    protected AbderaSession(AbderaClient client) {
+        super(client);
+    }
+    
+    protected AbderaClient getAbderaClient() {
+      return (AbderaClient) client;
+    }
+    
+    protected Abdera getAbdera() {
+      return getAbderaClient().getAbdera();
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected <T extends ClientResponse>T wrap(ClientResponse resp) {
+      return (T)(resp instanceof AbderaClientResponseImpl ?
+        resp : new AbderaClientResponseImpl(resp));
+    }
+    
+    /**
+     * Sends an HTTP POST request to the specified URI.
+     * 
+     * @param uri The request URI
+     * @param provider An EntityProvider implementation providing the payload of the request
+     * @param options The request options
+     */
+    public <T extends ClientResponse>T post(String uri, EntityProvider provider, RequestOptions options) {
+        return wrap(post(uri, new EntityProviderEntity(getAbdera(), provider), options));
+    }
+
+    /**
+     * Sends an HTTP POST request to the specified URI.
+     * 
+     * @param uri The request URI
+     * @param base An Abdera FOM Document or Element object providing the payload of the request
+     * @param options The request options
+     */
+    public <T extends ClientResponse>T post(String uri, Base base, RequestOptions options) {
+        if (base instanceof Document) {
+            Document<?> d = (Document<?>)base;
+            if (options.getSlug() == null && d.getSlug() != null)
+                options.setSlug(d.getSlug());
+        }
+        return wrap(execute("POST", uri, new AbderaEntity(base), options));
+    }
+
+    /**
+     * Sends an HTTP POST request to the specified URI. It uses the media and entry parameters to create a
+     * multipart/related object. If the contentType is not provided this method tries to get it from the type attribute
+     * of the entry content.
+     * 
+     * @param uri The request URI
+     * @param entry The entry that will be sent as the first element of the multipart/related object
+     * @param media The media object that will be sent as the second element of the multipart/related object
+     */
+    public <T extends ClientResponse>T post(String uri, Entry entry, ContentBody media) {
+        return wrap(post(uri, entry, media, getDefaultRequestOptions()));
+    }
+
+    /**
+     * Sends an HTTP POST request to the specified URI. It uses the media and entry parameters to create a
+     * multipart/related object. If the contentType is not provided this method tries to get it from the type attribute
+     * of the entry content.
+     * 
+     * @param uri The request URI
+     * @param entry The entry that will be sent as the first element of the multipart/related object
+     * @param media The media object that will be sent as the second element of the multipart/related object
+     * @param options The request options
+     */
+    public <T extends ClientResponse>T post(String uri, Entry entry, ContentBody media, RequestOptions options) {
+        return wrap(post(uri, entry, media, null, options));
+    }
+
+    /**
+     * Sends an HTTP POST request to the specified URI. It uses the media and entry parameters to create a
+     * multipart/related object.
+     * 
+     * @param uri The request URI
+     * @param entry The entry that will be sent as the first element of the multipart/related object
+     * @param media The media object that will be sent as the second element of the multipart/related object
+     * @param contentType the content type of the media object
+     * @param options The request options
+     */
+    public <T extends ClientResponse>T post(String uri, Entry entry, ContentBody media, String contentType, RequestOptions options) {
+        return wrap(execute("POST", uri, new MultipartRelatedEntity(entry, media, contentType), options));
+    }
+
+    /**
+     * Sends an HTTP PUT request to the specified URI.
+     * 
+     * @param uri The request URI
+     * @param provider An EntityProvider implementation providing the payload of the request
+     * @param options The request options
+     */
+    public <T extends ClientResponse>T put(String uri, EntityProvider provider, RequestOptions options) {
+        if (options == null)
+            options = getDefaultRequestOptions();
+        if (options.isConditionalPut()) {
+            EntityTag etag = provider.getEntityTag();
+            if (etag != null)
+                options.setIfMatch(etag);
+            else {
+                Date lm = provider.getLastModified();
+                if (lm != null)
+                    options.setIfUnmodifiedSince(lm);
+            }
+        }
+        return wrap(put(uri, new EntityProviderEntity(getAbdera(), provider), options));
+    }
+
+    /**
+     * Sends an HTTP PUT request to the specified URI.
+     * 
+     * @param uri The request URI
+     * @param base A FOM Document or Element providing the payload of the request
+     * @param options The request options
+     */
+    public <T extends ClientResponse>T put(String uri, Base base, RequestOptions options) {
+        if (options == null)
+            options = getDefaultRequestOptions();
+        if (base instanceof Document) {
+            Document<?> d = (Document<?>)base;
+            if (options.getSlug() == null && d.getSlug() != null)
+                options.setSlug(d.getSlug());
+
+            if (options.isConditionalPut()) {
+                if (d.getEntityTag() != null)
+                    options.setIfMatch(d.getEntityTag());
+                else if (d.getLastModified() != null)
+                    options.setIfUnmodifiedSince(d.getLastModified());
+            }
+        }
+        return wrap(execute("PUT", uri, new AbderaEntity(base), options));
+    }
+
+    /**
+     * Sends an HTTP POST request to the specified URI using the default options
+     * 
+     * @param uri The request URI
+     * @param provider An EntityProvider implementation providing the payload the request
+     */
+    public <T extends ClientResponse>T post(String uri, EntityProvider provider) {
+        return wrap(post(uri, provider, getDefaultRequestOptions()));
+    }
+
+    /**
+     * Sends an HTTP POST request to the specified URI using the default options
+     * 
+     * @param uri The request URI
+     * @param base A FOM Document or Element providing the payload of the request
+     */
+    public <T extends ClientResponse>T post(String uri, Base base) {
+        return wrap(post(uri, base, getDefaultRequestOptions()));
+    }
+
+    /**
+     * Sends an HTTP PUT request to the specified URI using the default options
+     * 
+     * @param uri The request URI
+     * @param provider An EntityProvider implementation providing the payload of the request
+     */
+    public <T extends ClientResponse>T put(String uri, EntityProvider provider) {
+        return wrap(put(uri, provider, getDefaultRequestOptions()));
+    }
+
+    /**
+     * Sends an HTTP PUT request to the specified URI using the default options
+     * 
+     * @param uri The request URI
+     * @param base A FOM Document or Element providing the payload of the request
+     */
+    public <T extends ClientResponse>T put(String uri, Base base) {
+        return wrap(put(uri, base, getDefaultRequestOptions()));
+    }
+
+    /**
+     * Sends the specified method request to the specified URI. This can be used to send extension HTTP methods to a
+     * server (e.g. PATCH, LOCK, etc)
+     * 
+     * @param method The HTTP method
+     * @param uri The request URI
+     * @param base A FOM Document and Element providing the payload for the request
+     * @param options The Request Options
+     */
+    public <T extends ClientResponse>T execute(
+        String method, 
+        String uri, 
+        Base base, 
+        RequestOptions options) {
+        return wrap(execute(
+            method, 
+            uri, 
+            new AbderaEntity(base), 
+            options));
+    }
+    
+    /**
+     * Sends the specified method request to the specified URI. This can be used to send extension HTTP methods to a
+     * server (e.g. PATCH, LOCK, etc)
+     * 
+     * @param method The HTTP method
+     * @param uri The request URI
+     * @param base A FOM Document and Element providing the payload for the request
+     * @param options The Request Options
+     */
+    public <T extends ClientResponse>T execute(
+        Method method, 
+        String uri, 
+        Base base, 
+        RequestOptions options) {
+        return wrap(execute(
+            method.name(), 
+            uri, 
+            new AbderaEntity(base), 
+            options));
+    }
+
+    /**
+     * Sends the specified method request to the specified URI. This can be used to send extension HTTP methods to a
+     * server (e.g. PATCH, LOCK, etc)
+     * 
+     * @param method The HTTP method
+     * @param uri The request URI
+     * @param provider An EntityProvider implementation providing the payload of the request
+     * @param options The Request Options
+     */
+    public <T extends ClientResponse>T execute(
+        String method, String uri, 
+        EntityProvider provider, 
+        RequestOptions options) {
+        if (options == null)
+            options = getDefaultRequestOptions();
+        return wrap(execute(
+            method, 
+            uri, 
+            new EntityProviderEntity(getAbdera(), provider), 
+            options));
+    }
+
+    /**
+     * Sends the specified method request to the specified URI. This can be used to send extension HTTP methods to a
+     * server (e.g. PATCH, LOCK, etc)
+     * 
+     * @param method The HTTP method
+     * @param uri The request URI
+     * @param provider An EntityProvider implementation providing the payload of the request
+     * @param options The Request Options
+     */
+    public <T extends ClientResponse>T execute(
+        Method method, String uri, 
+        EntityProvider provider, 
+        RequestOptions options) {
+          return wrap(execute(method.name(),uri,provider,options));
+    }
+    
+    @SuppressWarnings("unchecked")
+    protected <T extends ClientResponse>T checkRequestException(ClientResponse response, RequestOptions options) {
+        if (response == null)
+            return (T)response;
+        AbderaClientResponse acr = (AbderaClientResponse) response;
+        ResponseType type = response.getType();
+        if ((type.equals(ResponseType.CLIENT_ERROR) && options.is4xxRequestException()) || (type
+            .equals(ResponseType.SERVER_ERROR) && options.is5xxRequestException())) {
+            try {
+                Document<Element> doc = acr.getDocument();
+                org.apache.abdera2.protocol.error.Error error = null;
+                if (doc != null) {
+                    Element root = doc.getRoot();
+                    if (root instanceof Error)
+                        error = (Error)root;
+                }
+                if (error == null)
+                    error =
+                        org.apache.abdera2.protocol.error.Error.create(
+                          getAbdera(), 
+                          response.getStatus(), 
+                          response.getStatusText());
+                error.throwException();
+            } catch (AbderaProtocolException pe) {
+                throw pe;
+            } catch (RuntimeException e) {
+                throw e;
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return (T)response;
+    }
+    
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/AbderaSession.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicCachingClient.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicCachingClient.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicCachingClient.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicCachingClient.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.cache.HttpCacheStorage;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.client.cache.CacheConfig;
+import org.apache.http.impl.client.cache.CachingHttpClient;
+
+/**
+ * Alternative implementation of the Abdera Client that uses client-side 
+ * Caching. This is intended to be used as a drop-in replacement to the 
+ * base Client when caching capabilities are desired.
+ */
+public class BasicCachingClient extends BasicClient implements CachingClient {
+
+  private DefaultHttpClient inner;
+  private HttpCacheStorage store;
+    
+  public BasicCachingClient(HttpCacheStorage store) {
+    this(DEFAULT_USER_AGENT, store);
+  }
+  
+  public BasicCachingClient(String useragent, HttpCacheStorage store) {
+      this.store = store;
+      this.client = initClient(useragent);
+  }
+  
+  public BasicCachingClient(DefaultHttpClient client, HttpCacheStorage store) {
+      this.store = store;
+      this.inner = client;
+      this.client = initClient(DEFAULT_USER_AGENT); // TODO:
+  }
+  
+  public BasicCachingClient() {
+    super();
+  }
+
+  public BasicCachingClient(DefaultHttpClient client) {
+    this.inner = client;
+    this.client = initClient(DEFAULT_USER_AGENT);
+  }
+
+  public BasicCachingClient(String useragent) {
+    super(useragent);
+  }
+
+  protected HttpClient initClient(String useragent) {
+    return initClient(useragent,inner);
+  }
+  
+  protected HttpClient initClient(String useragent, DefaultHttpClient client) {
+    inner = client != null? client : (DefaultHttpClient) super.initClient(useragent);
+    CacheConfig cacheConfig = new CacheConfig();  
+    cacheConfig.setMaxCacheEntries(1000);
+    cacheConfig.setMaxObjectSizeBytes(8192);
+    cacheConfig.setHeuristicCachingEnabled(true);
+
+    return store != null ? 
+        new CachingHttpClient(inner,store,cacheConfig):
+        new CachingHttpClient(inner, cacheConfig);
+  }
+  
+  public DefaultHttpClient getDefaultHttpClient() {
+    return inner;
+  }
+  
+  public long cacheHits() {
+    return ((CachingHttpClient)getClient()).getCacheHits();
+  }
+  
+  public long cacheMisses() {
+    return ((CachingHttpClient)getClient()).getCacheMisses();
+  }
+  
+  public long cacheUpdates() {
+    return ((CachingHttpClient)getClient()).getCacheUpdates();
+  }
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicCachingClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicClient.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicClient.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicClient.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicClient.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,563 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.net.ProxySelector;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.apache.abdera2.common.anno.AnnoUtil;
+import org.apache.abdera2.common.anno.Version;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.Credentials;
+import org.apache.http.auth.params.AuthPNames;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.params.ClientPNames;
+import org.apache.http.client.params.CookiePolicy;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.params.ConnRoutePNames;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.impl.client.BasicCookieStore;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
+import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
+import org.apache.http.impl.cookie.BasicClientCookie;
+import org.apache.http.params.CoreConnectionPNames;
+import org.apache.http.params.CoreProtocolPNames;
+import org.apache.http.params.HttpParams;
+
+@Version(value="v2.0-SNAPSHOT",
+    name="Abdera",
+    uri="http://abdera.apache.org")
+@SuppressWarnings("unchecked")
+public class BasicClient implements Client {
+
+  protected HttpClient client;
+  
+  public BasicClient() {
+    this(DEFAULT_USER_AGENT);
+  }
+  
+  public BasicClient(String useragent) {
+      this.client = initClient(useragent);
+  }
+  
+  public BasicClient(DefaultHttpClient client) {
+    this.client = client;
+  }
+    
+  /**
+   * Default initialization of the Scheme Registry, subclasses
+   * may overload this to customize the scheme registry 
+   * configuration
+   */
+  protected SchemeRegistry initSchemeRegistry() {
+    SchemeRegistry schemeRegistry = new SchemeRegistry();
+    schemeRegistry.register(
+      new Scheme(
+        "http", 
+        80, 
+        PlainSocketFactory.getSocketFactory()));
+    schemeRegistry.register(
+      new Scheme(
+        "https", 
+        443, 
+        SSLSocketFactory.getSocketFactory()));
+    return schemeRegistry;
+  }
+  
+  /**
+   * Default initialization of the Client Connection Manager,
+   * subclasses may overload this to customize the connection
+   * manager configuration
+   */
+  protected ClientConnectionManager initConnectionManager(SchemeRegistry sr) {
+    ThreadSafeClientConnManager cm = 
+      new ThreadSafeClientConnManager(sr);
+    cm.setDefaultMaxPerRoute(initDefaultMaxConnectionsPerRoute());
+    cm.setMaxTotal(initDefaultMaxTotalConnections());    
+    return cm;
+  }
+  
+  protected int initDefaultMaxConnectionsPerRoute() {
+    return DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
+  }
+  
+  protected int initDefaultMaxTotalConnections() {
+    return DEFAULT_MAX_TOTAL_CONNECTIONS;
+  }
+  
+  protected void initDefaultParameters(HttpParams params) {
+    params.setParameter(
+      CoreProtocolPNames.USE_EXPECT_CONTINUE, 
+      Boolean.TRUE);
+    params.setParameter(
+      ClientPNames.MAX_REDIRECTS, 
+      DEFAULT_MAX_REDIRECTS);
+    params.setParameter(
+      ClientPNames.COOKIE_POLICY, 
+      CookiePolicy.BROWSER_COMPATIBILITY); 
+  }
+  
+  protected HttpClient initClient(String useragent) {
+    SchemeRegistry schemeRegistry = 
+      initSchemeRegistry();
+    ClientConnectionManager cm = 
+      initConnectionManager(schemeRegistry);
+    DefaultHttpClient client = new DefaultHttpClient(cm);
+    HttpParams params = client.getParams();
+    params.setParameter(CoreProtocolPNames.USER_AGENT, useragent);
+    initDefaultParameters(params);
+    return client;
+  }
+  
+  public <T extends Client>T addRequestInterceptor(
+    HttpRequestInterceptor i, 
+    int index) {
+    if (index == -1)
+      getDefaultHttpClient().addRequestInterceptor(i);
+    else
+      getDefaultHttpClient().addRequestInterceptor(i, index);
+    return (T)this;
+  }
+  
+  public <T extends Client>T addResponseInterceptor(
+    HttpResponseInterceptor i, 
+    int index) {
+    if (index == -1)
+      getDefaultHttpClient().addResponseInterceptor(i);
+    else
+      getDefaultHttpClient().addResponseInterceptor(i, index);
+    return (T)this;
+  }
+  
+  public <T extends Client>T clearRequestInterceptors() {
+    getDefaultHttpClient().clearRequestInterceptors();
+    return (T)this;
+  }
+  
+  public <T extends Client>T clearResponseInterceptors() {
+    getDefaultHttpClient().clearResponseInterceptors();
+    return (T)this;
+  }
+  
+  public <T extends Client>T registerScheme(
+    String scheme, 
+    int port, 
+    SchemeSocketFactory factory) {
+    SchemeRegistry sr = 
+      getClient().getConnectionManager().getSchemeRegistry();
+    sr.register(new Scheme(scheme,port,factory));
+    return (T)this;
+  }
+  
+  public HttpClient getClient() {
+    return client;
+  }
+  
+  public DefaultHttpClient getDefaultHttpClient() {
+    return (DefaultHttpClient)client;
+  }
+  
+  /**
+   * Add authentication credentials
+   */
+  public <T extends Client>T addCredentials(
+    String target, 
+    String realm, 
+    String scheme, 
+    Credentials credentials)
+      throws URISyntaxException {
+    String host = AuthScope.ANY_HOST;
+    int port = AuthScope.ANY_PORT;
+    if (target != null) {
+        URI uri = new URI(target);
+        host = uri.getHost();
+        port = uri.getPort();
+    }
+    HttpHost targetHost = new HttpHost(host,port,scheme);
+    getDefaultHttpClient().getCredentialsProvider().setCredentials(
+        new AuthScope(
+            targetHost.getHostName(), 
+            targetHost.getPort(), 
+            realm != null ? realm : AuthScope.ANY_REALM, 
+            scheme != null ? scheme : AuthScope.ANY_SCHEME), 
+        credentials);
+     return (T)this;
+  }
+
+  /**
+   * When multiple authentication schemes are supported by a server, the client will automatically select a scheme
+   * based on the configured priority. For instance, to tell the client to prefer "digest" over "basic", set the
+   * priority by calling setAuthenticationSchemePriority("digest","basic")
+   */
+  public <T extends Client>T setAuthenticationSchemePriority(String... scheme) {
+      List<?> authPrefs = java.util.Arrays.asList(scheme);
+      client.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authPrefs);
+      return (T)this;
+  }
+
+  /**
+   * Returns the current listing of preferred authentication schemes, in order of preference
+   * 
+   * @see setAuthenticationSchemePriority
+   */
+  public String[] getAuthenticationSchemePriority() {
+      List<?> list = (List<?>) client.getParams().getParameter(AuthPNames.TARGET_AUTH_PREF);
+      return list.toArray(new String[list.size()]);
+  }
+
+  /**
+   * Set the maximum number of connections allowed for a single host. This 
+   * is only effective if the Connection Manager implementation used is
+   * a ThreadSafeClientConnManager, otherwise, an IllegalStateException is
+   * thrown. Subclasses can override this method if a different Client
+   * Connection Manager implementation is used that supports setting the
+   * max connections per host.
+   */
+  public <T extends Client>T setMaxConnectionsPerHost(int max) {
+    ClientConnectionManager ccm = 
+      client.getConnectionManager();
+    if (ccm instanceof ThreadSafeClientConnManager) {
+      ThreadSafeClientConnManager cm = 
+        (ThreadSafeClientConnManager) ccm;
+      cm.setDefaultMaxPerRoute(max);
+    } else {
+      throw new IllegalStateException();
+    }
+    return (T)this;
+  }
+
+  /**
+   * Return the maximum number of connections allowed for a single host. This
+   * only returns a value if the Connection Manager implementation is a
+   * ThreadSafeClientConnManager instance, otherwise it returns -1. Subclasses
+   * can override this behavior if a different Connection Manager implementation
+   * is used.
+   */
+  public int getMaxConnectionsPerHost() {
+    ClientConnectionManager ccm = 
+      client.getConnectionManager();
+    if (ccm instanceof ThreadSafeClientConnManager) {
+      ThreadSafeClientConnManager cm = 
+        (ThreadSafeClientConnManager) client.getConnectionManager();
+      return cm.getDefaultMaxPerRoute();
+    } else return -1;
+  }
+
+  /**
+   * Return the maximum number of connections allowed for the client
+   */
+  public <T extends Client>T setMaxConnectionsTotal(int max) {
+    ClientConnectionManager ccm = 
+      client.getConnectionManager();
+    if (ccm instanceof ThreadSafeClientConnManager) {
+      ThreadSafeClientConnManager cm = 
+        (ThreadSafeClientConnManager) client.getConnectionManager();
+      cm.setMaxTotal(max);
+    } else {
+      throw new IllegalStateException();
+    }
+    return (T)this;
+  }
+
+  /**
+   * Return the maximum number of connections allowed for the client
+   */
+  public int getMaxConnectionsTotal() {
+    ClientConnectionManager ccm = 
+      client.getConnectionManager();
+    if (ccm instanceof ThreadSafeClientConnManager) {
+      ThreadSafeClientConnManager cm = 
+        (ThreadSafeClientConnManager) client.getConnectionManager();
+      return cm.getMaxTotal();
+    } return -1;
+  }
+
+  /**
+   * Configure the client to use the specified proxy
+   */
+  public <T extends Client>T setProxy(String host, int port) {
+      HttpHost proxy = 
+        new HttpHost(host, port);
+      client.getParams().setParameter(
+          ConnRoutePNames.DEFAULT_PROXY, proxy);
+      return (T)this;
+  }
+
+  /**
+   * Configure the client to use the proxy configured for the JVM
+   * @return
+   */
+  public <T extends Client>T setStandardProxy() {
+    ProxySelectorRoutePlanner routePlanner = 
+      new ProxySelectorRoutePlanner(
+        client.getConnectionManager().getSchemeRegistry(),
+        ProxySelector.getDefault());  
+    getDefaultHttpClient().setRoutePlanner(routePlanner);
+    return (T)this;
+  }
+  
+  /**
+   * Get the underlying HTTP Client's Cookie Store, creating it automatically
+   * if it does not already exist
+   */
+  public CookieStore getCookieStore() {
+    return getCookieStore(true);
+  }
+  
+  /**
+   * Get the underlying HTTP Client's Cookie Store, optionally creating it
+   * if it does not already exist
+   */
+  public CookieStore getCookieStore(boolean create) {
+    CookieStore store = getDefaultHttpClient().getCookieStore();
+    if (store == null && create) {
+      synchronized(this) {
+        store = new BasicCookieStore();
+        getDefaultHttpClient().setCookieStore(store);
+      }
+    }
+    return store;
+  }
+  
+  /**
+   * Set the underlying HTTP Client Cookie Store implementation
+   */
+  public <T extends Client>T setCookieStore(CookieStore cookieStore) {
+    getDefaultHttpClient().setCookieStore(cookieStore);
+    return (T)this;
+  }
+  
+  /**
+   * Manually add cookies
+   */
+  public <T extends Client>T addCookie(
+      String domain, 
+      String name, 
+      String value) {
+      BasicClientCookie cookie = 
+        new BasicClientCookie(name,value);
+      cookie.setVersion(0);
+      cookie.setDomain(domain);
+      getCookieStore().addCookie(cookie);
+      return (T)this;
+  }
+
+  /**
+   * Manually add cookies
+   */
+  public <T extends Client>T addCookie(
+    String domain, 
+    String name, 
+    String value, 
+    String path, 
+    Date expires, 
+    boolean secure) {
+    BasicClientCookie cookie = 
+      new BasicClientCookie(name,value);
+    cookie.setVersion(0);
+    cookie.setDomain(domain);
+    cookie.setPath(path);
+    cookie.setExpiryDate(expires);
+    cookie.setSecure(secure);
+    getCookieStore().addCookie(cookie);
+    return (T)this;
+  }
+
+  /**
+   * Manually add cookies
+   */
+  public <T extends Client>T addCookies(Cookie cookie) {
+      getCookieStore().addCookie(cookie);
+      return (T)this;
+  }
+
+  /**
+   * Manually add cookies
+   */
+  public <T extends Client>T addCookies(Cookie... cookies) {
+      for (Cookie cookie : cookies) 
+        getCookieStore().addCookie(cookie);
+      return (T)this;
+  }
+
+  /**
+   * Get all the cookies
+   */
+  public Iterable<Cookie> getCookies() {
+    return getCookieStore().getCookies();
+  }
+
+  /**
+   * Get the cookies for a specific domain and path
+   */
+  public Iterable<Cookie> getCookies(String domain, String path) {
+      List<Cookie> cookies = getCookieStore().getCookies();
+      List<Cookie> list = new ArrayList<Cookie>();
+      for (Cookie cookie : cookies) {
+          String test = cookie.getDomain();
+          if (test.startsWith("."))
+              test = test.substring(1);
+          if ((domain.endsWith(test) || test.endsWith(domain)) && 
+              (path == null || cookie.getPath().startsWith(path))) {
+              list.add(cookie);
+          }
+      }
+      return list;
+  }
+
+  /**
+   * Get the cookies for a specific domain
+   */
+  public Iterable<Cookie> getCookies(String domain) {
+      return getCookies(domain, null);
+  }
+
+  /**
+   * Clear the cookies
+   */
+  public <T extends Client>T clearCookies() {
+      getCookieStore().clear();
+      return (T)this;
+  }
+  
+  public <T extends Client>T clearExpiredCookies() {
+      getCookieStore().clearExpired(new Date());
+      return (T)this;
+  }
+
+  /**
+   * Sets the timeout until a connection is etablished. A value of zero means the timeout is not used. The default
+   * value is zero.
+   */
+  public <T extends Client>T setConnectionTimeout(int timeout) {
+      client.getParams().setIntParameter(
+        CoreConnectionPNames.CONNECTION_TIMEOUT, 
+        Math.max(0,timeout));
+      return (T)this;
+  }
+
+  /**
+   * Sets the default socket timeout (SO_TIMEOUT) in milliseconds which is the timeout for waiting for data. A timeout
+   * value of zero is interpreted as an infinite timeout.
+   */
+  public <T extends Client>T setSocketTimeout(int timeout) {
+    client.getParams().setIntParameter(
+      CoreConnectionPNames.SO_TIMEOUT, 
+      Math.max(0,timeout));
+      return (T)this;
+  }
+
+  /**
+   * Return the timeout until a connection is etablished, in milliseconds. A value of zero means the timeout is not
+   * used. The default value is zero.
+   */
+  public int getConnectionTimeout() {
+      return client.getParams().getIntParameter(
+        CoreConnectionPNames.CONNECTION_TIMEOUT, 0);
+  }
+
+  /**
+   * Return the socket timeout for the connection in milliseconds A timeout value of zero is interpreted as an
+   * infinite timeout.
+   */
+  public int getSocketTimeout() {
+      return client.getParams().getIntParameter(
+        CoreConnectionPNames.SO_TIMEOUT, 0);
+  }
+
+  /**
+   * Determines whether Nagle's algorithm is to be used. The Nagle's algorithm tries to conserve bandwidth by
+   * minimizing the number of segments that are sent. When applications wish to decrease network latency and increase
+   * performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY). Data will be sent earlier, at the
+   * cost of an increase in bandwidth consumption.
+   */
+  public void setTcpNoDelay(boolean enable) {
+      client.getParams().setBooleanParameter(
+        CoreConnectionPNames.TCP_NODELAY, enable);
+  }
+
+  /**
+   * Tests if Nagle's algorithm is to be used.
+   */
+  public boolean getTcpNoDelay() {
+    return client.getParams().getBooleanParameter(
+      CoreConnectionPNames.TCP_NODELAY, false);
+  }
+
+  /**
+   * Return the HttpConnectionManagerParams object of the underlying HttpClient. This enables you to configure options
+   * not explicitly exposed by the AbderaClient
+   */
+  public HttpParams getHttpConnectionManagerParams() {
+      return client.getParams();
+  }
+
+  /**
+   * Set the maximum number of redirects
+   */
+  public <T extends Client>T setMaximumRedirects(int redirects) {
+      client.getParams().setIntParameter(
+        ClientPNames.MAX_REDIRECTS, 
+        Math.max(0, redirects));
+      return (T)this;
+  }
+
+  /**
+   * Get the maximum number of redirects
+   */
+  public int getMaximumRedirects() {
+      return client.getParams().getIntParameter(
+        ClientPNames.MAX_REDIRECTS, 
+        DEFAULT_MAX_REDIRECTS);
+  }
+
+  /**
+   * Clear all credentials (including proxy credentials)
+   */
+  public <T extends Client>T clearCredentials() {
+      getDefaultHttpClient().getCredentialsProvider().clear();
+      return (T)this;
+  }
+
+  public <T extends Session>T newSession() {
+    return (T)new Session(this);
+  }
+  
+  public void shutdown() {
+    client.getConnectionManager().shutdown();
+  }
+
+  public static String getDefaultUserAgent() {
+    Version version = AnnoUtil.getVersion(BasicClient.class);
+    return String.format("%s/%s",version.name(),version.value());
+  }
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/BasicClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/CachingClient.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/CachingClient.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/CachingClient.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/CachingClient.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,11 @@
+package org.apache.abdera2.protocol.client;
+
+public interface CachingClient extends Client {
+
+  long cacheHits();
+
+  long cacheMisses();
+
+  long cacheUpdates();
+
+}
\ No newline at end of file

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/CachingClient.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Client.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Client.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Client.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Client.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,222 @@
+package org.apache.abdera2.protocol.client;
+
+import java.net.URISyntaxException;
+import java.util.Date;
+
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.HttpParams;
+
+public interface Client {
+
+  public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 100;
+  public static final int DEFAULT_MAX_REDIRECTS = 10;
+  public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 2;
+  public static final String DEFAULT_USER_AGENT = BasicClient.getDefaultUserAgent();
+
+  <T extends Client>T addRequestInterceptor(HttpRequestInterceptor i,
+      int index);
+
+  <T extends Client>T addResponseInterceptor(HttpResponseInterceptor i,
+      int index);
+
+  <T extends Client>T clearRequestInterceptors();
+
+  <T extends Client>T clearResponseInterceptors();
+
+  <T extends Client>T registerScheme(String scheme, int port,
+      SchemeSocketFactory factory);
+
+  HttpClient getClient();
+
+  DefaultHttpClient getDefaultHttpClient();
+
+  /**
+   * Add authentication credentials
+   */
+  <T extends Client>T addCredentials(String target, String realm,
+      String scheme, Credentials credentials) throws URISyntaxException;
+
+  /**
+   * When multiple authentication schemes are supported by a server, the client will automatically select a scheme
+   * based on the configured priority. For instance, to tell the client to prefer "digest" over "basic", set the
+   * priority by calling setAuthenticationSchemePriority("digest","basic")
+   */
+  <T extends Client>T setAuthenticationSchemePriority(String... scheme);
+
+  /**
+   * Returns the current listing of preferred authentication schemes, in order of preference
+   * 
+   * @see setAuthenticationSchemePriority
+   */
+  String[] getAuthenticationSchemePriority();
+
+  /**
+   * Set the maximum number of connections allowed for a single host. This 
+   * is only effective if the Connection Manager implementation used is
+   * a ThreadSafeClientConnManager, otherwise, an IllegalStateException is
+   * thrown. Subclasses can override this method if a different Client
+   * Connection Manager implementation is used that supports setting the
+   * max connections per host.
+   */
+  <T extends Client>T setMaxConnectionsPerHost(int max);
+
+  /**
+   * Return the maximum number of connections allowed for a single host. This
+   * only returns a value if the Connection Manager implementation is a
+   * ThreadSafeClientConnManager instance, otherwise it returns -1. Subclasses
+   * can override this behavior if a different Connection Manager implementation
+   * is used.
+   */
+  int getMaxConnectionsPerHost();
+
+  /**
+   * Return the maximum number of connections allowed for the client
+   */
+  <T extends Client>T setMaxConnectionsTotal(int max);
+
+  /**
+   * Return the maximum number of connections allowed for the client
+   */
+  int getMaxConnectionsTotal();
+
+  /**
+   * Configure the client to use the specified proxy
+   */
+  <T extends Client>T setProxy(String host, int port);
+
+  /**
+   * Configure the client to use the proxy configured for the JVM
+   * @return
+   */
+  <T extends Client>T setStandardProxy();
+
+  /**
+   * Get the underlying HTTP Client's Cookie Store, creating it automatically
+   * if it does not already exist
+   */
+  CookieStore getCookieStore();
+
+  /**
+   * Get the underlying HTTP Client's Cookie Store, optionally creating it
+   * if it does not already exist
+   */
+  CookieStore getCookieStore(boolean create);
+
+  /**
+   * Set the underlying HTTP Client Cookie Store implementation
+   */
+  <T extends Client>T setCookieStore(CookieStore cookieStore);
+
+  /**
+   * Manually add cookies
+   */
+  <T extends Client>T addCookie(String domain, String name, String value);
+
+  /**
+   * Manually add cookies
+   */
+  <T extends Client>T addCookie(String domain, String name, String value,
+      String path, Date expires, boolean secure);
+
+  /**
+   * Manually add cookies
+   */
+  <T extends Client>T addCookies(Cookie cookie);
+
+  /**
+   * Manually add cookies
+   */
+  <T extends Client>T addCookies(Cookie... cookies);
+
+  /**
+   * Get all the cookies
+   */
+  Iterable<Cookie> getCookies();
+
+  /**
+   * Get the cookies for a specific domain and path
+   */
+  Iterable<Cookie> getCookies(String domain, String path);
+
+  /**
+   * Get the cookies for a specific domain
+   */
+  Iterable<Cookie> getCookies(String domain);
+
+  /**
+   * Clear the cookies
+   */
+  <T extends Client>T clearCookies();
+
+  <T extends Client>T clearExpiredCookies();
+
+  /**
+   * Sets the timeout until a connection is etablished. A value of zero means the timeout is not used. The default
+   * value is zero.
+   */
+  <T extends Client>T setConnectionTimeout(int timeout);
+
+  /**
+   * Sets the default socket timeout (SO_TIMEOUT) in milliseconds which is the timeout for waiting for data. A timeout
+   * value of zero is interpreted as an infinite timeout.
+   */
+  <T extends Client>T setSocketTimeout(int timeout);
+
+  /**
+   * Return the timeout until a connection is etablished, in milliseconds. A value of zero means the timeout is not
+   * used. The default value is zero.
+   */
+  int getConnectionTimeout();
+
+  /**
+   * Return the socket timeout for the connection in milliseconds A timeout value of zero is interpreted as an
+   * infinite timeout.
+   */
+  int getSocketTimeout();
+
+  /**
+   * Determines whether Nagle's algorithm is to be used. The Nagle's algorithm tries to conserve bandwidth by
+   * minimizing the number of segments that are sent. When applications wish to decrease network latency and increase
+   * performance, they can disable Nagle's algorithm (that is enable TCP_NODELAY). Data will be sent earlier, at the
+   * cost of an increase in bandwidth consumption.
+   */
+  void setTcpNoDelay(boolean enable);
+
+  /**
+   * Tests if Nagle's algorithm is to be used.
+   */
+  boolean getTcpNoDelay();
+
+  /**
+   * Return the HttpConnectionManagerParams object of the underlying HttpClient. This enables you to configure options
+   * not explicitly exposed by the AbderaClient
+   */
+  HttpParams getHttpConnectionManagerParams();
+
+  /**
+   * Set the maximum number of redirects
+   */
+  <T extends Client>T setMaximumRedirects(int redirects);
+
+  /**
+   * Get the maximum number of redirects
+   */
+  int getMaximumRedirects();
+
+  /**
+   * Clear all credentials (including proxy credentials)
+   */
+  <T extends Client>T clearCredentials();
+
+  <T extends Session>T newSession();
+
+  void shutdown();
+
+}
\ No newline at end of file

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/Client.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.Date;
+
+import org.apache.abdera2.common.http.Method;
+import org.apache.abdera2.common.protocol.Response;
+
+public interface ClientResponse extends Response {
+
+    Session getSession();
+  
+    /**
+     * Return the request method
+     */
+    Method getMethod();
+
+    /**
+     * Return the request URI. The request was redirected, this will return the new URI
+     */
+    String getUri();
+
+    /**
+     * Release the resources associated with this response
+     */
+    void release();
+
+    /**
+     * Returns the inputstream used to read data from this response
+     */
+    InputStream getInputStream() throws IOException;
+
+    /**
+     * Returns a reader used to read data from this response. Will use the character set declared in the Content-Type to
+     * create the reader
+     */
+    Reader getReader() throws IOException;
+
+    /**
+     * Returns a reader used to read data from this response. Will use the character set specified to create the reader
+     */
+    Reader getReader(String charset) throws IOException;
+
+    /**
+     * Return the server-specified date returned in the response
+     */
+    Date getServerDate();
+
+    /**
+     * Return the character set encoding specified in the ContentType header, if any
+     */
+    String getCharacterEncoding();
+
+    void writeTo(OutputStream out) throws IOException;
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponse.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,308 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera2.common.http.Authentication;
+import org.apache.abdera2.common.http.CacheControl;
+import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.common.http.Method;
+import org.apache.abdera2.common.http.Preference;
+import org.apache.abdera2.common.http.ResponseType;
+import org.apache.abdera2.common.http.WebLink;
+import org.apache.abdera2.common.io.Compression;
+import org.apache.abdera2.common.iri.IRI;
+import org.apache.abdera2.common.lang.Lang;
+import org.apache.abdera2.common.text.Codec;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.entity.BufferedHttpEntity;
+import org.apache.http.impl.cookie.DateUtils;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+
+class ClientResponseImpl 
+  implements ClientResponse {
+
+  private final HttpResponse response;
+  private final Session session;
+  private final Method method;
+  private final HttpContext localContext;
+  private BufferedHttpEntity buffer;
+  
+  public ClientResponseImpl(
+    Session session,
+    HttpResponse response,
+    String method,
+    HttpContext localContext) {
+    this.response = response;
+    this.session = session;
+    this.method = Method.get(method,true);
+    this.localContext = localContext;
+  }
+  
+  public Session getSession() {
+    return session;
+  }
+  
+  public EntityTag getEntityTag() {
+    String et = getHeader("ETag");
+    return et != null ? new EntityTag(et) : null;
+  }
+
+  public ResponseType getType() {
+    return ResponseType.select(response.getStatusLine().getStatusCode());
+  }
+
+  public int getStatus() {
+    return response.getStatusLine().getStatusCode();
+  }
+
+  public String getStatusText() {
+    return response.getStatusLine().getReasonPhrase();
+  }
+
+  public Date getLastModified() {
+    return getDateHeader("Last-Modified");
+  }
+
+  public long getContentLength() {
+    try {
+      HttpEntity entity = getEntity();
+      return entity != null ? entity.getContentLength() : 0;
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
+    }
+  }
+
+  public String getAllow() {
+    return getHeader("Allow");
+  }
+
+  public IRI getLocation() {
+    String l = getHeader("Location");
+    return l != null ? new IRI(l) : null;
+  }
+
+  public long getAge() {
+    String a = getHeader("Age");
+    return a != null ? Long.parseLong(a) : -1;
+  }
+
+  public Date getExpires() {
+    return getDateHeader("Expires");
+  }
+
+  public String getHeader(String name) {
+    Header header = response.getFirstHeader(name);
+    return header != null ? header.getValue() : null;
+  }
+
+  public String getDecodedHeader(String name) {
+    String val = getHeader(name);
+    return val != null ? Codec.decode(val) : null;
+  }
+
+  @SuppressWarnings("unchecked")
+  public Iterable<Object> getHeaders(String name) {
+    Header[] headers = response.getHeaders(name);
+    if (headers == null) return Collections.EMPTY_LIST;
+    List<Object> ret = new ArrayList<Object>();
+    for (int n = 0; n < headers.length; n++) 
+      ret.add(headers[n].getValue());
+    return ret;
+  }
+
+  public Iterable<String> getDecodedHeaders(String name) {
+    Iterable<Object> headers = getHeaders(name);
+    List<String> ret = new ArrayList<String>();
+    for (Object h : headers)
+      ret.add(Codec.decode(h.toString()));
+    return ret;
+  }
+
+  public Iterable<String> getHeaderNames() {
+    Header[] headers = response.getAllHeaders();
+    Set<String> set = new HashSet<String>();
+    for (Header header : headers)
+      set.add(header.getName());
+    return set;
+  }
+
+  public String getSlug() {
+    return getHeader("Slug");
+  }
+
+  public MimeType getContentType() {
+    try {
+      String ct = getHeader("Content-Type");
+      return ct != null ? new MimeType(ct) : null;
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
+    }
+  }
+
+  public IRI getContentLocation() {
+    String ct = getHeader("Location");
+    return ct != null ? new IRI(ct) : null;
+  }
+
+  public String getContentLanguage() {
+    String ct = getHeader("Content-Language");
+    return ct != null ? new Lang(ct).toString() : null;
+  }
+
+  public Date getDateHeader(String name) {
+    try {
+      String ct = getHeader(name);
+      return ct != null ? DateUtils.parseDate(ct) : null;
+    } catch (Throwable t) {
+      throw new RuntimeException(t);
+    }
+  }
+
+  public CacheControl getCacheControl() {
+    String cc = getHeader("Cache-Control");
+    return cc != null ? new CacheControl(cc) : null;
+  }
+
+  @SuppressWarnings("unchecked")
+  public Iterable<Authentication> getAuthentication() {
+    String cc = getHeader("WWW-Authenticate");
+    return cc != null ? Authentication.parse(cc) : Collections.EMPTY_LIST;
+  }
+
+  public Method getMethod() {
+    return method;
+  }
+
+  public String getUri() {
+    HttpUriRequest currentReq = 
+      (HttpUriRequest) localContext.getAttribute( 
+        ExecutionContext.HTTP_REQUEST);
+    HttpHost currentHost = (HttpHost)  localContext.getAttribute( 
+        ExecutionContext.HTTP_TARGET_HOST);
+    String currentUrl = currentHost.toURI() + currentReq.getURI();
+    return currentUrl;
+  }
+
+  public void release() {
+    try {
+      EntityUtils.consume(response.getEntity());
+    } catch (Throwable t) {}
+  }
+
+  private HttpEntity getEntity() throws IOException {
+    if (buffer == null) {
+      HttpEntity entity = response.getEntity();
+      if (entity != null)
+        buffer = new BufferedHttpEntity(response.getEntity());
+    }
+    return buffer;
+  }
+  
+  public InputStream getInputStream() throws IOException {
+    InputStream in = null;
+    String ce = getHeader("Content-Encoding");
+    HttpEntity entity = getEntity();
+    in = entity != null ? entity.getContent() : null;
+    if (ce != null && in != null)
+        in = Compression.wrap(in, ce);
+    return in;
+  }
+
+  public Reader getReader() throws IOException {
+    return getReader(getCharacterEncoding());
+  }
+
+  public Reader getReader(String charset) throws IOException {
+    InputStream in = getInputStream();
+    if (in == null) return null;
+    Reader reader = 
+      charset != null ? 
+          new InputStreamReader(getInputStream(),charset) :
+          new InputStreamReader(getInputStream());
+    return reader;
+  }
+
+  public Date getServerDate() {
+    return getDateHeader("Date");
+  }
+
+  public String getCharacterEncoding() {
+    return getHeader("Content-Encoding");
+  }
+
+  public void writeTo(OutputStream out) throws IOException {
+    InputStream in = getInputStream();
+    byte[] buf = new byte[1024];
+    int r = -1;
+    while((r = in.read(buf)) > -1)
+      out.write(buf,0,r);
+  }
+
+  public Iterable<WebLink> getWebLinks() {
+    List<WebLink> links = new ArrayList<WebLink>();
+    Iterable<Object> headers = this.getHeaders("Link");
+    for (Object obj : headers) {
+      Iterable<WebLink> list = WebLink.parse(obj.toString());
+      for (WebLink link : list)
+        links.add(link);
+    }
+    return links;
+  }
+  
+  public Iterable<Preference> getPrefer() {
+    List<Preference> links = new ArrayList<Preference>();
+    Iterable<Object> headers = this.getHeaders("Prefer");
+    for (Object obj : headers) {
+      Iterable<Preference> list = Preference.parse(obj.toString());
+      for (Preference link : list)
+        links.add(link);
+    }
+    return links;
+  }
+  
+  public Iterable<Preference> getPreferApplied() {
+    List<Preference> links = new ArrayList<Preference>();
+    Iterable<Object> headers = this.getHeaders("Preference-Applied");
+    for (Object obj : headers) {
+      Iterable<Preference> list = Preference.parse(obj.toString());
+      for (Preference link : list)
+        links.add(link);
+    }
+    return links;
+  }
+}
\ No newline at end of file

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseImpl.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,169 @@
+package org.apache.abdera2.protocol.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.Date;
+
+import javax.activation.MimeType;
+
+import org.apache.abdera2.common.http.Authentication;
+import org.apache.abdera2.common.http.CacheControl;
+import org.apache.abdera2.common.http.EntityTag;
+import org.apache.abdera2.common.http.Method;
+import org.apache.abdera2.common.http.Preference;
+import org.apache.abdera2.common.http.ResponseType;
+import org.apache.abdera2.common.http.WebLink;
+import org.apache.abdera2.common.iri.IRI;
+
+public class ClientResponseWrapper 
+  implements ClientResponse {
+
+  private final ClientResponse internal;
+  
+  public ClientResponseWrapper(ClientResponse internal) {
+    this.internal = internal;
+  }
+  
+  public EntityTag getEntityTag() {
+    return internal.getEntityTag();
+  }
+
+  public ResponseType getType() {
+    return internal.getType();
+  }
+
+  public int getStatus() {
+    return internal.getStatus();
+  }
+
+  public String getStatusText() {
+    return internal.getStatusText();
+  }
+
+  public Date getLastModified() {
+    return internal.getLastModified();
+  }
+
+  public long getContentLength() {
+    return internal.getContentLength();
+  }
+
+  public String getAllow() {
+    return internal.getAllow();
+  }
+
+  public IRI getLocation() {
+    return internal.getLocation();
+  }
+
+  public long getAge() {
+    return internal.getAge();
+  }
+
+  public Date getExpires() {
+    return internal.getExpires();
+  }
+
+  public String getHeader(String name) {
+    return internal.getHeader(name);
+  }
+
+  public String getDecodedHeader(String name) {
+    return internal.getDecodedHeader(name);
+  }
+
+  public Iterable<Object> getHeaders(String name) {
+    return internal.getHeaders(name);
+  }
+
+  public Iterable<String> getDecodedHeaders(String name) {
+    return internal.getDecodedHeaders(name);
+  }
+
+  public Iterable<String> getHeaderNames() {
+    return internal.getHeaderNames();
+  }
+
+  public String getSlug() {
+    return internal.getSlug();
+  }
+
+  public MimeType getContentType() {
+    return internal.getContentType();
+  }
+
+  public IRI getContentLocation() {
+    return internal.getContentLocation();
+  }
+
+  public String getContentLanguage() {
+    return internal.getContentLanguage();
+  }
+
+  public Date getDateHeader(String name) {
+    return internal.getDateHeader(name);
+  }
+
+  public CacheControl getCacheControl() {
+    return internal.getCacheControl();
+  }
+
+  public Iterable<Authentication> getAuthentication() {
+    return internal.getAuthentication();
+  }
+
+  public Iterable<WebLink> getWebLinks() {
+    return internal.getWebLinks();
+  }
+
+  public Iterable<Preference> getPrefer() {
+    return internal.getPrefer();
+  }
+
+  public Iterable<Preference> getPreferApplied() {
+    return internal.getPreferApplied();
+  }
+
+  public Method getMethod() {
+    return internal.getMethod();
+  }
+
+  public String getUri() {
+    return internal.getUri();
+  }
+
+  public void release() {
+    internal.release();
+  }
+
+  public InputStream getInputStream() throws IOException {
+    return internal.getInputStream();
+  }
+
+  public Reader getReader() throws IOException {
+    return internal.getReader();
+  }
+
+  public Reader getReader(String charset) throws IOException {
+    return internal.getReader(charset);
+  }
+
+  public Date getServerDate() {
+    return internal.getServerDate();
+  }
+
+  public String getCharacterEncoding() {
+    return internal.getCharacterEncoding();
+  }
+
+  public void writeTo(OutputStream out) throws IOException {
+    internal.writeTo(out);
+  }
+
+  public Session getSession() {
+    return internal.getSession();
+  }
+
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientResponseWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientWrapper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientWrapper.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientWrapper.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientWrapper.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,211 @@
+package org.apache.abdera2.protocol.client;
+
+import java.net.URISyntaxException;
+import java.util.Date;
+
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.auth.Credentials;
+import org.apache.http.client.CookieStore;
+import org.apache.http.client.HttpClient;
+import org.apache.http.conn.scheme.SchemeSocketFactory;
+import org.apache.http.cookie.Cookie;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.params.HttpParams;
+
+@SuppressWarnings("unchecked")
+public abstract class ClientWrapper 
+  implements Client {
+
+  private final Client internal;
+  
+  protected ClientWrapper(Client client) {
+    this.internal = client;
+  }
+  
+  public <T extends Client>T  addRequestInterceptor(HttpRequestInterceptor i, int index) {
+    internal.addRequestInterceptor(i, index);
+    return (T)this;
+  }
+
+  public <T extends Client>T  addResponseInterceptor(HttpResponseInterceptor i, int index) {
+    internal.addResponseInterceptor(i,index);
+    return (T)this;
+  }
+
+  public <T extends Client>T  clearRequestInterceptors() {
+    internal.clearRequestInterceptors();
+    return (T)this;
+  }
+
+  public <T extends Client>T  clearResponseInterceptors() {
+    internal.clearResponseInterceptors();
+    return (T)this;
+  }
+
+  public <T extends Client>T  registerScheme(String scheme, int port,
+      SchemeSocketFactory factory) {
+    internal.registerScheme(scheme, port, factory);
+    return (T)this;
+  }
+
+  public HttpClient getClient() {
+    return internal.getClient();
+  }
+
+  public DefaultHttpClient getDefaultHttpClient() {
+    return internal.getDefaultHttpClient();
+  }
+
+  public <T extends Client>T  addCredentials(String target, String realm, String scheme,
+      Credentials credentials) throws URISyntaxException {
+    internal.addCredentials(target, realm, scheme, credentials);
+    return (T)this;
+  }
+
+  public <T extends Client>T  setAuthenticationSchemePriority(String... scheme) {
+    internal.setAuthenticationSchemePriority(scheme);
+    return (T)this;
+  }
+
+  public String[] getAuthenticationSchemePriority() {
+    return internal.getAuthenticationSchemePriority();
+  }
+
+  public <T extends Client>T  setMaxConnectionsPerHost(int max) {
+    internal.setMaxConnectionsPerHost(max);
+    return (T)this;
+  }
+
+  public int getMaxConnectionsPerHost() {
+    return internal.getMaxConnectionsPerHost();
+  }
+
+  public <T extends Client>T  setMaxConnectionsTotal(int max) {
+    internal.setMaxConnectionsTotal(max);
+    return (T)this;
+  }
+
+  public int getMaxConnectionsTotal() {
+    return internal.getMaxConnectionsTotal();
+  }
+
+  public <T extends Client>T  setProxy(String host, int port) {
+    internal.setProxy(host,port);
+    return (T)this;
+  }
+
+  public <T extends Client>T  setStandardProxy() {
+    internal.setStandardProxy();
+    return (T)this;
+  }
+
+  public CookieStore getCookieStore() {
+    return internal.getCookieStore();
+  }
+
+  public CookieStore getCookieStore(boolean create) {
+    return internal.getCookieStore(create);
+  }
+
+  public <T extends Client>T  setCookieStore(CookieStore cookieStore) {
+    internal.setCookieStore(cookieStore);
+    return (T)this;
+  }
+
+  public <T extends Client>T  addCookie(String domain, String name, String value) {
+    internal.addCookie(domain, name, value);
+    return (T)this;
+  }
+
+  public <T extends Client>T  addCookie(String domain, String name, String value,
+      String path, Date expires, boolean secure) {
+    internal.addCookie(domain, name, value, path, expires, secure);
+    return (T)this;
+  }
+
+  public <T extends Client>T  addCookies(Cookie cookie) {
+    internal.addCookies(cookie);
+    return (T)this;
+  }
+
+  public <T extends Client>T  addCookies(Cookie... cookies) {
+    internal.addCookies(cookies);
+    return (T)this;
+  }
+
+  public Iterable<Cookie> getCookies() {
+    return internal.getCookies();
+  }
+
+  public Iterable<Cookie> getCookies(String domain, String path) {
+    return internal.getCookies(domain, path);
+  }
+
+  public Iterable<Cookie> getCookies(String domain) {
+    return internal.getCookies(domain);
+  }
+
+  public <T extends Client>T  clearCookies() {
+    internal.clearCookies();
+    return (T)this;
+  }
+
+  public <T extends Client>T  clearExpiredCookies() {
+    internal.clearExpiredCookies();
+    return (T)this;
+  }
+
+  public <T extends Client>T  setConnectionTimeout(int timeout) {
+    internal.setConnectionTimeout(timeout);
+    return (T)this;
+  }
+
+  public <T extends Client>T  setSocketTimeout(int timeout) {
+    internal.setSocketTimeout(timeout);
+    return (T)this;
+  }
+
+  public int getConnectionTimeout() {
+    return internal.getConnectionTimeout();
+  }
+
+  public int getSocketTimeout() {
+    return internal.getSocketTimeout();
+  }
+
+  public void setTcpNoDelay(boolean enable) {
+    internal.setTcpNoDelay(enable);
+  }
+
+  public boolean getTcpNoDelay() {
+    return internal.getTcpNoDelay();
+  }
+
+  public HttpParams getHttpConnectionManagerParams() {
+   return internal.getHttpConnectionManagerParams();
+  }
+
+  public <T extends Client>T  setMaximumRedirects(int redirects) {
+    internal.setMaximumRedirects(redirects);
+    return (T)this;
+  }
+
+  public int getMaximumRedirects() {
+    return internal.getMaximumRedirects();
+  }
+
+  public <T extends Client>T  clearCredentials() {
+    internal.clearCredentials();
+    return (T)this;
+  }
+
+  public <T extends Session>T newSession() {
+    return (T)new Session(this);
+  }
+
+  public void shutdown() {
+    internal.shutdown();
+  }
+
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/ClientWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/EntityProviderEntity.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/EntityProviderEntity.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/EntityProviderEntity.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/EntityProviderEntity.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.abdera2.Abdera;
+import org.apache.abdera2.protocol.EntityProvider;
+import org.apache.abdera2.writer.StreamWriter;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.message.BasicHeader;
+
+/**
+ * Implementation of HttpEntity based on the EntityProvider interface
+ */
+public class EntityProviderEntity 
+    extends BasicHttpEntity 
+    implements HttpEntity {
+
+    private final Abdera abdera;
+    private final EntityProvider provider;
+    private byte[] buf = null;
+    private InputStream content = null;
+    private boolean auto_indent = false;
+    private String encoding = "UTF-8";
+    private final Header ct;
+
+    public EntityProviderEntity(
+      EntityProvider provider) {
+      this(Abdera.getInstance(),provider);
+    }
+    
+    public EntityProviderEntity(
+        Abdera abdera, 
+        EntityProvider provider) {
+          this.abdera = abdera;
+          this.provider = provider;
+          this.ct = new BasicHeader(
+            "Content-Type", provider.getContentType());
+    }
+
+    private void write(OutputStream out) {
+        provider.writeTo(
+            abdera.create(StreamWriter.class)
+              .setOutputStream(out, encoding)
+                .setAutoIndent(auto_indent));
+    }
+
+    public boolean isChunked() {
+      return true;
+    }
+    
+    public long getContentLength() {
+      return -1;
+    }
+
+    public Header getContentType() {
+        return ct;
+    }
+
+    public boolean isRepeatable() {
+        return provider.isRepeatable();
+    }
+
+    @Override
+    public InputStream getContent() {
+      InputStream in = null;
+      if (isRepeatable()) {
+        if (buf == null) {
+          ByteArrayOutputStream out = new ByteArrayOutputStream();
+          write(out);
+          buf = out.toByteArray();
+        }
+        in = new ByteArrayInputStream(buf);
+      } else {
+        if (content == null) {
+          if (buf == null) {
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            write(out);
+            buf = out.toByteArray();
+          }
+          content = new ByteArrayInputStream(buf);
+        }
+        in = content;
+      }
+      return in;
+    }
+    
+    @Override
+    public void writeTo(OutputStream out) throws IOException {
+      write(out);
+    }
+
+    public boolean isAutoIndent() {
+        return auto_indent;
+    }
+
+    public void setAutoIndent(boolean auto_indent) {
+        this.auto_indent = auto_indent;
+    }
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/EntityProviderEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/LocalizationHelper.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/LocalizationHelper.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/LocalizationHelper.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/LocalizationHelper.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Locale;
+
+import org.apache.abdera2.common.lang.Lang;
+import org.apache.abdera2.common.lang.Range;
+import org.apache.abdera2.model.Entry;
+import org.apache.abdera2.model.Link;
+import org.apache.abdera2.model.Source;
+
+public final class LocalizationHelper {
+
+    private LocalizationHelper() {
+    }
+
+    /**
+     * Select an appropriate subset of alternate links for the default locale
+     */
+    public static Iterable<Link> selectAlternate(Source source) {
+        return selectAlternate(source, Locale.getDefault());
+    }
+
+    /**
+     * Select an appropriate subset of alternate links for the default locale
+     */
+    public static Iterable<Link> selectAlternate(Entry entry) {
+        return selectAlternate(entry, Locale.getDefault());
+    }
+
+    /**
+     * Select an appropriate subset of alternate links for the specified locale
+     */
+    public static Iterable<Link> selectAlternate(Source source, Locale locale) {
+        return selectAlternate(source, new Range(Lang.fromLocale(locale), true));
+    }
+
+    /**
+     * Select an appropriate subset of alternate links for the specified locale
+     */
+    public static Iterable<Link> selectAlternate(Entry entry, Locale locale) {
+        return selectAlternate(entry, new Range(Lang.fromLocale(locale), true));
+    }
+
+    /**
+     * Select an appropriate subset of alternate links for the specified locales
+     */
+    public static Iterable<Link> selectAlternate(Entry entry, Locale... locales) {
+        Range[] ranges = new Range[locales.length];
+        for (int n = 0; n < locales.length; n++)
+            ranges[n] = new Range(Lang.fromLocale(locales[n]), true);
+        return selectAlternate(entry, ranges);
+    }
+
+    public static Iterable<Link> selectAlternate(Entry entry, Range range) {
+        return selectAlternate(entry, new Range[] {range});
+    }
+
+    public static Iterable<Link> selectAlternate(Entry entry, Range... ranges) {
+        return selectAlternate(entry.getLinks("alternate"), ranges);
+    }
+
+    public static Iterable<Link> selectAlternate(Entry entry, String range) {
+        return selectAlternate(entry, new String[] {range});
+    }
+
+    public static Iterable<Link> selectAlternate(Entry entry, String... ranges) {
+        Range[] r = new Range[ranges.length];
+        for (int n = 0; n < ranges.length; n++)
+            r[n] = new Range(ranges[n], true);
+        return selectAlternate(entry, r);
+    }
+
+    public static Iterable<Link> selectAlternate(Source source, Locale... locales) {
+        Range[] ranges = new Range[locales.length];
+        for (int n = 0; n < locales.length; n++)
+            ranges[n] = new Range(Lang.fromLocale(locales[n]), true);
+        return selectAlternate(source, ranges);
+    }
+
+    public static Iterable<Link> selectAlternate(Source source, Range range) {
+        return selectAlternate(source, new Range[] {range});
+    }
+
+    public static Iterable<Link> selectAlternate(Source source, Range... ranges) {
+        return selectAlternate(source.getLinks("alternate"), ranges);
+    }
+
+    public static Iterable<Link> selectAlternate(Source source, String range) {
+        return selectAlternate(source, new String[] {range});
+    }
+
+    public static Iterable<Link> selectAlternate(Source source, String... ranges) {
+        Range[] r = new Range[ranges.length];
+        for (int n = 0; n < ranges.length; n++)
+            r[n] = new Range(ranges[n], true);
+        return selectAlternate(source, r);
+    }
+
+    public static Iterable<Link> selectAlternate(List<Link> links, String range) {
+        return selectAlternate(links, new Range(range, true));
+    }
+
+    public static Iterable<Link> selectAlternate(List<Link> links, Range range) {
+        return selectAlternate(links, new Range[] {range});
+    }
+
+    public static Iterable<Link> selectAlternate(List<Link> links, Range... ranges) {
+        List<Link> matching = new ArrayList<Link>();
+        for (Range range : ranges) {
+            for (Link link : links) {
+                String hreflang = link.getHrefLang();
+                if (hreflang != null) {
+                    Lang lang = new Lang(hreflang);
+                    Range basic = range.toBasicRange();
+                    Lang blang = !basic.toString().equals("*") ? new Lang(basic.toString()) : null;
+                    if (range.matches(lang) || (blang != null && lang.isParentOf(blang)))
+                        matching.add(link);
+                }
+            }
+            Collections.sort(matching, new Comparator<Link>() {
+                public int compare(Link o1, Link o2) {
+                    Lang l1 = new Lang(o1.getHrefLang());
+                    Lang l2 = new Lang(o2.getHrefLang());
+                    return l1.compareTo(l2);
+                }
+            });
+        }
+        return matching;
+    }
+
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/LocalizationHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/MultipartRelatedEntity.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/MultipartRelatedEntity.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/MultipartRelatedEntity.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/MultipartRelatedEntity.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+
+import org.apache.abdera2.model.Element.Helper;
+import org.apache.abdera2.model.Entry;
+import org.apache.http.Header;
+import org.apache.http.HttpEntity;
+import org.apache.http.entity.BasicHttpEntity;
+import org.apache.http.entity.mime.FormBodyPart;
+import org.apache.http.entity.mime.HttpMultipart;
+import org.apache.http.entity.mime.HttpMultipartMode;
+import org.apache.http.entity.mime.content.ContentBody;
+import org.apache.http.message.BasicHeader;
+
+/**
+ * Implementation of the HttpEntity class for use with Multipart Atom Posts.
+ * The first part of the multipart related package is an Atom Entry document
+ * whose content element specifies a src="cid:..." attribute referencing the
+ * second part of the multipart package. This is used primarily as a means
+ * of simplifying posts to Atompub Media Collections.
+ */
+public class MultipartRelatedEntity 
+  extends BasicHttpEntity 
+  implements HttpEntity {
+
+    private final HttpMultipart multipart;
+    private final Header contentType;
+    
+    private String boundary;
+    
+    public MultipartRelatedEntity(
+      Entry entry, 
+      ContentBody other) {
+        this(entry, other, null, null);
+    }
+
+    public MultipartRelatedEntity(
+      Entry entry, 
+      ContentBody other, 
+      String contentType) {
+        this(entry, other, contentType, null);
+    }
+
+    public MultipartRelatedEntity(
+      Entry entry, 
+      ContentBody other, 
+      String contentType, 
+      String boundary) {
+        if (entry == null ||
+            other == null)
+          throw new IllegalArgumentException();
+        this.boundary = boundary != null ? boundary : String.valueOf(System.currentTimeMillis());
+        this.contentType = 
+          new BasicHeader(
+              "Content-Type",String.format("Multipart/Related; boundary=\"%s\";type=\"%s\"",this.boundary,Helper.getMimeType(entry)));
+        String cs = entry.getDocument().getCharset();
+        Charset charset = cs != null ? Charset.forName(cs) : Charset.defaultCharset();
+        multipart = new HttpMultipart("related", charset, this.boundary, HttpMultipartMode.STRICT);
+        multipart.addBodyPart(new FormBodyPart("entry",new AbderaBody(entry)));
+        String contentId = entry.getContentSrc().toString();
+        if (!contentId.matches("cid\\:.+")) {
+            throw new IllegalArgumentException("entry content source is not a correct content-ID");
+        }
+        FormBodyPart other_part = new FormBodyPart("other",other);
+        other_part.addField("Content-ID", String.format("<%s>",contentId.substring(4)));
+        other_part.addField("Content-Type", other.getMimeType());
+        multipart.addBodyPart(other_part);
+    }
+    
+    public void consumeContent()
+      throws IOException, UnsupportedOperationException{
+      if (isStreaming()) {
+        throw new UnsupportedOperationException(
+          "Streaming entity does not implement #consumeContent()");
+      }
+    }
+    
+    public InputStream getContent() {
+      throw new UnsupportedOperationException();
+    }
+    
+    public void writeTo(OutputStream out) throws IOException {
+      multipart.writeTo(out);
+    }
+
+    public long getContentLength() {
+        return -1;
+    }
+    
+    public Header getContentType() {
+       return contentType; 
+    }
+
+    public boolean isRepeatable() {
+      for (FormBodyPart part: this.multipart.getBodyParts()) {
+        ContentBody body = part.getBody();
+        if (body.getContentLength() < 0) {
+          return false;
+        }
+      }
+      return true;
+    }
+    
+    public boolean isChunked() {
+        return !isRepeatable();
+    } 
+    
+    public boolean isStreaming() {
+        return !isRepeatable();
+    }
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/MultipartRelatedEntity.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/NonOpTrustManager.java
URL: http://svn.apache.org/viewvc/abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/NonOpTrustManager.java?rev=1173209&view=auto
==============================================================================
--- abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/NonOpTrustManager.java (added)
+++ abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/NonOpTrustManager.java Tue Sep 20 15:56:46 2011
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  The ASF licenses this file to You
+ * under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.  For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.abdera2.protocol.client;
+
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
+import javax.net.ssl.X509TrustManager;
+
+public class NonOpTrustManager 
+  implements X509TrustManager {
+
+    public void checkClientTrusted(
+        X509Certificate[] arg0, String arg1) 
+          throws CertificateException {}
+
+    public void checkServerTrusted(
+        X509Certificate[] arg0, 
+        String arg1) throws CertificateException {}
+
+    public X509Certificate[] getAcceptedIssuers() {
+        return null;
+    }
+
+}

Propchange: abdera/abdera2/client/src/main/java/org/apache/abdera2/protocol/client/NonOpTrustManager.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message