From 58f03f42d134d353ae6047c794182986cfda8224 Mon Sep 17 00:00:00 2001 From: stritti Date: Fri, 28 Apr 2017 11:25:29 +0200 Subject: [PATCH 1/6] don't send coverage on pull requests --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 22833db..b04e191 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,7 @@ before_install: - chmod +x ./gradlew script: - 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then bash ./gradlew check; fi' -- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./gradlew test integrationTest; fi' -- "./gradlew sendCoverageToCodacy" +- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then bash ./gradlew test integrationTest sendCoverageToCodacy; fi' deploy: - provider: releases api_key: From 60ce60d83811faeddf0ec44c6bb5fd7a938baf1e Mon Sep 17 00:00:00 2001 From: stritti Date: Fri, 28 Apr 2017 14:30:07 +0200 Subject: [PATCH 2/6] improved assertions and docs --- .../java/com/sybit/airtable/Airtable.java | 18 +++++--- src/main/java/com/sybit/airtable/Base.java | 22 ++++++---- .../com/sybit/airtable/Configuration.java | 2 + .../com/sybit/airtable/GsonObjectMapper.java | 2 + src/main/java/com/sybit/airtable/IOUtils.java | 19 -------- src/main/java/com/sybit/airtable/Query.java | 2 + src/main/java/com/sybit/airtable/Sort.java | 4 +- src/main/java/com/sybit/airtable/Table.java | 43 ++++++++----------- .../HttpResponseExceptionHandler.java | 17 ++++++-- .../java/com/sybit/airtable/BaseTest.java | 12 ++++-- .../java/com/sybit/airtable/TableTest.java | 11 ++++- 11 files changed, 82 insertions(+), 70 deletions(-) delete mode 100644 src/main/java/com/sybit/airtable/IOUtils.java diff --git a/src/main/java/com/sybit/airtable/Airtable.java b/src/main/java/com/sybit/airtable/Airtable.java index be13a52..4eac69d 100644 --- a/src/main/java/com/sybit/airtable/Airtable.java +++ b/src/main/java/com/sybit/airtable/Airtable.java @@ -136,6 +136,9 @@ public Airtable configure(Configuration config) throws AirtableException { */ @SuppressWarnings("WeakerAccess") public Airtable configure(Configuration config, ObjectMapper objectMapper) throws AirtableException { + assert config != null : "config was null"; + assert objectMapper != null : "objectMapper was null"; + if(config.getApiKey() == null) { throw new AirtableException("Missing Airtable API-Key"); } @@ -157,17 +160,16 @@ public Airtable configure(Configuration config, ObjectMapper objectMapper) throw // Add specific Converter for Date DateTimeConverter dtConverter = new DateConverter(); - ListConverter lConverter = new ListConverter(); - MapConverter thConverter = new MapConverter(); - - lConverter.setListClass(Attachment.class); - thConverter.setMapClass(Thumbnail.class); dtConverter.setPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); - ConvertUtils.register(dtConverter, Date.class); + + ListConverter lConverter = new ListConverter(); + lConverter.setListClass(Attachment.class); ConvertUtils.register(lConverter, List.class); - ConvertUtils.register(thConverter, Map.class); + MapConverter thConverter = new MapConverter(); + thConverter.setMapClass(Thumbnail.class); + ConvertUtils.register(thConverter, Map.class); return this; } @@ -235,6 +237,8 @@ public Configuration getConfig() { } public void setConfig(Configuration config) { + assert config != null : "config was null"; + this.config = config; setProxy(config.getEndpointUrl()); } diff --git a/src/main/java/com/sybit/airtable/Base.java b/src/main/java/com/sybit/airtable/Base.java index 642a24f..9d72c72 100644 --- a/src/main/java/com/sybit/airtable/Base.java +++ b/src/main/java/com/sybit/airtable/Base.java @@ -24,19 +24,22 @@ public class Base { private final Map tableMap = new HashMap<>(); - private final String base; + private final String baseName; private final Airtable parent; /** - * Create Airtable Base with given base ID. + * Create Airtable Base with given baseName ID. * - * @param base base ID could be found at https://airtable.com if you select your current base. + * @param name base ID could be found at https://airtable.com if you select your current baseName. * @param airtable parent airtable object */ - public Base(String base, Airtable airtable) { - this.base = base; + public Base(String name, Airtable airtable) { + assert name != null : "baseName was null"; + assert airtable != null : "airtable was null"; + + this.baseName = name; this.parent = airtable; } @@ -54,7 +57,6 @@ public Airtable airtable() { * @return Object to access table. */ public Table table(String name) { - return table(name, Records.class); } @@ -65,6 +67,8 @@ public Table table(String name) { * @return Object to access table. */ public Table table(String name, Class clazz) { + assert name != null : "name was null"; + assert clazz != null : "clazz was null"; if(!tableMap.containsKey(name)) { LOG.debug("Create new instance for table [" + name + "]"); @@ -77,10 +81,10 @@ public Table table(String name, Class clazz) { } /** - * Get base id of base. - * @return base id + * Get baseName id of baseName. + * @return baseName id */ public String name() { - return base; + return baseName; } } diff --git a/src/main/java/com/sybit/airtable/Configuration.java b/src/main/java/com/sybit/airtable/Configuration.java index 9a929b0..d9e21ab 100644 --- a/src/main/java/com/sybit/airtable/Configuration.java +++ b/src/main/java/com/sybit/airtable/Configuration.java @@ -9,6 +9,8 @@ /** * Configuration settings for Airtable. * Used by class Airtable to configure basic settings. + * + * @since 0.1 */ public class Configuration { diff --git a/src/main/java/com/sybit/airtable/GsonObjectMapper.java b/src/main/java/com/sybit/airtable/GsonObjectMapper.java index 1fc5ee0..df5e76a 100644 --- a/src/main/java/com/sybit/airtable/GsonObjectMapper.java +++ b/src/main/java/com/sybit/airtable/GsonObjectMapper.java @@ -12,7 +12,9 @@ import java.util.logging.Logger; /** + * Default mapper based on GSON. * + * @since 0.1 * @author fzr */ class GsonObjectMapper implements ObjectMapper { diff --git a/src/main/java/com/sybit/airtable/IOUtils.java b/src/main/java/com/sybit/airtable/IOUtils.java deleted file mode 100644 index ccd7236..0000000 --- a/src/main/java/com/sybit/airtable/IOUtils.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.sybit.airtable; - -/* - * The MIT License (MIT) - * Copyright (c) 2017 Sybit GmbH - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - */ - -public final class IOUtils { - private IOUtils() {} - - - public static String convertStreamToString(java.io.InputStream is) { - java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; - } -} - diff --git a/src/main/java/com/sybit/airtable/Query.java b/src/main/java/com/sybit/airtable/Query.java index 43beb16..9d5eab4 100644 --- a/src/main/java/com/sybit/airtable/Query.java +++ b/src/main/java/com/sybit/airtable/Query.java @@ -9,6 +9,8 @@ /** * Interface for specific queries. + * + * @since 0.1 */ @SuppressWarnings("WeakerAccess") public interface Query { diff --git a/src/main/java/com/sybit/airtable/Sort.java b/src/main/java/com/sybit/airtable/Sort.java index 5a8cc21..82777b0 100644 --- a/src/main/java/com/sybit/airtable/Sort.java +++ b/src/main/java/com/sybit/airtable/Sort.java @@ -7,7 +7,9 @@ package com.sybit.airtable; /** - * Sortation helper. + * Sorting of query results. + * + * @since 0.1 */ public class Sort { diff --git a/src/main/java/com/sybit/airtable/Table.java b/src/main/java/com/sybit/airtable/Table.java index 0df2acb..c5409a5 100644 --- a/src/main/java/com/sybit/airtable/Table.java +++ b/src/main/java/com/sybit/airtable/Table.java @@ -13,12 +13,9 @@ import com.mashape.unirest.request.GetRequest; import com.sybit.airtable.exception.AirtableException; import com.sybit.airtable.exception.HttpResponseExceptionHandler; -import com.sybit.airtable.vo.Attachment; -import com.sybit.airtable.vo.Delete; -import com.sybit.airtable.vo.PostRecord; -import com.sybit.airtable.vo.RecordItem; -import com.sybit.airtable.vo.Records; +import com.sybit.airtable.vo.*; import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.beanutils.BeanUtilsBean; import org.apache.commons.beanutils.PropertyUtils; import org.apache.http.client.HttpResponseException; import org.slf4j.Logger; @@ -27,12 +24,9 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; - import java.util.List; import java.util.Map; -import org.apache.commons.beanutils.BeanUtilsBean; - /** * Representation Class of Airtable Tables. * @@ -49,12 +43,15 @@ public class Table { /** * - * @param name - * @param type + * @param name name of table. + * @param type class to represent table row */ public Table(String name, Class type) { - this.type = type; + assert name != null : "name was null"; + assert type != null : "type was null"; + this.name = name; + this.type = type; } /** @@ -78,10 +75,9 @@ public void setParent(Base parent) { } /** - * - * If no Parameter ser all querys to null. + * Select all rows of table. * - * @return + * @return List of all items. * @throws AirtableException */ public List select() throws AirtableException, HttpResponseException { @@ -122,8 +118,8 @@ public Integer getPageSize() { /** * Select List of data of table with defined Query Parameters. * - * @param query - * @return + * @param query defined query + * @return list of table items * @throws AirtableException */ @SuppressWarnings("WeakerAccess") @@ -311,10 +307,10 @@ public Integer getPageSize() { } /** - * select only Table data with defined Fields - * - * @param fields - * @return + * Select only Table data with defined fields. + * + * @param fields array of requested fields. + * @return list of item using only requested fields. * @throws AirtableException * @throws HttpResponseException */ @@ -385,7 +381,7 @@ private List getList(HttpResponse response) { */ public T find(String id) throws AirtableException { - RecordItem body = null; + RecordItem body; HttpResponse response; try { @@ -402,15 +398,14 @@ public T find(String id) throws AirtableException { body = response.getBody(); } else { HttpResponseExceptionHandler.onResponse(response); + body = null; } try { return transform(body, this.type.newInstance() ); } catch (InvocationTargetException | IllegalAccessException | InstantiationException e) { - LOG.error(e.getMessage(), e); + throw new AirtableException(e); } - - return null; } /** diff --git a/src/main/java/com/sybit/airtable/exception/HttpResponseExceptionHandler.java b/src/main/java/com/sybit/airtable/exception/HttpResponseExceptionHandler.java index 620e330..4aa83b7 100644 --- a/src/main/java/com/sybit/airtable/exception/HttpResponseExceptionHandler.java +++ b/src/main/java/com/sybit/airtable/exception/HttpResponseExceptionHandler.java @@ -7,17 +7,21 @@ import com.google.gson.Gson; import com.mashape.unirest.http.HttpResponse; -import com.sybit.airtable.IOUtils; import com.sybit.airtable.vo.Error; +/** + * Handle HTTP responses and create exceptions. + * + * @since 0.1 + */ public class HttpResponseExceptionHandler { public static void onResponse(HttpResponse response) throws AirtableException { - Integer statusCode = response.getStatus(); - String message = IOUtils.convertStreamToString(response.getRawBody()); + final Integer statusCode = response.getStatus(); + String message = convertStreamToString(response.getRawBody()); - Gson gson = new Gson(); + final Gson gson = new Gson(); Error err = gson.fromJson(message, Error.class); switch (statusCode) { case 401: @@ -48,4 +52,9 @@ public static void onResponse(HttpResponse response) throws AirtableException { throw new AirtableException("UNDEFINED_ERROR", message, statusCode); } } + + public static String convertStreamToString(java.io.InputStream is) { + java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } } diff --git a/src/test/java/com/sybit/airtable/BaseTest.java b/src/test/java/com/sybit/airtable/BaseTest.java index 9fc7dbb..5a445eb 100644 --- a/src/test/java/com/sybit/airtable/BaseTest.java +++ b/src/test/java/com/sybit/airtable/BaseTest.java @@ -6,11 +6,12 @@ package com.sybit.airtable; import com.sybit.airtable.exception.AirtableException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + /** * * @author fzr @@ -48,7 +49,10 @@ public void baseNameTest(){ Base base = new Base("base", this.airtable); assertEquals(base.name(),"base"); } - - + + @Test(expected = java.lang.AssertionError.class ) + public void baseAssertationTest() { + Base base = new Base(null,null); + } } diff --git a/src/test/java/com/sybit/airtable/TableTest.java b/src/test/java/com/sybit/airtable/TableTest.java index 709ad1e..95f6dea 100644 --- a/src/test/java/com/sybit/airtable/TableTest.java +++ b/src/test/java/com/sybit/airtable/TableTest.java @@ -7,10 +7,11 @@ import com.sybit.airtable.exception.AirtableException; import com.sybit.airtable.movies.Actor; -import static org.junit.Assert.assertNotNull; import org.junit.Before; import org.junit.Test; +import static org.junit.Assert.assertNotNull; + /** * * @author fzr @@ -26,7 +27,13 @@ public void before() throws AirtableException{ this.base = new Base("base", airtable); } - + + @Test(expected = java.lang.AssertionError.class ) + public void testTableAssertions(){ + Table table = new Table(null, null); + + } + @Test public void testTable(){ From e81ce631a5d6eb41861affeb6a629fec3e5735e4 Mon Sep 17 00:00:00 2001 From: Fabian Zeller Date: Tue, 16 May 2017 09:59:03 +0200 Subject: [PATCH 3/6] added https Proxy option and manual set Proxy --- .../java/com/sybit/airtable/Airtable.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sybit/airtable/Airtable.java b/src/main/java/com/sybit/airtable/Airtable.java index 4eac69d..17660a5 100644 --- a/src/main/java/com/sybit/airtable/Airtable.java +++ b/src/main/java/com/sybit/airtable/Airtable.java @@ -174,6 +174,17 @@ public Airtable configure(Configuration config, ObjectMapper objectMapper) throw return this; } + /** + * Set Proxy Manually. + * + * @param proxy + */ + public void setProxyManual(String proxy){ + if(proxy != null && !proxy.isEmpty() && !proxy.equals(" ")){ + Unirest.setProxy(HttpHost.create(proxy)); + } + } + /** * Set Proxy environment for Unirest. * @@ -182,14 +193,20 @@ public Airtable configure(Configuration config, ObjectMapper objectMapper) throw */ private void setProxy(String endpointUrl) { final String httpProxy = System.getenv("http_proxy"); + final String httpsProxy = System.getenv("https_proxy"); if(httpProxy != null && (endpointUrl.contains("127.0.0.1") || endpointUrl.contains("localhost"))) { LOG.info("Use Proxy: ignored for 'localhost' ann '127.0.0.1'"); Unirest.setProxy(null); - } else if(httpProxy != null) { + } else if(httpsProxy != null + && (endpointUrl.contains("https"))) { + LOG.info("Use Proxy: Environment variable 'https_proxy' found and used: " + httpsProxy); + Unirest.setProxy(HttpHost.create(httpsProxy)); + } else if(httpProxy != null + && (endpointUrl.contains("http"))){ LOG.info("Use Proxy: Environment variable 'http_proxy' found and used: " + httpProxy); - Unirest.setProxy(HttpHost.create(httpProxy)); + Unirest.setProxy(HttpHost.create(httpProxy)); } else { Unirest.setProxy(null); } From fce46d891014b0c3bcd3a643294d86b6aacdc08b Mon Sep 17 00:00:00 2001 From: Fabian Zeller Date: Tue, 16 May 2017 10:23:02 +0200 Subject: [PATCH 4/6] implemented proxy in configuration made proxyconfiguration with env only execute if no proxy is set --- .../java/com/sybit/airtable/Airtable.java | 126 +++++++++--------- .../com/sybit/airtable/Configuration.java | 26 +++- 2 files changed, 88 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/sybit/airtable/Airtable.java b/src/main/java/com/sybit/airtable/Airtable.java index 17660a5..f3bc48e 100644 --- a/src/main/java/com/sybit/airtable/Airtable.java +++ b/src/main/java/com/sybit/airtable/Airtable.java @@ -6,7 +6,6 @@ */ package com.sybit.airtable; - import com.mashape.unirest.http.ObjectMapper; import com.mashape.unirest.http.Unirest; import com.sybit.airtable.converter.ListConverter; @@ -29,22 +28,23 @@ import java.util.Map; import java.util.Properties; - /** - * Representation Class of Airtable. - * It is the entry class to access Airtable data. + * Representation Class of Airtable. It is the entry class to access Airtable + * data. * - * The API key could be passed to the app by - * + defining Java property AIRTABLE_API_KEY (e.g. -DAIRTABLE_API_KEY=foo). - * + defining OS environment variable AIRTABLE_API_KEY (e.g. export AIRTABLE_API_KEY=foo). - * + defining property file `credentials.properties` in root classpath containing key/value AIRTABLE_API_KEY=foo. - * + On the other hand the API-key could also be added by using the method Airtable.configure(String apiKey). + * The API key could be passed to the app by + defining Java property + * AIRTABLE_API_KEY (e.g. -DAIRTABLE_API_KEY=foo). + + * defining OS environment variable AIRTABLE_API_KEY (e.g. + * export AIRTABLE_API_KEY=foo). + defining property file + * `credentials.properties` in root classpath containing key/value + * AIRTABLE_API_KEY=foo. + On the other hand the API-key could also + * be added by using the method Airtable.configure(String apiKey). * * @since 0.1 */ public class Airtable { - private static final Logger LOG = LoggerFactory.getLogger( Airtable.class ); + private static final Logger LOG = LoggerFactory.getLogger(Airtable.class); private static final String AIRTABLE_API_KEY = "AIRTABLE_API_KEY"; private static final String AIRTABLE_BASE = "AIRTABLE_BASE"; @@ -52,8 +52,8 @@ public class Airtable { private Configuration config; /** - * Configure, AIRTABLE_API_KEY passed by Java property, enviroment variable - * or within credentials.properties. + * Configure, AIRTABLE_API_KEY passed by Java property, + * enviroment variable or within credentials.properties. * * @return An Airtable instance configured with GsonObjectMapper * @throws com.sybit.airtable.exception.AirtableException Missing API-Key @@ -64,8 +64,8 @@ public Airtable configure() throws AirtableException { } /** - * Configure, AIRTABLE_API_KEY passed by Java property, enviroment variable - * or within credentials.properties. + * Configure, AIRTABLE_API_KEY passed by Java property, + * enviroment variable or within credentials.properties. * * @param objectMapper A custom ObjectMapper implementation * @return An Airtable instance configured with supplied ObjectMapper @@ -74,22 +74,20 @@ public Airtable configure() throws AirtableException { @SuppressWarnings("UnusedReturnValue") public Airtable configure(ObjectMapper objectMapper) throws AirtableException { - LOG.info( "System-Property: Using Java property '-D" + AIRTABLE_API_KEY + "' to get apikey."); + LOG.info("System-Property: Using Java property '-D" + AIRTABLE_API_KEY + "' to get apikey."); String airtableApi = System.getProperty(AIRTABLE_API_KEY); - if(airtableApi == null) { - LOG.info( "Environment-Variable: Using OS environment '" + AIRTABLE_API_KEY + "' to get apikey."); + if (airtableApi == null) { + LOG.info("Environment-Variable: Using OS environment '" + AIRTABLE_API_KEY + "' to get apikey."); airtableApi = System.getenv(AIRTABLE_API_KEY); } - if(airtableApi == null) { + if (airtableApi == null) { airtableApi = getCredentialProperty(AIRTABLE_API_KEY); } return this.configure(airtableApi, objectMapper); } - - /** * Configure Airtable. * @@ -112,48 +110,49 @@ public Airtable configure(String apiKey) throws AirtableException { */ @SuppressWarnings("WeakerAccess") public Airtable configure(String apiKey, ObjectMapper objectMapper) throws AirtableException { - return configure(new Configuration(apiKey, Configuration.ENDPOINT_URL), objectMapper); + return configure(new Configuration(apiKey, Configuration.ENDPOINT_URL, null), objectMapper); } /** * * @param config * @return - * @throws com.sybit.airtable.exception.AirtableException Missing API-Key or Endpoint + * @throws com.sybit.airtable.exception.AirtableException Missing API-Key or + * Endpoint */ @SuppressWarnings("WeakerAccess") public Airtable configure(Configuration config) throws AirtableException { return configure(config, new GsonObjectMapper()); } - /** * * @param config * @param objectMapper A custom ObjectMapper implementation * @return - * @throws com.sybit.airtable.exception.AirtableException Missing API-Key or Endpoint + * @throws com.sybit.airtable.exception.AirtableException Missing API-Key or + * Endpoint */ @SuppressWarnings("WeakerAccess") public Airtable configure(Configuration config, ObjectMapper objectMapper) throws AirtableException { assert config != null : "config was null"; assert objectMapper != null : "objectMapper was null"; - if(config.getApiKey() == null) { + if (config.getApiKey() == null) { throw new AirtableException("Missing Airtable API-Key"); } - if(config.getEndpointUrl() == null) { + if (config.getEndpointUrl() == null) { throw new AirtableException("Missing endpointUrl"); } this.config = config; - if(config.getTimeout() != null) { + if (config.getTimeout() != null) { LOG.info("Set connection timeout to: " + config.getTimeout() + "ms."); Unirest.setTimeouts(config.getTimeout(), config.getTimeout()); } - setProxy(config.getEndpointUrl()); + configureProxy(config.getEndpointUrl()); // Only one time Unirest.setObjectMapper(objectMapper); @@ -176,39 +175,43 @@ public Airtable configure(Configuration config, ObjectMapper objectMapper) throw /** * Set Proxy Manually. - * - * @param proxy + * + * @param proxy */ - public void setProxyManual(String proxy){ - if(proxy != null && !proxy.isEmpty() && !proxy.equals(" ")){ - Unirest.setProxy(HttpHost.create(proxy)); + public void setProxy(String proxy) { + if (proxy != null && !proxy.isEmpty() && !proxy.equals(" ")) { + this.config.setProxy(proxy); } } - + /** - * Set Proxy environment for Unirest. + * Set Proxy environment in Configuration. + * + * Proxy will be ignored for endpointUrls containing localhost + * or 127.0.0.1,/code> * - * Proxy will be ignored for endpointUrls containing localhost or 127.0.0.1,/code> * @param endpointUrl */ - private void setProxy(String endpointUrl) { - final String httpProxy = System.getenv("http_proxy"); - final String httpsProxy = System.getenv("https_proxy"); - if(httpProxy != null - && (endpointUrl.contains("127.0.0.1") - || endpointUrl.contains("localhost"))) { - LOG.info("Use Proxy: ignored for 'localhost' ann '127.0.0.1'"); - Unirest.setProxy(null); - } else if(httpsProxy != null + private void configureProxy(String endpointUrl) { + if (this.config.getProxy() == null) { + final String httpProxy = System.getenv("http_proxy"); + final String httpsProxy = System.getenv("https_proxy"); + if (httpProxy != null + && (endpointUrl.contains("127.0.0.1") + || endpointUrl.contains("localhost"))) { + LOG.info("Use Proxy: ignored for 'localhost' ann '127.0.0.1'"); + this.config.setProxy(null); + } else if (httpsProxy != null && (endpointUrl.contains("https"))) { - LOG.info("Use Proxy: Environment variable 'https_proxy' found and used: " + httpsProxy); - Unirest.setProxy(HttpHost.create(httpsProxy)); - } else if(httpProxy != null - && (endpointUrl.contains("http"))){ - LOG.info("Use Proxy: Environment variable 'http_proxy' found and used: " + httpProxy); - Unirest.setProxy(HttpHost.create(httpProxy)); - } else { - Unirest.setProxy(null); + LOG.info("Use Proxy: Environment variable 'https_proxy' found and used: " + httpsProxy); + this.config.setProxy(httpProxy); + } else if (httpProxy != null + && (endpointUrl.contains("http"))) { + LOG.info("Use Proxy: Environment variable 'http_proxy' found and used: " + httpProxy); + this.config.setProxy(httpsProxy); + } else { + this.config.setProxy(null); + } } } @@ -216,18 +219,19 @@ private void setProxy(String endpointUrl) { * Getting the base by given property AIRTABLE_BASE. * * @return the base object. - * @throws com.sybit.airtable.exception.AirtableException Missing Airtable_BASE + * @throws com.sybit.airtable.exception.AirtableException Missing + * Airtable_BASE */ public Base base() throws AirtableException { LOG.info("Using Java property '-D" + AIRTABLE_BASE + "' to get key."); String val = System.getProperty(AIRTABLE_BASE); - if(val == null) { + if (val == null) { LOG.info("Environment-Variable: Using OS environment '" + AIRTABLE_BASE + "' to get base name."); val = System.getenv(AIRTABLE_BASE); } - if(val == null) { + if (val == null) { val = getCredentialProperty(AIRTABLE_BASE); } @@ -236,12 +240,14 @@ public Base base() throws AirtableException { /** * Builder method to create base of given base id. + * * @param base the base id. * @return - * @throws com.sybit.airtable.exception.AirtableException AIRTABLE_BASE was Null + * @throws com.sybit.airtable.exception.AirtableException AIRTABLE_BASE was + * Null */ public Base base(String base) throws AirtableException { - if(base == null) { + if (base == null) { throw new AirtableException("base was null"); } final Base b = new Base(base, this); @@ -257,7 +263,7 @@ public void setConfig(Configuration config) { assert config != null : "config was null"; this.config = config; - setProxy(config.getEndpointUrl()); + configureProxy(config.getEndpointUrl()); } /** @@ -306,6 +312,6 @@ private String getCredentialProperty(String key) { public void setEndpointUrl(String endpointUrl) { this.config.setEndpointUrl(endpointUrl); - setProxy(endpointUrl); + configureProxy(endpointUrl); } } diff --git a/src/main/java/com/sybit/airtable/Configuration.java b/src/main/java/com/sybit/airtable/Configuration.java index d9e21ab..ead026b 100644 --- a/src/main/java/com/sybit/airtable/Configuration.java +++ b/src/main/java/com/sybit/airtable/Configuration.java @@ -16,17 +16,18 @@ public class Configuration { public static final String ENDPOINT_URL = "https://api.airtable.com/v0"; - private String endpointUrl; + private String endpointUrl; private String apiKey; + private String proxy; private Long timeout; /** - * Configure API using given API Key and default endpoint. + * Configure API using given API Key ,default endpoint and no Proxy. * * @param apiKey */ public Configuration(String apiKey) { - this(apiKey, ENDPOINT_URL); + this(apiKey, ENDPOINT_URL,null); } /** @@ -35,9 +36,10 @@ public Configuration(String apiKey) { * @param apiKey * @param endpointUrl */ - public Configuration(String apiKey, String endpointUrl) { + public Configuration(String apiKey, String endpointUrl, String proxy) { this.apiKey = apiKey; this.endpointUrl = endpointUrl; + this.proxy = proxy; } public String getEndpointUrl() { @@ -71,4 +73,20 @@ public Long getTimeout() { public void setTimeout(Long timeout) { this.timeout = timeout; } + + /** + * @return the proxy + */ + public String getProxy() { + return proxy; + } + + /** + * @param proxy the proxy to set + */ + public void setProxy(String proxy) { + this.proxy = proxy; + } + + } From 65a977e042e5d35f6420d2a042a72555878fcaaf Mon Sep 17 00:00:00 2001 From: Fabian Zeller Date: Tue, 16 May 2017 10:25:46 +0200 Subject: [PATCH 5/6] configured tests --- src/test/java/com/sybit/airtable/BaseTest.java | 2 +- src/test/java/com/sybit/airtable/TableTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/sybit/airtable/BaseTest.java b/src/test/java/com/sybit/airtable/BaseTest.java index 5a445eb..5328601 100644 --- a/src/test/java/com/sybit/airtable/BaseTest.java +++ b/src/test/java/com/sybit/airtable/BaseTest.java @@ -23,7 +23,7 @@ public class BaseTest { @Before public void before() throws AirtableException{ - this.airtable = new Airtable().configure(new Configuration("123","url")); + this.airtable = new Airtable().configure(new Configuration("123","url",null)); } diff --git a/src/test/java/com/sybit/airtable/TableTest.java b/src/test/java/com/sybit/airtable/TableTest.java index 95f6dea..8106340 100644 --- a/src/test/java/com/sybit/airtable/TableTest.java +++ b/src/test/java/com/sybit/airtable/TableTest.java @@ -23,7 +23,7 @@ public class TableTest { @Before public void before() throws AirtableException{ - Airtable airtable = new Airtable().configure(new Configuration("123","url")); + Airtable airtable = new Airtable().configure(new Configuration("123","url",null)); this.base = new Base("base", airtable); } From 2c864c398ad09b224e134e98d77fb2890dc3b8e2 Mon Sep 17 00:00:00 2001 From: Fabian Zeller Date: Tue, 16 May 2017 10:52:01 +0200 Subject: [PATCH 6/6] configured tests --- src/itest/java/com/sybit/airtable/AirtableTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/itest/java/com/sybit/airtable/AirtableTest.java b/src/itest/java/com/sybit/airtable/AirtableTest.java index d033392..65a9fb6 100644 --- a/src/itest/java/com/sybit/airtable/AirtableTest.java +++ b/src/itest/java/com/sybit/airtable/AirtableTest.java @@ -41,7 +41,7 @@ public void airtableConfigTest() throws AirtableException{ Airtable airtable = new Airtable(); assertNull(airtable.getConfig()); - airtable.configure(new Configuration("KEY","URL")); + airtable.configure(new Configuration("KEY","URL","PROXY")); assertEquals(airtable.apiKey(),"KEY"); assertEquals(airtable.endpointUrl(),"URL");