embulk-input-http 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/classpath/{embulk-input-http-0.0.13.jar → embulk-input-http-0.0.14.jar} +0 -0
- data/classpath/{httpclient-4.4.jar → httpclient-4.5.jar} +0 -0
- data/classpath/{httpcore-4.4.jar → httpcore-4.4.1.jar} +0 -0
- metadata +5 -28
- data/.gitignore +0 -8
- data/LICENSE.txt +0 -21
- data/README.md +0 -188
- data/build.gradle +0 -76
- data/config/checkstyle/checkstyle.xml +0 -128
- data/config/checkstyle/default.xml +0 -108
- data/example/json-example.yml +0 -21
- data/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/gradle/wrapper/gradle-wrapper.properties +0 -6
- data/gradlew +0 -164
- data/gradlew.bat +0 -90
- data/lib/embulk/input/http.rb +0 -3
- data/settings.gradle +0 -1
- data/src/main/java/org/embulk/input/BasicAuthConfig.java +0 -39
- data/src/main/java/org/embulk/input/HttpInputPlugin.java +0 -332
- data/src/main/java/org/embulk/input/PagerConfig.java +0 -86
- data/src/main/java/org/embulk/input/ParamsConfig.java +0 -82
- data/src/main/java/org/embulk/input/QueryConfig.java +0 -171
- data/src/main/java/org/embulk/input/RetryableHandler.java +0 -90
- data/src/test/java/org/embulk/input/TestHttpInputPlugin.java +0 -5
- data/src/test/java/org/embulk/input/TestPagerConfig.java +0 -78
- data/src/test/java/org/embulk/input/TestParamsConfig.java +0 -105
- data/src/test/java/org/embulk/input/TestQueryConfig.java +0 -125
data/gradlew
DELETED
@@ -1,164 +0,0 @@
|
|
1
|
-
#!/usr/bin/env bash
|
2
|
-
|
3
|
-
##############################################################################
|
4
|
-
##
|
5
|
-
## Gradle start up script for UN*X
|
6
|
-
##
|
7
|
-
##############################################################################
|
8
|
-
|
9
|
-
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
10
|
-
DEFAULT_JVM_OPTS=""
|
11
|
-
|
12
|
-
APP_NAME="Gradle"
|
13
|
-
APP_BASE_NAME=`basename "$0"`
|
14
|
-
|
15
|
-
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
16
|
-
MAX_FD="maximum"
|
17
|
-
|
18
|
-
warn ( ) {
|
19
|
-
echo "$*"
|
20
|
-
}
|
21
|
-
|
22
|
-
die ( ) {
|
23
|
-
echo
|
24
|
-
echo "$*"
|
25
|
-
echo
|
26
|
-
exit 1
|
27
|
-
}
|
28
|
-
|
29
|
-
# OS specific support (must be 'true' or 'false').
|
30
|
-
cygwin=false
|
31
|
-
msys=false
|
32
|
-
darwin=false
|
33
|
-
case "`uname`" in
|
34
|
-
CYGWIN* )
|
35
|
-
cygwin=true
|
36
|
-
;;
|
37
|
-
Darwin* )
|
38
|
-
darwin=true
|
39
|
-
;;
|
40
|
-
MINGW* )
|
41
|
-
msys=true
|
42
|
-
;;
|
43
|
-
esac
|
44
|
-
|
45
|
-
# For Cygwin, ensure paths are in UNIX format before anything is touched.
|
46
|
-
if $cygwin ; then
|
47
|
-
[ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
|
48
|
-
fi
|
49
|
-
|
50
|
-
# Attempt to set APP_HOME
|
51
|
-
# Resolve links: $0 may be a link
|
52
|
-
PRG="$0"
|
53
|
-
# Need this for relative symlinks.
|
54
|
-
while [ -h "$PRG" ] ; do
|
55
|
-
ls=`ls -ld "$PRG"`
|
56
|
-
link=`expr "$ls" : '.*-> \(.*\)$'`
|
57
|
-
if expr "$link" : '/.*' > /dev/null; then
|
58
|
-
PRG="$link"
|
59
|
-
else
|
60
|
-
PRG=`dirname "$PRG"`"/$link"
|
61
|
-
fi
|
62
|
-
done
|
63
|
-
SAVED="`pwd`"
|
64
|
-
cd "`dirname \"$PRG\"`/" >&-
|
65
|
-
APP_HOME="`pwd -P`"
|
66
|
-
cd "$SAVED" >&-
|
67
|
-
|
68
|
-
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
69
|
-
|
70
|
-
# Determine the Java command to use to start the JVM.
|
71
|
-
if [ -n "$JAVA_HOME" ] ; then
|
72
|
-
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
73
|
-
# IBM's JDK on AIX uses strange locations for the executables
|
74
|
-
JAVACMD="$JAVA_HOME/jre/sh/java"
|
75
|
-
else
|
76
|
-
JAVACMD="$JAVA_HOME/bin/java"
|
77
|
-
fi
|
78
|
-
if [ ! -x "$JAVACMD" ] ; then
|
79
|
-
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
80
|
-
|
81
|
-
Please set the JAVA_HOME variable in your environment to match the
|
82
|
-
location of your Java installation."
|
83
|
-
fi
|
84
|
-
else
|
85
|
-
JAVACMD="java"
|
86
|
-
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
87
|
-
|
88
|
-
Please set the JAVA_HOME variable in your environment to match the
|
89
|
-
location of your Java installation."
|
90
|
-
fi
|
91
|
-
|
92
|
-
# Increase the maximum file descriptors if we can.
|
93
|
-
if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
|
94
|
-
MAX_FD_LIMIT=`ulimit -H -n`
|
95
|
-
if [ $? -eq 0 ] ; then
|
96
|
-
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
97
|
-
MAX_FD="$MAX_FD_LIMIT"
|
98
|
-
fi
|
99
|
-
ulimit -n $MAX_FD
|
100
|
-
if [ $? -ne 0 ] ; then
|
101
|
-
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
102
|
-
fi
|
103
|
-
else
|
104
|
-
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
105
|
-
fi
|
106
|
-
fi
|
107
|
-
|
108
|
-
# For Darwin, add options to specify how the application appears in the dock
|
109
|
-
if $darwin; then
|
110
|
-
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
111
|
-
fi
|
112
|
-
|
113
|
-
# For Cygwin, switch paths to Windows format before running java
|
114
|
-
if $cygwin ; then
|
115
|
-
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
116
|
-
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
117
|
-
|
118
|
-
# We build the pattern for arguments to be converted via cygpath
|
119
|
-
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
120
|
-
SEP=""
|
121
|
-
for dir in $ROOTDIRSRAW ; do
|
122
|
-
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
123
|
-
SEP="|"
|
124
|
-
done
|
125
|
-
OURCYGPATTERN="(^($ROOTDIRS))"
|
126
|
-
# Add a user-defined pattern to the cygpath arguments
|
127
|
-
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
128
|
-
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
129
|
-
fi
|
130
|
-
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
131
|
-
i=0
|
132
|
-
for arg in "$@" ; do
|
133
|
-
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
134
|
-
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
135
|
-
|
136
|
-
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
137
|
-
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
138
|
-
else
|
139
|
-
eval `echo args$i`="\"$arg\""
|
140
|
-
fi
|
141
|
-
i=$((i+1))
|
142
|
-
done
|
143
|
-
case $i in
|
144
|
-
(0) set -- ;;
|
145
|
-
(1) set -- "$args0" ;;
|
146
|
-
(2) set -- "$args0" "$args1" ;;
|
147
|
-
(3) set -- "$args0" "$args1" "$args2" ;;
|
148
|
-
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
149
|
-
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
150
|
-
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
151
|
-
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
152
|
-
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
153
|
-
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
154
|
-
esac
|
155
|
-
fi
|
156
|
-
|
157
|
-
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
|
158
|
-
function splitJvmOpts() {
|
159
|
-
JVM_OPTS=("$@")
|
160
|
-
}
|
161
|
-
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
|
162
|
-
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
|
163
|
-
|
164
|
-
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
|
data/gradlew.bat
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
@if "%DEBUG%" == "" @echo off
|
2
|
-
@rem ##########################################################################
|
3
|
-
@rem
|
4
|
-
@rem Gradle startup script for Windows
|
5
|
-
@rem
|
6
|
-
@rem ##########################################################################
|
7
|
-
|
8
|
-
@rem Set local scope for the variables with windows NT shell
|
9
|
-
if "%OS%"=="Windows_NT" setlocal
|
10
|
-
|
11
|
-
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
12
|
-
set DEFAULT_JVM_OPTS=
|
13
|
-
|
14
|
-
set DIRNAME=%~dp0
|
15
|
-
if "%DIRNAME%" == "" set DIRNAME=.
|
16
|
-
set APP_BASE_NAME=%~n0
|
17
|
-
set APP_HOME=%DIRNAME%
|
18
|
-
|
19
|
-
@rem Find java.exe
|
20
|
-
if defined JAVA_HOME goto findJavaFromJavaHome
|
21
|
-
|
22
|
-
set JAVA_EXE=java.exe
|
23
|
-
%JAVA_EXE% -version >NUL 2>&1
|
24
|
-
if "%ERRORLEVEL%" == "0" goto init
|
25
|
-
|
26
|
-
echo.
|
27
|
-
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
28
|
-
echo.
|
29
|
-
echo Please set the JAVA_HOME variable in your environment to match the
|
30
|
-
echo location of your Java installation.
|
31
|
-
|
32
|
-
goto fail
|
33
|
-
|
34
|
-
:findJavaFromJavaHome
|
35
|
-
set JAVA_HOME=%JAVA_HOME:"=%
|
36
|
-
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
37
|
-
|
38
|
-
if exist "%JAVA_EXE%" goto init
|
39
|
-
|
40
|
-
echo.
|
41
|
-
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
42
|
-
echo.
|
43
|
-
echo Please set the JAVA_HOME variable in your environment to match the
|
44
|
-
echo location of your Java installation.
|
45
|
-
|
46
|
-
goto fail
|
47
|
-
|
48
|
-
:init
|
49
|
-
@rem Get command-line arguments, handling Windowz variants
|
50
|
-
|
51
|
-
if not "%OS%" == "Windows_NT" goto win9xME_args
|
52
|
-
if "%@eval[2+2]" == "4" goto 4NT_args
|
53
|
-
|
54
|
-
:win9xME_args
|
55
|
-
@rem Slurp the command line arguments.
|
56
|
-
set CMD_LINE_ARGS=
|
57
|
-
set _SKIP=2
|
58
|
-
|
59
|
-
:win9xME_args_slurp
|
60
|
-
if "x%~1" == "x" goto execute
|
61
|
-
|
62
|
-
set CMD_LINE_ARGS=%*
|
63
|
-
goto execute
|
64
|
-
|
65
|
-
:4NT_args
|
66
|
-
@rem Get arguments from the 4NT Shell from JP Software
|
67
|
-
set CMD_LINE_ARGS=%$
|
68
|
-
|
69
|
-
:execute
|
70
|
-
@rem Setup the command line
|
71
|
-
|
72
|
-
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
73
|
-
|
74
|
-
@rem Execute Gradle
|
75
|
-
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
76
|
-
|
77
|
-
:end
|
78
|
-
@rem End local scope for the variables with windows NT shell
|
79
|
-
if "%ERRORLEVEL%"=="0" goto mainEnd
|
80
|
-
|
81
|
-
:fail
|
82
|
-
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
83
|
-
rem the _cmd.exe /c_ return code!
|
84
|
-
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
85
|
-
exit /b 1
|
86
|
-
|
87
|
-
:mainEnd
|
88
|
-
if "%OS%"=="Windows_NT" endlocal
|
89
|
-
|
90
|
-
:omega
|
data/lib/embulk/input/http.rb
DELETED
data/settings.gradle
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rootProject.name = 'embulk-input-http'
|
@@ -1,39 +0,0 @@
|
|
1
|
-
package org.embulk.input;
|
2
|
-
|
3
|
-
import com.fasterxml.jackson.annotation.JsonCreator;
|
4
|
-
import com.fasterxml.jackson.annotation.JsonProperty;
|
5
|
-
import com.google.common.base.Objects;
|
6
|
-
|
7
|
-
public class BasicAuthConfig {
|
8
|
-
|
9
|
-
private final String user;
|
10
|
-
private final String password;
|
11
|
-
|
12
|
-
@JsonCreator
|
13
|
-
public BasicAuthConfig(
|
14
|
-
@JsonProperty("user") String user,
|
15
|
-
@JsonProperty("password") String password) {
|
16
|
-
this.user = user;
|
17
|
-
this.password = password;
|
18
|
-
}
|
19
|
-
|
20
|
-
@JsonProperty("user")
|
21
|
-
public String getUser() {
|
22
|
-
return user;
|
23
|
-
}
|
24
|
-
|
25
|
-
@JsonProperty("password")
|
26
|
-
public String getPassword() {
|
27
|
-
return password;
|
28
|
-
}
|
29
|
-
|
30
|
-
@Override
|
31
|
-
public int hashCode() {
|
32
|
-
return Objects.hashCode(user, password);
|
33
|
-
}
|
34
|
-
|
35
|
-
@Override
|
36
|
-
public String toString() {
|
37
|
-
return String.format("BasicAuthConfig[%s, %s]", getUser(), getPassword());
|
38
|
-
}
|
39
|
-
}
|
@@ -1,332 +0,0 @@
|
|
1
|
-
package org.embulk.input;
|
2
|
-
|
3
|
-
import com.google.common.base.Optional;
|
4
|
-
import com.google.common.base.Throwables;
|
5
|
-
import com.google.common.collect.Lists;
|
6
|
-
import org.apache.http.Header;
|
7
|
-
import org.apache.http.NameValuePair;
|
8
|
-
import org.apache.http.auth.AuthScope;
|
9
|
-
import org.apache.http.auth.UsernamePasswordCredentials;
|
10
|
-
import org.apache.http.client.CredentialsProvider;
|
11
|
-
import org.apache.http.client.HttpClient;
|
12
|
-
import org.apache.http.client.config.RequestConfig;
|
13
|
-
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
14
|
-
import org.apache.http.client.methods.HttpGet;
|
15
|
-
import org.apache.http.client.methods.HttpPost;
|
16
|
-
import org.apache.http.client.methods.HttpRequestBase;
|
17
|
-
import org.apache.http.client.utils.URIBuilder;
|
18
|
-
import org.apache.http.impl.client.BasicCredentialsProvider;
|
19
|
-
import org.apache.http.impl.client.HttpClientBuilder;
|
20
|
-
import org.apache.http.message.BasicHeader;
|
21
|
-
import org.apache.http.message.BasicNameValuePair;
|
22
|
-
import org.embulk.config.*;
|
23
|
-
import org.embulk.spi.BufferAllocator;
|
24
|
-
import org.embulk.spi.Exec;
|
25
|
-
import org.embulk.spi.FileInputPlugin;
|
26
|
-
import org.embulk.spi.TransactionalFileInput;
|
27
|
-
import org.embulk.spi.util.InputStreamFileInput;
|
28
|
-
import org.embulk.spi.util.RetryExecutor;
|
29
|
-
import org.slf4j.Logger;
|
30
|
-
|
31
|
-
import java.io.IOException;
|
32
|
-
import java.io.InputStream;
|
33
|
-
import java.io.UnsupportedEncodingException;
|
34
|
-
import java.net.URISyntaxException;
|
35
|
-
import java.util.ArrayList;
|
36
|
-
import java.util.List;
|
37
|
-
import java.util.Map;
|
38
|
-
|
39
|
-
public class HttpInputPlugin implements FileInputPlugin {
|
40
|
-
|
41
|
-
private final Logger logger = Exec.getLogger(getClass());
|
42
|
-
|
43
|
-
public interface PluginTask extends Task {
|
44
|
-
@Config("url")
|
45
|
-
public String getUrl();
|
46
|
-
|
47
|
-
@Config("charset")
|
48
|
-
@ConfigDefault("\"utf-8\"")
|
49
|
-
public String getCharset();
|
50
|
-
|
51
|
-
@Config("method")
|
52
|
-
@ConfigDefault("\"get\"")
|
53
|
-
public String getMethod();
|
54
|
-
|
55
|
-
@Config("user_agent")
|
56
|
-
@ConfigDefault("\"Embulk::Input::HttpInputPlugin\"")
|
57
|
-
public String getUserAgent();
|
58
|
-
|
59
|
-
@Config("open_timeout")
|
60
|
-
@ConfigDefault("2000")
|
61
|
-
public int getOpenTimeout();
|
62
|
-
|
63
|
-
@Config("read_timeout")
|
64
|
-
@ConfigDefault("10000")
|
65
|
-
public int getReadTimeout();
|
66
|
-
|
67
|
-
@Config("max_retries")
|
68
|
-
@ConfigDefault("5")
|
69
|
-
public int getMaxRetries();
|
70
|
-
|
71
|
-
@Config("retry_interval")
|
72
|
-
@ConfigDefault("10000")
|
73
|
-
public int getRetryInterval();
|
74
|
-
|
75
|
-
@Config("request_interval")
|
76
|
-
@ConfigDefault("0")
|
77
|
-
public int getRequestInterval();
|
78
|
-
|
79
|
-
public void setRequestInterval(int requestInterval);
|
80
|
-
|
81
|
-
@Config("interval_includes_response_time")
|
82
|
-
@ConfigDefault("null")
|
83
|
-
public boolean getIntervalIncludesResponseTime();
|
84
|
-
|
85
|
-
@Config("params")
|
86
|
-
@ConfigDefault("null")
|
87
|
-
public Optional<ParamsConfig> getParams();
|
88
|
-
|
89
|
-
@Config("basic_auth")
|
90
|
-
@ConfigDefault("null")
|
91
|
-
public Optional<BasicAuthConfig> getBasicAuth();
|
92
|
-
|
93
|
-
@Config("pager")
|
94
|
-
@ConfigDefault("null")
|
95
|
-
public Optional<PagerConfig> getPager();
|
96
|
-
|
97
|
-
@Config("request_headers")
|
98
|
-
@ConfigDefault("{}")
|
99
|
-
public Map<String, String> getRequestHeaders();
|
100
|
-
|
101
|
-
@ConfigInject
|
102
|
-
public BufferAllocator getBufferAllocator();
|
103
|
-
|
104
|
-
public List<List<QueryConfig.Query>> getQueries();
|
105
|
-
|
106
|
-
public void setQueries(List<List<QueryConfig.Query>> queries);
|
107
|
-
|
108
|
-
public HttpMethod getHttpMethod();
|
109
|
-
|
110
|
-
public void setHttpMethod(HttpMethod httpMethod);
|
111
|
-
}
|
112
|
-
|
113
|
-
public enum HttpMethod {
|
114
|
-
POST,
|
115
|
-
GET
|
116
|
-
}
|
117
|
-
|
118
|
-
@Override
|
119
|
-
public ConfigDiff transaction(ConfigSource config, FileInputPlugin.Control control) {
|
120
|
-
PluginTask task = config.loadConfig(PluginTask.class);
|
121
|
-
|
122
|
-
final int tasks;
|
123
|
-
if (task.getParams().isPresent()) {
|
124
|
-
List<List<QueryConfig.Query>> queries = task.getParams().get().generateQueries(task.getPager());
|
125
|
-
task.setQueries(queries);
|
126
|
-
tasks = queries.size();
|
127
|
-
} else if (task.getPager().isPresent()) {
|
128
|
-
List<List<QueryConfig.Query>> queries = task.getPager().get().expand();
|
129
|
-
task.setQueries(queries);
|
130
|
-
tasks = queries.size();
|
131
|
-
} else {
|
132
|
-
task.setQueries(Lists.<List<QueryConfig.Query>>newArrayList());
|
133
|
-
task.setRequestInterval(0);
|
134
|
-
tasks = 1;
|
135
|
-
}
|
136
|
-
|
137
|
-
task.setHttpMethod(HttpMethod.valueOf(task.getMethod().toUpperCase()));
|
138
|
-
|
139
|
-
return resume(task.dump(), tasks, control);
|
140
|
-
}
|
141
|
-
|
142
|
-
@Override
|
143
|
-
public ConfigDiff resume(TaskSource taskSource,
|
144
|
-
int taskCount,
|
145
|
-
FileInputPlugin.Control control) {
|
146
|
-
control.run(taskSource, taskCount);
|
147
|
-
return Exec.newConfigDiff();
|
148
|
-
}
|
149
|
-
|
150
|
-
@Override
|
151
|
-
public void cleanup(TaskSource taskSource, int taskCount, List<TaskReport> successTaskReports) {
|
152
|
-
}
|
153
|
-
|
154
|
-
@Override
|
155
|
-
public TransactionalFileInput open(TaskSource taskSource, int taskIndex) {
|
156
|
-
PluginTask task = taskSource.loadTask(PluginTask.class);
|
157
|
-
|
158
|
-
HttpRequestBase request;
|
159
|
-
try {
|
160
|
-
request = makeRequest(task, taskIndex);
|
161
|
-
} catch (URISyntaxException | UnsupportedEncodingException e) {
|
162
|
-
throw Throwables.propagate(e);
|
163
|
-
}
|
164
|
-
|
165
|
-
HttpClientBuilder builder = HttpClientBuilder.create()
|
166
|
-
.disableAutomaticRetries()
|
167
|
-
.setDefaultRequestConfig(makeRequestConfig(task))
|
168
|
-
.setDefaultHeaders(makeHeaders(task));
|
169
|
-
|
170
|
-
if (task.getBasicAuth().isPresent()) {
|
171
|
-
builder.setDefaultCredentialsProvider(makeCredentialsProvider(task.getBasicAuth().get(), request));
|
172
|
-
}
|
173
|
-
|
174
|
-
HttpClient client = builder.build();
|
175
|
-
|
176
|
-
logger.info(String.format("%s \"%s\"", task.getMethod().toUpperCase(), request.getURI().toString()));
|
177
|
-
|
178
|
-
RetryableHandler retryable = new RetryableHandler(client, request);
|
179
|
-
long startTimeMills = System.currentTimeMillis();
|
180
|
-
try {
|
181
|
-
RetryExecutor.retryExecutor().
|
182
|
-
withRetryLimit(task.getMaxRetries()).
|
183
|
-
withInitialRetryWait(task.getRetryInterval()).
|
184
|
-
withMaxRetryWait(30 * 60 * 1000).
|
185
|
-
runInterruptible(retryable);
|
186
|
-
InputStream stream = retryable.getResponse().getEntity().getContent();
|
187
|
-
PluginFileInput input = new PluginFileInput(task, stream, startTimeMills);
|
188
|
-
stream = null;
|
189
|
-
return input;
|
190
|
-
} catch (Exception e) {
|
191
|
-
throw Throwables.propagate(e);
|
192
|
-
}
|
193
|
-
}
|
194
|
-
|
195
|
-
private CredentialsProvider makeCredentialsProvider(BasicAuthConfig config, HttpRequestBase scopeRequest) {
|
196
|
-
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
|
197
|
-
final AuthScope authScope = new AuthScope(scopeRequest.getURI().getHost(),
|
198
|
-
scopeRequest.getURI().getPort());
|
199
|
-
credentialsProvider.setCredentials(authScope,
|
200
|
-
new UsernamePasswordCredentials(config.getUser(), config.getPassword()));
|
201
|
-
return credentialsProvider;
|
202
|
-
}
|
203
|
-
|
204
|
-
private HttpRequestBase makeRequest(PluginTask task, int taskIndex)
|
205
|
-
throws URISyntaxException, UnsupportedEncodingException {
|
206
|
-
final List<QueryConfig.Query> queries = (task.getQueries().isEmpty()) ?
|
207
|
-
null : task.getQueries().get(taskIndex);
|
208
|
-
if (task.getHttpMethod() == HttpMethod.GET) {
|
209
|
-
HttpGet request = new HttpGet(task.getUrl());
|
210
|
-
if (queries != null) {
|
211
|
-
URIBuilder builder = new URIBuilder(request.getURI());
|
212
|
-
for (QueryConfig.Query q : queries) {
|
213
|
-
for (String v : q.getValues()) {
|
214
|
-
builder.addParameter(q.getName(), v);
|
215
|
-
}
|
216
|
-
}
|
217
|
-
request.setURI(builder.build());
|
218
|
-
}
|
219
|
-
return request;
|
220
|
-
} else if (task.getHttpMethod() == HttpMethod.POST) {
|
221
|
-
HttpPost request = new HttpPost(task.getUrl());
|
222
|
-
if (queries != null) {
|
223
|
-
List<NameValuePair> pairs = new ArrayList<>();
|
224
|
-
for (QueryConfig.Query q : queries) {
|
225
|
-
for (String v : q.getValues()) {
|
226
|
-
pairs.add(new BasicNameValuePair(q.getName(), v));
|
227
|
-
}
|
228
|
-
}
|
229
|
-
request.setEntity(new UrlEncodedFormEntity(pairs));
|
230
|
-
}
|
231
|
-
return request;
|
232
|
-
}
|
233
|
-
throw new IllegalArgumentException(String.format("Unsupported http method %s", task.getMethod()));
|
234
|
-
}
|
235
|
-
|
236
|
-
private List<Header> makeHeaders(PluginTask task) {
|
237
|
-
List<Header> headers = new ArrayList<>();
|
238
|
-
headers.add(new BasicHeader("Accept", "*/*"));
|
239
|
-
headers.add(new BasicHeader("Accept-Charset", task.getCharset()));
|
240
|
-
headers.add(new BasicHeader("Accept-Encoding", "gzip, deflate"));
|
241
|
-
headers.add(new BasicHeader("Accept-Language", "en-us,en;q=0.5"));
|
242
|
-
headers.add(new BasicHeader("User-Agent", task.getUserAgent()));
|
243
|
-
for (Map.Entry<String, String> entry : task.getRequestHeaders().entrySet()) {
|
244
|
-
headers.add(new BasicHeader(entry.getKey(), entry.getValue()));
|
245
|
-
}
|
246
|
-
return headers;
|
247
|
-
}
|
248
|
-
|
249
|
-
private RequestConfig makeRequestConfig(PluginTask task) {
|
250
|
-
return RequestConfig.custom()
|
251
|
-
.setCircularRedirectsAllowed(true)
|
252
|
-
.setMaxRedirects(10)
|
253
|
-
.setRedirectsEnabled(true)
|
254
|
-
.setConnectTimeout(task.getOpenTimeout())
|
255
|
-
.setSocketTimeout(task.getReadTimeout())
|
256
|
-
.build();
|
257
|
-
}
|
258
|
-
|
259
|
-
public static class PluginFileInput extends InputStreamFileInput
|
260
|
-
implements TransactionalFileInput {
|
261
|
-
|
262
|
-
private final Logger logger = Exec.getLogger(getClass());
|
263
|
-
|
264
|
-
private final long startTimeMills;
|
265
|
-
private final PluginTask task;
|
266
|
-
|
267
|
-
public PluginFileInput(PluginTask task, InputStream stream, long startTimeMills) {
|
268
|
-
super(task.getBufferAllocator(), new SingleFileProvider(stream));
|
269
|
-
this.startTimeMills = startTimeMills;
|
270
|
-
this.task = task;
|
271
|
-
}
|
272
|
-
|
273
|
-
public TaskReport commit() {
|
274
|
-
return Exec.newTaskReport();
|
275
|
-
}
|
276
|
-
|
277
|
-
@Override
|
278
|
-
public void close() {
|
279
|
-
super.close();
|
280
|
-
handleInterval();
|
281
|
-
}
|
282
|
-
|
283
|
-
@Override
|
284
|
-
public void abort() {
|
285
|
-
}
|
286
|
-
|
287
|
-
protected void handleInterval() {
|
288
|
-
if (task.getRequestInterval() <= 0) {
|
289
|
-
return;
|
290
|
-
}
|
291
|
-
long interval = task.getRequestInterval();
|
292
|
-
if (task.getIntervalIncludesResponseTime()) {
|
293
|
-
interval = interval - (System.currentTimeMillis() - startTimeMills);
|
294
|
-
}
|
295
|
-
if (interval > 0) {
|
296
|
-
logger.info(String.format("waiting %d msec ...", interval));
|
297
|
-
try {
|
298
|
-
Thread.sleep(interval);
|
299
|
-
} catch (InterruptedException e) {
|
300
|
-
Throwables.propagate(e);
|
301
|
-
}
|
302
|
-
}
|
303
|
-
}
|
304
|
-
|
305
|
-
private static class SingleFileProvider
|
306
|
-
implements InputStreamFileInput.Provider {
|
307
|
-
|
308
|
-
private final InputStream stream;
|
309
|
-
private boolean opened = false;
|
310
|
-
|
311
|
-
public SingleFileProvider(InputStream stream) {
|
312
|
-
this.stream = stream;
|
313
|
-
}
|
314
|
-
|
315
|
-
@Override
|
316
|
-
public InputStream openNext() throws IOException {
|
317
|
-
if (opened) {
|
318
|
-
return null;
|
319
|
-
}
|
320
|
-
opened = true;
|
321
|
-
return stream;
|
322
|
-
}
|
323
|
-
|
324
|
-
@Override
|
325
|
-
public void close() throws IOException {
|
326
|
-
if (!opened) {
|
327
|
-
stream.close();
|
328
|
-
}
|
329
|
-
}
|
330
|
-
}
|
331
|
-
}
|
332
|
-
}
|