Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
apollo
Project
Overview
Details
Activity
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
openSource
apollo
Commits
060126fd
Commit
060126fd
authored
Jul 06, 2016
by
张乐
Committed by
GitHub
Jul 06, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #309 from nobodyiam/fix-client-url-encoding
Fix client url encoding
parents
3b7e50ec
eccc3a30
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
71 additions
and
29 deletions
+71
-29
pom.xml
apollo-adminservice/pom.xml
+1
-1
pom.xml
apollo-assembly/pom.xml
+1
-1
pom.xml
apollo-biz/pom.xml
+1
-1
pom.xml
apollo-buildtools/pom.xml
+1
-1
README.md
apollo-client/README.md
+1
-1
pom.xml
apollo-client/pom.xml
+1
-1
ConfigServiceLocator.java
...trip/framework/apollo/internals/ConfigServiceLocator.java
+3
-3
RemoteConfigRepository.java
...ip/framework/apollo/internals/RemoteConfigRepository.java
+15
-14
RemoteConfigRepositoryTest.java
...ramework/apollo/internals/RemoteConfigRepositoryTest.java
+41
-0
pom.xml
apollo-common/pom.xml
+1
-1
pom.xml
apollo-configservice/pom.xml
+1
-1
pom.xml
apollo-core/pom.xml
+1
-1
pom.xml
apollo-demo/pom.xml
+1
-1
pom.xml
apollo-portal/pom.xml
+1
-1
pom.xml
pom.xml
+1
-1
No files found.
apollo-adminservice/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-assembly/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-biz/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apollo-biz
</artifactId>
<artifactId>
apollo-biz
</artifactId>
...
...
apollo-buildtools/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-client/README.md
View file @
060126fd
...
@@ -88,7 +88,7 @@ If you need this functionality, you could specify the cluster as follows:
...
@@ -88,7 +88,7 @@ If you need this functionality, you could specify the cluster as follows:
<dependency>
<dependency>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo-client
</artifactId>
<artifactId>
apollo-client
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
</dependency>
</dependency>
## III. Client Usage
## III. Client Usage
...
...
apollo-client/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java
View file @
060126fd
...
@@ -45,6 +45,7 @@ public class ConfigServiceLocator implements Initializable {
...
@@ -45,6 +45,7 @@ public class ConfigServiceLocator implements Initializable {
private
Type
m_responseType
;
private
Type
m_responseType
;
private
ScheduledExecutorService
m_executorService
;
private
ScheduledExecutorService
m_executorService
;
private
static
final
Joiner
.
MapJoiner
MAP_JOINER
=
Joiner
.
on
(
"&"
).
withKeyValueSeparator
(
"="
);
private
static
final
Joiner
.
MapJoiner
MAP_JOINER
=
Joiner
.
on
(
"&"
).
withKeyValueSeparator
(
"="
);
private
static
final
Escaper
queryParamEscaper
=
UrlEscapers
.
urlFormParameterEscaper
();
/**
/**
* Create a config service locator.
* Create a config service locator.
...
@@ -145,11 +146,10 @@ public class ConfigServiceLocator implements Initializable {
...
@@ -145,11 +146,10 @@ public class ConfigServiceLocator implements Initializable {
String
appId
=
m_configUtil
.
getAppId
();
String
appId
=
m_configUtil
.
getAppId
();
String
localIp
=
m_configUtil
.
getLocalIp
();
String
localIp
=
m_configUtil
.
getLocalIp
();
Escaper
escaper
=
UrlEscapers
.
urlPathSegmentEscaper
();
Map
<
String
,
String
>
queryParams
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
queryParams
=
Maps
.
newHashMap
();
queryParams
.
put
(
"appId"
,
e
scaper
.
escape
(
appId
));
queryParams
.
put
(
"appId"
,
queryParamE
scaper
.
escape
(
appId
));
if
(!
Strings
.
isNullOrEmpty
(
localIp
))
{
if
(!
Strings
.
isNullOrEmpty
(
localIp
))
{
queryParams
.
put
(
"ip"
,
e
scaper
.
escape
(
localIp
));
queryParams
.
put
(
"ip"
,
queryParamE
scaper
.
escape
(
localIp
));
}
}
return
domainName
+
"/services/config?"
+
MAP_JOINER
.
join
(
queryParams
);
return
domainName
+
"/services/config?"
+
MAP_JOINER
.
join
(
queryParams
);
...
...
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java
View file @
060126fd
...
@@ -65,6 +65,8 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
...
@@ -65,6 +65,8 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
private
AtomicReference
<
ApolloConfigNotification
>
m_longPollResult
;
private
AtomicReference
<
ApolloConfigNotification
>
m_longPollResult
;
private
RateLimiter
m_longPollRateLimiter
;
private
RateLimiter
m_longPollRateLimiter
;
private
RateLimiter
m_loadConfigRateLimiter
;
private
RateLimiter
m_loadConfigRateLimiter
;
private
static
final
Escaper
pathEscaper
=
UrlEscapers
.
urlPathSegmentEscaper
();
private
static
final
Escaper
queryParamEscaper
=
UrlEscapers
.
urlFormParameterEscaper
();
static
{
static
{
m_executorService
=
Executors
.
newScheduledThreadPool
(
1
,
m_executorService
=
Executors
.
newScheduledThreadPool
(
1
,
...
@@ -235,26 +237,26 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
...
@@ -235,26 +237,26 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
throw
new
ApolloConfigException
(
message
,
exception
);
throw
new
ApolloConfigException
(
message
,
exception
);
}
}
private
String
assembleQueryConfigUrl
(
String
uri
,
String
appId
,
String
cluster
,
String
namespace
,
String
assembleQueryConfigUrl
(
String
uri
,
String
appId
,
String
cluster
,
String
namespace
,
String
dataCenter
,
ApolloConfig
previousConfig
)
{
String
dataCenter
,
ApolloConfig
previousConfig
)
{
Escaper
escaper
=
UrlEscapers
.
urlPathSegmentEscaper
();
String
path
=
"configs/%s/%s/%s"
;
String
path
=
"configs/%s/%s/%s"
;
List
<
String
>
pathParams
=
List
<
String
>
pathParams
=
Lists
.
newArrayList
(
escaper
.
escape
(
appId
),
e
scaper
.
escape
(
cluster
),
Lists
.
newArrayList
(
pathEscaper
.
escape
(
appId
),
pathE
scaper
.
escape
(
cluster
),
e
scaper
.
escape
(
namespace
));
pathE
scaper
.
escape
(
namespace
));
Map
<
String
,
String
>
queryParams
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
queryParams
=
Maps
.
newHashMap
();
if
(
previousConfig
!=
null
)
{
if
(
previousConfig
!=
null
)
{
queryParams
.
put
(
"releaseKey"
,
escaper
.
escape
(
String
.
valueOf
(
previousConfig
.
getReleaseKey
()
)));
queryParams
.
put
(
"releaseKey"
,
queryParamEscaper
.
escape
(
previousConfig
.
getReleaseKey
(
)));
}
}
if
(!
Strings
.
isNullOrEmpty
(
dataCenter
))
{
if
(!
Strings
.
isNullOrEmpty
(
dataCenter
))
{
queryParams
.
put
(
"dataCenter"
,
e
scaper
.
escape
(
dataCenter
));
queryParams
.
put
(
"dataCenter"
,
queryParamE
scaper
.
escape
(
dataCenter
));
}
}
String
localIp
=
m_configUtil
.
getLocalIp
();
String
localIp
=
m_configUtil
.
getLocalIp
();
if
(!
Strings
.
isNullOrEmpty
(
localIp
))
{
if
(!
Strings
.
isNullOrEmpty
(
localIp
))
{
queryParams
.
put
(
"ip"
,
e
scaper
.
escape
(
localIp
));
queryParams
.
put
(
"ip"
,
queryParamE
scaper
.
escape
(
localIp
));
}
}
String
pathExpanded
=
String
.
format
(
path
,
pathParams
.
toArray
());
String
pathExpanded
=
String
.
format
(
path
,
pathParams
.
toArray
());
...
@@ -356,23 +358,22 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
...
@@ -356,23 +358,22 @@ public class RemoteConfigRepository extends AbstractConfigRepository {
}
}
}
}
private
String
assembleLongPollRefreshUrl
(
String
uri
,
String
appId
,
String
cluster
,
String
assembleLongPollRefreshUrl
(
String
uri
,
String
appId
,
String
cluster
,
String
namespace
,
String
dataCenter
,
String
namespace
,
String
dataCenter
,
ApolloConfigNotification
previousResult
)
{
ApolloConfigNotification
previousResult
)
{
Escaper
escaper
=
UrlEscapers
.
urlPathSegmentEscaper
();
Map
<
String
,
String
>
queryParams
=
Maps
.
newHashMap
();
Map
<
String
,
String
>
queryParams
=
Maps
.
newHashMap
();
queryParams
.
put
(
"appId"
,
e
scaper
.
escape
(
appId
));
queryParams
.
put
(
"appId"
,
queryParamE
scaper
.
escape
(
appId
));
queryParams
.
put
(
"cluster"
,
e
scaper
.
escape
(
cluster
));
queryParams
.
put
(
"cluster"
,
queryParamE
scaper
.
escape
(
cluster
));
if
(!
Strings
.
isNullOrEmpty
(
namespace
))
{
if
(!
Strings
.
isNullOrEmpty
(
namespace
))
{
queryParams
.
put
(
"namespace"
,
e
scaper
.
escape
(
namespace
));
queryParams
.
put
(
"namespace"
,
queryParamE
scaper
.
escape
(
namespace
));
}
}
if
(!
Strings
.
isNullOrEmpty
(
dataCenter
))
{
if
(!
Strings
.
isNullOrEmpty
(
dataCenter
))
{
queryParams
.
put
(
"dataCenter"
,
e
scaper
.
escape
(
dataCenter
));
queryParams
.
put
(
"dataCenter"
,
queryParamE
scaper
.
escape
(
dataCenter
));
}
}
String
localIp
=
m_configUtil
.
getLocalIp
();
String
localIp
=
m_configUtil
.
getLocalIp
();
if
(!
Strings
.
isNullOrEmpty
(
localIp
))
{
if
(!
Strings
.
isNullOrEmpty
(
localIp
))
{
queryParams
.
put
(
"ip"
,
e
scaper
.
escape
(
localIp
));
queryParams
.
put
(
"ip"
,
queryParamE
scaper
.
escape
(
localIp
));
}
}
if
(
previousResult
!=
null
)
{
if
(
previousResult
!=
null
)
{
...
...
apollo-client/src/test/java/com/ctrip/framework/apollo/internals/RemoteConfigRepositoryTest.java
View file @
060126fd
...
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
...
@@ -32,6 +32,7 @@ import java.util.concurrent.TimeUnit;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Matchers
.
eq
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
times
;
import
static
org
.
mockito
.
Mockito
.
times
;
...
@@ -165,6 +166,46 @@ public class RemoteConfigRepositoryTest extends ComponentTestCase {
...
@@ -165,6 +166,46 @@ public class RemoteConfigRepositoryTest extends ComponentTestCase {
assertEquals
(
newConfigurations
,
captor
.
getValue
());
assertEquals
(
newConfigurations
,
captor
.
getValue
());
}
}
@Test
public
void
testAssembleLongPollRefreshUrl
()
throws
Exception
{
String
someUri
=
"http://someServer"
;
String
someAppId
=
"someAppId"
;
String
someCluster
=
"someCluster+ &.-_someSign"
;
RemoteConfigRepository
remoteConfigRepository
=
new
RemoteConfigRepository
(
someNamespace
);
String
longPollRefreshUrl
=
remoteConfigRepository
.
assembleLongPollRefreshUrl
(
someUri
,
someAppId
,
someCluster
,
someNamespace
,
null
,
null
);
assertTrue
(
longPollRefreshUrl
.
contains
(
"http://someServer/notifications?"
));
assertTrue
(
longPollRefreshUrl
.
contains
(
"appId=someAppId"
));
assertTrue
(
longPollRefreshUrl
.
contains
(
"cluster=someCluster%2B+%26.-_someSign"
));
assertTrue
(
longPollRefreshUrl
.
contains
(
"namespace="
+
someNamespace
));
}
@Test
public
void
testAssembleQueryConfigUrl
()
throws
Exception
{
String
someUri
=
"http://someServer"
;
String
someAppId
=
"someAppId"
;
String
someCluster
=
"someCluster+ &.-_someSign"
;
String
someReleaseKey
=
"20160705193346-583078ef5716c055+20160705193308-31c471ddf9087c3f"
;
RemoteConfigRepository
remoteConfigRepository
=
new
RemoteConfigRepository
(
someNamespace
);
ApolloConfig
someApolloConfig
=
mock
(
ApolloConfig
.
class
);
when
(
someApolloConfig
.
getReleaseKey
()).
thenReturn
(
someReleaseKey
);
String
queryConfigUrl
=
remoteConfigRepository
.
assembleQueryConfigUrl
(
someUri
,
someAppId
,
someCluster
,
someNamespace
,
null
,
someApolloConfig
);
assertTrue
(
queryConfigUrl
.
contains
(
"http://someServer/configs/someAppId/someCluster+%20&.-_someSign/"
+
someNamespace
));
assertTrue
(
queryConfigUrl
.
contains
(
"releaseKey=20160705193346-583078ef5716c055%2B20160705193308-31c471ddf9087c3f"
));
}
private
ApolloConfig
assembleApolloConfig
(
Map
<
String
,
String
>
configurations
)
{
private
ApolloConfig
assembleApolloConfig
(
Map
<
String
,
String
>
configurations
)
{
String
someAppId
=
"appId"
;
String
someAppId
=
"appId"
;
String
someClusterName
=
"cluster"
;
String
someClusterName
=
"cluster"
;
...
...
apollo-common/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-configservice/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-core/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
apollo-demo/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<artifactId>
apollo-demo
</artifactId>
<artifactId>
apollo-demo
</artifactId>
...
...
apollo-portal/pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<parent>
<parent>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<relativePath>
../pom.xml
</relativePath>
<relativePath>
../pom.xml
</relativePath>
</parent>
</parent>
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
...
...
pom.xml
View file @
060126fd
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.ctrip.framework.apollo
</groupId>
<groupId>
com.ctrip.framework.apollo
</groupId>
<artifactId>
apollo
</artifactId>
<artifactId>
apollo
</artifactId>
<version>
0.0.
3
</version>
<version>
0.0.
4
</version>
<name>
Apollo
</name>
<name>
Apollo
</name>
<packaging>
pom
</packaging>
<packaging>
pom
</packaging>
<description>
Ctrip Configuration Center
</description>
<description>
Ctrip Configuration Center
</description>
...
...
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