mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
Merge pull request #350 from xiaolongzuo/master
Add test case for alicloud-context.
This commit is contained in:
commit
d6334fbe87
@ -113,6 +113,20 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-module-junit4</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.powermock</groupId>
|
||||
<artifactId>powermock-api-mockito2</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
@ -42,9 +42,8 @@ public abstract class AbstractOnceApplicationListener<T extends ApplicationEvent
|
||||
ApplicationContext applicationContext = ((ApplicationContextEvent) event)
|
||||
.getApplicationContext();
|
||||
// skip bootstrap context or super parent context.
|
||||
if (applicationContext.getParent() == null
|
||||
|| BOOTSTRAP_CONFIG_NAME_VALUE.equals(applicationContext
|
||||
.getEnvironment().getProperty(BOOTSTRAP_CONFIG_NAME_KEY))) {
|
||||
if (BOOTSTRAP_CONFIG_NAME_VALUE.equals(applicationContext.getEnvironment()
|
||||
.getProperty(BOOTSTRAP_CONFIG_NAME_KEY))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ import org.springframework.cloud.alicloud.context.listener.AbstractOnceApplicati
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
*/
|
||||
public class NacosParameterInitListener
|
||||
extends AbstractOnceApplicationListener<ApplicationEnvironmentPreparedEvent> {
|
||||
private static final Logger log = LoggerFactory
|
||||
@ -33,7 +36,8 @@ public class NacosParameterInitListener
|
||||
|
||||
log.info("Initialize Nacos Parameter from edas change order,is edas managed {}.",
|
||||
edasChangeOrderConfiguration.isEdasManaged());
|
||||
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.server-mode",
|
||||
"EDAS");
|
||||
// initialize nacos configuration
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.server-addr", "");
|
||||
System.getProperties().setProperty("spring.cloud.nacos.config.endpoint",
|
||||
|
@ -19,6 +19,7 @@ package org.springframework.cloud.alicloud.context.oss;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
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.cloud.alicloud.context.AliCloudContextAutoConfiguration;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
@ -39,6 +40,7 @@ import com.aliyun.oss.OSSClientBuilder;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.oss.OssAutoConfiguration")
|
||||
@ConditionalOnProperty(name = "spring.cloud.alicloud.oss.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(OssProperties.class)
|
||||
@ImportAutoConfiguration(AliCloudContextAutoConfiguration.class)
|
||||
public class OssContextAutoConfiguration {
|
||||
|
@ -22,6 +22,7 @@ import com.alibaba.edas.schedulerx.SchedulerXClient;
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
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.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
|
||||
@ -34,6 +35,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(name = "org.springframework.cloud.alicloud.scx.ScxAutoConfiguration")
|
||||
@ConditionalOnProperty(name = "spring.cloud.alicloud.scx.enabled", matchIfMissing = true)
|
||||
@EnableConfigurationProperties(ScxProperties.class)
|
||||
@ImportAutoConfiguration(EdasContextAutoConfiguration.class)
|
||||
public class ScxContextAutoConfiguration {
|
||||
@ -41,10 +43,10 @@ public class ScxContextAutoConfiguration {
|
||||
@Bean(initMethod = "init")
|
||||
@ConditionalOnMissingBean
|
||||
public SchedulerXClient schedulerXClient(AliCloudProperties aliCloudProperties,
|
||||
EdasProperties edasProperties, ScxProperties scxProperties,
|
||||
AliCloudEdasSdk aliCloudEdasSdk) {
|
||||
EdasProperties edasProperties, ScxProperties scxProperties,
|
||||
AliCloudEdasSdk aliCloudEdasSdk) {
|
||||
return AliCloudScxInitializer.initialize(aliCloudProperties, edasProperties,
|
||||
scxProperties, aliCloudEdasSdk);
|
||||
scxProperties, aliCloudEdasSdk);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,107 +0,0 @@
|
||||
package org.springframework.cloud.alicloud.context.sms;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.cloud.alicloud.sms")
|
||||
public class SmsConfigProperties implements Serializable {
|
||||
|
||||
// 产品名称:云通信短信API产品,开发者无需替换
|
||||
public static final String smsProduct = "Dysmsapi";
|
||||
// 产品域名,开发者无需替换
|
||||
public static final String smsDomain = "dysmsapi.aliyuncs.com";
|
||||
|
||||
private AliCloudProperties aliCloudProperties;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String reportQueueName;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private String upQueueName;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected String connnectTimeout = "10000";
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected String readTimeout = "10000";
|
||||
|
||||
public SmsConfigProperties(AliCloudProperties aliCloudProperties) {
|
||||
this.aliCloudProperties = aliCloudProperties;
|
||||
}
|
||||
|
||||
public String getConnnectTimeout() {
|
||||
return connnectTimeout;
|
||||
}
|
||||
|
||||
public void setConnnectTimeout(String connnectTimeout) {
|
||||
this.connnectTimeout = connnectTimeout;
|
||||
}
|
||||
|
||||
public String getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeout(String readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public void overiideFromEnv(Environment environment) {
|
||||
overiideCustomFromEnv(environment);
|
||||
if (StringUtils.isEmpty(connnectTimeout)) {
|
||||
String resolveResult = environment.resolveRequiredPlaceholders(
|
||||
"${spring.cloud.alibaba.sms.connect-timeout:}");
|
||||
this.setConnnectTimeout(
|
||||
StringUtils.isEmpty(resolveResult) ? "10000" : resolveResult);
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(readTimeout)) {
|
||||
String resolveResult = environment.resolveRequiredPlaceholders(
|
||||
"${spring.cloud.alibaba.sms.read-timeout:}");
|
||||
this.setReadTimeout(
|
||||
StringUtils.isEmpty(resolveResult) ? "10000" : resolveResult);
|
||||
}
|
||||
}
|
||||
|
||||
public void overiideCustomFromEnv(Environment environment) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public String getReportQueueName() {
|
||||
return reportQueueName;
|
||||
}
|
||||
|
||||
public void setReportQueueName(String reportQueueName) {
|
||||
this.reportQueueName = reportQueueName;
|
||||
}
|
||||
|
||||
public String getUpQueueName() {
|
||||
return upQueueName;
|
||||
}
|
||||
|
||||
public String getAccessKeyId() {
|
||||
return aliCloudProperties.getAccessKey();
|
||||
}
|
||||
|
||||
public String getAccessKeySecret() {
|
||||
return aliCloudProperties.getSecretKey();
|
||||
}
|
||||
|
||||
public void setUpQueueName(String upQueueName) {
|
||||
this.upQueueName = upQueueName;
|
||||
}
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package org.springframework.cloud.alicloud.context.sms;
|
||||
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
*/
|
||||
public class SmsConfigRegistration {
|
||||
|
||||
private Environment environment;
|
||||
|
||||
private SmsConfigProperties smsConfigProperties;
|
||||
|
||||
public SmsConfigRegistration(Environment environment,
|
||||
SmsConfigProperties smsConfigProperties) {
|
||||
this.environment = environment;
|
||||
this.smsConfigProperties = smsConfigProperties;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void initSmsConfigRegistration() {
|
||||
smsConfigProperties.overiideFromEnv(environment);
|
||||
}
|
||||
}
|
@ -3,28 +3,16 @@ package org.springframework.cloud.alicloud.context.sms;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
@EnableConfigurationProperties(SmsProperties.class)
|
||||
@ConditionalOnClass(name = "com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest")
|
||||
@ConditionalOnProperty(value = "spring.cloud.alibaba.deshao.enable.sms", matchIfMissing = true)
|
||||
public class SmsContextAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public SmsConfigProperties smsConfigProperties(
|
||||
AliCloudProperties aliCloudProperties) {
|
||||
|
||||
return new SmsConfigProperties(aliCloudProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SmsConfigRegistration smsConfigRegistration(Environment environment,
|
||||
SmsConfigProperties smsConfigProperties) {
|
||||
|
||||
return new SmsConfigRegistration(environment, smsConfigProperties);
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package org.springframework.cloud.alicloud.context.sms;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "spring.cloud.alicloud.sms")
|
||||
public class SmsProperties {
|
||||
|
||||
/**
|
||||
* Product name.
|
||||
*/
|
||||
public static final String smsProduct = "Dysmsapi";
|
||||
|
||||
/**
|
||||
* Product domain.
|
||||
*/
|
||||
public static final String smsDomain = "dysmsapi.aliyuncs.com";
|
||||
|
||||
/**
|
||||
* Report queue name.
|
||||
*/
|
||||
private String reportQueueName;
|
||||
|
||||
/**
|
||||
* Up queue name.
|
||||
*/
|
||||
private String upQueueName;
|
||||
|
||||
/**
|
||||
* Connect timeout.
|
||||
*/
|
||||
private String connectTimeout = "10000";
|
||||
|
||||
/**
|
||||
* Read timeout.
|
||||
*/
|
||||
private String readTimeout = "10000";
|
||||
|
||||
public String getConnectTimeout() {
|
||||
return connectTimeout;
|
||||
}
|
||||
|
||||
public void setConnectTimeout(String connectTimeout) {
|
||||
this.connectTimeout = connectTimeout;
|
||||
}
|
||||
|
||||
public String getReadTimeout() {
|
||||
return readTimeout;
|
||||
}
|
||||
|
||||
public void setReadTimeout(String readTimeout) {
|
||||
this.readTimeout = readTimeout;
|
||||
}
|
||||
|
||||
public String getReportQueueName() {
|
||||
return reportQueueName;
|
||||
}
|
||||
|
||||
public void setReportQueueName(String reportQueueName) {
|
||||
this.reportQueueName = reportQueueName;
|
||||
}
|
||||
|
||||
public String getUpQueueName() {
|
||||
return upQueueName;
|
||||
}
|
||||
|
||||
public void setUpQueueName(String upQueueName) {
|
||||
this.upQueueName = upQueueName;
|
||||
}
|
||||
|
||||
}
|
@ -46,6 +46,10 @@ import com.alibaba.cloud.context.statistics.StatisticsTask;
|
||||
AcmContextBootstrapConfiguration.class })
|
||||
public class StatisticsTaskStarter implements InitializingBean {
|
||||
|
||||
private static final String NACOS_CONFIG_SERVER_MODE_KEY = "spring.cloud.nacos.config.server-mode";
|
||||
|
||||
private static final String NACOS_CONFIG_SERVER_MODE_VALUE = "EDAS";
|
||||
|
||||
@Autowired(required = false)
|
||||
private AliCloudEdasSdk aliCloudEdasSdk;
|
||||
|
||||
@ -102,6 +106,10 @@ public class StatisticsTaskStarter implements InitializingBean {
|
||||
if (acmContextBootstrapConfiguration != null && acmEnableEdas) {
|
||||
components.add("SC-ACM");
|
||||
}
|
||||
if (NACOS_CONFIG_SERVER_MODE_VALUE
|
||||
.equals(System.getProperty(NACOS_CONFIG_SERVER_MODE_KEY))) {
|
||||
components.add("SC-NACOS-CONFIG");
|
||||
}
|
||||
return components;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.alibaba.csp.sentinel.datasource.nacos;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class NacosDataSource {
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.aliyuncs.dysmsapi.model.v20170525;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class SendSmsRequest {
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alibaba.nacos;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class NacosConfigAutoConfiguration {
|
||||
}
|
@ -16,36 +16,35 @@
|
||||
|
||||
package org.springframework.cloud.alicloud.context;
|
||||
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = AliCloudSpringApplicationTests.AliCloudDisabledApp.class, properties = {
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PowerMockRunnerDelegate(SpringRunner.class)
|
||||
@PowerMockIgnore("javax.management.*")
|
||||
@SpringBootTest(classes = BaseAliCloudSpringApplication.AliCloudApplication.class, properties = {
|
||||
"spring.application.name=myapp",
|
||||
"spring.cloud.alicloud.edas.application.name=myapp",
|
||||
"spring.cloud.alicloud.access-key=ak", "spring.cloud.alicloud.secret-key=sk",
|
||||
"spring.cloud.alicloud.oss.endpoint=test",
|
||||
"spring.cloud.alicloud.scx.group-id=1-2-3-4",
|
||||
"spring.cloud.alicloud.edas.namespace=cn-test" }, webEnvironment = RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
public class AliCloudSpringApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
System.out.println("Context load...");
|
||||
}
|
||||
"spring.cloud.alicloud.edas.namespace=cn-test",
|
||||
"spring.cloud.alicloud.ans.server-list=192.168.1.100",
|
||||
"spring.cloud.alicloud.ans.server-port=8888",
|
||||
"spring.cloud.alicloud.oss.enabled=false",
|
||||
"spring.cloud.alicloud.scx.enabled=false" })
|
||||
public abstract class BaseAliCloudSpringApplication {
|
||||
|
||||
@SpringBootApplication
|
||||
public static class AliCloudDisabledApp {
|
||||
public static class AliCloudApplication {
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.ans;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class AnsContextApplicationListenerTests extends BaseAliCloudSpringApplication {
|
||||
|
||||
@Test
|
||||
public void testAnsContextApplicationListenerDefault() {
|
||||
assertThat(System
|
||||
.getProperty("com.alibaba.ans.shaded.com.taobao.vipserver.serverlist"))
|
||||
.isEqualTo("192.168.1.100");
|
||||
assertThat(System.getProperty("vipserver.server.port")).isEqualTo("8888");
|
||||
}
|
||||
|
||||
}
|
@ -18,7 +18,17 @@ package org.springframework.cloud.alicloud.context.ans;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration;
|
||||
@ -29,6 +39,8 @@ import com.alibaba.cloud.context.AliCloudServerMode;
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({ NetworkInterface.class, AnsProperties.class })
|
||||
public class AnsPropertiesTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
@ -37,8 +49,7 @@ public class AnsPropertiesTests {
|
||||
AliCloudContextAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void testConfigurationValueDefaultsAreAsExpected()
|
||||
throws ClassNotFoundException {
|
||||
public void testConfigurationValueDefaultsAreAsExpected() {
|
||||
this.contextRunner.withPropertyValues().run(context -> {
|
||||
AnsProperties ansProperties = context.getBean(AnsProperties.class);
|
||||
assertThat(ansProperties.getServerMode()).isEqualTo(AliCloudServerMode.LOCAL);
|
||||
@ -65,7 +76,7 @@ public class AnsPropertiesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded() {
|
||||
public void testConfigurationValuesAreCorrectlyLoaded1() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.alicloud.ans.server-mode=EDAS",
|
||||
"spring.cloud.alicloud.ans.server-port=11111",
|
||||
@ -99,4 +110,37 @@ public class AnsPropertiesTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException.class)
|
||||
public void testConfigurationValuesAreCorrectlyLoaded2() {
|
||||
this.contextRunner.withPropertyValues(
|
||||
"spring.cloud.alicloud.ans.client-interface-name=noneinterfacename")
|
||||
.run(context -> {
|
||||
AnsProperties ansProperties = context.getBean(AnsProperties.class);
|
||||
assertThat(ansProperties.getClientInterfaceName())
|
||||
.isEqualTo("noneinterfacename");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded3() throws SocketException {
|
||||
NetworkInterface networkInterface = PowerMockito.mock(NetworkInterface.class);
|
||||
Vector<InetAddress> inetAddressList = new Vector<>();
|
||||
Inet4Address inetAddress = PowerMockito.mock(Inet4Address.class);
|
||||
PowerMockito.when(inetAddress.getHostAddress()).thenReturn("192.168.1.100");
|
||||
inetAddressList.add(inetAddress);
|
||||
PowerMockito.when(networkInterface.getInetAddresses())
|
||||
.thenReturn(inetAddressList.elements());
|
||||
PowerMockito.mockStatic(NetworkInterface.class);
|
||||
PowerMockito.when(NetworkInterface.getByName("eth0"))
|
||||
.thenReturn(networkInterface);
|
||||
this.contextRunner
|
||||
.withPropertyValues(
|
||||
"spring.cloud.alicloud.ans.client-interface-name=eth0")
|
||||
.run(context -> {
|
||||
AnsProperties ansProperties = context.getBean(AnsProperties.class);
|
||||
assertThat(ansProperties.getClientInterfaceName()).isEqualTo("eth0");
|
||||
assertThat(ansProperties.getClientIp()).isEqualTo("192.168.1.100");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.nacos;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication;
|
||||
import org.springframework.cloud.alicloud.utils.ChangeOrderUtils;
|
||||
|
||||
import com.alibaba.cloud.context.ans.AliCloudAnsInitializer;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
|
||||
NacosParameterInitListener.class, AliCloudAnsInitializer.class })
|
||||
public class NacosParameterInitListenerTests extends BaseAliCloudSpringApplication {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
ChangeOrderUtils.mockChangeOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNacosParameterInitListener() {
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.server-mode"))
|
||||
.isEqualTo("EDAS");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.server-addr"))
|
||||
.isEqualTo("");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.endpoint"))
|
||||
.isEqualTo("testDomain");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.namespace"))
|
||||
.isEqualTo("testTenantId");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.access-key"))
|
||||
.isEqualTo("testAK");
|
||||
assertThat(System.getProperty("spring.cloud.nacos.config.secret-key"))
|
||||
.isEqualTo("testSK");
|
||||
|
||||
}
|
||||
}
|
@ -35,11 +35,13 @@ public class OssAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(OssContextAutoConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.alicloud.accessKey=your-ak")
|
||||
.withPropertyValues("spring.cloud.alicloud.secretKey=your-sk")
|
||||
.withPropertyValues(
|
||||
"spring.cloud.alicloud.oss.endpoint=http://oss-cn-beijing.aliyuncs.com")
|
||||
.withPropertyValues("spring.cloud.alicloud.oss.config.userAgent=alibaba");
|
||||
.withPropertyValues("spring.cloud.alicloud.accessKey=your-ak",
|
||||
"spring.cloud.alicloud.secretKey=your-sk",
|
||||
"spring.cloud.alicloud.oss.endpoint=http://oss-cn-beijing.aliyuncs.com",
|
||||
"spring.cloud.alicloud.oss.config.userAgent=alibaba",
|
||||
"spring.cloud.alicloud.oss.sts.access-key=your-sts-ak",
|
||||
"spring.cloud.alicloud.oss.sts.secret-key=your-sts-sk",
|
||||
"spring.cloud.alicloud.oss.sts.security-token=your-sts-token");
|
||||
|
||||
@Test
|
||||
public void testOSSProperties() {
|
||||
@ -53,11 +55,15 @@ public class OssAutoConfigurationTests {
|
||||
assertThat(ossProperties.getEndpoint())
|
||||
.isEqualTo("http://oss-cn-beijing.aliyuncs.com");
|
||||
assertThat(ossProperties.getConfig().getUserAgent()).isEqualTo("alibaba");
|
||||
assertThat(ossProperties.getSts().getAccessKey()).isEqualTo("your-sts-ak");
|
||||
assertThat(ossProperties.getSts().getSecretKey()).isEqualTo("your-sts-sk");
|
||||
assertThat(ossProperties.getSts().getSecurityToken())
|
||||
.isEqualTo("your-sts-token");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOSSClient() {
|
||||
public void testOSSClient1() {
|
||||
this.contextRunner.run(context -> {
|
||||
assertThat(context.getBeansOfType(OSS.class).size() == 1).isTrue();
|
||||
assertThat(context.getBeanNamesForType(OSS.class)[0]).isEqualTo("ossClient");
|
||||
@ -74,4 +80,26 @@ public class OssAutoConfigurationTests {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOSSClient2() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.alicloud.oss.authorization-mode=STS")
|
||||
.run(context -> {
|
||||
assertThat(context.getBeansOfType(OSS.class).size() == 1).isTrue();
|
||||
assertThat(context.getBeanNamesForType(OSS.class)[0])
|
||||
.isEqualTo("ossClient");
|
||||
OSSClient ossClient = (OSSClient) context.getBean(OSS.class);
|
||||
assertThat(ossClient.getEndpoint().toString())
|
||||
.isEqualTo("http://oss-cn-beijing.aliyuncs.com");
|
||||
assertThat(ossClient.getClientConfiguration().getUserAgent())
|
||||
.isEqualTo("alibaba");
|
||||
assertThat(ossClient.getCredentialsProvider().getCredentials()
|
||||
.getAccessKeyId()).isEqualTo("your-sts-ak");
|
||||
assertThat(ossClient.getCredentialsProvider().getCredentials()
|
||||
.getSecretAccessKey()).isEqualTo("your-sts-sk");
|
||||
assertThat(ossClient.getCredentialsProvider().getCredentials()
|
||||
.getSecurityToken()).isEqualTo("your-sts-token");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.sentinel;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.springframework.cloud.alicloud.context.BaseAliCloudSpringApplication;
|
||||
import org.springframework.cloud.alicloud.context.Constants;
|
||||
import org.springframework.cloud.alicloud.utils.ChangeOrderUtils;
|
||||
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
@PrepareForTest({ EdasChangeOrderConfigurationFactory.class,
|
||||
SentinelAliCloudListener.class })
|
||||
public class SentinelAliCloudListenerTests extends BaseAliCloudSpringApplication {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
ChangeOrderUtils.mockChangeOrder();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNacosParameterInitListener() {
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_ENDPOINT))
|
||||
.isEqualTo("testDomain");
|
||||
assertThat(System.getProperty(Constants.Sentinel.PROJECT_NAME))
|
||||
.isEqualTo("testProjectName");
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_NAMESPACE))
|
||||
.isEqualTo("testTenantId");
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_AK))
|
||||
.isEqualTo("testAK");
|
||||
assertThat(System.getProperty(Constants.Sentinel.NACOS_DATASOURCE_SK))
|
||||
.isEqualTo("testSK");
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.context.sms;
|
||||
|
||||
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
|
||||
|
||||
import org.assertj.core.api.AssertionsForClassTypes;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudContextAutoConfiguration;
|
||||
import org.springframework.cloud.alicloud.context.edas.EdasContextAutoConfiguration;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class SmsPropertiesTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(SmsContextAutoConfiguration.class,
|
||||
EdasContextAutoConfiguration.class,
|
||||
AliCloudContextAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void testConfigurationValueDefaultsAreAsExpected() {
|
||||
this.contextRunner.run(context -> {
|
||||
SmsProperties config = context.getBean(SmsProperties.class);
|
||||
assertThat(config.getReportQueueName()).isNull();
|
||||
assertThat(config.getUpQueueName()).isNull();
|
||||
assertThat(config.getConnectTimeout()).isEqualTo("10000");
|
||||
assertThat(config.getReadTimeout()).isEqualTo("10000");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationValuesAreCorrectlyLoaded() {
|
||||
this.contextRunner
|
||||
.withPropertyValues("spring.cloud.alicloud.sms.reportQueueName=q1",
|
||||
"spring.cloud.alicloud.sms.upQueueName=q2",
|
||||
"spring.cloud.alicloud.sms.connect-timeout=20",
|
||||
"spring.cloud.alicloud.sms.read-timeout=30")
|
||||
.run(context -> {
|
||||
SmsProperties config = context.getBean(SmsProperties.class);
|
||||
AssertionsForClassTypes.assertThat(config.getReportQueueName())
|
||||
.isEqualTo("q1");
|
||||
AssertionsForClassTypes.assertThat(config.getUpQueueName())
|
||||
.isEqualTo("q2");
|
||||
AssertionsForClassTypes.assertThat(config.getConnectTimeout())
|
||||
.isEqualTo("20");
|
||||
AssertionsForClassTypes.assertThat(config.getReadTimeout())
|
||||
.isEqualTo("30");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.alicloud.utils;
|
||||
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfiguration;
|
||||
import com.alibaba.cloud.context.edas.EdasChangeOrderConfigurationFactory;
|
||||
|
||||
/**
|
||||
* @author xiaolongzuo
|
||||
*/
|
||||
public class ChangeOrderUtils {
|
||||
|
||||
private ChangeOrderUtils() {
|
||||
}
|
||||
|
||||
public static void mockChangeOrder() {
|
||||
EdasChangeOrderConfiguration edasChangeOrderConfiguration = PowerMockito
|
||||
.mock(EdasChangeOrderConfiguration.class);
|
||||
PowerMockito.when(edasChangeOrderConfiguration.isEdasManaged()).thenReturn(true);
|
||||
PowerMockito.when(edasChangeOrderConfiguration.getAddressServerDomain())
|
||||
.thenReturn("testDomain");
|
||||
PowerMockito.when(edasChangeOrderConfiguration.getTenantId())
|
||||
.thenReturn("testTenantId");
|
||||
PowerMockito.when(edasChangeOrderConfiguration.getDauthAccessKey())
|
||||
.thenReturn("testAK");
|
||||
PowerMockito.when(edasChangeOrderConfiguration.getDauthSecretKey())
|
||||
.thenReturn("testSK");
|
||||
PowerMockito.when(edasChangeOrderConfiguration.getProjectName())
|
||||
.thenReturn("testProjectName");
|
||||
PowerMockito.when(edasChangeOrderConfiguration.getAddressServerPort())
|
||||
.thenReturn("8080");
|
||||
PowerMockito.mockStatic(EdasChangeOrderConfigurationFactory.class);
|
||||
PowerMockito
|
||||
.when(EdasChangeOrderConfigurationFactory
|
||||
.getEdasChangeOrderConfiguration())
|
||||
.thenReturn(edasChangeOrderConfiguration);
|
||||
}
|
||||
}
|
@ -15,12 +15,12 @@
|
||||
*/
|
||||
package org.springframework.cloud.alicloud.sms;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.aliyuncs.DefaultAcsClient;
|
||||
import com.aliyuncs.IAcsClient;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author pbting
|
||||
@ -29,6 +29,7 @@ public abstract class AbstractSmsService implements ISmsService {
|
||||
|
||||
private ConcurrentHashMap<String, IAcsClient> acsClientConcurrentHashMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public IAcsClient getHangZhouRegionClientProfile(String accessKeyId,
|
||||
String accessKeySecret) {
|
||||
|
||||
|
@ -18,7 +18,7 @@ package org.springframework.cloud.alicloud.sms;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import org.springframework.boot.context.event.ApplicationStartedEvent;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsConfigProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsProperties;
|
||||
import org.springframework.cloud.alicloud.sms.base.MessageListener;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -35,11 +35,11 @@ public class SmsInitializerEventListener
|
||||
|
||||
private final AtomicBoolean isCalled = new AtomicBoolean(false);
|
||||
|
||||
private SmsConfigProperties msConfigProperties;
|
||||
private SmsProperties msConfigProperties;
|
||||
|
||||
private ISmsService smsService;
|
||||
|
||||
public SmsInitializerEventListener(SmsConfigProperties msConfigProperties,
|
||||
public SmsInitializerEventListener(SmsProperties msConfigProperties,
|
||||
ISmsService smsService) {
|
||||
this.msConfigProperties = msConfigProperties;
|
||||
this.smsService = smsService;
|
||||
@ -54,13 +54,13 @@ public class SmsInitializerEventListener
|
||||
// 整个application context refreshed then do
|
||||
// 可自助调整超时时间
|
||||
System.setProperty("sun.net.client.defaultConnectTimeout",
|
||||
msConfigProperties.getConnnectTimeout());
|
||||
msConfigProperties.getConnectTimeout());
|
||||
System.setProperty("sun.net.client.defaultReadTimeout",
|
||||
msConfigProperties.getReadTimeout());
|
||||
// 初始化acsClient,暂不支持region化
|
||||
try {
|
||||
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou",
|
||||
SmsConfigProperties.smsProduct, SmsConfigProperties.smsDomain);
|
||||
SmsProperties.smsProduct, SmsProperties.smsDomain);
|
||||
Collection<MessageListener> messageListeners = event.getApplicationContext()
|
||||
.getBeansOfType(MessageListener.class).values();
|
||||
if (messageListeners.isEmpty()) {
|
||||
|
@ -15,17 +15,19 @@
|
||||
*/
|
||||
package org.springframework.cloud.alicloud.sms;
|
||||
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.*;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.exceptions.ServerException;
|
||||
import java.text.ParseException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsConfigProperties;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsProperties;
|
||||
import org.springframework.cloud.alicloud.sms.base.DefaultAlicomMessagePuller;
|
||||
import org.springframework.cloud.alicloud.sms.endpoint.EndpointManager;
|
||||
import org.springframework.cloud.alicloud.sms.endpoint.ReceiveMessageEntity;
|
||||
|
||||
import java.text.ParseException;
|
||||
import com.aliyuncs.dysmsapi.model.v20170525.*;
|
||||
import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.exceptions.ServerException;
|
||||
|
||||
/**
|
||||
* @author pbting
|
||||
@ -38,17 +40,22 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @param sendSmsRequest
|
||||
* @return
|
||||
*/
|
||||
private SmsConfigProperties smsConfigProperties;
|
||||
private SmsProperties smsProperties;
|
||||
|
||||
public SmsServiceImpl(SmsConfigProperties smsConfigProperties) {
|
||||
this.smsConfigProperties = smsConfigProperties;
|
||||
private AliCloudProperties aliCloudProperties;
|
||||
|
||||
public SmsServiceImpl(AliCloudProperties aliCloudProperties,
|
||||
SmsProperties smsProperties) {
|
||||
this.aliCloudProperties = aliCloudProperties;
|
||||
this.smsProperties = smsProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest)
|
||||
throws ClientException {
|
||||
|
||||
return sendSmsRequest(sendSmsRequest, smsConfigProperties.getAccessKeyId(),
|
||||
smsConfigProperties.getAccessKeySecret());
|
||||
return sendSmsRequest(sendSmsRequest, aliCloudProperties.getAccessKey(),
|
||||
aliCloudProperties.getSecretKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,6 +69,7 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @throws ClientException
|
||||
* @return SendSmsResponse
|
||||
*/
|
||||
@Override
|
||||
public SendSmsResponse sendSmsRequest(SendSmsRequest sendSmsRequest,
|
||||
String accessKeyId, String accessKeySecret)
|
||||
throws ServerException, ClientException {
|
||||
@ -76,10 +84,12 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @param smsReportMessageListener
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean startSmsReportMessageListener(
|
||||
SmsReportMessageListener smsReportMessageListener) {
|
||||
String messageType = "SmsReport";// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String queueName = smsConfigProperties.getReportQueueName();
|
||||
// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String messageType = "SmsReport";
|
||||
String queueName = smsProperties.getReportQueueName();
|
||||
return startReceiveMsg(messageType, queueName, smsReportMessageListener);
|
||||
}
|
||||
|
||||
@ -88,9 +98,11 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
* @param smsUpMessageListener
|
||||
* @return boolean
|
||||
*/
|
||||
@Override
|
||||
public boolean startSmsUpMessageListener(SmsUpMessageListener smsUpMessageListener) {
|
||||
String messageType = "SmsUp";// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String queueName = smsConfigProperties.getUpQueueName();
|
||||
// 短信回执:SmsReport,短信上行:SmsUp
|
||||
String messageType = "SmsUp";
|
||||
String queueName = smsProperties.getUpQueueName();
|
||||
return startReceiveMsg(messageType, queueName, smsUpMessageListener);
|
||||
}
|
||||
|
||||
@ -103,8 +115,8 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
*/
|
||||
private boolean startReceiveMsg(String messageType, String queueName,
|
||||
SmsMessageListener messageListener) {
|
||||
String accessKeyId = smsConfigProperties.getAccessKeyId();
|
||||
String accessKeySecret = smsConfigProperties.getAccessKeySecret();
|
||||
String accessKeyId = aliCloudProperties.getAccessKey();
|
||||
String accessKeySecret = aliCloudProperties.getSecretKey();
|
||||
boolean result = true;
|
||||
try {
|
||||
new DefaultAlicomMessagePuller().startReceiveMsg(accessKeyId, accessKeySecret,
|
||||
@ -135,9 +147,8 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
SendBatchSmsRequest sendBatchSmsRequest)
|
||||
throws ServerException, ClientException {
|
||||
|
||||
return sendSmsBatchRequest(sendBatchSmsRequest,
|
||||
smsConfigProperties.getAccessKeyId(),
|
||||
smsConfigProperties.getAccessKeySecret());
|
||||
return sendSmsBatchRequest(sendBatchSmsRequest, aliCloudProperties.getAccessKey(),
|
||||
aliCloudProperties.getSecretKey());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -181,7 +192,7 @@ public final class SmsServiceImpl extends AbstractSmsService {
|
||||
@Override
|
||||
public QuerySendDetailsResponse querySendDetails(QuerySendDetailsRequest request)
|
||||
throws ClientException {
|
||||
return querySendDetails(request, smsConfigProperties.getAccessKeyId(),
|
||||
smsConfigProperties.getAccessKeySecret());
|
||||
return querySendDetails(request, aliCloudProperties.getAccessKey(),
|
||||
aliCloudProperties.getSecretKey());
|
||||
}
|
||||
}
|
@ -18,7 +18,8 @@ package org.springframework.cloud.alicloud.sms.config;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsConfigProperties;
|
||||
import org.springframework.cloud.alicloud.context.AliCloudProperties;
|
||||
import org.springframework.cloud.alicloud.context.sms.SmsProperties;
|
||||
import org.springframework.cloud.alicloud.sms.ISmsService;
|
||||
import org.springframework.cloud.alicloud.sms.SmsInitializerEventListener;
|
||||
import org.springframework.cloud.alicloud.sms.SmsServiceImpl;
|
||||
@ -37,13 +38,14 @@ import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
||||
public class SmsAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public SmsServiceImpl smsService(SmsConfigProperties smsConfigProperties) {
|
||||
return new SmsServiceImpl(smsConfigProperties);
|
||||
public SmsServiceImpl smsService(AliCloudProperties aliCloudProperties,
|
||||
SmsProperties smsProperties) {
|
||||
return new SmsServiceImpl(aliCloudProperties, smsProperties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SmsInitializerEventListener smsInitializePostListener(
|
||||
SmsConfigProperties msConfigProperties, ISmsService smsService) {
|
||||
return new SmsInitializerEventListener(msConfigProperties, smsService);
|
||||
SmsProperties smsProperties, ISmsService smsService) {
|
||||
return new SmsInitializerEventListener(smsProperties, smsService);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user