|
|
@ -17,25 +17,30 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.apache.dolphinscheduler.common.utils; |
|
|
|
package org.apache.dolphinscheduler.common.utils; |
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
|
|
|
|
import junit.framework.Test; |
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
|
|
|
|
import junit.framework.TestSuite; |
|
|
|
|
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
import org.apache.dolphinscheduler.common.Constants; |
|
|
|
|
|
|
|
|
|
|
|
import org.apache.http.client.config.RequestConfig; |
|
|
|
import org.apache.http.client.config.RequestConfig; |
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.CloseableHttpClient; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
import org.apache.http.impl.client.HttpClients; |
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
public class LocalServerHttpUtilsTest extends TestCase{ |
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import junit.framework.Test; |
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
|
|
|
|
import junit.framework.TestSuite; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class LocalServerHttpUtilsTest extends TestCase { |
|
|
|
|
|
|
|
|
|
|
|
public static final Logger logger = LoggerFactory.getLogger(LocalServerHttpUtilsTest.class); |
|
|
|
public static final Logger logger = LoggerFactory.getLogger(LocalServerHttpUtilsTest.class); |
|
|
|
private static LocalJettyHttpServer server = null; |
|
|
|
private static LocalJettyHttpServer server = null; |
|
|
|
public static Test suite(){ |
|
|
|
|
|
|
|
TestSuite suite=new TestSuite(); |
|
|
|
public static Test suite() { |
|
|
|
|
|
|
|
TestSuite suite = new TestSuite(); |
|
|
|
suite.addTestSuite(LocalServerHttpUtilsTest.class); |
|
|
|
suite.addTestSuite(LocalServerHttpUtilsTest.class); |
|
|
|
server = new LocalJettyHttpServer(suite); |
|
|
|
server = new LocalJettyHttpServer(suite); |
|
|
|
return server; |
|
|
|
return server; |
|
|
@ -44,21 +49,21 @@ public class LocalServerHttpUtilsTest extends TestCase{ |
|
|
|
public void testGetTest() throws Exception { |
|
|
|
public void testGetTest() throws Exception { |
|
|
|
// success
|
|
|
|
// success
|
|
|
|
String result = null; |
|
|
|
String result = null; |
|
|
|
result = HttpUtils.get("http://localhost:" + server.getServerPort()+ "/test.json"); |
|
|
|
result = HttpUtils.get("http://localhost:" + server.getServerPort() + "/test.json"); |
|
|
|
Assert.assertNotNull(result); |
|
|
|
Assert.assertNotNull(result); |
|
|
|
ObjectNode jsonObject = JSONUtils.parseObject(result); |
|
|
|
ObjectNode jsonObject = JSONUtils.parseObject(result); |
|
|
|
Assert.assertEquals("Github",jsonObject.path("name").asText()); |
|
|
|
Assert.assertEquals("Github", jsonObject.path("name").asText()); |
|
|
|
result = HttpUtils.get("http://123.333.111.33/ccc"); |
|
|
|
result = HttpUtils.get("http://123.333.111.33/ccc"); |
|
|
|
Assert.assertNull(result); |
|
|
|
Assert.assertNull(result); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testGetResponseContentString() { |
|
|
|
public void testGetResponseContentString() { |
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault(); |
|
|
|
CloseableHttpClient httpclient = HttpClients.createDefault(); |
|
|
|
HttpGet httpget = new HttpGet("http://localhost:" +server.getServerPort()+"/test.json"); |
|
|
|
HttpGet httpget = new HttpGet("http://localhost:" + server.getServerPort() + "/test.json"); |
|
|
|
/** set timeout、request time、socket timeout */ |
|
|
|
/** set timeout、request time、socket timeout */ |
|
|
|
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT) |
|
|
|
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(Constants.HTTP_CONNECT_TIMEOUT) |
|
|
|
.setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT) |
|
|
|
.setConnectionRequestTimeout(Constants.HTTP_CONNECTION_REQUEST_TIMEOUT) |
|
|
|
.setSocketTimeout(Constants.SOCKET_TIMEOUT).setRedirectsEnabled(true).build(); |
|
|
|
.setSocketTimeout(Constants.SOCKET_TIMEOUT).setRedirectsEnabled(true).build(); |
|
|
|
httpget.setConfig(requestConfig); |
|
|
|
httpget.setConfig(requestConfig); |
|
|
|
|
|
|
|
|
|
|
|
String responseContent = null; |
|
|
|
String responseContent = null; |
|
|
@ -77,4 +82,26 @@ public class LocalServerHttpUtilsTest extends TestCase{ |
|
|
|
CloseableHttpClient httpClient2 = HttpUtils.getInstance(); |
|
|
|
CloseableHttpClient httpClient2 = HttpUtils.getInstance(); |
|
|
|
Assert.assertEquals(httpClient1, httpClient2); |
|
|
|
Assert.assertEquals(httpClient1, httpClient2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testKerberosHttpsGet() { |
|
|
|
|
|
|
|
logger.info(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_USERNAME)); |
|
|
|
|
|
|
|
logger.info(PropertyUtils.getString(Constants.LOGIN_USER_KEY_TAB_PATH)); |
|
|
|
|
|
|
|
logger.info(PropertyUtils.getString(Constants.JAVA_SECURITY_KRB5_CONF_PATH)); |
|
|
|
|
|
|
|
String url = "https://www.apache.org/"; |
|
|
|
|
|
|
|
logger.info(KerberosHttpClient.get(url)); |
|
|
|
|
|
|
|
Assert.assertTrue(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testHttpsGet() { |
|
|
|
|
|
|
|
String url = "https://www.apache.org/"; |
|
|
|
|
|
|
|
logger.info(HttpUtils.get(url)); |
|
|
|
|
|
|
|
Assert.assertTrue(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void testHttpGet() { |
|
|
|
|
|
|
|
String url = "http://www.apache.org/"; |
|
|
|
|
|
|
|
logger.info(HttpUtils.get(url)); |
|
|
|
|
|
|
|
Assert.assertTrue(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|