23
23
24
24
import javax .servlet .http .HttpServletRequest ;
25
25
26
+ import com .ericsson .ei .frontend .model .BackEndInformation ;
26
27
import org .apache .http .HttpEntity ;
27
28
import org .apache .http .HttpResponse ;
28
29
import org .apache .http .client .HttpClient ;
34
35
import org .apache .http .impl .client .HttpClients ;
35
36
import org .slf4j .Logger ;
36
37
import org .slf4j .LoggerFactory ;
38
+ import org .springframework .beans .factory .annotation .Autowired ;
37
39
import org .springframework .boot .context .properties .ConfigurationProperties ;
38
40
import org .springframework .http .HttpHeaders ;
39
41
import org .springframework .http .HttpStatus ;
46
48
import org .springframework .web .bind .annotation .RestController ;
47
49
48
50
@ RestController
49
- @ ConfigurationProperties (prefix = "ei" )
50
- // @RequestMapping(value = "")
51
51
public class EIRequestsController {
52
52
53
53
private static final Logger LOG = LoggerFactory .getLogger (EIRequestsController .class );
54
54
55
- private String backendServerHost ;
56
- private int backendServerPort ;
57
- private String backendContextPath ;
58
- private boolean useSecureHttp ;
55
+ @ Autowired
56
+ private BackEndInformation backEndInformation ;
59
57
60
- private static final String APPLICATION_JSON = "application/json" ;
61
-
62
- // Backend host and port (Getter & Setters), application.properties ->
63
- // greeting.xxx
64
- public String getBackendServerHost () {
65
- return backendServerHost ;
66
- }
67
-
68
- public void setBackendServerHost (String backendServerHost ) {
69
- this .backendServerHost = backendServerHost ;
70
- }
71
-
72
- public int getBackendServerPort () {
73
- return backendServerPort ;
74
- }
75
-
76
- public void setBackendServerPort (int backendServerPort ) {
77
- this .backendServerPort = backendServerPort ;
78
- }
79
-
80
- public String getBackendContextPath () {
81
- return backendContextPath ;
82
- }
83
-
84
- public void setBackendContextPath (String backendContextPath ) {
85
- this .backendContextPath = backendContextPath ;
86
- }
87
-
88
- public boolean getUseSecureHttp () {
89
- return useSecureHttp ;
90
- }
91
-
92
- public void setUseSecureHttp (boolean useSecureHttp ) {
93
- this .useSecureHttp = useSecureHttp ;
94
- }
95
-
96
- public String getEIBackendSubscriptionAddress () {
58
+ private String getEIBackendSubscriptionAddress () {
97
59
String httpMethod = "http" ;
98
- if (useSecureHttp ) {
60
+ if (backEndInformation . isHttps () ) {
99
61
httpMethod = "https" ;
100
62
}
101
63
102
- if (backendContextPath != null && !backendContextPath .isEmpty ()) {
103
- return httpMethod + "://" + this . getBackendServerHost () + ":" + this . getBackendServerPort () + "/"
104
- + backendContextPath ;
64
+ if (backEndInformation . getPath () != null && !backEndInformation . getPath () .isEmpty ()) {
65
+ return httpMethod + "://" + backEndInformation . getHost () + ":" + backEndInformation . getPort () + "/"
66
+ + backEndInformation . getPath () ;
105
67
}
106
- return httpMethod + "://" + this . getBackendServerHost () + ":" + this . getBackendServerPort ();
68
+ return httpMethod + "://" + backEndInformation . getHost () + ":" + backEndInformation . getPort ();
107
69
}
108
70
109
71
/**
@@ -326,5 +288,4 @@ public ResponseEntity<String> deleteRequests(Model model, HttpServletRequest req
326
288
HttpStatus .valueOf (eiResponse .getStatusLine ().getStatusCode ()));
327
289
return responseEntity ;
328
290
}
329
-
330
291
}
0 commit comments