sparkpost / java-sparkpost Goto Github PK
View Code? Open in Web Editor NEWSparkPost client library for Java
Home Page: https://www.sparkpost.com/
License: Other
SparkPost client library for Java
Home Page: https://www.sparkpost.com/
License: Other
Packages are a more common convention than using class names to namespace, we should refactor the SDK to make it follow Java conventions
Some recommendations:
com.sparkpost.sdk
dto
package for DTO's. Remove DTO from class names.resource
package for resources and SPEndpoint. Remove Resource from class names.Each time this project is built with mvn clean install
and the unit tests runs and it clutters up the users SparkPost account. The unit tests should be unit tests and not integration tests.
There should be integration level samples that hit the live site and perform specific tasks.
Here is an example of the SparkPost account after just a few builds:
There are some use cases where users would like to not call HTTPUrlConnection.disconnect()
after a request to the server.
Enable user of the SparkPost Library to be able to configure this behavior.
Does substitutionData
changes the data for all the recipients or is there a way to substitute the data according to each recipient.
For example, if I had a country field
in my Email and I wanted to change it according to each recipient's country, something like this:
hello, Mr.X from country_filed
Could I write something like below to substitute that field according to each recipient:
Map<String, Object> substitutionData = new HashMap<String, Object>();
substitutionData.put("country_filed", recipient.country);
transmission.setSubstitutionData(substitutionData);
is that possible to do it with one transmission or I have to create separate transmissions for each recipient and call transmission.setSubstitutionData
for each one?
Would be nice to have a set of POJO's that could be used with GSON for decoding the JSON Relay Webhook response.
In RestConnection.java there is some duplication of HTTP response stream. This should be refactored out into it's own method.
Here is one suggestion from @kalnik-a-a:
What about separate method for reading Response from InputStream?
Now it is duplicated in 3 places(2 in receiveSuccessResponse and 1 in receiveErrorResponse).
Something like this:
private Response readResponseFromInputStream(InputStream inputStream, StringBuilder sb, Response response) throws IOException {
BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream, DEFAULT_CHARSET));
String line = "";
while ((line = rd.readLine()) != null) {
sb.append(line);
}
response.setResponseBody(sb.toString());
logger.error("Server Response:\n" + sb.toString() + "\n");
return response;
}
We recently added OAuth and Basic Auth support to webhooks and deprecated the auth_token
field. We should update the SDK to add support for these new auth methods. See https://www.sparkpost.com/api#/reference/webhooks
As use migrate from Mandrill to SparkPost they will find it to their benefit to convert their Mandrill Blacklist to SparkPosts suppression list otherwise they will start seeing deliverability issues that they did not see at Mandrill.
TODO: add a sample that imports Mandrill's blacklist into SparkPost suppression list.
I am trying to send email with image attachment how can i achieve it in sparkpost
Travis build is broken. It looks like Java 7 is no longer available on the build machine.
See here
I want to send transmission using TransmissionWithRecipientList.
The problem is that ResourceTransmissions.create method accepts only TransmissionWithRecipientArray.
Could you update the method to use TransmissionBase as type of the transmission?
Hi,
Neither the basic not the template example from the README.md works. I get a 400 error on the basic example and 422 on the template example. There is no detail provided as to why I get the errors. A simple curl sample works though. I have setup an API key.
I also added the template ID to the example for templates in the README.md but still get a 422
{
"recipients": [
{
"address": {
"email": "[email protected]"
}
}
],
"substitution_data": {
"from": "[email protected]"
},
"return_path": "[email protected]",
"content": {
"template_id": "my-first-email",
"email_rfc822": "testing an email here"
}
}
We use coveralls.io for our other client libraries. Would be nice to add this for the java lib as well. Example: https://coveralls.io/github/SparkPost/php-sparkpost
Need to include the LICENSE that has been approved by @SparkPost/legal team (we should be able to use the one from the NodeSDK.
Need to update the readme.md file to have complete documentation for all existing TODO items.
Add documentation which is Java specific for:
We need to be able to send attachments and inline_images through the java library
Hi there,
I have build sparkpost interface by using jsp and sevrlets,I can send test mail through it, but when I am trying to send bulk mail by connecting to my local mysql database then it send only first mail in the list and rest of the are appear as bounced back
While running still I am using log4j properties file in my webapp
I got one warning every time by log4j frame still I am using log4j properties file in my webapp
Hi Team,
Where excatly is the dependency hosted,
<dependency>
<groupId>com.sparkpost</groupId>
<artifactId>client-server-protocol-lib</artifactId>
<version>0.8</version>
</dependency>
Could not find the jar reported in http://mvnrepository.com/artifact/com.sparkpost
using sparkpost-lib 0.17, it appears to have no timeout value set for either a the connect timeout nor the read timeout.
i got this today:
java.lang.Thread.run(Thread.java:745) Caused by: java.lang.NullPointerException at com.sparkpost.transport.RestConnection.receiveResponse(RestConnection.java:226) at com.sparkpost.transport.RestConnection.doHttpMethod(RestConnection.java:279) at com.sparkpost.transport.RestConnection.post(RestConnection.java:322) at com.sparkpost.resources.ResourceTransmissions.create(ResourceTransmissions.java:28) at
Hi,
It looks like substitution data can only be strings key/value pairs but the value should be an array too.
Am I missing something to do so ?
Thanks
Using sparkpost-lib 0.16.1
.
When using ResourceTemplates.retrieve
to retrieve a template, the following JsonSyntaxException
occurs when parsing the from
field.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 242 path $.results.content.from
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
com.google.gson.Gson.fromJson(Gson.java:810)
com.google.gson.Gson.fromJson(Gson.java:775)
com.google.gson.Gson.fromJson(Gson.java:724)
com.sparkpost.model.responses.Response.decode(Response.java:47)
com.sparkpost.resources.ResourceTemplates.retrieve(ResourceTemplates.java:38)
It seems like the java code expects a JSON object but the API returns a simple string.
Here is what the from field looks like when manually hitting the API at https://api.sparkpost.com/api/v1/templates/mytemplate
with postman
"from": "My Company <[email protected]>",
When an error occurs the library shows the request JSON but the response JSON is not shown.
It will make it much easier to debug if error is shown.
Need a single place for developers to view the history of changes by release number.
Need to add support for setting SPC EU endpoint to the sendMessage methods.
Here is one workaround provided:
https://gist.github.com/AledLewis/740968ff68e3b5351a6892af79a97819
Slack Conversation:
Hi,
Trying to run the sample with sparky.sendMessage()
and getting the following error:
{ "errors": [ { "message": "Resource could not be found" } ] }
Looks like the code is adding an extra slash (before transmissions) into the url calling
https://api.sparkpost.com/api/v1//transmissions?num_rcpt_errors=0
We are using apache httpclient-4.5.3.jar (on Win 10).
Can anyone please fix it?
TIA,
Oleg.
Hi,
In readme defined lib
com.sparkpost
client-server-protocol-lib
0.10
need to define
Being able to detect whether a webhook is active as well as being able to perform a PUT
and re-activating a webhook is not currently possible since the WebhookDescription
/Webhook
model does not have the active
property on it.
The transmission endpoint now respects options.sandbox
when sending from sparkpostbox.com
so our "easy button" API clients should set the field appropriately when they detect sandbox domain use. The highest profile use of Client.sendMessage()
is here.
Currently, the Java SparkPost library sends/receives HTTP data uncompressed. It should provide a way to compress and decompress HTTP streams.
At the moment I see no possibility to set the from name when sending an email. Only the from address can be set.
Instead of directly depending on log4j, using the SLF4J logging facade will allow dependent applications of the Sparkpost library to pick/configure a logging library of their choice or at least not conflict with different versions of log4j.
The use case for me was that I'm using the logback logging library in my application, but the sparkpost library required me to configure both log4j and logback to have the same kind of logging formats, levels, and appenders.
I'll be submitting a PR in a few that contains the changes necessary for this.
We need to retrieve a template object in order to be able to send attachments with the transmission object.
Add delete
to the ResourceTransmissions
class.
According to ESCSP-1390, java-sparkpost sometimes request to endpoint with duplicate slashes. While it used to work earlier and broken now which we're fixing it may not work in future (when we move to ALB routing).
/api/v1//transmissions
Currently the text field is not mapped to TemplatePreviewData
when previewing templates although it is present in the returned json from the server.
I created a PR for this issue: #81
Hi team,
I used Gradle please
but that's giving me concurrent exception error while building also , depency is ignored 'org.apache:commons' httpclient
Please provide clear instruction on how to use sparkpost from android.
Thanks and Regards,
Creating a com.sparkpost.transport.RestConnection with a null baseUrl throws an NPE. The RestConnection sets a default url if it is null, but then refers the parameter, not the field when checking for URL validity.
Add 'sandbox' and 'ip_pool' parameters to transmission options
Create Examples of lib usage.
A good starting point will be parity with python-sparkpost
This is not current, please update with an accurate list of properties.
https://github.com/SparkPost/java-sparkpost/blob/master/libs/sparkpost-lib/src/main/java/com/sparkpost/model/webhook/event/DeliveryEvent.java
I tried to implement it in our code with logic like this, but it's not working. I'd totally appreciate any assistance/guidance in checking the response code properly:
catch (SparkPostErrorServerResponseException spex) {
...
else if (500 <= spex.getResponseCode() && spex.getResponseCode() < 510){
Logger.log("Sparkpost " + spex.getResponseCode() + " errors, skipping for now: " + em.id);
...
Thanks!
This should not have been deprecated when the string path methods were deprecated:
/*
* (non-Javadoc)
* @see com.sparkpost.transport.IRestConnection#get(com.sparkpost.resources.Endpoint)
*/
@Override
@Deprecated
public Response get(Endpoint endpoint) throws SparkPostException {
Response response = new Response();
return doHttpMethod(endpoint, Method.GET, null, response);
}
Need to add the SparkPost logo (most recent and appropriate version) to the main README.md file
Add support for Message Events API
The Message Events API allows searching for recent events, and supports various types of result filtering. Available events include message status - injection, delivery, bounce - as well as recipient engagement - clicks and opens. Message Events is an on-demand (pull) interface to the same underlying event data that gets delivered in a near-real-time (push) fashion via Webhooks.
You can get all event types or only specific ones, such as bounces, deliveries, or clicks. You can filter by date range, campaign, or just about any other field. Event data is retained for 10 days and is generally available within 1 minute. Of course, aggregate reporting data is available via our metrics endpoint or the UI reports for much longer.
GET/api/v1/message-events{?bounce_classes,campaign_ids,delimiter,events,friendly_froms,from,message_ids,page,per_page,reason,recipients,subaccounts,template_ids,timezone,to,transmission_ids}
Unless I am missing something there seems to be no support for managing subaccounts. Would be nice to add so we don't have to write seperate clients.
For example, this gets thrown as SparkPostErrorServerResponseException:
SEVERE: Error reading server response: { "errors": [ { "message": "Message generation rejected", "description": "recipient address suppressed due to customer policy", "code": "1902" } ], "results": { "total_rejected_recipients": 0, "total_accepted_recipients": 1, "id": "84509310299791535" } }(Bad Request)
..which is not really developer friendly. Basically, when exceptions for responses like 4XX are thrown the whole response body is concat to the exception message. If I want to get the internal error code (1902) to store it somewhere I need to first remove the "Error reading server response" from message, then write a custom POJO to parse the remaining body into it.
It would be way nicer if we could grab the error response body directly from SparkPostException as an object, not needing to parse the text message ourself. Or at least get the clean response text.
Right now the library basically hides the response body from us and I don't see any good way to retreive it other than the way mentioned above.
In order to retrieve large suppression lists search function should use cursors so the end user can page through all suppression results.
Remove deprecated methods from IRestConnection to simplify alternative implementations.
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.