1
1
/*
2
2
Copyright 2017 Ericsson AB.
3
3
For a full list of individual contributors, please see the commit history.
4
-
5
4
Licensed under the Apache License, Version 2.0 (the "License");
6
5
you may not use this file except in compliance with the License.
7
6
You may obtain a copy of the License at
8
-
9
7
http://www.apache.org/licenses/LICENSE-2.0
10
-
11
8
Unless required by applicable law or agreed to in writing, software
12
9
distributed under the License is distributed on an "AS IS" BASIS,
13
10
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
13
*/
17
14
package com .ericsson .ei .frontend ;
18
15
19
- import java .io .BufferedReader ;
20
- import java .io .IOException ;
21
- import java .io .InputStream ;
22
- import java .io .InputStreamReader ;
23
-
24
- import javax .servlet .http .HttpServletRequest ;
25
-
16
+ import com .ericsson .ei .frontend .model .BackEndInformation ;
26
17
import org .apache .http .HttpEntity ;
27
18
import org .apache .http .client .methods .*;
28
19
import org .apache .http .entity .ByteArrayEntity ;
29
20
import org .apache .http .impl .client .CloseableHttpClient ;
30
21
import org .apache .http .impl .client .HttpClientBuilder ;
31
22
import org .slf4j .Logger ;
32
23
import org .slf4j .LoggerFactory ;
33
- import org .springframework .boot . context . properties . ConfigurationProperties ;
24
+ import org .springframework .beans . factory . annotation . Autowired ;
34
25
import org .springframework .http .HttpHeaders ;
35
26
import org .springframework .http .HttpStatus ;
36
27
import org .springframework .http .MediaType ;
41
32
import org .springframework .web .bind .annotation .RequestMethod ;
42
33
import org .springframework .web .bind .annotation .RestController ;
43
34
35
+ import javax .servlet .http .HttpServletRequest ;
36
+ import java .io .BufferedReader ;
37
+ import java .io .IOException ;
38
+ import java .io .InputStream ;
39
+ import java .io .InputStreamReader ;
40
+
44
41
@ RestController
45
- @ ConfigurationProperties (prefix = "ei" )
46
42
public class EIRequestsController {
47
43
48
44
private static final Logger LOG = LoggerFactory .getLogger (EIRequestsController .class );
49
45
50
46
private CloseableHttpClient client = HttpClientBuilder .create ().build ();
51
47
52
- private String backendServerHost ;
53
- private int backendServerPort ;
54
- private String backendContextPath ;
55
- private boolean useSecureHttp ;
56
-
57
- // Backend host and port (Getter & Setters), application.properties ->
58
- // greeting.xxx
59
- public String getBackendServerHost () {
60
- return backendServerHost ;
61
- }
62
-
63
- public void setBackendServerHost (String backendServerHost ) {
64
- this .backendServerHost = backendServerHost ;
65
- }
66
-
67
- public int getBackendServerPort () {
68
- return backendServerPort ;
69
- }
70
-
71
- public void setBackendServerPort (int backendServerPort ) {
72
- this .backendServerPort = backendServerPort ;
73
- }
74
-
75
- public String getBackendContextPath () {
76
- return backendContextPath ;
77
- }
78
-
79
- public void setBackendContextPath (String backendContextPath ) {
80
- this .backendContextPath = backendContextPath ;
81
- }
82
-
83
- public boolean getUseSecureHttp () {
84
- return useSecureHttp ;
85
- }
86
-
87
- public void setUseSecureHttp (boolean useSecureHttp ) {
88
- this .useSecureHttp = useSecureHttp ;
89
- }
48
+ @ Autowired
49
+ private BackEndInformation backEndInformation ;
90
50
91
51
/**
92
52
* Bridge authorized EI Http Requests with GET method. Used for login and logout
93
- *
94
53
*/
95
54
@ CrossOrigin
96
55
@ RequestMapping (value = "/auth/login" , method = RequestMethod .GET )
97
56
public ResponseEntity <String > getAuthRequests (Model model , HttpServletRequest request ) {
98
57
String eiBackendAddressSuffix = request .getServletPath ();
99
58
String newRequestUrl = getEIBackendSubscriptionAddress () + eiBackendAddressSuffix ;
100
59
LOG .info ("Got HTTP Request with method GET.\n UrlSuffix: " + eiBackendAddressSuffix +
101
- "\n Forwarding Request to EI Backend with url: " + newRequestUrl );
60
+ "\n Forwarding Request to EI Backend with url: " + newRequestUrl );
102
61
103
62
try {
104
63
client .close ();
@@ -120,7 +79,6 @@ public ResponseEntity<String> getAuthRequests(Model model, HttpServletRequest re
120
79
/**
121
80
* Bridge all EI Http Requests with GET method. Used for fetching
122
81
* Subscription by id or all subscriptions and EI Env Info.
123
- *
124
82
*/
125
83
@ CrossOrigin
126
84
@ RequestMapping (value = { "/subscriptions" , "/subscriptions/*" , "/information" , "/auth" ,
@@ -138,10 +96,9 @@ public ResponseEntity<String> getRequests(Model model, HttpServletRequest reques
138
96
139
97
/**
140
98
* Bridge all EI Http Requests with POST method.
141
- *
142
99
*/
143
100
@ CrossOrigin
144
- @ RequestMapping (value = { "/subscriptions" , "/rules/rule-check/aggregation" }, method = RequestMethod .POST )
101
+ @ RequestMapping (value = {"/subscriptions" , "/rules/rule-check/aggregation" }, method = RequestMethod .POST )
145
102
public ResponseEntity <String > postRequests (Model model , HttpServletRequest request ) {
146
103
String eiBackendAddressSuffix = request .getServletPath ();
147
104
String newRequestUrl = getEIBackendSubscriptionAddress () + eiBackendAddressSuffix ;
@@ -172,7 +129,6 @@ public ResponseEntity<String> postRequests(Model model, HttpServletRequest reque
172
129
/**
173
130
* Bridge all EI Http Requests with PUT method. E.g. Making Update
174
131
* Subscription Request.
175
- *
176
132
*/
177
133
@ CrossOrigin
178
134
@ RequestMapping (value = "/subscriptions" , method = RequestMethod .PUT )
@@ -206,7 +162,6 @@ public ResponseEntity<String> putRequests(Model model, HttpServletRequest reques
206
162
/**
207
163
* Bridge all EI Http Requests with DELETE method. Used for DELETE
208
164
* subscriptions.
209
- *
210
165
*/
211
166
@ CrossOrigin
212
167
@ RequestMapping (value = "/subscriptions/*" , method = RequestMethod .DELETE )
@@ -223,15 +178,15 @@ public ResponseEntity<String> deleteRequests(Model model, HttpServletRequest req
223
178
224
179
private String getEIBackendSubscriptionAddress () {
225
180
String httpMethod = "http" ;
226
- if (useSecureHttp ) {
181
+ if (backEndInformation . isHttps () ) {
227
182
httpMethod = "https" ;
228
183
}
229
184
230
- if (backendContextPath != null && !backendContextPath .isEmpty ()) {
231
- return httpMethod + "://" + this . getBackendServerHost () + ":" + this . getBackendServerPort () + "/"
232
- + backendContextPath ;
185
+ if (backEndInformation . getPath () != null && !backEndInformation . getPath () .isEmpty ()) {
186
+ return httpMethod + "://" + backEndInformation . getHost () + ":" + backEndInformation . getPort () + "/"
187
+ + backEndInformation . getPath () ;
233
188
}
234
- return httpMethod + "://" + this . getBackendServerHost () + ":" + this . getBackendServerPort ();
189
+ return httpMethod + "://" + backEndInformation . getHost () + ":" + backEndInformation . getPort ();
235
190
}
236
191
237
192
private ResponseEntity <String > getResponse (HttpRequestBase request ) {
@@ -248,8 +203,8 @@ private ResponseEntity<String> getResponse(HttpRequestBase request) {
248
203
}
249
204
statusCode = eiResponse .getStatusLine ().getStatusCode ();
250
205
LOG .info ("EI Http Reponse Status Code: " + eiResponse .getStatusLine ().getStatusCode ()
251
- + "\n EI Recevied jsonContent:\n " + jsonContent
252
- + "\n Forwarding response back to EI Frontend WebUI." );
206
+ + "\n EI Recevied jsonContent:\n " + jsonContent
207
+ + "\n Forwarding response back to EI Frontend WebUI." );
253
208
bufReader .close ();
254
209
inStream .close ();
255
210
} catch (IOException e ) {
0 commit comments