Search in sources :

Example 56 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project cu-kfs by CU-CommunityApps.

the class PaymentWorksWebServiceCallsServiceImpl method buildXmlOutput.

private Response buildXmlOutput(URI uri) {
    Client client = null;
    Response response = null;
    try {
        ClientConfig clientConfig = new ClientConfig();
        client = ClientBuilder.newClient(clientConfig);
        Invocation request = buildXmlClientRequest(client, uri);
        response = request.invoke();
        response.bufferEntity();
        return response;
    } finally {
        CURestClientUtils.closeQuietly(client);
    }
}
Also used : Response(javax.ws.rs.core.Response) Invocation(javax.ws.rs.client.Invocation) Client(javax.ws.rs.client.Client) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 57 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project kafka-streams-examples by confluentinc.

the class EndToEndTest method getClient.

private Client getClient() {
    final ClientConfig clientConfig = new ClientConfig();
    clientConfig.property(ClientProperties.CONNECT_TIMEOUT, 60000).property(ClientProperties.READ_TIMEOUT, 60000);
    return ClientBuilder.newClient(clientConfig);
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 58 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project crnk-framework by crnk-project.

the class JsonApiResponseFilterTestBase method setup.

@BeforeClass
public static void setup() {
    ClientConfig config = new ClientConfig();
    config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
    httpClient = ClientBuilder.newClient(config);
}
Also used : ClientConfig(org.glassfish.jersey.client.ClientConfig) BeforeClass(org.junit.BeforeClass)

Example 59 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project ff4j by ff4j.

the class AbstractEmbeddedGrizzlyIntegrationTest method initOnce.

@BeforeClass
public static void initOnce() throws IOException {
    // WebContext for testing
    webappContext = new WebappContext("Test Context");
    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerResponseFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
    servletRegistration.setInitParameter("com.sun.jersey.spi.container.ContainerRequestFilters", "com.sun.jersey.api.container.filter.LoggingFilter");
    servletRegistration.setInitParameter("javax.ws.rs.Application", SampleFF4jJersey2Application.class.getCanonicalName());
    servletRegistration.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", "true");
    servletRegistration.addMapping("/*");
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.register(JacksonJsonProvider.class);
    clientConfig.register(FF4jJacksonMapper.class);
    client = ClientBuilder.newClient(clientConfig);
    server = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", HOST, PORT);
    server.addListener(listener);
    webappContext.deploy(server);
}
Also used : ServletRegistration(org.glassfish.grizzly.servlet.ServletRegistration) WebappContext(org.glassfish.grizzly.servlet.WebappContext) HttpServer(org.glassfish.grizzly.http.server.HttpServer) SampleFF4jJersey2Application(org.ff4j.web.api.test.SampleFF4jJersey2Application) ClientConfig(org.glassfish.jersey.client.ClientConfig) NetworkListener(org.glassfish.grizzly.http.server.NetworkListener) BeforeClass(org.junit.BeforeClass)

Example 60 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project incubator-pulsar by apache.

the class ProxyPublishConsumeTest method testProxyStats.

/**
 * It verifies proxy topic-stats and proxy-metrics api
 *
 * @throws Exception
 */
@Test(timeOut = 10000)
public void testProxyStats() throws Exception {
    final String topic = "my-property/use/my-ns/my-topic6";
    final String consumerUri = "ws://localhost:" + port + "/ws/consumer/persistent/" + topic + "/my-sub?subscriptionType=Failover";
    final String producerUri = "ws://localhost:" + port + "/ws/producer/persistent/" + topic + "/";
    final String readerUri = "ws://localhost:" + port + "/ws/reader/persistent/" + topic;
    System.out.println(consumerUri + ", " + producerUri);
    URI consumeUri = URI.create(consumerUri);
    URI produceUri = URI.create(producerUri);
    URI readUri = URI.create(readerUri);
    WebSocketClient consumeClient1 = new WebSocketClient();
    SimpleConsumerSocket consumeSocket1 = new SimpleConsumerSocket();
    WebSocketClient produceClient = new WebSocketClient();
    SimpleProducerSocket produceSocket = new SimpleProducerSocket();
    WebSocketClient readClient = new WebSocketClient();
    SimpleConsumerSocket readSocket = new SimpleConsumerSocket();
    try {
        consumeClient1.start();
        ClientUpgradeRequest consumeRequest1 = new ClientUpgradeRequest();
        Future<Session> consumerFuture1 = consumeClient1.connect(consumeSocket1, consumeUri, consumeRequest1);
        log.info("Connecting to : {}", consumeUri);
        readClient.start();
        ClientUpgradeRequest readRequest = new ClientUpgradeRequest();
        Future<Session> readerFuture = readClient.connect(readSocket, readUri, readRequest);
        log.info("Connecting to : {}", readUri);
        Assert.assertTrue(consumerFuture1.get().isOpen());
        Assert.assertTrue(readerFuture.get().isOpen());
        Thread.sleep(500);
        ClientUpgradeRequest produceRequest = new ClientUpgradeRequest();
        produceClient.start();
        Future<Session> producerFuture = produceClient.connect(produceSocket, produceUri, produceRequest);
        // let it connect
        Assert.assertTrue(producerFuture.get().isOpen());
        // sleep so, proxy can deliver few messages to consumers for stats
        int retry = 0;
        int maxRetry = 400;
        while (consumeSocket1.getReceivedMessagesCount() < 2) {
            Thread.sleep(10);
            if (retry++ > maxRetry) {
                final String msg = String.format("Consumer still has not received the message after %s ms", (maxRetry * 10));
                log.warn(msg);
                break;
            }
        }
        Client client = ClientBuilder.newClient(new ClientConfig().register(LoggingFeature.class));
        final String baseUrl = pulsar.getWebServiceAddress().replace(Integer.toString(pulsar.getConfiguration().getWebServicePort()), (Integer.toString(port))) + "/admin/proxy-stats/";
        // verify proxy metrics
        verifyProxyMetrics(client, baseUrl);
        // verify proxy stats
        verifyProxyStats(client, baseUrl, topic);
        // verify topic stat
        verifyTopicStat(client, baseUrl, topic);
    } finally {
        stopWebSocketClient(consumeClient1, produceClient);
    }
}
Also used : LoggingFeature(org.glassfish.jersey.logging.LoggingFeature) ClientUpgradeRequest(org.eclipse.jetty.websocket.client.ClientUpgradeRequest) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) Client(javax.ws.rs.client.Client) WebSocketClient(org.eclipse.jetty.websocket.client.WebSocketClient) ClientConfig(org.glassfish.jersey.client.ClientConfig) URI(java.net.URI) Session(org.eclipse.jetty.websocket.api.Session) Test(org.testng.annotations.Test)

Aggregations

ClientConfig (org.glassfish.jersey.client.ClientConfig)169 Client (javax.ws.rs.client.Client)129 Test (org.junit.Test)85 Response (javax.ws.rs.core.Response)66 JerseyTest (org.glassfish.jersey.test.JerseyTest)52 WebTarget (javax.ws.rs.client.WebTarget)48 ClientBuilder (javax.ws.rs.client.ClientBuilder)17 SSLContext (javax.net.ssl.SSLContext)12 Invocation (javax.ws.rs.client.Invocation)12 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)10 IOException (java.io.IOException)9 IntegrationTest (com.hortonworks.streamline.common.test.IntegrationTest)8 URI (java.net.URI)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 PoolingHttpClientConnectionManager (org.apache.http.impl.conn.PoolingHttpClientConnectionManager)7 CountDownLatch (java.util.concurrent.CountDownLatch)6 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)5