Search in sources :

Example 21 with DefaultHttpRequestConfig

use of io.cdap.cdap.common.http.DefaultHttpRequestConfig in project cdap by caskdata.

the class SupportBundleServiceMainTest method testSupportBundleService.

@Test
public void testSupportBundleService() throws Exception {
    Injector injector = getServiceMainInstance(SupportBundleServiceMain.class).getInjector();
    URL url = getRouterBaseURI().resolve("/v3/support/bundle").toURL();
    HttpResponse response = HttpRequests.execute(HttpRequest.post(url).build(), new DefaultHttpRequestConfig(false));
    Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
    SupportBundleService supportBundleService = injector.getInstance(SupportBundleService.class);
    SupportBundleConfiguration supportBundleConfiguration = new SupportBundleConfiguration(NamespaceId.DEFAULT.getNamespace(), null, null, ProgramType.WORKFLOW, "DataPipelineWorkflow", 1);
    String uuid = supportBundleService.generateSupportBundle(supportBundleConfiguration);
    Assert.assertNotNull(uuid);
}
Also used : Injector(com.google.inject.Injector) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) SupportBundleService(io.cdap.cdap.support.internal.app.services.SupportBundleService) SupportBundleConfiguration(io.cdap.cdap.support.status.SupportBundleConfiguration) URL(java.net.URL) Test(org.junit.Test)

Example 22 with DefaultHttpRequestConfig

use of io.cdap.cdap.common.http.DefaultHttpRequestConfig in project cdap by caskdata.

the class LogsServiceMainTest method doGet.

private HttpResponse doGet(String path, DiscoveryServiceClient discoveryServiceClient, String serviceName) throws IOException {
    Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(serviceName)).pick(10, TimeUnit.SECONDS);
    Assert.assertNotNull(discoverable);
    URL url = URIScheme.createURI(discoverable, path).toURL();
    return HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) URL(java.net.URL) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 23 with DefaultHttpRequestConfig

use of io.cdap.cdap.common.http.DefaultHttpRequestConfig in project cdap by caskdata.

the class SupportBundleServiceMainTest method doPost.

private HttpResponse doPost(String path, DiscoveryServiceClient discoveryServiceClient, String serviceName) throws IOException {
    Discoverable discoverable = new RandomEndpointStrategy(() -> discoveryServiceClient.discover(serviceName)).pick(10, TimeUnit.SECONDS);
    Assert.assertNotNull(discoverable);
    URL url = URIScheme.createURI(discoverable, path).toURL();
    return HttpRequests.execute(HttpRequest.post(url).build(), new DefaultHttpRequestConfig(false));
}
Also used : Discoverable(org.apache.twill.discovery.Discoverable) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) URL(java.net.URL) RandomEndpointStrategy(io.cdap.cdap.common.discovery.RandomEndpointStrategy)

Example 24 with DefaultHttpRequestConfig

use of io.cdap.cdap.common.http.DefaultHttpRequestConfig in project cdap by caskdata.

the class RouterServiceMainWithSecurityDisabledTest method testRouterServiceWithAuthenticationDisabled.

@Test
public void testRouterServiceWithAuthenticationDisabled() throws Exception {
    URL url = getRouterBaseURI().resolve("/").toURL();
    HttpResponse response = HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
    Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
}
Also used : DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) Test(org.junit.Test)

Example 25 with DefaultHttpRequestConfig

use of io.cdap.cdap.common.http.DefaultHttpRequestConfig in project cdap by cdapio.

the class TrafficRelayServerTest method testRelay.

@Test
public void testRelay() throws Exception {
    NettyHttpService httpServer = NettyHttpService.builder("test").setHttpHandlers(new TestHandler()).build();
    httpServer.start();
    try {
        TrafficRelayServer relayServer = new TrafficRelayServer(InetAddress.getLoopbackAddress(), httpServer::getBindAddress);
        relayServer.startAndWait();
        try {
            InetSocketAddress relayAddr = relayServer.getBindAddress();
            // GET
            URL url = new URL(String.format("http://%s:%d/ping", relayAddr.getHostName(), relayAddr.getPort()));
            HttpResponse response = HttpRequests.execute(HttpRequest.get(url).build(), new DefaultHttpRequestConfig(false));
            Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
            // POST
            url = new URL(String.format("http://%s:%d/echo", relayAddr.getHostName(), relayAddr.getPort()));
            response = HttpRequests.execute(HttpRequest.post(url).withBody("Testing").build(), new DefaultHttpRequestConfig(false));
            Assert.assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
            Assert.assertEquals("Testing", response.getResponseBodyAsString());
        } finally {
            relayServer.stopAndWait();
        }
    } finally {
        httpServer.stop();
    }
}
Also used : TestHandler(io.cdap.cdap.internal.app.runtime.monitor.proxy.TestHandler) InetSocketAddress(java.net.InetSocketAddress) DefaultHttpRequestConfig(io.cdap.cdap.common.http.DefaultHttpRequestConfig) NettyHttpService(io.cdap.http.NettyHttpService) HttpResponse(io.cdap.common.http.HttpResponse) URL(java.net.URL) TrafficRelayServer(io.cdap.cdap.internal.app.runtime.monitor.TrafficRelayServer) Test(org.junit.Test)

Aggregations

DefaultHttpRequestConfig (io.cdap.cdap.common.http.DefaultHttpRequestConfig)82 HttpResponse (io.cdap.common.http.HttpResponse)62 URL (java.net.URL)56 Test (org.junit.Test)50 HttpRequest (io.cdap.common.http.HttpRequest)24 RunnableTaskRequest (io.cdap.cdap.api.service.worker.RunnableTaskRequest)14 URI (java.net.URI)14 InetSocketAddress (java.net.InetSocketAddress)12 Discoverable (org.apache.twill.discovery.Discoverable)12 RandomEndpointStrategy (io.cdap.cdap.common.discovery.RandomEndpointStrategy)8 Gson (com.google.gson.Gson)7 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)6 ETLBatchConfig (io.cdap.cdap.etl.proto.v2.ETLBatchConfig)6 ETLStage (io.cdap.cdap.etl.proto.v2.ETLStage)6 HttpRequestConfig (io.cdap.common.http.HttpRequestConfig)6 File (java.io.File)6 SConfiguration (io.cdap.cdap.common.conf.SConfiguration)4 ResolvingDiscoverable (io.cdap.cdap.common.discovery.ResolvingDiscoverable)4 NoOpInternalAuthenticator (io.cdap.cdap.common.internal.remote.NoOpInternalAuthenticator)4 RemoteClient (io.cdap.cdap.common.internal.remote.RemoteClient)4