Java Code Examples for com.sun.jersey.api.client.Client#setConnectTimeout()
The following examples show how to use
com.sun.jersey.api.client.Client#setConnectTimeout() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Neo4jDBHandler.java From Insights with Apache License 2.0 | 6 votes |
/** * @param requestJson * @return ClientResponse */ private ClientResponse doCommitCall(JsonObject requestJson) { Client client = Client.create(); if(ApplicationConfigProvider.getInstance().getGraph().getConnectionExpiryTimeOut() != null) { client.setConnectTimeout(ApplicationConfigProvider.getInstance().getGraph().getConnectionExpiryTimeOut() * 1000); } WebResource resource = client // .resource("http://localhost:7474/db/data/transaction/commit"); .resource(ApplicationConfigProvider.getInstance().getGraph().getEndpoint() + "/db/data/transaction/commit"); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON) .header("Authorization", ApplicationConfigProvider.getInstance().getGraph().getAuthToken()) // ClientResponse response = resource.accept( MediaType.APPLICATION_JSON // ).header("Authorization", "Basic bmVvNGo6YWRtaW4=") .type(MediaType.APPLICATION_JSON).entity(requestJson.toString()).post(ClientResponse.class); return response; }
Example 2
Source File: Neo4jDBHandler.java From Insights with Apache License 2.0 | 6 votes |
/** * Add the field index for give label and field * * @param label * @param field * @return */ public JsonObject addFieldIndex(String label, String field) { JsonObject requestJson = new JsonObject(); JsonArray properties = new JsonArray(); properties.add(field); requestJson.add("property_keys", properties); Client client = Client.create(); if(ApplicationConfigProvider.getInstance().getGraph().getConnectionExpiryTimeOut() != null) { client.setConnectTimeout(ApplicationConfigProvider.getInstance().getGraph().getConnectionExpiryTimeOut() * 1000); } WebResource resource = client.resource( ApplicationConfigProvider.getInstance().getGraph().getEndpoint() + "/db/data/schema/index/" + label); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON) .header("Authorization", ApplicationConfigProvider.getInstance().getGraph().getAuthToken()) .type(MediaType.APPLICATION_JSON).entity(requestJson.toString()).post(ClientResponse.class); return new JsonParser().parse(response.getEntity(String.class)).getAsJsonObject(); }
Example 3
Source File: ElasticSearchDBHandler.java From Insights with Apache License 2.0 | 6 votes |
public String search(String url) { ClientResponse response = null; String result = ""; try { Client client = Client.create(); client.setConnectTimeout(5001); WebResource resource = client.resource(url); response = resource.accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON) .get(ClientResponse.class); result = response.getEntity(String.class); } catch (Exception e) { log.error("Exception while getting data of url " + url, e); } finally { if (response != null) { response.close(); } } return result; }
Example 4
Source File: RemoteNiFiUtils.java From localization_nifi with Apache License 2.0 | 5 votes |
private Client getClient(final SSLContext sslContext) { final Client client; if (sslContext == null) { client = WebUtils.createClient(null); } else { client = WebUtils.createClient(null, sslContext); } client.setReadTimeout(READ_TIMEOUT); client.setConnectTimeout(CONNECT_TIMEOUT); return client; }
Example 5
Source File: OlogClient.java From phoebus with Eclipse Public License 1.0 | 5 votes |
private OlogClient(URI ologURI, ClientConfig config, boolean withHTTPBasicAuthFilter, String username, String password) { config.getClasses().add(MultiPartWriter.class); Client client = Client.create(config); if (withHTTPBasicAuthFilter) { client.addFilter(new HTTPBasicAuthFilter(username, password)); } if (Logger.getLogger(OlogClient.class.getName()).isLoggable(Level.ALL)) { client.addFilter(new RawLoggingFilter(Logger.getLogger(OlogClient.class.getName()))); } client.setFollowRedirects(true); client.setConnectTimeout(3000); this.service = client.resource(UriBuilder.fromUri(ologURI).build()); }
Example 6
Source File: Neo4jDBHandler.java From Insights with Apache License 2.0 | 5 votes |
/** * Load the available field indices in Neo4J * * @return */ public JsonArray loadFieldIndices() { Client client = Client.create(); if(ApplicationConfigProvider.getInstance().getGraph().getConnectionExpiryTimeOut() != null) { client.setConnectTimeout(ApplicationConfigProvider.getInstance().getGraph().getConnectionExpiryTimeOut() * 1000); } WebResource resource = client .resource(ApplicationConfigProvider.getInstance().getGraph().getEndpoint() + "/db/data/schema/index"); ClientResponse response = resource.accept(MediaType.APPLICATION_JSON) .header("Authorization", ApplicationConfigProvider.getInstance().getGraph().getAuthToken()) .type(MediaType.APPLICATION_JSON).get(ClientResponse.class); return new JsonParser().parse(response.getEntity(String.class)).getAsJsonArray(); }
Example 7
Source File: SystemStatus.java From Insights with Apache License 2.0 | 5 votes |
public static String jerseyGetClientWithAuthentication(String url, String name, String password,String authtoken) { String output; String authStringEnc; ClientResponse response = null; try { if(authtoken==null) { String authString = name + ":" + password; authStringEnc= new BASE64Encoder().encode(authString.getBytes()); }else { authStringEnc=authtoken; } Client restClient = Client.create(); restClient.setConnectTimeout(5001); WebResource webResource = restClient.resource(url); response= webResource.accept("application/json") .header("Authorization", "Basic " + authStringEnc) .get(ClientResponse.class); if(response.getStatus() != 200){ throw new RuntimeException("Failed : HTTP error code : "+ response.getStatus()); }else { output= response.getEntity(String.class); } } catch (Exception e) { log.error(" error while getting jerseyGetClientWithAuthentication "+e.getMessage()); throw new RuntimeException("Failed : error while getting jerseyGetClientWithAuthentication : "+ e.getMessage()); }finally { if(response!=null) { response.close(); } } return output; }
Example 8
Source File: SystemStatus.java From Insights with Apache License 2.0 | 5 votes |
public static String jerseyPostClientWithAuthentication(String url, String name, String password, String authtoken, String data) { String output; String authStringEnc; ClientResponse response = null; try { if (authtoken == null) { String authString = name + ":" + password; authStringEnc = new BASE64Encoder().encode(authString.getBytes()); } else { authStringEnc = authtoken; } JsonParser parser = new JsonParser(); JsonElement dataJson = parser.parse(data);//new Gson().fromJson(data, JsonElement.class) Client restClient = Client.create(); restClient.setConnectTimeout(5001); WebResource webResource = restClient.resource(url); response = webResource.accept("application/json") //.header("Authorization", "Basic " + authStringEnc) .post(ClientResponse.class, dataJson.toString());//"{aa}" if (response.getStatus() != 200) { throw new RuntimeException("Failed : HTTP error code : " + response.getStatus()); } else { output = response.getEntity(String.class); } System.out.print(" response code " + response.getStatus() + " output " + output); } catch (Exception e) { System.out.println(" error while getGetting jerseyPostClientWithAuthentication " + e.getMessage()); throw new RuntimeException( "Failed : error while getGetting jerseyPostClientWithAuthentication : " + e.getMessage()); } finally { if (response != null) { response.close(); } } return output; }
Example 9
Source File: TestRestClientManager.java From conductor with Apache License 2.0 | 5 votes |
@Test public void clientDefaultsSetWhenRequestedAgain() { Configuration mockConfiguration = Mockito.mock(Configuration.class); Mockito.when(mockConfiguration.getIntProperty(Mockito.eq(RestClientManager.HTTP_TASK_CONNECT_TIMEOUT), Mockito.eq(RestClientManager.DEFAULT_CONNECT_TIMEOUT))).thenReturn(200); Mockito.when(mockConfiguration.getIntProperty(Mockito.eq(RestClientManager.HTTP_TASK_READ_TIMEOUT), Mockito.eq(RestClientManager.DEFAULT_READ_TIMEOUT))).thenReturn(170); RestClientManager clientManager = new RestClientManager(mockConfiguration); Client client = clientManager.getClient(null); client.setReadTimeout(90); client.setConnectTimeout(90); client = clientManager.getClient(null); Assert.assertEquals(client.getProperties().get("com.sun.jersey.client.property.readTimeout"),170); Assert.assertEquals(client.getProperties().get("com.sun.jersey.client.property.connectTimeout"),200); }
Example 10
Source File: RestClientManager.java From conductor with Apache License 2.0 | 4 votes |
public Client getClient(Input input) { Client client = threadLocalClient.get(); client.setReadTimeout(defaultReadTimeout); client.setConnectTimeout(defaultConnectTimeout); return client; }
Example 11
Source File: WebServiceClient.java From nextreports-server with Apache License 2.0 | 4 votes |
protected Client createJerseyClient() { ClientConfig config = new DefaultClientConfig(); // DefaultApacheHttpClientConfig config = new DefaultApacheHttpClientConfig(); config.getClasses().add(XStreamXmlProvider.class); // ApacheHttpClient client = ApacheHttpClient.create(config); if (server.startsWith("https")) { log("* Use https protocol"); try { initSSL(config); } catch (Exception ex) { if (tm != null) { try { installCertificates(); initSSL(config); } catch (Exception e) { throw new RuntimeException(e); } } else { throw new RuntimeException(ex); } } } Client client = Client.create(config); if (isDebug()) { client.addFilter(new LoggingFilter()); } if ((username != null) && (password != null)) { // client.addFilter(new HTTPBasicAuthFilter(username, password)); String encodedPassword = password; if (passwordEncoder != null) { encodedPassword = passwordEncoder.encode(password); } client.addFilter(new HttpBasicAuthenticationFilter(username, encodedPassword)); // config.getState().setCredentials(null, null, -1, username, encodedPassword); } if (timeout != UNDEFINED) { client.setConnectTimeout(timeout); } return client; }