Compare commits
2 Commits
vdrokov_fi
...
hwang/TUP-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd75351bf0 | ||
|
|
a638ce96e5 |
@@ -18,6 +18,7 @@ import java.util.List;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.talend.utils.thread.TimeoutManager;
|
||||
|
||||
/**
|
||||
* DOC wzhang class global comment. Detailled comment
|
||||
@@ -59,6 +60,16 @@ public class BabiliUpdateUtil {
|
||||
*/
|
||||
public static String sendGetRequest(String url) throws Exception {
|
||||
HttpClient httpclient = new HttpClient();
|
||||
|
||||
if(TimeoutManager.getSocketTimeout() != null) {
|
||||
httpclient.getParams().setIntParameter(TimeoutManager.SOCKET_TIMEOUT,
|
||||
TimeoutManager.getSocketTimeout());
|
||||
}
|
||||
if(TimeoutManager.getConnectionTimeout() != null) {
|
||||
httpclient.getParams().setIntParameter(TimeoutManager.CONNECTION_TIMEOUT,
|
||||
TimeoutManager.getConnectionTimeout());
|
||||
}
|
||||
|
||||
GetMethod getMethod = new GetMethod(url);
|
||||
httpclient.executeMethod(getMethod);
|
||||
String response = getMethod.getResponseBodyAsString();
|
||||
|
||||
@@ -44,6 +44,7 @@ import org.talend.core.runtime.CoreRuntimePlugin;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.designer.core.IDesignerCoreService;
|
||||
import org.talend.utils.thread.TimeoutManager;
|
||||
|
||||
/**
|
||||
* DOC ggu class global comment. Detailled comment
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.talend.core.nexus.NexusConstants;
|
||||
import org.talend.core.runtime.maven.MavenArtifact;
|
||||
import org.talend.core.runtime.maven.MavenUrlHelper;
|
||||
import org.talend.designer.maven.aether.RepositorySystemFactory;
|
||||
import org.talend.utils.thread.TimeoutManager;
|
||||
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
@@ -86,6 +87,14 @@ public class ArtifacoryRepositoryHandler extends AbstractArtifactRepositoryHandl
|
||||
HttpGet get = new HttpGet(repositoryUrl);
|
||||
get.addHeader(authority);
|
||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||
if(TimeoutManager.getSocketTimeout() != null) {
|
||||
httpclient.getParams().setIntParameter(TimeoutManager.SOCKET_TIMEOUT,
|
||||
TimeoutManager.getSocketTimeout());
|
||||
}
|
||||
if(TimeoutManager.getConnectionTimeout() != null) {
|
||||
httpclient.getParams().setIntParameter(TimeoutManager.CONNECTION_TIMEOUT,
|
||||
TimeoutManager.getConnectionTimeout());
|
||||
}
|
||||
HttpResponse response = httpclient.execute(get);
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
return true;
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.talend.librariesmanager.nexus.nexus3.handler.INexus3SearchHandler;
|
||||
import org.talend.librariesmanager.nexus.nexus3.handler.Nexus3BetaSearchHandler;
|
||||
import org.talend.librariesmanager.nexus.nexus3.handler.Nexus3ScriptSearchHandler;
|
||||
import org.talend.librariesmanager.nexus.nexus3.handler.Nexus3V1SearchHandler;
|
||||
import org.talend.utils.thread.TimeoutManager;
|
||||
|
||||
/**
|
||||
* created by wchen on Aug 2, 2017 Detailled comment
|
||||
@@ -94,6 +95,14 @@ public class Nexus3RepositoryHandler extends AbstractArtifactRepositoryHandler {
|
||||
HttpGet get = new HttpGet(repositoryUrl);
|
||||
get.addHeader(authority);
|
||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||
if(TimeoutManager.getSocketTimeout() != null) {
|
||||
httpclient.getParams().setIntParameter(TimeoutManager.SOCKET_TIMEOUT,
|
||||
TimeoutManager.getSocketTimeout());
|
||||
}
|
||||
if(TimeoutManager.getConnectionTimeout() != null) {
|
||||
httpclient.getParams().setIntParameter(TimeoutManager.CONNECTION_TIMEOUT,
|
||||
TimeoutManager.getConnectionTimeout());
|
||||
}
|
||||
HttpResponse response = httpclient.execute(get);
|
||||
if (response.getStatusLine().getStatusCode() == 200) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.utils.thread;
|
||||
|
||||
|
||||
/**
|
||||
* DOC hwang class global comment. Detailled comment
|
||||
*/
|
||||
public class TimeoutManager {
|
||||
|
||||
public static final String SOCKET_TIMEOUT = "http.socket.timeout";//$NON-NLS-1$
|
||||
|
||||
public static final String CONNECTION_TIMEOUT = "http.connection.timeout";//$NON-NLS-1$
|
||||
|
||||
public static Integer getSocketTimeout() {
|
||||
String so_timeOut = System.getProperty(TimeoutManager.SOCKET_TIMEOUT);
|
||||
if(so_timeOut == null || "".equals(so_timeOut)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(so_timeOut);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Integer getConnectionTimeout() {
|
||||
String co_timeOut = System.getProperty(TimeoutManager.CONNECTION_TIMEOUT);
|
||||
if(co_timeOut == null || "".equals(co_timeOut)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Integer.parseInt(co_timeOut);
|
||||
} catch (NumberFormatException e) {
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.utils.thread;
|
||||
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* DOC hwang class global comment. Detailled comment
|
||||
*/
|
||||
public class TimeoutManagerTest {
|
||||
|
||||
@Test
|
||||
public void testGetSocketTimeout() {
|
||||
System.setProperty(TimeoutManager.SOCKET_TIMEOUT, null);
|
||||
Assert.assertNull(TimeoutManager.getSocketTimeout());
|
||||
|
||||
System.setProperty(TimeoutManager.SOCKET_TIMEOUT, "aa");
|
||||
Assert.assertNull(TimeoutManager.getSocketTimeout());
|
||||
|
||||
System.setProperty(TimeoutManager.SOCKET_TIMEOUT, "50");
|
||||
Assert.assertTrue(TimeoutManager.getSocketTimeout() == 50);
|
||||
|
||||
System.setProperty(TimeoutManager.SOCKET_TIMEOUT, "");
|
||||
Assert.assertNull(TimeoutManager.getSocketTimeout());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConnectionTimeout() {
|
||||
System.setProperty(TimeoutManager.CONNECTION_TIMEOUT, null);
|
||||
Assert.assertNull(TimeoutManager.getConnectionTimeout());
|
||||
|
||||
System.setProperty(TimeoutManager.CONNECTION_TIMEOUT, "aa");
|
||||
Assert.assertNull(TimeoutManager.getConnectionTimeout());
|
||||
|
||||
System.setProperty(TimeoutManager.CONNECTION_TIMEOUT, "50");
|
||||
Assert.assertTrue(TimeoutManager.getConnectionTimeout() == 50);
|
||||
|
||||
System.setProperty(TimeoutManager.CONNECTION_TIMEOUT, "");
|
||||
Assert.assertNull(TimeoutManager.getConnectionTimeout());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user