Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
apollo
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Administrator
apollo
Commits
f36d948c
Commit
f36d948c
authored
Apr 19, 2016
by
Yiming Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add auth header in client
parent
4054304f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
10 deletions
+25
-10
apollo-biz/pom.xml
apollo-biz/pom.xml
+5
-0
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-configservice/src/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
...java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
+3
-1
No files found.
apollo-biz/pom.xml
View file @
f36d948c
...
@@ -26,5 +26,10 @@
...
@@ -26,5 +26,10 @@
<groupId>
mysql
</groupId>
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
apollo-client/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
View file @
f36d948c
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.util.http;
...
@@ -2,6 +2,7 @@ package com.ctrip.apollo.util.http;
import
com.google.common.base.Charsets
;
import
com.google.common.base.Charsets
;
import
com.google.common.base.Function
;
import
com.google.common.base.Function
;
import
com.google.common.io.BaseEncoding
;
import
com.google.gson.Gson
;
import
com.google.gson.Gson
;
import
com.ctrip.apollo.util.ConfigUtil
;
import
com.ctrip.apollo.util.ConfigUtil
;
...
@@ -12,6 +13,7 @@ import org.unidal.lookup.annotation.Named;
...
@@ -12,6 +13,7 @@ import org.unidal.lookup.annotation.Named;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.UnsupportedEncodingException
;
import
java.lang.reflect.Type
;
import
java.lang.reflect.Type
;
import
java.net.HttpURLConnection
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
...
@@ -24,9 +26,15 @@ public class HttpUtil {
...
@@ -24,9 +26,15 @@ public class HttpUtil {
@Inject
@Inject
private
ConfigUtil
m_configUtil
;
private
ConfigUtil
m_configUtil
;
private
Gson
gson
;
private
Gson
gson
;
private
String
basicAuth
;
public
HttpUtil
()
{
public
HttpUtil
()
{
gson
=
new
Gson
();
gson
=
new
Gson
();
try
{
basicAuth
=
"Basic "
+
BaseEncoding
.
base64
().
encode
(
""
.
getBytes
(
"UTF-8"
));
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
}
}
/**
/**
...
@@ -74,6 +82,7 @@ public class HttpUtil {
...
@@ -74,6 +82,7 @@ public class HttpUtil {
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
httpRequest
.
getUrl
()).
openConnection
();
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestMethod
(
"GET"
);
conn
.
setRequestProperty
(
"Authorization"
,
basicAuth
);
int
connectTimeout
=
httpRequest
.
getConnectTimeout
();
int
connectTimeout
=
httpRequest
.
getConnectTimeout
();
if
(
connectTimeout
<
0
)
{
if
(
connectTimeout
<
0
)
{
...
@@ -102,9 +111,8 @@ public class HttpUtil {
...
@@ -102,9 +111,8 @@ public class HttpUtil {
return
new
HttpResponse
<>(
statusCode
,
null
);
return
new
HttpResponse
<>(
statusCode
,
null
);
}
}
throw
new
RuntimeException
(
throw
new
RuntimeException
(
String
.
format
(
"Get operation failed for %s, status code - %d"
,
String
.
format
(
"Get operation failed for %s, status code - %d"
,
httpRequest
.
getUrl
(),
httpRequest
.
getUrl
(),
statusCode
));
statusCode
));
}
catch
(
Throwable
ex
)
{
}
catch
(
Throwable
ex
)
{
throw
new
RuntimeException
(
"Could not complete get operation"
,
ex
);
throw
new
RuntimeException
(
"Could not complete get operation"
,
ex
);
...
@@ -113,7 +121,7 @@ public class HttpUtil {
...
@@ -113,7 +121,7 @@ public class HttpUtil {
try
{
try
{
is
.
close
();
is
.
close
();
}
catch
(
IOException
ex
)
{
}
catch
(
IOException
ex
)
{
//ignore
//
ignore
}
}
}
}
}
}
...
...
apollo-configservice/src/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
View file @
f36d948c
...
@@ -6,9 +6,11 @@ import org.springframework.context.annotation.ComponentScan.Filter;
...
@@ -6,9 +6,11 @@ import org.springframework.context.annotation.ComponentScan.Filter;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.FilterType
;
import
org.springframework.context.annotation.FilterType
;
import
com.ctrip.apollo.common.controller.WebSecurityConfig
;
@Configuration
@Configuration
@ComponentScan
(
excludeFilters
=
{
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
value
=
{
@ComponentScan
(
excludeFilters
=
{
@Filter
(
type
=
FilterType
.
ASSIGNABLE_TYPE
,
value
=
{
SampleConfigServiceApplication
.
class
,
ConfigServiceApplication
.
class
})})
SampleConfigServiceApplication
.
class
,
ConfigServiceApplication
.
class
,
WebSecurityConfig
.
class
})})
@EnableAutoConfiguration
@EnableAutoConfiguration
public
class
ConfigServiceTestConfiguration
{
public
class
ConfigServiceTestConfiguration
{
...
...
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