Skip to content

Commit

Permalink
Multi domain support for serviceGenerator
Browse files Browse the repository at this point in the history
The service generator now can generate services with custom BASE_URL values.

This allows services to be instantiated for different environments
  • Loading branch information
Umut Ay Bora committed Sep 22, 2022
1 parent 379818b commit 7a86710
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.Umutayb</groupId>
<artifactId>Pickleib</artifactId>
<version>1.1.6</version>
<version>1.1.7</version>
<packaging>jar</packaging>

<name>Pickleib</name>
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/utils/ServiceGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@

import static utils.FileUtilities.properties;

@SuppressWarnings("unused")
public class ServiceGenerator {

Headers headers = new Headers.Builder().build();

String BASE_URL = "";
private final Printer log = new Printer(ServiceGenerator.class);

public ServiceGenerator(Headers headers, String BASE_URL) {
this.BASE_URL = BASE_URL;
setHeaders(headers);
}

public ServiceGenerator(Headers headers) {setHeaders(headers);}

public ServiceGenerator(String BASE_URL) {this.BASE_URL = BASE_URL;}

public ServiceGenerator(){}

/**
Expand All @@ -37,7 +45,7 @@ public ServiceGenerator(){}
*/
public <S> S generate(Class<S> serviceClass) {

String BASE_URL = (String) new ObjectUtilities().getFieldValue("BASE_URL", serviceClass);
if (BASE_URL.isEmpty()) BASE_URL = (String) new ObjectUtilities().getFieldValue("BASE_URL", serviceClass);

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
HttpLoggingInterceptor headerInterceptor = new HttpLoggingInterceptor();
Expand Down

0 comments on commit 7a86710

Please sign in to comment.