Search in sources :

Example 41 with HttpClientErrorException

use of org.springframework.web.client.HttpClientErrorException in project promregator by promregator.

the class SingleTargetMetricsEndpoint method filterInstanceList.

@Override
protected List<Instance> filterInstanceList(List<Instance> instanceList) {
    String instanceId = String.format("%s:%s", applicationId, instanceNumber);
    Instance selectedInstance = null;
    for (Instance instance : instanceList) {
        if (instance.getInstanceId().equals(instanceId)) {
            selectedInstance = instance;
            break;
        }
    }
    if (selectedInstance == null) {
        throw new HttpClientErrorException(HttpStatus.NOT_FOUND);
    }
    List<Instance> response = new LinkedList<Instance>();
    response.add(selectedInstance);
    return response;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) Instance(org.cloudfoundry.promregator.scanner.Instance) LinkedList(java.util.LinkedList)

Example 42 with HttpClientErrorException

use of org.springframework.web.client.HttpClientErrorException in project elastest-torm by elastest.

the class TJobService method executeTJob.

public TJobExecution executeTJob(Long tJobId, List<Parameter> parameters, List<Parameter> sutParameters) throws HttpClientErrorException {
    TJob tJob = tJobRepo.findOne(tJobId);
    SutSpecification sut = tJob.getSut();
    // activating yet
    if (sut != null && sut.isInstrumentedByElastest() && sut.getEimMonitoringConfig() != null && sut.getEimMonitoringConfig().getBeatsStatus() == BeatsStatusEnum.ACTIVATING) {
        throw new HttpClientErrorException(HttpStatus.ACCEPTED);
    }
    TJobExecution tJobExec = new TJobExecution();
    tJobExec.setStartDate(new Date());
    if (tJob.getSut() != null && sutParameters != null && !sutParameters.isEmpty()) {
        tJob.getSut().setParameters(sutParameters);
    }
    tJobExec.setTjob(tJob);
    if (parameters != null && !parameters.isEmpty()) {
        tJobExec.setParameters(parameters);
    }
    tJobExec = tJobExecRepositoryImpl.save(tJobExec);
    // After first save, get real Id
    tJobExec.generateMonitoringIndex();
    tJobExec = tJobExecRepositoryImpl.save(tJobExec);
    Future<Void> asyncExec;
    if (!tJob.isExternal()) {
        asyncExec = tJobExecOrchestratorService.executeTJob(tJobExec, tJob.getSelectedServices());
        asyncExecs.put(getMapNameByTJobExec(tJobExec), asyncExec);
    } else {
        tJobExecOrchestratorService.executeExternalJob(tJobExec);
    }
    return tJobExec;
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) TJobExecution(io.elastest.etm.model.TJobExecution) SutSpecification(io.elastest.etm.model.SutSpecification) TJob(io.elastest.etm.model.TJob) Date(java.util.Date)

Example 43 with HttpClientErrorException

use of org.springframework.web.client.HttpClientErrorException in project nextprot-api by calipho-sib.

the class SparqlProxyEndpointImpl method sparqlInternal.

private ResponseEntity<String> sparqlInternal(String queryString) {
    ResponseEntity<String> responseEntity;
    String url = sparqlEndpoint.getUrl() + ((queryString != null) ? ("?" + queryString) : "");
    try {
        RestTemplate template = new RestTemplate();
        responseEntity = template.getForEntity(new URI(url), String.class);
        return responseEntity;
    } catch (HttpServerErrorException | HttpClientErrorException e) {
        throw new NextProtException(e.getResponseBodyAsString(), e);
    } catch (RestClientException | URISyntaxException e) {
        throw new NextProtException(e);
    }
}
Also used : NextProtException(org.nextprot.api.commons.exception.NextProtException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) RestTemplate(org.springframework.web.client.RestTemplate) RestClientException(org.springframework.web.client.RestClientException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException)

Example 44 with HttpClientErrorException

use of org.springframework.web.client.HttpClientErrorException in project x-pipe by ctripcorp.

the class RetryNTimesTest method testGetOriginalException.

@Test
public void testGetOriginalException() {
    assertTrue(RetryNTimes.getOriginalException(new IOException("test")) instanceof IOException);
    assertTrue(RetryNTimes.getOriginalException(new ExecutionException(new IllegalArgumentException("test"))) instanceof IllegalArgumentException);
    assertTrue(RetryNTimes.getOriginalException(new ExecutionException(null)) instanceof ExecutionException);
    assertTrue(RetryNTimes.getOriginalException(new ExecutionException(new InvocationTargetException(new HttpClientErrorException(HttpStatus.BAD_REQUEST, "test")))) instanceof HttpClientErrorException);
    assertTrue(RetryNTimes.getOriginalException(new ExecutionException(new InvocationTargetException(null))) instanceof InvocationTargetException);
    assertTrue(RetryNTimes.getOriginalException(new InvocationTargetException(new IOException("test"))) instanceof IOException);
    assertTrue(RetryNTimes.getOriginalException(new InvocationTargetException(null)) instanceof InvocationTargetException);
    assertFalse(RetryNTimes.getOriginalException(new InvocationTargetException(new IOException())) instanceof InvocationTargetException);
    assertFalse(RetryNTimes.getOriginalException(new ExecutionException(new InvocationTargetException(new IOException("test")))) instanceof ExecutionException);
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test) AbstractTest(com.ctrip.xpipe.AbstractTest)

Example 45 with HttpClientErrorException

use of org.springframework.web.client.HttpClientErrorException in project spring-framework by spring-projects.

the class SimpleUrlHandlerMappingIntegrationTests method testHandlerNotFound.

@ParameterizedHttpServerTest
void testHandlerNotFound(HttpServer httpServer) throws Exception {
    startServer(httpServer);
    URI url = new URI("http://localhost:" + this.port + "/oops");
    RequestEntity<Void> request = RequestEntity.get(url).build();
    try {
        new RestTemplate().exchange(request, byte[].class);
    } catch (HttpClientErrorException ex) {
        assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
    }
}
Also used : HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) RestTemplate(org.springframework.web.client.RestTemplate) URI(java.net.URI)

Aggregations

HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)113 HttpHeaders (org.springframework.http.HttpHeaders)31 Test (org.junit.Test)25 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24 HashMap (java.util.HashMap)21 HttpServerErrorException (org.springframework.web.client.HttpServerErrorException)21 MediaType (org.springframework.http.MediaType)19 RestTemplate (org.springframework.web.client.RestTemplate)19 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)18 HttpEntity (org.springframework.http.HttpEntity)16 URI (java.net.URI)15 Map (java.util.Map)8 HttpStatus (org.springframework.http.HttpStatus)8 RestClientException (org.springframework.web.client.RestClientException)8 ResourceAccessException (org.springframework.web.client.ResourceAccessException)7 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)6 Date (java.util.Date)5 List (java.util.List)5 OpenAppNamespaceDTO (com.ctrip.framework.apollo.openapi.dto.OpenAppNamespaceDTO)4 ArrayList (java.util.ArrayList)4