Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wrr-cat
apollo
提交
2d0b0e8a
apollo
项目概览
wrr-cat
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2d0b0e8a
编写于
4月 19, 2016
作者:
J
Jason Song
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #109 from yiming187/rest_factory
Support auth in RestTemplateFactory
上级
fd08a717
f36d948c
变更
18
隐藏空白更改
内联
并排
Showing
18 changed file
with
109 addition
and
29 deletion
+109
-29
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
...m/ctrip/apollo/adminservice/controller/AppController.java
+1
-1
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
...rip/apollo/adminservice/controller/ClusterController.java
+1
-1
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
.../ctrip/apollo/adminservice/controller/ItemController.java
+1
-1
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemSetController.java
...rip/apollo/adminservice/controller/ItemSetController.java
+1
-1
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
...p/apollo/adminservice/controller/NamespaceController.java
+1
-1
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
...rip/apollo/adminservice/controller/ReleaseController.java
+1
-1
apollo-client/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
...nt/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
+17
-9
apollo-common/pom.xml
apollo-common/pom.xml
+4
-0
apollo-common/src/main/java/com/ctrip/apollo/common/auth/ActiveUser.java
...rc/main/java/com/ctrip/apollo/common/auth/ActiveUser.java
+1
-1
apollo-common/src/main/java/com/ctrip/apollo/common/auth/RestTemplateFactory.java
...ava/com/ctrip/apollo/common/auth/RestTemplateFactory.java
+41
-0
apollo-configservice/pom.xml
apollo-configservice/pom.xml
+5
-0
apollo-configservice/src/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
...java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
+3
-1
apollo-portal/src/main/java/com/ctrip/apollo/PortalApplication.java
...tal/src/main/java/com/ctrip/apollo/PortalApplication.java
+1
-1
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/API.java
...portal/src/main/java/com/ctrip/apollo/portal/api/API.java
+16
-4
apollo-portal/src/main/resources/application.yml
apollo-portal/src/main/resources/application.yml
+1
-1
apollo-portal/src/test/java/com/ctrip/apollo/SamplePortalApplication.java
...c/test/java/com/ctrip/apollo/SamplePortalApplication.java
+11
-0
apollo-portal/src/test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
...test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
+2
-0
apollo-portal/src/test/resources/application.yml
apollo-portal/src/test/resources/application.yml
+1
-6
未找到文件。
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/AppController.java
浏览文件 @
2d0b0e8a
...
...
@@ -17,7 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
import
com.ctrip.apollo.biz.entity.App
;
import
com.ctrip.apollo.biz.service.AdminService
;
import
com.ctrip.apollo.biz.service.AppService
;
import
com.ctrip.apollo.common.
controller
.ActiveUser
;
import
com.ctrip.apollo.common.
auth
.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.AppDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ClusterController.java
浏览文件 @
2d0b0e8a
...
...
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
import
com.ctrip.apollo.biz.entity.Cluster
;
import
com.ctrip.apollo.biz.service.ClusterService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.
controller
.ActiveUser
;
import
com.ctrip.apollo.common.
auth
.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ClusterDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemController.java
浏览文件 @
2d0b0e8a
...
...
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
import
com.ctrip.apollo.biz.entity.Item
;
import
com.ctrip.apollo.biz.service.ItemService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.
controller
.ActiveUser
;
import
com.ctrip.apollo.common.
auth
.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ItemDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ItemSetController.java
浏览文件 @
2d0b0e8a
...
...
@@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import
org.springframework.web.bind.annotation.RestController
;
import
com.ctrip.apollo.biz.service.ItemSetService
;
import
com.ctrip.apollo.common.
controller
.ActiveUser
;
import
com.ctrip.apollo.common.
auth
.ActiveUser
;
import
com.ctrip.apollo.core.dto.ItemChangeSets
;
@RestController
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/NamespaceController.java
浏览文件 @
2d0b0e8a
...
...
@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
import
com.ctrip.apollo.biz.entity.Namespace
;
import
com.ctrip.apollo.biz.service.NamespaceService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.
controller
.ActiveUser
;
import
com.ctrip.apollo.common.
auth
.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.NamespaceDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
...
...
apollo-adminservice/src/main/java/com/ctrip/apollo/adminservice/controller/ReleaseController.java
浏览文件 @
2d0b0e8a
...
...
@@ -14,7 +14,7 @@ import com.ctrip.apollo.biz.entity.Release;
import
com.ctrip.apollo.biz.service.ConfigService
;
import
com.ctrip.apollo.biz.service.ReleaseService
;
import
com.ctrip.apollo.biz.service.ViewService
;
import
com.ctrip.apollo.common.
controller
.ActiveUser
;
import
com.ctrip.apollo.common.
auth
.ActiveUser
;
import
com.ctrip.apollo.common.utils.BeanUtils
;
import
com.ctrip.apollo.core.dto.ReleaseDTO
;
import
com.ctrip.apollo.core.exception.NotFoundException
;
...
...
apollo-client/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
浏览文件 @
2d0b0e8a
...
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.util.http;
import
com.google.common.base.Charsets
;
import
com.google.common.base.Function
;
import
com.google.common.io.BaseEncoding
;
import
com.google.gson.Gson
;
import
com.ctrip.apollo.util.ConfigUtil
;
...
...
@@ -12,6 +13,7 @@ import org.unidal.lookup.annotation.Named;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.reflect.Type
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
...
...
@@ -24,15 +26,21 @@ public class HttpUtil {
@Inject
private
ConfigUtil
m_configUtil
;
private
Gson
gson
;
private
String
basicAuth
;
public
HttpUtil
()
{
gson
=
new
Gson
();
try
{
basicAuth
=
"Basic "
+
BaseEncoding
.
base64
().
encode
(
""
.
getBytes
(
"UTF-8"
));
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
}
/**
* Do get operation for the http request.
*
* @param httpRequest
the request
* @param httpRequest the request
* @param responseType the response type
* @return the response
* @throws RuntimeException if any error happened or response code is neither 200 nor 304
...
...
@@ -51,7 +59,7 @@ public class HttpUtil {
/**
* Do get operation for the http request.
*
* @param httpRequest
the request
* @param httpRequest the request
* @param responseType the response type
* @return the response
* @throws RuntimeException if any error happened or response code is neither 200 nor 304
...
...
@@ -68,13 +76,14 @@ public class HttpUtil {
}
private
<
T
>
HttpResponse
<
T
>
doGetWithSerializeFunction
(
HttpRequest
httpRequest
,
Function
<
String
,
T
>
serializeFunction
)
{
Function
<
String
,
T
>
serializeFunction
)
{
InputStream
is
=
null
;
try
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestProperty
(
"Authorization"
,
basicAuth
);
int
connectTimeout
=
httpRequest
.
getConnectTimeout
();
if
(
connectTimeout
<
0
)
{
connectTimeout
=
m_configUtil
.
getConnectTimeout
();
...
...
@@ -102,9 +111,8 @@ public class HttpUtil {
return
new
HttpResponse
<>(
statusCode
,
null
);
}
throw
new
RuntimeException
(
String
.
format
(
"Get operation failed for %s, status code - %d"
,
httpRequest
.
getUrl
(),
statusCode
));
throw
new
RuntimeException
(
String
.
format
(
"Get operation failed for %s, status code - %d"
,
httpRequest
.
getUrl
(),
statusCode
));
}
catch
(
Throwable
ex
)
{
throw
new
RuntimeException
(
"Could not complete get operation"
,
ex
);
...
...
@@ -113,7 +121,7 @@ public class HttpUtil {
try
{
is
.
close
();
}
catch
(
IOException
ex
)
{
//ignore
//
ignore
}
}
}
...
...
apollo-common/pom.xml
浏览文件 @
2d0b0e8a
...
...
@@ -38,6 +38,10 @@
<groupId>
org.springframework.data
</groupId>
<artifactId>
spring-data-commons
</artifactId>
</dependency>
<dependency>
<groupId>
org.apache.httpcomponents
</groupId>
<artifactId>
httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
ch.qos.logback
</groupId>
<artifactId>
logback-classic
</artifactId>
...
...
apollo-common/src/main/java/com/ctrip/apollo/common/
controller
/ActiveUser.java
→
apollo-common/src/main/java/com/ctrip/apollo/common/
auth
/ActiveUser.java
浏览文件 @
2d0b0e8a
package
com.ctrip.apollo.common.
controller
;
package
com.ctrip.apollo.common.
auth
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.ElementType
;
...
...
apollo-common/src/main/java/com/ctrip/apollo/common/auth/RestTemplateFactory.java
0 → 100644
浏览文件 @
2d0b0e8a
package
com.ctrip.apollo.common.auth
;
import
org.apache.http.auth.AuthScope
;
import
org.apache.http.auth.UsernamePasswordCredentials
;
import
org.apache.http.impl.client.BasicCredentialsProvider
;
import
org.apache.http.impl.client.CloseableHttpClient
;
import
org.apache.http.impl.client.HttpClientBuilder
;
import
org.springframework.beans.factory.FactoryBean
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.http.client.HttpComponentsClientHttpRequestFactory
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
@Component
public
class
RestTemplateFactory
implements
FactoryBean
<
RestTemplate
>,
InitializingBean
{
private
RestTemplate
restTemplate
;
public
RestTemplate
getObject
()
{
return
restTemplate
;
}
public
Class
<
RestTemplate
>
getObjectType
()
{
return
RestTemplate
.
class
;
}
public
boolean
isSingleton
()
{
return
true
;
}
public
void
afterPropertiesSet
()
{
BasicCredentialsProvider
credentialsProvider
=
new
BasicCredentialsProvider
();
credentialsProvider
.
setCredentials
(
AuthScope
.
ANY
,
new
UsernamePasswordCredentials
(
"apollo"
,
""
));
CloseableHttpClient
httpClient
=
HttpClientBuilder
.
create
().
setDefaultCredentialsProvider
(
credentialsProvider
).
build
();
restTemplate
=
new
RestTemplate
(
new
HttpComponentsClientHttpRequestFactory
(
httpClient
));
}
}
apollo-configservice/pom.xml
浏览文件 @
2d0b0e8a
...
...
@@ -67,6 +67,11 @@
</exclusions>
</dependency>
<!-- end of eureka -->
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
<plugins>
...
...
apollo-configservice/src/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
浏览文件 @
2d0b0e8a
...
...
@@ -6,9 +6,11 @@ import org.springframework.context.annotation.ComponentScan.Filter;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
import
com.ctrip.apollo.common.controller.WebSecurityConfig
;
@Configuration
@ComponentScan
(
excludeFilters
=
{
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
value
=
{
SampleConfigServiceApplication
.
class
,
ConfigServiceApplication
.
class
})})
SampleConfigServiceApplication
.
class
,
ConfigServiceApplication
.
class
,
WebSecurityConfig
.
class
})})
@EnableAutoConfiguration
public
class
ConfigServiceTestConfiguration
{
...
...
apollo-portal/src/main/java/com/ctrip/apollo/
portal/
PortalApplication.java
→
apollo-portal/src/main/java/com/ctrip/apollo/PortalApplication.java
浏览文件 @
2d0b0e8a
package
com.ctrip.apollo
.portal
;
package
com.ctrip.apollo
;
import
org.springframework.boot.SpringApplication
;
import
org.springframework.boot.actuate.system.ApplicationPidFileWriter
;
...
...
apollo-portal/src/main/java/com/ctrip/apollo/portal/api/API.java
浏览文件 @
2d0b0e8a
package
com.ctrip.apollo.portal.api
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.service.ServiceLocator
;
import
javax.annotation.PostConstruct
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.client.RestTemplate
;
import
com.ctrip.apollo.common.auth.RestTemplateFactory
;
import
com.ctrip.apollo.core.enums.Env
;
import
com.ctrip.apollo.core.exception.ServiceException
;
import
com.ctrip.apollo.portal.service.ServiceLocator
;
public
class
API
{
@Autowired
protected
ServiceLocator
serviceLocator
;
protected
RestTemplate
restTemplate
=
new
RestTemplate
();
@Autowired
private
RestTemplateFactory
restTemplateFactory
;
protected
RestTemplate
restTemplate
;
@PostConstruct
private
void
postConstruct
()
{
restTemplate
=
restTemplateFactory
.
getObject
();
}
public
String
getAdminServiceHost
(
Env
env
)
{
// 本地测试用
...
...
@@ -24,4 +35,5 @@ public class API {
}
return
""
;
}
}
apollo-portal/src/main/resources/application.yml
浏览文件 @
2d0b0e8a
...
...
@@ -15,4 +15,4 @@ ctrip:
apollo
:
portal
:
env
:
dev
env
:
local
apollo-portal/src/test/java/com/ctrip/apollo/SamplePortalApplication.java
0 → 100644
浏览文件 @
2d0b0e8a
package
com.ctrip.apollo
;
import
org.springframework.boot.autoconfigure.SpringBootApplication
;
import
org.springframework.boot.builder.SpringApplicationBuilder
;
@SpringBootApplication
public
class
SamplePortalApplication
{
public
static
void
main
(
String
[]
args
)
{
new
SpringApplicationBuilder
(
SamplePortalApplication
.
class
).
run
(
args
);
}
}
apollo-portal/src/test/java/com/ctrip/apollo/portal/AbstractPortalTest.java
浏览文件 @
2d0b0e8a
...
...
@@ -4,6 +4,8 @@ import org.junit.runner.RunWith;
import
org.springframework.boot.test.SpringApplicationConfiguration
;
import
org.springframework.test.context.junit4.SpringJUnit4ClassRunner
;
import
com.ctrip.apollo.PortalApplication
;
@RunWith
(
SpringJUnit4ClassRunner
.
class
)
@SpringApplicationConfiguration
(
classes
=
PortalApplication
.
class
)
public
abstract
class
AbstractPortalTest
{
...
...
apollo-portal/src/test/resources/application.yml
浏览文件 @
2d0b0e8a
...
...
@@ -4,11 +4,6 @@ server:
spring
:
application
:
name
:
apollo-portal
datasource
:
url
:
jdbc:h2:mem:~/fxapolloportaldb
jpa
:
hibernate
:
naming_strategy
:
org.hibernate.cfg.EJB3NamingStrategy
logging
:
level
:
...
...
@@ -20,4 +15,4 @@ ctrip:
apollo
:
portal
:
env
:
dev
env
:
local
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录