Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
ipgallery
/
mde
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Registry
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d0e45843
authored
Mar 05, 2017
by
Gil Sade
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
added getToken
parent
320b8ba5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
13 deletions
src/main/java/logic/GEManager.java
src/main/java/logic/GEManager.java
View file @
d0e45843
...
...
@@ -8,24 +8,27 @@ import http.simpleHttpClient.SimpleHttpClient;
import
http.simpleHttpClient.SimpleHttpRequest
;
import
http.simpleHttpClient.SimpleHttpResponse
;
import
microservice.RequestContext
;
import
microservice.io.iface.ILogger
;
import
microservice.types.BaseRestResponse
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.util.ArrayList
;
import
java.util.Deque
;
import
java.util.List
;
import
java.util.Map
;
/**
* Created by gil on 01/03/17.
*/
public
class
GEManager
{
public
static
String
baseUrl
=
"ie-cities-metadata.run.asv-pr-pub.ice.predix.io"
;
public
static
String
assetListUrl
=
"v2/assets/search"
;
public
static
String
token
=
"eyJhbGciOiJSUzI1NiIsImtpZCI6ImxlZ2FjeS10b2tlbi1rZXkiLCJ0eXAiOiJKV1QifQ.eyJqdGkiOiJlOTc5MTUyNjE5MjE0NDBhOGE3NWQ5YzQ3NGM0ODNjYSIsInN1YiI6ImlwZ2FsbGVyeSIsInNjb3BlIjpbImllLWN1cnJlbnQuaWNzLUlFLVBVQkxJQy1TQUZFVFkuSUUtUFVCTElDLVNBRkVUWS5MSU1JVEVELkRFVkVMT1AiLCJ1YWEucmVzb3VyY2UiLCJpZS1jdXJyZW50Lmljcy1JRS1FTlZJUk9OTUVOVEFMLklFLUVOVklST05NRU5UQUwuRl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pqDOCoWmxTvB25vokHzYy9g2_vWY3Bh_1xW6Abc_bYrmI140zflG6m0h1gbT7u3s-GLP7MPc2Ci4WiL6FK1q_YwsQkelh6nYIf9Aq9dSWRCA90HBgD2MJlBR2ww3xr-5eUMsu-pAeKfpEkm8gl1DGnHC1XQ7J27MdFTcNh0o-P0R5jAC4tsm9fQ1rFto8YBiK2Pk61UNP0SCQPyzKM-4tLI3WoidGl4yiqnI4tLocr1Wwkjjq0HrdNSWYlcr9Mf4ZCcdqTJBKmEusw2S-V45opmhA9fSFK1YH8F3hQq_WEG9w"
;
public
static
String
parking_zone_id
=
"ics-IE-PARKING"
;
public
static
String
AUTH
=
"Basic aXBnYWxsZXJ5OjFQR2FsbDNyeQ=="
;
public
static
String
AUTH_URL
=
"8553482c-1d32-4d38-8597-2e56ab642dd3.predix-uaa.run.asv-pr.ice.predix.io"
;
public
static
String
AUTH_PATH
=
"oauth/token"
;
public
static
String
AUTH_PARAMS
=
"grant_type=client_credentials&client_id=ipgallery"
;
public
static
String
BASE_URL
=
"ie-cities-metadata.run.asv-pr-pub.ice.predix.io"
;
public
static
String
ASSET_LIST_URL
=
"v2/assets/search"
;
// public static String TOKEN = "eyJhbGciOiJSUzI1NiIsImtpZCI6ImxlZ2FjeS10b2tlbi1rZXkiLCJ0eXAiOiJKV1QifQ.eyJqdGkiOiJlOTc5MTUyNjE5MjE0NDBhOGE3NWQ5YzQ3NGM0ODNjYSIsInN1YiI6ImlwZ2FsbGVyeSIsInNjb3BlIjpbImllLWN1cnJlbnQuaWNzLUlFLVBVQkxJQy1TQUZFVFkuSUUtUFVCTElDLVNBRkVUWS5MSU1JVEVELkRFVkVMT1AiLCJ1YWEucmVzb3VyY2UiLCJpZS1jdXJyZW50Lmljcy1JRS1FTlZJUk9OTUVOVEFMLklFLUVOVklST05NRU5UQUwuRlJFRS5ERVZFTE9QIiwiaWUtY3VycmVudC5pY3MtSUUtUEFSS0lORy5JRS1QQVJLSU5HLkxJTUlURUQuREVWRUxP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_YwsQkelh6nYIf9Aq9dSWRCA90HBgD2MJlBR2ww3xr-5eUMsu-pAeKfpEkm8gl1DGnHC1XQ7J27MdFTcNh0o-P0R5jAC4tsm9fQ1rFto8YBiK2Pk61UNP0SCQPyzKM-4tLI3WoidGl4yiqnI4tLocr1Wwkjjq0HrdNSWYlcr9Mf4ZCcdqTJBKmEusw2S-V45opmhA9fSFK1YH8F3hQq_WEG9w";
public
static
String
PARKING_ZONE_ID
=
"ics-IE-PARKING"
;
public
static
String
TOKEN
=
"1111"
;
private
SimpleHttpClient
httpClient
=
null
;
public
GEManager
()
throws
Exception
{
...
...
@@ -52,8 +55,25 @@ public class GEManager {
}
if
(
resp
.
getStatusCode
()
==
200
)
return
buildResp
(
resp
);
else
return
new
BaseRestResponse
(
false
,
String
.
valueOf
(
resp
.
getStatusCode
()));
else
if
(
resp
.
getStatusCode
()
==
403
||
resp
.
getStatusCode
()
==
401
)
{
req
=
buildGetTokenRequest
();
try
{
resp
=
httpClient
.
processRequest
(
req
);
String
cont
=
resp
.
getContent
();
ObjectMapper
mapper
=
new
ObjectMapper
();
try
{
JsonNode
contObj
=
mapper
.
readTree
(
cont
);
TOKEN
=
contObj
.
get
(
"access_token"
).
asText
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
UnsupportedEncodingException
e
)
{
e
.
printStackTrace
();
}
}
return
new
BaseRestResponse
(
false
,
String
.
valueOf
(
resp
.
getStatusCode
()));
}
private
BaseRestResponse
buildResp
(
SimpleHttpResponse
resp
)
{
...
...
@@ -99,12 +119,12 @@ public class GEManager {
private
SimpleHttpRequest
buildCameraHttpRequest
(
RequestContext
requestContext
,
JsonNode
content
)
{
SimpleHttpRequest
request
=
new
SimpleHttpRequest
();
request
.
setProtocol
(
"https"
);
request
.
setDomain
(
baseUrl
);
request
.
setDomain
(
BASE_URL
);
request
.
setPort
(
443
);
request
.
setMethod
(
SimpleHttpRequest
.
Method
.
GET
);
request
.
setPath
(
assetListUrl
);
request
.
addHeader
(
"Authorization"
,
"Bearer "
+
token
);
request
.
addHeader
(
"Predix-Zone-Id"
,
parking_zone_id
);
request
.
setPath
(
ASSET_LIST_URL
);
request
.
addHeader
(
"Authorization"
,
"Bearer "
+
TOKEN
);
request
.
addHeader
(
"Predix-Zone-Id"
,
PARKING_ZONE_ID
);
Map
<
String
,
Deque
<
String
>>
queryParams
=
requestContext
.
queryParameters
;
if
(
queryParams
!=
null
&&
!
queryParams
.
isEmpty
())
{
String
bbox
=
"bbox="
+
queryParams
.
get
(
"bbox"
).
pop
()
+
"&page=0&size=500&q=assetType:CAMERA"
;
...
...
@@ -114,4 +134,16 @@ public class GEManager {
request
.
setContent
(
content
.
toString
());
return
request
;
}
private
SimpleHttpRequest
buildGetTokenRequest
()
{
SimpleHttpRequest
request
=
new
SimpleHttpRequest
();
request
.
setProtocol
(
"https"
);
request
.
setDomain
(
AUTH_URL
);
request
.
setPort
(
443
);
request
.
setMethod
(
SimpleHttpRequest
.
Method
.
GET
);
request
.
setPath
(
AUTH_PATH
);
request
.
setQueryString
(
AUTH_PARAMS
);
request
.
addHeader
(
"Authorization"
,
AUTH
);
return
request
;
}
}
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