FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
amadeus-java/src/main/java/com/amadeus/Request.java at master · tambert/amadeus-java · GitHub
tambert
/
amadeus-java
Public
forked from
amadeus4dev/amadeus-java
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
amadeus-java
/
src
/
main
/
java
/
com
/
amadeus
/
Request.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
155 lines (142 loc) · 4.37 KB
Breadcrumbs
amadeus-java
/
src
/
main
/
java
/
com
/
amadeus
/
Request.java
Copy path
File metadata and controls
155 lines (142 loc) · 4.37 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package
com
.
amadeus
;
import
com
.
amadeus
.
Constants
;
import
java
.
io
.
IOException
;
import
java
.
net
.
HttpURLConnection
;
import
java
.
net
.
URL
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
import
lombok
.
Getter
;
import
lombok
.
ToString
;
import
lombok
.
experimental
.
Accessors
;
/**
* An object containing all the details of the request made, including the host,
* path, port, params, and headers. Generally this object can be accessed as part of
* an API response, and can be used to debug the API call made.
*/
@
Accessors
(
chain
=
true
)
@
ToString
public
class
Request
{
/**
* The HTTPClient verb to use for API calls.
*/
private
@
Getter
String
verb
;
/**
* The scheme to use for API calls.
*/
private
@
Getter
String
scheme
;
/**
* The host domain to use for API calls.
*/
private
@
Getter
String
host
;
/**
* The path use for API calls.
*/
private
@
Getter
String
path
;
/**
* The params to send to the API endpoint.
*/
private
@
Getter
Params
params
;
/**
* The bearer token used to authenticate the API call.
*/
private
@
Getter
String
bearerToken
;
/**
* The version of the SDK used.
*/
private
@
Getter
String
clientVersion
;
/**
* The version of Java used.
*/
private
@
Getter
String
languageVersion
;
/**
* The custom Application ID passed in the user agent.
*/
private
@
Getter
String
appId
;
/**
* The custom Application Version passed in the user agent.
*/
private
@
Getter
String
appVersion
;
/**
* Whether this connection uses SSL.
*/
private
@
Getter
boolean
ssl
;
/**
* The port to use for this request.
*/
private
@
Getter
int
port
;
/**
* The headers for this request.
*/
private
@
Getter
HashMap
<
String
,
String
>
headers
;
/**
* The full URI for this request, based on the
* verb, port, path, host, etc.
*/
private
@
Getter
String
uri
;
// The connection used to make the API call.
private
@
Getter
HttpURLConnection
connection
;
protected
Request
(
String
verb
,
String
path
,
Params
params
,
String
bearerToken
,
HTTPClient
client
) {
Configuration
config
=
client
.
getConfiguration
();
this
.
verb
=
verb
;
this
.
host
=
config
.
getHost
();
this
.
path
=
path
;
this
.
params
=
params
;
this
.
bearerToken
=
bearerToken
;
this
.
languageVersion
=
System
.
getProperty
(
"java.version"
);
this
.
clientVersion
=
Amadeus
.
VERSION
;
this
.
appId
=
config
.
getCustomAppId
();
this
.
appVersion
=
config
.
getCustomAppVersion
();
this
.
port
=
config
.
getPort
();
this
.
ssl
=
config
.
isSsl
();
determineScheme
();
prepareUrl
();
prepareHeaders
();
}
// Builds a HttpURLConnection using all the data for this request.
protected
void
establishConnection
()
throws
IOException
{
this
.
connection
= (
HttpURLConnection
)
new
URL
(
uri
).
openConnection
();
connection
.
setRequestMethod
(
verb
);
connection
.
setDoInput
(
true
);
connection
.
setDoOutput
(
true
);
for
(
Map
.
Entry
<
String
,
String
>
entry
:
headers
.
entrySet
()) {
connection
.
setRequestProperty
(
entry
.
getKey
(),
entry
.
getValue
());
}
}
// Determines the scheme based on the SSL value
private
void
determineScheme
() {
this
.
scheme
=
isSsl
() ?
Constants
.
HTTPS
:
Constants
.
HTTP
;
}
// Prepares the full URL based on the scheme, host, port and path.
private
void
prepareUrl
() {
this
.
uri
=
String
.
format
(
"%s://%s:%s%s?%s"
,
scheme
,
host
,
port
,
path
,
getQueryParams
());
}
// Prepares the headers to be sent in the request
private
void
prepareHeaders
() {
this
.
headers
=
new
HashMap
<
String
,
String
>();
headers
.
put
(
Constants
.
USER_AGENT
,
buildUserAgent
());
headers
.
put
(
Constants
.
ACCEPT
,
"application/json, application/vnd.amadeus+json"
);
if
(
bearerToken
!=
null
) {
headers
.
put
(
Constants
.
AUTHORIZATION
,
bearerToken
);
}
}
// Determines the User-Agent header, based on the client version, language version, and custom
// app information.
private
String
buildUserAgent
() {
String
userAgent
=
String
.
format
(
"amadeus-java/%s"
,
clientVersion
);
userAgent
=
userAgent
.
concat
(
String
.
format
(
" java/%s"
,
languageVersion
));
if
(
appId
!=
null
) {
userAgent
=
userAgent
.
concat
(
String
.
format
(
" %s/%s"
,
appId
,
appVersion
));
}
return
userAgent
;
}
// Gets the serialized params, only if this is a Get call
private
String
getQueryParams
() {
if
(
verb
==
Constants
.
GET
&&
params
!=
null
) {
return
params
.
toQueryString
();
}
else
{
return
""
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL