Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
47807b89
Commit
47807b89
authored
May 12, 2017
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgrade to SendGrid 3.2.0
Closes gh-9211
parent
97a3a940
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
19 additions
and
80 deletions
+19
-80
SendGridAutoConfiguration.java
...oot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
+7
-33
SendGridProperties.java
...ework/boot/autoconfigure/sendgrid/SendGridProperties.java
+2
-27
SendGridAutoConfigurationTests.java
...utoconfigure/sendgrid/SendGridAutoConfigurationTests.java
+9
-17
pom.xml
spring-boot-dependencies/pom.xml
+1
-1
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+0
-2
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
View file @
47807b89
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -16,18 +16,17 @@
package
org
.
springframework
.
boot
.
autoconfigure
.
sendgrid
;
import
com.sendgrid.Client
;
import
com.sendgrid.SendGrid
;
import
org.apache.http.HttpHost
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.springframework.boot.autoconfigure.EnableAutoConfiguration
;
import
org.springframework.boot.autoconfigure.condition.AnyNestedCondition
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnClass
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Conditional
;
import
org.springframework.context.annotation.Configuration
;
/**
...
...
@@ -35,11 +34,12 @@ import org.springframework.context.annotation.Configuration;
*
* @author Maciej Walkowiak
* @author Patrick Bray
* @author Andy Wilkinson
* @since 1.3.0
*/
@Configuration
@ConditionalOnClass
(
SendGrid
.
class
)
@Conditional
(
SendGridAutoConfiguration
.
SendGridPropertyCondition
.
class
)
@Conditional
OnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"api-key"
)
@EnableConfigurationProperties
(
SendGridProperties
.
class
)
public
class
SendGridAutoConfiguration
{
...
...
@@ -52,39 +52,13 @@ public class SendGridAutoConfiguration {
@Bean
@ConditionalOnMissingBean
(
SendGrid
.
class
)
public
SendGrid
sendGrid
()
{
SendGrid
sendGrid
=
createSendGrid
();
if
(
this
.
properties
.
isProxyConfigured
())
{
HttpHost
proxy
=
new
HttpHost
(
this
.
properties
.
getProxy
().
getHost
(),
this
.
properties
.
getProxy
().
getPort
());
sendGrid
.
setClient
(
HttpClientBuilder
.
create
().
setProxy
(
proxy
)
.
setUserAgent
(
"sendgrid/"
+
sendGrid
.
getVersion
()
+
";java"
).
build
(
));
return
new
SendGrid
(
this
.
properties
.
getApiKey
(),
new
Client
(
HttpClientBuilder
.
create
().
setProxy
(
proxy
).
build
()
));
}
return
sendGrid
;
}
private
SendGrid
createSendGrid
()
{
if
(
this
.
properties
.
getApiKey
()
!=
null
)
{
return
new
SendGrid
(
this
.
properties
.
getApiKey
());
}
return
new
SendGrid
(
this
.
properties
.
getUsername
(),
this
.
properties
.
getPassword
());
}
static
class
SendGridPropertyCondition
extends
AnyNestedCondition
{
SendGridPropertyCondition
()
{
super
(
ConfigurationPhase
.
PARSE_CONFIGURATION
);
}
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"username"
)
static
class
SendGridUserProperty
{
}
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"api-key"
)
static
class
SendGridApiKeyProperty
{
}
return
new
SendGrid
(
this
.
properties
.
getApiKey
());
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridProperties.java
View file @
47807b89
/*
* Copyright 2012-201
6
the original author or authors.
* Copyright 2012-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -22,21 +22,12 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* {@link ConfigurationProperties} for SendGrid.
*
* @author Maciej Walkowiak
* @author Andy Wilkinson
* @since 1.3.0
*/
@ConfigurationProperties
(
prefix
=
"spring.sendgrid"
)
public
class
SendGridProperties
{
/**
* SendGrid username. Alternative to api key.
*/
private
String
username
;
/**
* SendGrid password.
*/
private
String
password
;
/**
* SendGrid api key. Alternative to username/password.
*/
...
...
@@ -47,22 +38,6 @@ public class SendGridProperties {
*/
private
Proxy
proxy
;
public
String
getUsername
()
{
return
this
.
username
;
}
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
}
public
String
getPassword
()
{
return
this
.
password
;
}
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
}
public
String
getApiKey
()
{
return
this
.
apiKey
;
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java
View file @
47807b89
...
...
@@ -47,19 +47,11 @@ public class SendGridAutoConfigurationTests {
}
}
@Test
public
void
expectedSendGridBeanCreatedUsername
()
{
loadContext
(
"spring.sendgrid.username:user"
,
"spring.sendgrid.password:secret"
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
assertThat
(
sendGrid
).
extracting
(
"username"
).
containsExactly
(
"user"
);
assertThat
(
sendGrid
).
extracting
(
"password"
).
containsExactly
(
"secret"
);
}
@Test
public
void
expectedSendGridBeanCreatedApiKey
()
{
loadContext
(
"spring.sendgrid.api
K
ey:SG.SECRET-API-KEY"
);
loadContext
(
"spring.sendgrid.api
-k
ey:SG.SECRET-API-KEY"
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
assertThat
(
sendGrid
).
extracting
(
"
password
"
).
containsExactly
(
"SG.SECRET-API-KEY"
);
assertThat
(
sendGrid
).
extracting
(
"
apiKey
"
).
containsExactly
(
"SG.SECRET-API-KEY"
);
}
@Test
(
expected
=
NoSuchBeanDefinitionException
.
class
)
...
...
@@ -70,20 +62,20 @@ public class SendGridAutoConfigurationTests {
@Test
public
void
autoConfigurationNotFiredWhenBeanAlreadyCreated
()
{
loadContext
(
ManualSendGridConfiguration
.
class
,
"spring.sendgrid.username:user"
,
"spring.sendgrid.
password:secret
"
);
loadContext
(
ManualSendGridConfiguration
.
class
,
"spring.sendgrid.
api-key:SG.SECRET-API-KEY
"
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
assertThat
(
sendGrid
).
extracting
(
"username"
).
containsExactly
(
"manual-user"
);
assertThat
(
sendGrid
).
extracting
(
"password"
).
containsExactly
(
"manual-secret"
);
assertThat
(
sendGrid
).
extracting
(
"apiKey"
).
containsExactly
(
"SG.CUSTOM_API_KEY"
);
}
@Test
public
void
expectedSendGridBeanWithProxyCreated
()
{
loadContext
(
"spring.sendgrid.
username:user"
,
"spring.sendgrid.password:secret
"
,
loadContext
(
"spring.sendgrid.
api-key:SG.SECRET-API-KEY
"
,
"spring.sendgrid.proxy.host:localhost"
,
"spring.sendgrid.proxy.port:5678"
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
assertThat
(
sendGrid
).
extracting
(
"client"
).
extracting
(
"routePlanner"
)
assertThat
(
sendGrid
).
extracting
(
"client"
).
extracting
(
"httpClient"
)
.
extracting
(
"routePlanner"
)
.
hasOnlyElementsOfType
(
DefaultProxyRoutePlanner
.
class
);
}
...
...
@@ -107,7 +99,7 @@ public class SendGridAutoConfigurationTests {
@Bean
SendGrid
sendGrid
()
{
return
new
SendGrid
(
"
manual-user"
,
"manual-secret"
);
return
new
SendGrid
(
"
SG.CUSTOM_API_KEY"
,
true
);
}
}
...
...
spring-boot-dependencies/pom.xml
View file @
47807b89
...
...
@@ -145,7 +145,7 @@
<rxjava2.version>
2.1.0
</rxjava2.version>
<selenium.version>
3.4.0
</selenium.version>
<selenium-htmlunit.version>
2.26
</selenium-htmlunit.version>
<sendgrid.version>
2.2.2
</sendgrid.version>
<sendgrid.version>
3.2.0
</sendgrid.version>
<servlet-api.version>
3.1.0
</servlet-api.version>
<simple-json.version>
1.1.1
</simple-json.version>
<slf4j.version>
1.7.25
</slf4j.version>
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
47807b89
...
...
@@ -134,8 +134,6 @@ content into your application; rather pick only the properties that you need.
# SENDGRID ({sc-spring-boot-autoconfigure}/sendgrid/SendGridAutoConfiguration.{sc-ext}[SendGridAutoConfiguration])
spring.sendgrid.api-key= # SendGrid api key (alternative to username/password)
spring.sendgrid.username= # SendGrid account username
spring.sendgrid.password= # SendGrid account password
spring.sendgrid.proxy.host= # SendGrid proxy host
spring.sendgrid.proxy.port= # SendGrid proxy port
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment