Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
browser-backend
Project
Project
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
Administrator
browser-backend
Commits
afe81d26
Commit
afe81d26
authored
Jun 09, 2020
by
jim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ip
parent
e7c4e436
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
17 deletions
+26
-17
BrowserTask.java
...va/com/edgec/browserbackend/browser/task/BrowserTask.java
+26
-17
No files found.
src/main/java/com/edgec/browserbackend/browser/task/BrowserTask.java
View file @
afe81d26
...
@@ -26,12 +26,8 @@ import org.slf4j.Logger;
...
@@ -26,12 +26,8 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.http.HttpEntity
;
import
org.springframework.http.HttpHeaders
;
import
org.springframework.http.MediaType
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.client.RestTemplate
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.time.Instant
;
import
java.time.Instant
;
...
@@ -83,15 +79,14 @@ public class BrowserTask {
...
@@ -83,15 +79,14 @@ public class BrowserTask {
return
headers
;
return
headers
;
}
}
public
HttpHeaders
buildPostHeader
()
{
public
Map
<
String
,
String
>
buildPostHeader
()
{
HttpHeaders
header
=
new
HttpHeaders
();
Map
<
String
,
String
>
headers
=
new
HashMap
<>();
header
.
setContentType
(
MediaType
.
APPLICATION_JSON
);
headers
.
put
(
"Content-Type"
,
"application/json"
);
if
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
{
if
(
profiles
.
equals
(
"dev"
)
||
profiles
.
equals
(
"staging"
))
header
.
setBearerAuth
(
"oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm"
);
headers
.
put
(
"Authorization"
,
"Bearer oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm"
);
}
else
if
(
profiles
.
equals
(
"prod"
))
{
else
if
(
profiles
.
equals
(
"prod"
))
header
.
setBearerAuth
(
"tKWsuHzcngf0RQPMss70f9jgymDIwgQ9zbLfESJdcou3pZSNWl7lNTzto8VQgwaO"
);
headers
.
put
(
"Authorization"
,
"Bearer tKWsuHzcngf0RQPMss70f9jgymDIwgQ9zbLfESJdcou3pZSNWl7lNTzto8VQgwaO"
);
}
return
headers
;
return
header
;
}
}
private
IpChargeRequestDto
buildIpChargeRequestDto
(
IpResource
request
,
int
chargeType
,
int
payMethod
)
{
private
IpChargeRequestDto
buildIpChargeRequestDto
(
IpResource
request
,
int
chargeType
,
int
payMethod
)
{
...
@@ -117,8 +112,7 @@ public class BrowserTask {
...
@@ -117,8 +112,7 @@ public class BrowserTask {
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
if
(
ipResourceRepository
.
lockTask
(
ipResource
))
{
try
{
try
{
boolean
result
=
false
;
boolean
result
=
false
;
RestTemplate
restTemplate
=
new
RestTemplate
();
Map
<
String
,
String
>
header
=
buildPostHeader
();
HttpHeaders
header
=
buildPostHeader
();
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
HashMap
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"name"
,
ipResource
.
getUsername
());
map
.
put
(
"name"
,
ipResource
.
getUsername
());
map
.
put
(
"region"
,
ipResource
.
getRegion
());
map
.
put
(
"region"
,
ipResource
.
getRegion
());
...
@@ -130,10 +124,11 @@ public class BrowserTask {
...
@@ -130,10 +124,11 @@ public class BrowserTask {
map
.
put
(
"startscript"
,
""
);
map
.
put
(
"startscript"
,
""
);
map
.
put
(
"ipkeptperiod"
,
7
);
map
.
put
(
"ipkeptperiod"
,
7
);
map
.
put
(
"persistSystemDiskOnTermination"
,
false
);
map
.
put
(
"persistSystemDiskOnTermination"
,
false
);
HttpEntity
<
Map
<
String
,
Object
>>
httpEntity
=
new
HttpEntity
<>(
map
,
header
);
//
HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header);
IpBuyResultDto
ipBuyResultDto
=
null
;
IpBuyResultDto
ipBuyResultDto
=
null
;
try
{
try
{
ipBuyResultDto
=
restTemplate
.
postForObject
(
URL
+
"/intelligroup/ipresources?accountId=browser"
,
httpEntity
,
IpBuyResultDto
.
class
);
String
requestResult
=
HttpClientutils
.
doPost
(
URL
+
"/intelligroup/ipresources?accountId=browser"
,
header
,
JSONObject
.
toJSONString
(
map
));
ipBuyResultDto
=
JSONObject
.
parseObject
(
requestResult
,
IpBuyResultDto
.
class
);
if
(
StringUtils
.
isNotBlank
(
ipBuyResultDto
.
getErrorCode
()))
{
if
(
StringUtils
.
isNotBlank
(
ipBuyResultDto
.
getErrorCode
()))
{
log
.
error
(
"fail to buy ip"
);
log
.
error
(
"fail to buy ip"
);
log
.
error
(
ipBuyResultDto
.
getErrorCode
());
log
.
error
(
ipBuyResultDto
.
getErrorCode
());
...
@@ -358,6 +353,20 @@ public class BrowserTask {
...
@@ -358,6 +353,20 @@ public class BrowserTask {
return
responseBody
.
string
();
return
responseBody
.
string
();
}
}
public
static
String
doPost
(
String
url
,
Map
<
String
,
String
>
headers
,
String
body
)
throws
IOException
{
Headers
httpHeaders
=
Headers
.
of
(
headers
);
Request
request
=
new
Request
.
Builder
()
.
post
(
RequestBody
.
create
(
body
,
okhttp3
.
MediaType
.
get
(
"json"
)))
.
url
(
url
)
.
headers
(
httpHeaders
)
.
build
();
Call
call
=
client
.
newCall
(
request
);
Response
response
=
call
.
execute
();
ResponseBody
responseBody
=
response
.
body
();
return
responseBody
.
string
();
}
}
}
...
...
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