1010import org .springframework .stereotype .Component ;
1111import org .springframework .util .Assert ;
1212
13+ import it .eng .dome .brokerage .billing .utils .UrlPathUtils ;
14+
1315@ Component (value = "tmfApiFactory" )
1416@ Scope (value = ConfigurableBeanFactory .SCOPE_SINGLETON )
1517public final class TmfApiFactory implements InitializingBean {
@@ -38,14 +40,15 @@ public final class TmfApiFactory implements InitializingBean {
3840
3941 public it .eng .dome .tmforum .tmf620 .v4 .ApiClient getTMF620CatalogApiClient () {
4042 final it .eng .dome .tmforum .tmf620 .v4 .ApiClient apiClient = it .eng .dome .tmforum .tmf620 .v4 .Configuration .getDefaultApiClient ();
41- if ( tmfEnvoy ) {
42- // usage of envoyProxy to access on TMForum APIs
43- apiClient . setBasePath ( tmfEndpoint + "/" + tmf620CatalogPath );
44- } else {
45- // use direct access on specific TMForum APIs software
46- apiClient . setBasePath ( tmfEndpoint + TMF_ENDPOINT_CONCAT_PATH + "product-catalog" + "." + tmfNamespace + "." + tmfPostfix + ":" + tmfPort + "/" + tmf620CatalogPath );
47- }
43+
44+ String basePath = tmfEndpoint ;
45+ if (! tmfEnvoy ) { // no envoy specific path
46+ basePath += TMF_ENDPOINT_CONCAT_PATH + "product-catalog" + "." + tmfNamespace + "." + tmfPostfix + ":" + tmfPort ;
47+ }
48+
49+ apiClient . setBasePath ( basePath + "/" + tmf620CatalogPath );
4850 log .debug ("Invoke Catalog API at endpoint: " + apiClient .getBasePath ());
51+
4952 return apiClient ;
5053 }
5154
@@ -63,29 +66,13 @@ public void afterPropertiesSet() throws Exception {
6366 Assert .state (!StringUtils .isBlank (tmf620CatalogPath ), "Billing Scheduler not properly configured. The tmf620_catalog_path property has no value." );
6467
6568 if (tmfEndpoint .endsWith ("/" )) {
66- tmfEndpoint = removeFinalSlash (tmfEndpoint );
69+ tmfEndpoint = UrlPathUtils . removeFinalSlash (tmfEndpoint );
6770 }
6871
6972 if (tmf620CatalogPath .startsWith ("/" )) {
70- tmf620CatalogPath = removeInitialSlash (tmf620CatalogPath );
73+ tmf620CatalogPath = UrlPathUtils . removeInitialSlash (tmf620CatalogPath );
7174 }
7275
7376 }
74-
75- private String removeFinalSlash (String s ) {
76- String path = s ;
77- while (path .endsWith ("/" ))
78- path = path .substring (0 , path .length () - 1 );
79-
80- return path ;
81- }
82-
83- private String removeInitialSlash (String s ) {
84- String path = s ;
85- while (path .startsWith ("/" )) {
86- path = path .substring (1 );
87- }
88- return path ;
89- }
9077
9178}
0 commit comments