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
3562026e
Commit
3562026e
authored
Jan 26, 2016
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish contribution
Closes gh-4574
parent
3bf6c2fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
37 deletions
+36
-37
SendGridAutoConfiguration.java
...oot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
+17
-16
SendGridProperties.java
...ework/boot/autoconfigure/sendgrid/SendGridProperties.java
+12
-12
SendGridAutoConfigurationTests.java
...utoconfigure/sendgrid/SendGridAutoConfigurationTests.java
+6
-9
appendix-application-properties.adoc
...cs/src/main/asciidoc/appendix-application-properties.adoc
+1
-0
No files found.
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfiguration.java
View file @
3562026e
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -35,6 +35,7 @@ import org.springframework.context.annotation.Configuration;
...
@@ -35,6 +35,7 @@ import org.springframework.context.annotation.Configuration;
* {@link EnableAutoConfiguration Auto-configuration} for SendGrid.
* {@link EnableAutoConfiguration Auto-configuration} for SendGrid.
*
*
* @author Maciej Walkowiak
* @author Maciej Walkowiak
* @author Patrick Bray
* @since 1.3.0
* @since 1.3.0
*/
*/
@Configuration
@Configuration
...
@@ -49,27 +50,27 @@ public class SendGridAutoConfiguration {
...
@@ -49,27 +50,27 @@ public class SendGridAutoConfiguration {
@Bean
@Bean
@ConditionalOnMissingBean
(
SendGrid
.
class
)
@ConditionalOnMissingBean
(
SendGrid
.
class
)
public
SendGrid
sendGrid
()
{
public
SendGrid
sendGrid
()
{
SendGrid
sendGrid
=
createSendGrid
();
SendGrid
sendGrid
;
if
(
this
.
properties
.
getApikey
()
!=
null
)
{
sendGrid
=
new
SendGrid
(
this
.
properties
.
getApikey
());
}
else
{
sendGrid
=
new
SendGrid
(
this
.
properties
.
getUsername
(),
this
.
properties
.
getPassword
());
}
if
(
this
.
properties
.
isProxyConfigured
())
{
if
(
this
.
properties
.
isProxyConfigured
())
{
HttpHost
proxy
=
new
HttpHost
(
this
.
properties
.
getProxy
().
getHost
(),
HttpHost
proxy
=
new
HttpHost
(
this
.
properties
.
getProxy
().
getHost
(),
this
.
properties
.
getProxy
().
getPort
());
this
.
properties
.
getProxy
().
getPort
());
sendGrid
.
setClient
(
HttpClientBuilder
.
create
().
setProxy
(
proxy
)
sendGrid
.
setClient
(
HttpClientBuilder
.
create
().
setProxy
(
proxy
)
.
setUserAgent
(
"sendgrid/"
+
sendGrid
.
getVersion
()
+
";java"
).
build
());
.
setUserAgent
(
"sendgrid/"
+
sendGrid
.
getVersion
()
+
";java"
).
build
());
}
}
return
sendGrid
;
return
sendGrid
;
}
}
private
SendGrid
createSendGrid
()
{
if
(
this
.
properties
.
getApiKey
()
!=
null
)
{
return
new
SendGrid
(
this
.
properties
.
getApiKey
());
}
else
{
return
new
SendGrid
(
this
.
properties
.
getUsername
(),
this
.
properties
.
getPassword
());
}
}
static
class
SendGridPropertyCondition
extends
AnyNestedCondition
{
static
class
SendGridPropertyCondition
extends
AnyNestedCondition
{
SendGridPropertyCondition
()
{
SendGridPropertyCondition
()
{
...
@@ -77,11 +78,11 @@ public class SendGridAutoConfiguration {
...
@@ -77,11 +78,11 @@ public class SendGridAutoConfiguration {
}
}
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"username"
)
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"username"
)
private
class
SendGridUserProperty
{
static
class
SendGridUserProperty
{
}
}
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"apikey"
)
@ConditionalOnProperty
(
prefix
=
"spring.sendgrid"
,
value
=
"api
-
key"
)
private
class
SendGridApiKeyProperty
{
static
class
SendGridApiKeyProperty
{
}
}
}
}
}
}
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/sendgrid/SendGridProperties.java
View file @
3562026e
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -28,7 +28,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
...
@@ -28,7 +28,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
public
class
SendGridProperties
{
public
class
SendGridProperties
{
/**
/**
* SendGrid username.
* SendGrid username.
Alternative to api key.
*/
*/
private
String
username
;
private
String
username
;
...
@@ -38,23 +38,15 @@ public class SendGridProperties {
...
@@ -38,23 +38,15 @@ public class SendGridProperties {
private
String
password
;
private
String
password
;
/**
/**
* SendGrid api key.
* SendGrid api key.
Alternative to username/password.
*/
*/
private
String
api
k
ey
;
private
String
api
K
ey
;
/**
/**
* Proxy configuration.
* Proxy configuration.
*/
*/
private
Proxy
proxy
;
private
Proxy
proxy
;
public
String
getApikey
()
{
return
this
.
apikey
;
}
public
void
setApikey
(
final
String
apikey
)
{
this
.
apikey
=
apikey
;
}
public
String
getUsername
()
{
public
String
getUsername
()
{
return
this
.
username
;
return
this
.
username
;
}
}
...
@@ -71,6 +63,14 @@ public class SendGridProperties {
...
@@ -71,6 +63,14 @@ public class SendGridProperties {
this
.
password
=
password
;
this
.
password
=
password
;
}
}
public
String
getApiKey
()
{
return
this
.
apiKey
;
}
public
void
setApiKey
(
final
String
apiKey
)
{
this
.
apiKey
=
apiKey
;
}
public
Proxy
getProxy
()
{
public
Proxy
getProxy
()
{
return
this
.
proxy
;
return
this
.
proxy
;
}
}
...
...
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/sendgrid/SendGridAutoConfigurationTests.java
View file @
3562026e
/*
/*
* Copyright 2012-201
5
the original author or authors.
* Copyright 2012-201
6
the original author or authors.
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* you may not use this file except in compliance with the License.
...
@@ -38,6 +38,7 @@ import static org.junit.Assert.assertThat;
...
@@ -38,6 +38,7 @@ import static org.junit.Assert.assertThat;
* Tests for {@link SendGridAutoConfiguration}.
* Tests for {@link SendGridAutoConfiguration}.
*
*
* @author Maciej Walkowiak
* @author Maciej Walkowiak
* @author Patrick Bray
*/
*/
public
class
SendGridAutoConfigurationTests
{
public
class
SendGridAutoConfigurationTests
{
...
@@ -51,7 +52,7 @@ public class SendGridAutoConfigurationTests {
...
@@ -51,7 +52,7 @@ public class SendGridAutoConfigurationTests {
}
}
@Test
@Test
public
void
expectedSendGridBeanCreated
()
{
public
void
expectedSendGridBeanCreated
Username
()
{
loadContext
(
"spring.sendgrid.username:user"
,
"spring.sendgrid.password:secret"
);
loadContext
(
"spring.sendgrid.username:user"
,
"spring.sendgrid.password:secret"
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
assertEquals
(
"user"
,
ReflectionTestUtils
.
getField
(
sendGrid
,
"username"
));
assertEquals
(
"user"
,
ReflectionTestUtils
.
getField
(
sendGrid
,
"username"
));
...
@@ -59,14 +60,10 @@ public class SendGridAutoConfigurationTests {
...
@@ -59,14 +60,10 @@ public class SendGridAutoConfigurationTests {
}
}
@Test
@Test
public
void
expectedSendGridBeanCreated_UsingApiKey
()
{
public
void
expectedSendGridBeanCreatedApiKey
()
{
loadContext
(
"spring.sendgrid.apiKey:SG.SECRET-API-KEY"
);
loadContext
(
"spring.sendgrid.apikey:SG.SECRET-API-KEY"
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
SendGrid
sendGrid
=
this
.
context
.
getBean
(
SendGrid
.
class
);
assertEquals
(
"SG.SECRET-API-KEY"
,
ReflectionTestUtils
.
getField
(
sendGrid
,
"password"
));
assertEquals
(
"SG.SECRET-API-KEY"
,
ReflectionTestUtils
.
getField
(
sendGrid
,
"password"
));
}
}
@Test
(
expected
=
NoSuchBeanDefinitionException
.
class
)
@Test
(
expected
=
NoSuchBeanDefinitionException
.
class
)
...
...
spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc
View file @
3562026e
...
@@ -120,6 +120,7 @@ content into your application; rather pick only the properties that you need.
...
@@ -120,6 +120,7 @@ content into your application; rather pick only the properties that you need.
spring.profiles.include= # Unconditionally activate the specified comma separated profiles.
spring.profiles.include= # Unconditionally activate the specified comma separated profiles.
# SENDGRID ({sc-spring-boot-autoconfigure}/sendgrid/SendGridAutoConfiguration.{sc-ext}[SendGridAutoConfiguration])
# 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.username= # SendGrid account username
spring.sendgrid.password= # SendGrid account password
spring.sendgrid.password= # SendGrid account password
spring.sendgrid.proxy.host= # SendGrid proxy host
spring.sendgrid.proxy.host= # SendGrid proxy host
...
...
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