Example usage for org.springframework.web.client RestClientException RestClientException

List of usage examples for org.springframework.web.client RestClientException RestClientException

Introduction

In this page you can find the example usage for org.springframework.web.client RestClientException RestClientException.

Prototype

public RestClientException(String msg, Throwable ex) 

Source Link

Document

Construct a new instance of RestClientException with the given message and exception.

Usage

From source file:org.zalando.riptide.Router.java

final <A> Capture route(final ClientHttpResponse response, final List<HttpMessageConverter<?>> converters,
        final Selector<A> selector, final Collection<Binding<A>> bindings) {

    final Optional<A> attribute;

    try {//from  w w w.jav  a 2s. co m
        attribute = selector.attributeOf(response);
    } catch (final IOException e) {
        throw new RestClientException("Unable to retrieve attribute of response", e);
    }

    final Map<Optional<A>, Binding<A>> index = bindings.stream()
            .collect(toMap(Binding::getAttribute, identity(), this::denyDuplicates, LinkedHashMap::new));

    final Optional<Binding<A>> match = selector.select(attribute, index);

    try {
        if (match.isPresent()) {
            final Binding<A> binding = match.get();

            try {
                return binding.execute(response, converters);
            } catch (final NoRouteException e) {
                return propagateNoMatch(response, converters, index, e);
            }
        } else {
            return routeNone(response, converters, index);
        }
    } catch (final IOException e) {
        throw new RestClientException("Unable to execute binding", e);
    }
}

From source file:org.apache.ambari.view.internal.actor.repository.Scanner.java

private void scan() {
    log().info("Scanning URL '{}' for new packages.", url);

    Optional<Date> lastScannedTs = packageService.getLastScannedTimestamp(name);
    Long lastScanned = lastScannedTs.map(Date::getTime).orElse(0L);

    URI uri = null;/*from www  .j  a  v a2s  . c o m*/

    try {
        URIBuilder builder = new URIBuilder(url);
        builder.addParameter("after", String.valueOf(lastScanned));
        uri = builder.build();
    } catch (URISyntaxException e) {
        throw new RestClientException("URL Syntax error", e);
    }

    ApplicationsWrapper wrapper = ws.getForObject(uri, ApplicationsWrapper.class);
    packageService.updateApplications(wrapper.getApplications(), name);

    // Do Something
    scheduleRescanMessage();
}

From source file:org.opendaylight.defense4all.framework.cli.ControlappsConnector.java

public synchronized void postToControlApps(String urlPrefix, Object object) throws RestClientException {

    try {//from w ww. j a va  2s.c o  m
        String url = mkUrl(urlPrefix);
        HttpEntity<String> entity = buildHttpEntityFromObject(object);
        restTemplate.postForLocation(url, entity);
    } catch (Throwable e) {
        throw new RestClientException("Failed to post to controller " + RESTSERVICE_HOSTNAME, e);
    }
}

From source file:org.opendaylight.defense4all.framework.cli.ControlappsConnector.java

public synchronized void putToControlApps(String urlPrefix, Object object) throws RestClientException {

    try {//from w w w .  j a  v a 2 s.c om
        String url = mkUrl(urlPrefix);
        HttpEntity<String> entity = buildHttpEntityFromObject(object);
        restTemplate.put(url, entity);
    } catch (Throwable e) {
        throw new RestClientException("Failed to put to controller " + object + " to " + RESTSERVICE_HOSTNAME,
                e);
    }
}

From source file:org.opendaylight.defense4all.odl.controller.Connector.java

protected synchronized <T> T getFromController(String urlPrefix, TypeReference<?> typeRef,
        JsonPreprocessor preProcessor) throws RestClientException {

    T t;/*  w  w w  .  java 2s .  c  om*/
    try {
        String url = mkUrl(urlPrefix);
        log.debug("Caller: " + getMethodName(2) + " Class:" + typeRef.getType().toString()
                + " Invoking restTemplate.getForObject" + "Calling - URL: " + url + " JSON: ");
        String result = //restTemplate.getForObject(url, String.class);
                restCallWithAutorization(url, "admin", "admin");
        if (result == null)
            return null;
        // Don't print it to log - it may contain non-printable chars
        // log.debug("Caller: "+getMethodName(2)+" Class:"+typeRef.getType().toString()+" URL: "+url+" JSON: "+result.toString());
        if (preProcessor != null)
            result = preProcessor.preProcess(result);

        t = fasterxmlObjMapper.readValue(result, typeRef);
    } catch (Throwable e) {
        log.error("Failed to get from controller " + odlOFC.hostname, e);
        throw new RestClientException("Failed to get from controller " + odlOFC.hostname, e);
    }

    return t;
}

From source file:org.opendaylight.defense4all.framework.cli.ControlappsConnector.java

private HttpEntity<String> buildHttpEntityFromObject(Object object) throws RestClientException {

    String jsonStr;//from   ww  w  . j a v  a 2 s  . c o  m

    try {
        if (String.class.isInstance(object))
            jsonStr = (String) object;
        else
            jsonStr = objMapper.writeValueAsString(object);
    } catch (Throwable e) {
        String msg = "Failed to writeValueAsString ";
        throw new RestClientException(msg, e);
    }

    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    HttpEntity<String> entity = new HttpEntity<String>(jsonStr, headers);
    return entity;
}

From source file:org.opendaylight.defense4all.framework.cli.ControlappsConnector.java

public synchronized void putToControlApps(String urlPrefix) throws RestClientException {

    try {//from w  w w . j a  v a2s. co  m
        String url = mkUrl(urlPrefix);
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        restTemplate.put(url, null);
    } catch (Throwable e) {
        throw new RestClientException("Failed to put to controller " + RESTSERVICE_HOSTNAME, e);
    }
}

From source file:org.opendaylight.defense4all.framework.cli.ControlappsConnector.java

public synchronized void delFromControlApps(String urlPrefix) throws RestClientException {

    try {/*w ww.java2  s . co m*/
        String url = mkUrl(urlPrefix);
        restTemplate.delete(url);
    } catch (Throwable e) {
        throw new RestClientException("Failed to put to controller " + RESTSERVICE_HOSTNAME, e);
    }
}

From source file:org.opendaylight.defense4all.odl.controller.Connector.java

protected synchronized void postToController(String urlPrefix, Object object) throws RestClientException {

    try {//from w  ww  .  j  a v  a2 s .  c  om
        String url = mkUrl(urlPrefix);
        log.debug("Caller: URL: " + url);
        HttpEntity<String> entity = buildHttpEntityFromObject(object);
        restTemplate.postForLocation(url, entity);
    } catch (Throwable e) {
        log.error("Failed to post to controller " + odlOFC.hostname, e);
        throw new RestClientException("Failed to post to controller " + odlOFC.hostname, e);
    }
}

From source file:org.opendaylight.defense4all.odl.controller.Connector.java

protected synchronized void putToController(String urlPrefix, Object object) throws RestClientException {

    try {//ww w  . ja  v  a  2s  .  c  om
        String url = mkUrl(urlPrefix);
        log.debug("Caller: URL: " + url);
        HttpEntity<String> entity = buildHttpEntityFromObject(object);
        restTemplate.put(url, entity);
    } catch (Throwable e) {
        log.error("Failed to put to controller " + object + " to " + odlOFC.hostname, e);
        throw new RestClientException("Failed to put to controller " + object + " to " + odlOFC.hostname, e);
    }
}