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
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
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
10 deletions
+25
-10
pom.xml
apollo-biz/pom.xml
+5
-0
HttpUtil.java
...nt/src/main/java/com/ctrip/apollo/util/http/HttpUtil.java
+17
-9
ConfigServiceTestConfiguration.java
...java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
+3
-1
No files found.
apollo-biz/pom.xml
View file @
f36d948c
...
...
@@ -26,5 +26,10 @@
<groupId>
mysql
</groupId>
<artifactId>
mysql-connector-java
</artifactId>
</dependency>
<dependency>
<groupId>
com.h2database
</groupId>
<artifactId>
h2
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
</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;
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-configservice/src/test/java/com/ctrip/apollo/ConfigServiceTestConfiguration.java
View file @
f36d948c
...
...
@@ -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
{
...
...
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