Skip to content

Commit

Permalink
Merge branch 'master' into gzip
Browse files Browse the repository at this point in the history
Conflicts:
	src/test/groovy/groovyx/net/http/thirdparty/GAETest.groovy
  • Loading branch information
jgritman committed Oct 31, 2012
2 parents 0a6151e + 979d8af commit b0a1cb3
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 118 deletions.
23 changes: 8 additions & 15 deletions pom.xml
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>http-builder</artifactId>
<groupId>org.codehaus.groovy.modules.http-builder</groupId>
<version>0.6-SNAPSHOT</version>
<version>0.7-SNAPSHOT</version>
<name>HTTP client framework for Groovy</name>
<url>http://groovy.codehaus.org/modules/http-builder/</url>
<inceptionYear>2008</inceptionYear>
Expand Down Expand Up @@ -180,7 +179,7 @@
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<!--execution>
<id>release</id>
<phase>deploy</phase>
<goals>
Expand All @@ -189,7 +188,7 @@
<configuration>
<source>${pom.basedir}/src/main/script/release_tweet.groovy</source>
</configuration>
</execution>
</execution-->
</executions>
</plugin>
<plugin>
Expand Down Expand Up @@ -333,12 +332,8 @@
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<!--
<artifactId>wagon-http</artifactId>
<artifactId>wagon-webdav</artifactId>
-->
<artifactId>wagon-http-lightweight</artifactId>
<version>1.0</version>
<artifactId>wagon-webdav-jackrabbit</artifactId>
<version>2.2</version>
</extension>
</extensions>
</build>
Expand Down Expand Up @@ -409,10 +404,8 @@
</pluginRepositories>

<scm>
<developerConnection>scm:https://svn.codehaus.org/gmod/httpbuilder/</developerConnection>
<connection>scm:http://svn.codehaus.org/gmod/httpbuilder/</connection>
<tag>trunk</tag>
<url>http://fisheye.codehaus.org/browse/gmod/httpbuilder/</url>
<developerConnection>scm:git:git@github.com:jgritman/httpbuilder.git</developerConnection>
<url>http://github.com/jgritman/httpbuilder</url>
</scm>

<distributionManagement>
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/groovyx/net/http/AsyncHTTPBuilder.java
Expand Up @@ -82,7 +82,6 @@ public class AsyncHTTPBuilder extends HTTPBuilder {
* </dl>
*/
public AsyncHTTPBuilder( Map<String, ?> args ) throws URISyntaxException {
super();
int poolSize = DEFAULT_POOL_SIZE;
ExecutorService threadPool = null;
if ( args != null ) {
Expand Down Expand Up @@ -154,8 +153,7 @@ private Object doRequestSuper( RequestConfigDelegate delegate ) throws IOExcepti
protected void initThreadPools( final int poolSize, final ExecutorService threadPool ) {
if (poolSize < 1) throw new IllegalArgumentException("poolSize may not be < 1");
// Create and initialize HTTP parameters
HttpParams params = client != null ? client.getParams()
: new BasicHttpParams();
HttpParams params = getClient().getParams();
ConnManagerParams.setMaxTotalConnections(params, poolSize);
ConnManagerParams.setMaxConnectionsPerRoute(params,
new ConnPerRouteBean(poolSize));
Expand All @@ -171,7 +169,7 @@ protected void initThreadPools( final int poolSize, final ExecutorService thread

ClientConnectionManager cm = new ThreadSafeClientConnManager(
params, schemeRegistry );
super.client = new DefaultHttpClient( cm, params );
setClient(new DefaultHttpClient( cm, params ));

this.threadPool = threadPool != null ? threadPool :
new ThreadPoolExecutor( poolSize, poolSize, 120, TimeUnit.SECONDS,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/groovyx/net/http/AuthConfig.java
Expand Up @@ -130,9 +130,9 @@ public void certificate( String certURL, String password )
*/
public void oauth( String consumerKey, String consumerSecret,
String accessToken, String secretToken ) {
this.builder.client.removeRequestInterceptorByClass( OAuthSigner.class );
this.builder.getClient().removeRequestInterceptorByClass( OAuthSigner.class );
if ( consumerKey != null )
this.builder.client.addRequestInterceptor( new OAuthSigner(
this.builder.getClient().addRequestInterceptor( new OAuthSigner(
consumerKey, consumerSecret, accessToken, secretToken ) );
}

Expand Down
56 changes: 30 additions & 26 deletions src/main/java/groovyx/net/http/HTTPBuilder.java
Expand Up @@ -164,7 +164,7 @@
*/
public class HTTPBuilder {

protected AbstractHttpClient client;
private AbstractHttpClient client;
protected URIBuilder defaultURI = null;
protected AuthConfig auth = new AuthConfig( this );

Expand All @@ -186,26 +186,10 @@ public class HTTPBuilder {
* Creates a new instance with a <code>null</code> default URI.
*/
public HTTPBuilder() {
super();
HttpParams defaultParams = new BasicHttpParams();
defaultParams.setParameter( CookieSpecPNames.DATE_PATTERNS,
Arrays.asList("EEE, dd-MMM-yyyy HH:mm:ss z",
"EEE, dd MMM yyyy HH:mm:ss z") );
this.client = this.createClient(defaultParams);
this.setContentEncoding( ContentEncoding.Type.GZIP,
setContentEncoding( ContentEncoding.Type.GZIP,
ContentEncoding.Type.DEFLATE );
}

/**
* Override this method in a subclass to customize creation of the
* HttpClient instance.
* @param params
* @return
*/
protected AbstractHttpClient createClient( HttpParams params ) {
return new DefaultHttpClient(params);
}

/**
* Give a default URI to be used for all request methods that don't
* explicitly take a URI parameter.
Expand All @@ -215,8 +199,7 @@ protected AbstractHttpClient createClient( HttpParams params ) {
* @throws URISyntaxException if the given argument does not represent a valid URI
*/
public HTTPBuilder( Object defaultURI ) throws URISyntaxException {
this();
this.setUri( defaultURI );
setUri( defaultURI );
}

/**
Expand All @@ -231,8 +214,7 @@ public HTTPBuilder( Object defaultURI ) throws URISyntaxException {
* @throws URISyntaxException if the uri argument does not represent a valid URI
*/
public HTTPBuilder( Object defaultURI, Object defaultContentType ) throws URISyntaxException {
this();
this.setUri( defaultURI );
setUri( defaultURI );
this.defaultContentType = defaultContentType;
}

Expand Down Expand Up @@ -474,7 +456,7 @@ protected Object doRequest( final RequestConfigDelegate delegate )
}

HttpResponseDecorator resp = new HttpResponseDecorator(
client.execute( reqMethod, delegate.getContext() ),
getClient().execute( reqMethod, delegate.getContext() ),
delegate.getContext(), null );
try {
int status = resp.getStatusLine().getStatusCode();
Expand Down Expand Up @@ -774,7 +756,7 @@ public boolean isAutoAcceptHeader() {
* string that is known by the {@link ContentEncodingRegistry}
*/
public void setContentEncoding( Object... encodings ) {
this.contentEncodingHandler.setInterceptors( client, encodings );
this.contentEncodingHandler.setInterceptors( getClient(), encodings );
}

/**
Expand Down Expand Up @@ -829,7 +811,29 @@ public Map<?,?> getHeaders() {
* Return the underlying HTTPClient that is used to handle HTTP requests.
* @return the client instance.
*/
public AbstractHttpClient getClient() { return this.client; }
public AbstractHttpClient getClient() {
if (client == null) {
HttpParams defaultParams = new BasicHttpParams();
defaultParams.setParameter( CookieSpecPNames.DATE_PATTERNS,
Arrays.asList("EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd MMM yyyy HH:mm:ss z") );
client = createClient(defaultParams);
}
return client;
}

public void setClient(AbstractHttpClient client) {
this.client = client;
}

/**
* Override this method in a subclass to customize creation of the
* HttpClient instance.
* @param params
* @return
*/
protected AbstractHttpClient createClient( HttpParams params ) {
return new DefaultHttpClient(params);
}

/**
* Used to access the {@link AuthConfig} handler used to configure common
Expand Down Expand Up @@ -893,7 +897,7 @@ public void setProxy( String host, int port, String scheme ) {
* @see ClientConnectionManager#shutdown()
*/
public void shutdown() {
client.getConnectionManager().shutdown();
getClient().getConnectionManager().shutdown();
}


Expand Down
8 changes: 8 additions & 0 deletions src/site/apt/changes.apt
Expand Up @@ -8,6 +8,14 @@
Change Log

See the {{{./jira-report.html}JIRA Report}} for a comprehensive change list.
* v0.6.0 - Oct 16 2012
* Now requires Groovy 1.8

* Upgrade HttpClient dependency to 4.2.1

* Upgrade Nekohtml dependency to 1.9.16

* Changed to use Groovy's native JsonSlurper to consume JSON, rather than jsonlib

* v0.5.2 - 26 Dec 2011

Expand Down
6 changes: 6 additions & 0 deletions src/site/apt/index.apt
Expand Up @@ -10,6 +10,12 @@ News

You can also follow project updates on {{{http://twitter.com/httpbuilder}Twitter}}

* 16 Oct 2012 - 0.6.0 released, source now hosted on Github

The 0.6.0 release is now available which takes care of upgrading some older dependencies.

The source code is now {{{https://github.com/jgritman/httpbuilder}hosted on Github}}

* 26 Dec 2011 - 0.5.2 finally finally released for reals

With so many other projects, HTTPBuilder has taken a back seat, to say the least.
Expand Down
2 changes: 2 additions & 0 deletions src/test/groovy/groovyx/net/http/AsyncHTTPBuilderTest.groovy
Expand Up @@ -21,6 +21,7 @@
*/
package groovyx.net.http

import org.junit.Ignore
import org.junit.Test
import static groovyx.net.http.ContentType.*
import static groovyx.net.http.Method.*
Expand Down Expand Up @@ -74,6 +75,7 @@ public class AsyncHTTPBuilderTest {
println 'done.'
}

@Ignore
@Test public void testDefaultConstructor() {
def http = new AsyncHTTPBuilder()
def resp = http.get( uri:'http://ajax.googleapis.com',
Expand Down
4 changes: 3 additions & 1 deletion src/test/groovy/groovyx/net/http/HTTPBuilderTest.groovy
Expand Up @@ -15,6 +15,7 @@ import org.apache.commons.io.IOUtils
import org.apache.http.client.HttpResponseException
import org.apache.http.params.HttpConnectionParams
import org.apache.xml.resolver.tools.CatalogResolver
import org.junit.Ignore
import org.junit.Test

class HTTPBuilderTest {
Expand Down Expand Up @@ -275,6 +276,7 @@ class HTTPBuilderTest {
/* http://googlesystem.blogspot.com/2008/04/google-search-rest-api.html
* http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Earth%20Day
*/
@Ignore
@Test public void testJSON() {

def builder = new HTTPBuilder()
Expand All @@ -283,7 +285,7 @@ class HTTPBuilderTest {

builder.request('http://ajax.googleapis.com',GET,JSON) {
uri.path = '/ajax/services/search/web'
uri.query = [ v:'1.0', q: 'Calvin and Hobbes' ]
uri.query = [ v:'1.0', q: 'Earth Day' ]
//UA header required to get Google to GZIP response:
headers.'User-Agent' = "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.0.4) Gecko/2008111319 Ubuntu/8.10 (intrepid) Firefox/3.0.4"
response.success = { resp, json ->
Expand Down

0 comments on commit b0a1cb3

Please sign in to comment.