use of org.springframework.web.client.HttpClientErrorException in project ETSMobile-Android2 by ApplETS.
the class MonETSNotificationsRequest method loadDataFromNetwork.
@Override
public MonETSNotificationList loadDataFromNetwork() throws Exception {
accountManager = AccountManager.get(context);
Account[] accounts = accountManager.getAccountsByType(Constants.ACCOUNT_TYPE);
if (accounts.length > 0) {
authToken = accountManager.peekAuthToken(accounts[0], Constants.AUTH_TOKEN_TYPE);
}
String url = context.getString(R.string.portail_api_base_url);
if (onlyNewNotifs) {
url += "/api/notification/dossier/1";
} else {
url += "/api/notification";
}
ClientHttpRequestInterceptor interceptor = new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
HttpRequestWrapper requestWrapper = new HttpRequestWrapper(request);
requestWrapper.getHeaders().set("Cookie", authToken);
return execution.execute(requestWrapper, body);
}
};
RestTemplate restTemplate = getRestTemplate();
List<ClientHttpRequestInterceptor> list = new ArrayList<ClientHttpRequestInterceptor>();
list.add(interceptor);
restTemplate.setInterceptors(list);
try {
return restTemplate.getForObject(url, MonETSNotificationList.class);
} catch (HttpClientErrorException e) {
if (e.getStatusCode().value() == 401) {
if (accounts.length > 0) {
accountManager.invalidateAuthToken(Constants.ACCOUNT_TYPE, authToken);
authToken = accountManager.blockingGetAuthToken(accounts[0], Constants.AUTH_TOKEN_TYPE, true);
interceptor = new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
HttpRequestWrapper requestWrapper = new HttpRequestWrapper(request);
requestWrapper.getHeaders().set("Cookie", authToken);
return execution.execute(requestWrapper, body);
}
};
list.clear();
list.add(interceptor);
restTemplate.setInterceptors(list);
}
}
} finally {
return restTemplate.getForObject(url, MonETSNotificationList.class);
}
}
use of org.springframework.web.client.HttpClientErrorException in project h2o-2 by h2oai.
the class h2oService method BuildGBMModel.
public String BuildGBMModel(String destination_key, String source_key) {
/*http://localhost:54321/2/GBM.html?destination_key=gbm&source=prostate_csv2.hex&response=CAPSULE&ignored_cols=0&
classification=1&validation=&n_folds=0&holdout_fraction=.1&keep_cross_validation_splits=0&ntrees=50&max_depth=5&min_rows=10&nbins=20&score_each_iteration=0&importance=1&balance_classes=0
&class_sampling_factors=&max_after_balance_size=Infinity&checkpoint=&overwrite_checkpoint=1&family=AUTO&learn_rate=0.1&grid_parallelism=1&seed=-1&group_split=1
*/
String h2oUrlGBMEndPoint = H2O_HOST_URL + H2O_GBM_MODEL_URL + "destination_key={destination_key}&source={source}&response={response}&ignored_cols={ignored_cols}" + "&classification={classification}&validation={validation}" + "&ntrees={ntrees}&max_depth={max_depth}&min_rows={min_rows}&nbins={nbins}&score_each_iteration={score_each_iteration}" + "&importance={importance}&balance_classes={balance_classes}" + "&class_sampling_factors={class_sampling_factors}&max_after_balance_size={max_after_balance_size}&checkpoint={checkpoint}" + "&overwrite_checkpoint={overwrite_checkpoint}&family={family}&learn_rate={learn_rate}&grid_parallelism={grid_parallelism}&seed={seed}&group_split={group_split}";
System.out.println("@@@ h2oUrlGBMEndPoint : " + h2oUrlGBMEndPoint);
final HashMap<String, String> parameters = new HashMap<String, String>();
//MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
parameters.put("destination_key", destination_key);
parameters.put("source", source_key);
parameters.put("response", "CAPSULE");
parameters.put("ignored_cols", "0");
// this means regression
parameters.put("classification", "1");
parameters.put("validation", "");
parameters.put("n_folds", "10");
//parameters.put("holdout_fraction", "0.1");
parameters.put("keep_cross_validation_splits", "0");
parameters.put("ntrees", "50");
parameters.put("max_depth", "5");
parameters.put("min_rows", "10");
parameters.put("nbins", "20");
parameters.put("score_each_iteration", "0");
parameters.put("importance", "1");
parameters.put("balance_classes", "0");
parameters.put("class_sampling_factors", "");
parameters.put("max_after_balance_size", "Infinity");
parameters.put("checkpoint", "");
parameters.put("overwrite_checkpoint", "");
parameters.put("family", "AUTO");
parameters.put("learn_rate", "0.1");
parameters.put("grid_parallelism", "1");
parameters.put("seed", "-1");
parameters.put("group_split", "1");
try {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
//HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(parameters, headers);
//ResponseEntity<String> response = restTemplate.exchange(h2oUrlGBMEndPoint, HttpMethod.GET, request, String.class);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(h2oUrlGBMEndPoint, String.class, parameters);
String responseBody = responseEntity.getBody();
JSONObject jsonobject = new JSONObject(responseBody);
String job_key = (String) jsonobject.get("job_key");
String ret_destination_key = (String) jsonobject.get("destination_key");
System.out.println("!!!!!! GBM Job Key : " + job_key);
System.out.println("!!!!!! GBM Destination Key : " + ret_destination_key);
String gbm_status = GBMJobStatus(job_key, ret_destination_key);
if (gbm_status != null) {
System.out.println("gbm_status : " + gbm_status);
}
return ret_destination_key;
} catch (HttpClientErrorException e) {
log.debug("Error occured in building model {}", e.getResponseBodyAsString());
log.debug("Root cause in GBM {}", e.getRootCause().getMessage());
e.printStackTrace();
return null;
} catch (Exception ex) {
log.debug("!!!!!Error occured in deep learning {}", ex.getMessage());
ex.printStackTrace();
return null;
}
}
use of org.springframework.web.client.HttpClientErrorException in project apollo by ctripcorp.
the class AppControllerTest method testCreateTwice.
@Test
@Sql(scripts = "/controller/cleanup.sql", executionPhase = ExecutionPhase.AFTER_TEST_METHOD)
public void testCreateTwice() {
AppDTO dto = generateSampleDTOData();
ResponseEntity<AppDTO> response = restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
AppDTO first = response.getBody();
Assert.assertEquals(HttpStatus.OK, response.getStatusCode());
Assert.assertEquals(dto.getAppId(), first.getAppId());
Assert.assertTrue(first.getId() > 0);
App savedApp = appRepository.findOne(first.getId());
Assert.assertEquals(dto.getAppId(), savedApp.getAppId());
Assert.assertNotNull(savedApp.getDataChangeCreatedTime());
try {
restTemplate.postForEntity(getBaseAppUrl(), dto, AppDTO.class);
} catch (HttpClientErrorException e) {
Assert.assertEquals(HttpStatus.BAD_REQUEST, e.getStatusCode());
}
}
use of org.springframework.web.client.HttpClientErrorException in project webofneeds by researchstudio-sat.
the class ActiveMQServiceImpl method getBrokerEndpoint.
// todo: rename this method to getBrokerURIForNode
public final URI getBrokerEndpoint(URI resourceUri) {
logger.debug("obtaining broker URI for node {}", resourceUri);
URI activeMQEndpoint = null;
try {
logger.debug("trying to get broker endpoint for {} on resource {}", protocolType, resourceUri);
Path path = PathParser.parse(PATH_BROKER_URI, PrefixMapping.Standard);
Dataset resourceDataset = linkedDataSource.getDataForResource(resourceUri);
logger.debug("ResourceModel for {}: {}", resourceUri, resourceDataset);
activeMQEndpoint = RdfUtils.getURIPropertyForPropertyPath(resourceDataset, resourceUri, path);
// check if we've found the information we were looking for
if (activeMQEndpoint != null) {
return activeMQEndpoint;
}
logger.debug("could not to get broker URI from resource {}, trying to obtain won node URI", resourceUri);
// we didnt't get the queue name. Check if the model contains a triple <baseuri> won:hasWonNode
// <wonNode> and get the information from there.
URI wonNodeUri = WonLinkedDataUtils.getWonNodeURIForNeedOrConnection(resourceUri, resourceDataset);
logger.debug("wonNodeUri: {}", wonNodeUri);
resourceDataset = linkedDataSource.getDataForResource(wonNodeUri);
activeMQEndpoint = RdfUtils.getURIPropertyForPropertyPath(resourceDataset, wonNodeUri, path);
} catch (HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return null;
} else
throw e;
}
logger.debug("returning brokerUri {} for resourceUri {} ", activeMQEndpoint, resourceUri);
return activeMQEndpoint;
}
use of org.springframework.web.client.HttpClientErrorException in project webofneeds by researchstudio-sat.
the class ActiveMQServiceImpl method getProtocolQueueNameWithResource.
@Override
public final String getProtocolQueueNameWithResource(URI resourceUri) {
String activeMQOwnerProtocolQueueName = null;
try {
logger.debug("trying to get queue name prototol type {} on resource {}", protocolType, resourceUri);
Path path = PathParser.parse(queueNamePath, PrefixMapping.Standard);
Dataset resourceDataset = linkedDataSource.getDataForResource(resourceUri);
activeMQOwnerProtocolQueueName = RdfUtils.getStringPropertyForPropertyPath(resourceDataset, resourceUri, path);
// check if we've found the information we were looking for
if (activeMQOwnerProtocolQueueName != null) {
return activeMQOwnerProtocolQueueName;
}
logger.debug("could not to get queue name from resource {}, trying to obtain won node URI", resourceUri);
URI wonNodeUri = WonLinkedDataUtils.getWonNodeURIForNeedOrConnection(resourceUri, resourceDataset);
activeMQOwnerProtocolQueueName = RdfUtils.getStringPropertyForPropertyPath(linkedDataSource.getDataForResource(wonNodeUri), wonNodeUri, path);
// now, even if it's null, we return the result.
logger.debug("returning queue name {}", activeMQOwnerProtocolQueueName);
return activeMQOwnerProtocolQueueName;
} catch (HttpClientErrorException e) {
logger.warn("Could not obtain data for URI:{}", resourceUri);
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
return null;
} else
throw e;
}
}
Aggregations