add timeout support
This commit is contained in:
parent
8dc8e294f7
commit
9a469fce17
@ -26,6 +26,8 @@ import com.google.api.services.fusiontables.FusiontablesScopes;
|
|||||||
import com.google.api.services.sheets.v4.Sheets;
|
import com.google.api.services.sheets.v4.Sheets;
|
||||||
import com.google.api.services.sheets.v4.SheetsScopes;
|
import com.google.api.services.sheets.v4.SheetsScopes;
|
||||||
|
|
||||||
|
import com.google.refine.ProjectManager;
|
||||||
|
import com.google.refine.preference.PreferenceStore;
|
||||||
import com.google.refine.util.ParsingUtilities;
|
import com.google.refine.util.ParsingUtilities;
|
||||||
|
|
||||||
import edu.mit.simile.butterfly.ButterflyModule;
|
import edu.mit.simile.butterfly.ButterflyModule;
|
||||||
@ -43,6 +45,13 @@ abstract public class GoogleAPIExtension {
|
|||||||
|
|
||||||
private static final String[] SCOPES = {DriveScopes.DRIVE, SheetsScopes.SPREADSHEETS, FusiontablesScopes.FUSIONTABLES};
|
private static final String[] SCOPES = {DriveScopes.DRIVE, SheetsScopes.SPREADSHEETS, FusiontablesScopes.FUSIONTABLES};
|
||||||
|
|
||||||
|
private static PreferenceStore prefStore = ProjectManager.singleton.getPreferenceStore();
|
||||||
|
|
||||||
|
private static final String CONNECT_TIME_OUT_KEY = "googleConnectTimeOut";
|
||||||
|
private static final String READ_TIME_OUT_KEY = "googleReadTimeOut";
|
||||||
|
private static final int CONNECT_TIME_OUT_DEFAULT = 3 * 60000; // 3 minutes connect timeout
|
||||||
|
private static final int READ_TIME_OUT_DEFAULT = 3 * 60000; // 3 minutes read timeout
|
||||||
|
|
||||||
static public String getAuthorizationUrl(ButterflyModule module, HttpServletRequest request)
|
static public String getAuthorizationUrl(ButterflyModule module, HttpServletRequest request)
|
||||||
throws MalformedURLException {
|
throws MalformedURLException {
|
||||||
String authorizedUrl = makeRedirectUrl(module, request);
|
String authorizedUrl = makeRedirectUrl(module, request);
|
||||||
@ -101,8 +110,8 @@ abstract public class GoogleAPIExtension {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(HttpRequest httpRequest) throws IOException {
|
public void initialize(HttpRequest httpRequest) throws IOException {
|
||||||
credential.initialize(httpRequest);
|
credential.initialize(httpRequest);
|
||||||
httpRequest.setConnectTimeout(3 * 60000); // 3 minutes connect timeout
|
httpRequest.setConnectTimeout(3 * 60000);
|
||||||
httpRequest.setReadTimeout(3 * 60000); // 3 minutes read timeout
|
httpRequest.setReadTimeout(3 * 60000);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setApplicationName(SERVICE_APP_NAME).build();
|
.setApplicationName(SERVICE_APP_NAME).build();
|
||||||
@ -141,10 +150,29 @@ abstract public class GoogleAPIExtension {
|
|||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public static Sheets getSheetsService(String token) throws IOException {
|
public static Sheets getSheetsService(String token) throws IOException {
|
||||||
return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY,
|
GoogleCredential credential = new GoogleCredential().setAccessToken(token);
|
||||||
new GoogleCredential().setAccessToken(token))
|
int connectTimeout = getConnectTimeout();
|
||||||
.setApplicationName(SERVICE_APP_NAME)
|
int readTimeout = getReadTimeout();
|
||||||
.build();
|
|
||||||
|
return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).setHttpRequestInitializer(new HttpRequestInitializer() {
|
||||||
|
@Override
|
||||||
|
public void initialize(HttpRequest httpRequest) throws IOException {
|
||||||
|
credential.initialize(httpRequest);
|
||||||
|
httpRequest.setConnectTimeout(connectTimeout);
|
||||||
|
httpRequest.setReadTimeout(readTimeout); // 3 minutes read timeout
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setApplicationName(SERVICE_APP_NAME).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getConnectTimeout() {
|
||||||
|
return prefStore.get(CONNECT_TIME_OUT_KEY) == null ? CONNECT_TIME_OUT_DEFAULT :
|
||||||
|
Integer.parseInt((String) prefStore.get(CONNECT_TIME_OUT_KEY));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getReadTimeout() {
|
||||||
|
return prefStore.get(READ_TIME_OUT_KEY) == null ? READ_TIME_OUT_DEFAULT :
|
||||||
|
Integer.parseInt((String) prefStore.get(READ_TIME_OUT_KEY));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String extractSpreadSheetId(String url)
|
public static String extractSpreadSheetId(String url)
|
||||||
|
Loading…
Reference in New Issue
Block a user