Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Change placeholder processing & better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmefox committed May 29, 2017
1 parent 8445f49 commit b22aedc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public FoxHttpRequestBuilder activateFoxHttpLogger(boolean activate) {
*/
public FoxHttpRequest build() throws FoxHttpRequestException {
FoxHttpRequest request = new FoxHttpRequest();
request.setFoxHttpClient(this.foxHttpClient);

if (this.foxHttpPlaceholderStrategy != null) {
request.getFoxHttpPlaceholderStrategy().getPlaceholderMap().putAll(this.foxHttpPlaceholderStrategy.getPlaceholderMap());
Expand All @@ -353,7 +354,6 @@ public FoxHttpRequest build() throws FoxHttpRequestException {
request.setRequestBody(this.requestBody);
request.setFollowRedirect(this.followRedirect);
request.setSkipResponseBody(this.skipResponseBody);
request.setFoxHttpClient(this.foxHttpClient);

return request;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

/**
* @author [email protected]
Expand Down Expand Up @@ -49,11 +50,20 @@ public void addPlaceholder(String placeholder, String value) {
}


public String processPlaceholders(String processedURL, FoxHttpClient foxHttpClient) {
public String processPlaceholders(final String processedURL, FoxHttpClient foxHttpClient) {
String parsedString = processedURL;
Pattern p = Pattern.compile(placeholderEscapeCharEnd);
for (Map.Entry<String, String> entry : this.getPlaceholderMap().entrySet()) {
foxHttpClient.getFoxHttpLogger().log("-> " + this.getPlaceholderEscapeCharStart() + entry.getKey() + this.getPlaceholderEscapeCharEnd() + " -> " + entry.getValue());
processedURL = processedURL.replace(this.getPlaceholderEscapeCharStart() + entry.getKey() + this.getPlaceholderEscapeCharEnd(), entry.getValue());
if (p.matcher(parsedString).find()) {
parsedString = parsedString.replace(this.getPlaceholderEscapeCharStart() + entry.getKey() + this.getPlaceholderEscapeCharEnd(), entry.getValue());
foxHttpClient.getFoxHttpLogger().log(
processedURL +
" -> (" + this.getPlaceholderEscapeCharStart() + entry.getKey() + this.getPlaceholderEscapeCharEnd() + " -> " + entry.getValue() +
") -> " + parsedString);
} else {
break;
}
}
return processedURL;
return parsedString;
}
}

0 comments on commit b22aedc

Please sign in to comment.