smartystreets / smartystreets-java-sdk Goto Github PK
View Code? Open in Web Editor NEWThe official client libraries for accessing SmartyStreets APIs from Java (and JRE-based languages)
Home Page: https://smartystreets.com/docs/sdk/java
The official client libraries for accessing SmartyStreets APIs from Java (and JRE-based languages)
Home Page: https://smartystreets.com/docs/sdk/java
Exception Strace :
java.lang.NullPointerException: Attempt to read from field 'byte[] vz5.payload' on a null object reference
at com.smartystreets.api.Response.getPayload
at com.smartystreets.api.us_autocomplete_pro.Client.send(SourceFile:31)
the latest version does not appear to be in the pom.xml file
I tried doing this:
this.client = new ClientBuilder(new StaticCredentials(authId, authToken))
.withLicenses(license.getLicenses())
.withMaxTimeout(timeoutSeconds * 1000)
.buildUsStreetApiClient();
and variations of this, but couldn't get it to work. Then I realized that your ClientBuilder.buildUsStreetApiClient()
calls SmartySender(int maxTimeout)
constructor.
The maxTimeout
is ignored and this constructor should be something like this:
public SmartySender(int maxTimeout) {
this.maxTimeOut = maxTimeout;
this.client = new OkHttpClient.Builder()
.writeTimeout(this.maxTimeOut, TimeUnit.MILLISECONDS)
.readTimeout(this.maxTimeOut, TimeUnit.MILLISECONDS)
.connectTimeout(this.maxTimeOut, TimeUnit.MILLISECONDS)
.build();
}
Are you guys open to PRs from community?
Unauthorized: The credentials were provided incorrectly or did not match any existing, active credentials. code: 401
For example I have tried below Valid US addresses.
Below address is valid but I am getting invalid address in response.
`
lookup.setStreet("Hartford Street");
lookup.setCity("San Francisco");
lookup.setState("CA");
lookup.setZipCode("94114");`
And
Wrong City is being returned by the API i.e. Alameda. Also, City is being returned in Country.
`
lookup.setCity("Pleasanton");
lookup.setStreet("5776 Stoneridge Mall Road");
lookup.setState("CA");
lookup.setZipCode("94588");`
I have tried with
com.smartystreets.api:smartystreets-java-sdk:2.1.2
and
com.smartystreets.api:smartystreets-java-sdk:3.2.0
I keep getting this error:
java.lang.NullPointerException
at com.smartystreets.api.us_street.Client.send(Client.java:51)
I'm still struggling to get more details because it happens in a cloud environment, and the exception doesn't provide much help. What I've managed to figure out is that this.sender.send(request) returns null. This suggests that one of the senders in the chain is returning null, and Client doesn't have any logic to handle it.
It's worth mentioning that the problem occurs in some cases, but not all. Most of the addresses are normalized just fine.
The Smarty SDK version I'm using is 3.16.1. The normalization occurs as a part of an Apache Beam pipeline, executed in Dataflow.
Hello Smartystreets team,
Thank you for updating your java sdk, my company currently uses it in our Sendwave app and it works great.
I was wondering, where can one get release notes for the latest update? We tend to attach these notes to PR's when we update our libraries.
hello folks,
say we have client side integration that gets the address via client side calls, how can one verify (the candidate) client sends to our service is valid?
I am having this issue when trying to run some tests.
java.lang.NoClassDefFoundError: java/net/http/HttpClient
at com.smartystreets.api.GoogleSender.(GoogleSender.java:24)
Isnt java.net.http.HttpClient from Java 11?
That will render your API not compatible with versions prior to 11.
If I construct a batch query to the UsZipCode API using the SS Java SDK as follows:
String authId = System.getenv("ss.authId");
String authToken = System.getenv("ss.authToken");
Credentials creds = new StaticCredentials(authId, authToken);
Client client = new ClientBuilder(creds).buildUsZipCodeApiClient();
Batch batch = new Batch();
try {
batch.add(new Lookup("92093"));
batch.add(new Lookup("87714"));
client.send(batch);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
This results in:
java.lang.NullPointerException: Cannot invoke "com.smartystreets.api.Response.getPayload()" because "response" is null
at com.smartystreets.api.us_zipcode.Client.send(Client.java:49)
Digging into the SDK code, I see that the server is returning HTTP 415. This is because the SDK by default is not passing a content-type header with the request.
I can work around this by constructing my client with a custom header of "Content-type: application/json" as follows:
Map<String, Object> headers = new HashMap<>();
headers.put("Content-type", "application/json");
Client client = new ClientBuilder(creds).withCustomHeaders(headers).buildUsZipCodeApiClient();
But shouldn't this header be aded automatically in the SDK client code? I can't pass any other value for the content type other than "application/json" since JSON what the SDK client sends.
Hi,
The changes in 3.11.0 "Moved to Java 11 to support HTTP Client. This is a breaking change for anyone using earlier versions of Java", has prevented Android users from importing the smartystreets-java-sdk
from maven. Android/Google only provides a subset of features in Java 11. One of them is not java.net.http.HttpClient
. Therefore, when we try to instantiate a client with ClientBuilder
, we get
Caused by: java.lang.ClassNotFoundException: Didn't find class "java.net.http.HttpClient" on path: DexPathList
.
I could go back to the previous version of 3.10.7 which uses com.google.api.client.http
, but the issue with that is, my product manager has asked that we set the source to "postal" to eliminate P.O box results, and that option was not added to US Autocomplete Pro lookup until 3.11.0. We are currently in the evaluation process, and my PM has not purchased a license yet, but if I can't find a way to import java.net.http.HttpClient
into our Android project, then this catch-22 with java.net.http.HttpClient
/source field availability, may force us to have to go with Google Places. So, I wanted to ask what you would recommend? Hopefully, we can receive an answer asap, as my requirements are to finish the address search feature this sprint.
Thank you in advance.
Here is a link showing what java.net
classes are available on Android:
https://developer.android.com/reference/java/net/package-summary
Unfortunately, importing java.net.http
as a library is not a viable option. See some of the reasons here in this StackOverFlow:
https://stackoverflow.com/questions/69750452/how-can-i-use-jdk-11-http-packages-in-android
Hi,
With Java 11 now required (and using the new HttpClient), are the dependencies on google-http-client / http-client-jackson2 really necessary?
/home/********/********/app/build.gradle: Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
/home/********/********/app/build.gradle: Error: httpclient defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]
You should make a note when this is being included with an Android project to exclude those. Thanks!
Else smartystreets dependency leads to a transitive dependency to junit
According to the output field definitions, the input_id
field should be available as identical to the input id defined on the Lookup. However, the Candidate does not seem to have an inputId property. Please advise.
The Java SDK Docs give an example with version 3.4.0
.
The latest artifact I could find was 3.3.8
. https://search.maven.org/artifact/com.smartystreets.api/smartystreets-java-sdk/3.3.8/jar
Following the getting started documentation, on latest builds, I get the following error on JDK 8:
java.lang.NoClassDefFoundError: java/net/http/HttpClient
at com.smartystreets.api.GoogleSender.<init>(GoogleSender.java:24)
I believe the java.net.http.HttpClient
is only available in JDK 11+? But documentation says Java SDK (targets Java 7 or above)
and under requirements Download and install Java 7 or higher.
Am I missing something?
In the RetrySender.send
method the client sleeps for 10 seconds when a TooManyRequestsResponse is received. As far as I know SmartyStreets rate limits are based on requests per second, so this wait time seems excessive. It would be ideal if this value was configurable via the ClientBuilder
like the maxRetries
used in this class or if it used an incremental backoff like in the RetrySender.trySend
method.
The hardcoded wait time section:
public Response send(Request request) throws SmartyException, IOException, InterruptedException {
for(int i = 0; i <= this.maxRetries; ++i) {
Response response = this.trySend(request, i);
if (response instanceof TooManyRequestsResponse) {
long wait = 10L;
...
The code in question is in us_autocomplete/Client.java
for (String item : list) { filterList += (item + ","); }
This is invalid according to the SDK documentation for building this list, which requires a semi-colon separator.
My issue was not being able to import the latest version (3.4.0) into my Android app. I currently use the version 3.3.8
and it doesn't work, but when I upgrade to 3.4.0
, gradle fails to build with error ERROR: Failed to resolve: com.smartystreets.api:smartystreets-java-sdk:3.4.0
.
I'm importing this as;
implementation 'com.smartystreets.api:smartystreets-java-sdk:3.4.0'
That's based on the Maven import structure.
This also doesn't work
implementation 'com.github.smartystreets:smartystreets-java-sdk:3.4.0'
Which is based on the structure of the old version which works.
Thank you for including custom headers in the new 3.3.0 release.
I noticed an issue if I use the Authorization custom header(s) with this package:
val url = "api-gateway-test/smartystreets/street-address"
val customHeaders = new HashMap[String, String]()
val bearerToken = "test123"
customHeaders.put("Authorization", s"Bearer ${bearerToken}")
val client = new ClientBuilder(credentials)
.withCustomBaseUrl(url)
.withCustomHeaders(customHeaders)
.buildUsStreetApiClient()
val lookup = new Lookup();
lookup.setStreet("1600 Amphitheatre Pkwy");
lookup.setCity("Mountain View");
lookup.setState("CA");
batch.add(lookup);
client.send(batch);
Exception: java.lang.IllegalArgumentException: Can not set java.util.List field com.google.api.client.http.HttpHeaders.authorization to java.lang.String.
Any thoughts on how I would pass custom Authorization headers to the client?
Thanks for your time.
Marko Vujovic
Hi,
I've noticed that when I'm making a batch request, some lookups aren't getting any results. But when I make a single request per single problematic lookup, it gets me a result just fine (screenshots attached).
Smarty Client init:
Credentials credentials = new StaticCredentials(smartyProperties.getAuthId(), smartyProperties.getAuthToken());
Client client = new ClientBuilder(credentials).withLicenses(List.of(smartyProperties.getLicense()))
.buildUsStreetApiClient();
License is us-core-enterprise-cloud
Hi Team,
amazing work on the api / service - more of a question / issue - depending on how you look at it .
When an API is called for an address, I get back something like below. Wondering if there is a standard binding in Java that ties all these things together (I looked briefly - but could not find it). I am looking for an object (DTO / Domain) object that has all these things - so that I don't have to recreate it.
{
"input_index": 0,
"candidate_index": 0,
"delivery_line_1": "200 Wachesaw Dr",
"last_line": "Piedmont SC 29673-6409",
"delivery_point_barcode": "296736409004",
"components": {
"primary_number": "200",
"street_name": "Wachesaw",
"street_suffix": "Dr",
"city_name": "Piedmont",
"default_city_name": "Piedmont",
"state_abbreviation": "SC",
"zipcode": "29673",
"plus4_code": "6409",
"delivery_point": "00",
"delivery_point_check_digit": "4"
},
"metadata": {
"record_type": "S",
"zip_type": "Standard",
"county_fips": "45007",
"county_name": "Anderson",
"carrier_route": "R016",
"congressional_district": "03",
"rdi": "Residential",
"elot_sequence": "0080",
"elot_sort": "A",
"latitude": 34.78051,
"longitude": -82.47835,
"precision": "Zip8",
"time_zone": "Eastern",
"utc_offset": -5,
"dst": true
},
"analysis": {
"dpv_match_code": "Y",
"dpv_footnotes": "AABB",
"dpv_cmra": "N",
"dpv_vacant": "N",
"dpv_no_stat": "N",
"active": "Y"
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.