Issue 145:Add custom user agent

This commit is contained in:
Adrian Cole 2012-01-15 15:41:17 -08:00
parent bc9634165f
commit 22fc14fc09
5 changed files with 14 additions and 5 deletions

View File

@ -51,6 +51,7 @@ import javax.net.ssl.SSLContext;
import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.HttpHeaders;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.JcloudsVersion;
import org.jclouds.crypto.CryptoStreams; import org.jclouds.crypto.CryptoStreams;
import org.jclouds.http.HttpCommandExecutorService; import org.jclouds.http.HttpCommandExecutorService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -77,7 +78,9 @@ import com.google.common.io.CountingOutputStream;
@Singleton @Singleton
public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorService<HttpURLConnection> { public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorService<HttpURLConnection> {
public static final String USER_AGENT = "jclouds/1.0 java/" + System.getProperty("java.version"); public static final String USER_AGENT = String.format("jclouds/%s java/%s", JcloudsVersion.get(), System
.getProperty("java.version"));
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
private final Supplier<SSLContext> untrustedSSLContextProvider; private final Supplier<SSLContext> untrustedSSLContextProvider;

View File

@ -27,6 +27,7 @@ import java.util.Properties;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService; import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
import org.testng.annotations.Test;
import com.google.inject.Module; import com.google.inject.Module;
@ -35,6 +36,7 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test
public class JavaUrlHttpCommandExecutorServiceIntegrationTest extends BaseHttpCommandExecutorServiceIntegrationTest { public class JavaUrlHttpCommandExecutorServiceIntegrationTest extends BaseHttpCommandExecutorServiceIntegrationTest {
protected Module createConnectionModule() { protected Module createConnectionModule() {

View File

@ -43,6 +43,7 @@ import org.apache.http.entity.FileEntity;
import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity; import org.apache.http.entity.StringEntity;
import org.apache.http.params.CoreProtocolPNames; import org.apache.http.params.CoreProtocolPNames;
import org.jclouds.JcloudsVersion;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.io.payloads.BasePayload; import org.jclouds.io.payloads.BasePayload;
@ -59,8 +60,8 @@ import com.google.common.base.Throwables;
*/ */
@Singleton @Singleton
public class ApacheHCUtils { public class ApacheHCUtils {
//TODO: look up httpclient version
public static final String USER_AGENT = "jclouds/1.0 httpclient/4.0.1"; public static final String USER_AGENT = String.format("jclouds/%s httpclient/%s", JcloudsVersion.get(), "4.1.1");
public static HttpUriRequest convertToApacheRequest(HttpRequest request) { public static HttpUriRequest convertToApacheRequest(HttpRequest request) {
HttpUriRequest apacheRequest; HttpUriRequest apacheRequest;

View File

@ -26,6 +26,7 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.Constants; import org.jclouds.Constants;
import org.jclouds.JcloudsVersion;
import org.jclouds.concurrent.SingleThreaded; import org.jclouds.concurrent.SingleThreaded;
import org.jclouds.http.HttpCommandExecutorService; import org.jclouds.http.HttpCommandExecutorService;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
@ -50,8 +51,9 @@ import com.google.common.annotations.VisibleForTesting;
@SingleThreaded @SingleThreaded
@Singleton @Singleton
public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorService<HTTPRequest> { public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorService<HTTPRequest> {
public static final String USER_AGENT = "jclouds/1.0 urlfetch/1.3.5"; //TODO: look up gae version
public static final String USER_AGENT = String.format("jclouds/%s urlfetch/%s", JcloudsVersion.get(), "1.4.3");
private final URLFetchService urlFetchService; private final URLFetchService urlFetchService;
private final ConvertToGaeRequest convertToGaeRequest; private final ConvertToGaeRequest convertToGaeRequest;
private final ConvertToJcloudsResponse convertToJcloudsResponse; private final ConvertToJcloudsResponse convertToJcloudsResponse;

View File

@ -63,6 +63,7 @@ import com.google.inject.Module;
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test
public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpCommandExecutorServiceIntegrationTest { public class AsyncGaeHttpCommandExecutorServiceIntegrationTest extends BaseHttpCommandExecutorServiceIntegrationTest {
Logger logger = Logger.CONSOLE; Logger logger = Logger.CONSOLE;