-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: put method in http postprocessor (#217)
* feat: put method in http postprocessor * feat: add endpointVariables functionality in http GET postprocessor * chore: bump version * add: unit test to parse endpointVariables * remove: generated source * add: include generated-sources in gitignore * fix: null string validation * doc: update documentation * refactor: use []Object instead of string to handle endpointVariables * remove: empty string validation * test: add more unit test for multiple endpointVariables case
- Loading branch information
Showing
19 changed files
with
282 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ target/ | |
bin | ||
.settings | ||
.gradletasknamecache | ||
.DS_Store | ||
.DS_Store | ||
dagger-common/src/generated-sources/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...main/java/io/odpf/dagger/core/processors/external/http/request/HttpPutRequestHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.odpf.dagger.core.processors.external.http.request; | ||
|
||
import com.google.gson.Gson; | ||
import io.netty.util.internal.StringUtil; | ||
import io.odpf.dagger.core.exception.InvalidConfigurationException; | ||
import io.odpf.dagger.core.processors.external.http.HttpSourceConfig; | ||
import org.asynchttpclient.AsyncHttpClient; | ||
import org.asynchttpclient.BoundRequestBuilder; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UnknownFormatConversionException; | ||
|
||
/** | ||
* The Http post request handler. | ||
*/ | ||
public class HttpPutRequestHandler implements HttpRequestHandler { | ||
private HttpSourceConfig httpSourceConfig; | ||
private AsyncHttpClient httpClient; | ||
private Object[] requestVariablesValues; | ||
private Object[] dynamicHeaderVariablesValues; | ||
private Object[] endpointVariablesValues; | ||
/** | ||
* Instantiates a new Http post request handler. | ||
* | ||
* @param httpSourceConfig the http source config | ||
* @param httpClient the http client | ||
* @param requestVariablesValues the request variables values | ||
* @param endpointVariablesValues the endpoint variables values | ||
*/ | ||
public HttpPutRequestHandler(HttpSourceConfig httpSourceConfig, AsyncHttpClient httpClient, Object[] requestVariablesValues, Object[] dynamicHeaderVariablesValues, Object[] endpointVariablesValues) { | ||
this.httpSourceConfig = httpSourceConfig; | ||
this.httpClient = httpClient; | ||
this.requestVariablesValues = requestVariablesValues; | ||
this.dynamicHeaderVariablesValues = dynamicHeaderVariablesValues; | ||
this.endpointVariablesValues = endpointVariablesValues; | ||
} | ||
|
||
@Override | ||
public BoundRequestBuilder create() { | ||
String requestBody = String.format(httpSourceConfig.getPattern(), requestVariablesValues); | ||
String endpoint = String.format(httpSourceConfig.getEndpoint(), endpointVariablesValues); | ||
|
||
BoundRequestBuilder putRequest = httpClient | ||
.preparePut(endpoint) | ||
.setBody(requestBody); | ||
Map<String, String> headers = httpSourceConfig.getHeaders(); | ||
if (!StringUtil.isNullOrEmpty(httpSourceConfig.getHeaderPattern())) { | ||
try { | ||
String dynamicHeader = String.format(httpSourceConfig.getHeaderPattern(), dynamicHeaderVariablesValues); | ||
headers.putAll(new Gson().fromJson(dynamicHeader, HashMap.class)); | ||
} catch (UnknownFormatConversionException e) { | ||
throw new InvalidConfigurationException(String.format("pattern config '%s' is invalid", httpSourceConfig.getHeaderPattern())); | ||
} catch (IllegalArgumentException e) { | ||
throw new InvalidConfigurationException(String.format("pattern config '%s' is incompatible with the variable config '%s'", httpSourceConfig.getHeaderPattern(), httpSourceConfig.getHeaderVariables())); | ||
} | ||
} | ||
return addHeaders(putRequest, headers); | ||
} | ||
|
||
@Override | ||
public boolean canCreate() { | ||
return httpSourceConfig.getVerb().equalsIgnoreCase("put"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.