Example usage for org.springframework.web.client RestTemplate getForObject

List of usage examples for org.springframework.web.client RestTemplate getForObject

Introduction

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

Prototype

@Override
    @Nullable
    public <T> T getForObject(String url, Class<T> responseType, Map<String, ?> uriVariables)
            throws RestClientException 

Source Link

Usage

From source file:org.egov.stms.transactions.service.SewerageThirdPartyServices.java

public AssessmentDetails getPropertyDetails(final String assessmentNumber, final HttpServletRequest request) {
    final RestTemplate restTemplate = new RestTemplate();

    final String url = String.format(PTIS_DETAILS_RESTURL, WebUtils.extractRequestDomainURL(request, false));

    if (LOGGER.isInfoEnabled()) {

        LOGGER.info("Request URL : " + request.getRequestURL());
        LOGGER.info("Extract DOMAIN URL : " + WebUtils.extractRequestDomainURL(request, false));

        LOGGER.info("Response : " + restTemplate.getForObject(url, AssessmentDetails.class, assessmentNumber));
    }// w ww  . j  a va2s .  co m
    return restTemplate.getForObject(url, AssessmentDetails.class, assessmentNumber);

}

From source file:org.egov.wtms.application.service.WaterConnectionDetailsService.java

public AssessmentDetails getPropertyDetails(final String assessmentNumber, final HttpServletRequest request) {
    final RestTemplate restTemplate = new RestTemplate();
    final String url = String.format(PTIS_DETAILS_URL, WebUtils.extractRequestDomainURL(request, false));
    return restTemplate.getForObject(url, AssessmentDetails.class, assessmentNumber);
}

From source file:org.jboss.windup.decorator.integration.mvn.MavenCentralSHA1VersionDecorator.java

@Override
public void processMeta(ZipMetadata meta) {
    if (!active) {
        return;//  ww  w. j a  v a 2s  .  c  o m
    }
    if (!knownArchiveProfiler.isExclusivelyKnownArchive(meta)) {
        return;
    }

    String sha1Hash = null;
    for (AbstractDecoration result : meta.getDecorations()) {
        if (result instanceof PomVersion) {
            LOG.debug("Already has version result: " + result.toString());
            return;
        } else if (result instanceof Hash) {
            if (((Hash) result).getHashType() == HashType.SHA1) {
                sha1Hash = ((Hash) result).getHash();
            }
        }
    }

    if (sha1Hash == null) {
        LOG.debug("No SHA-1 Hash found. Returning.");
        return;
    }
    LOG.info("No Version Found: " + meta.getRelativePath() + "; trying Maven Central");
    if (LOG.isDebugEnabled()) {
        LOG.debug("SHA1: " + sha1Hash);
    }
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJacksonHttpMessageConverter());

    try {
        MavenCentralSHA1VersionResponseWrapper result = restTemplate.getForObject(MAVEN_API_URL,
                MavenCentralSHA1VersionResponseWrapper.class, sha1Hash);

        if (result != null && result.getResponse() != null && result.getResponse().getNumFound() > 0) {
            MavenCentralSHA1VersionResponseItem rsp = result.getResponse().getDocs()[0];
            String groupId = rsp.getGroupId();
            String artifactId = rsp.getArtifactId();
            String version = rsp.getVersion();

            String url = generateUrl(groupId, artifactId, version);

            // pull the POM from the URL.
            ClientHttpRequestFactory request = new SimpleClientHttpRequestFactory();
            try {
                ClientHttpRequest pomRequest = request.createRequest(new URI(url), HttpMethod.GET);
                ClientHttpResponse resp = pomRequest.execute();

                String outputDir = meta.getArchiveOutputDirectory().getAbsolutePath() + File.separator
                        + "maven-remote";
                FileUtils.forceMkdir(new File(outputDir));

                File outputPath = new File(outputDir + File.separator + "pom.xml");
                IOUtils.copy(new InputStreamReader(resp.getBody()), new FileOutputStream(outputPath));

                XmlMetadata xmlMeta = new XmlMetadata();
                xmlMeta.setFilePointer(outputPath);
                xmlMeta.setArchiveMeta(meta);

                pomInterrogator.processMeta(xmlMeta);
                LOG.info("Fetched remote POM for: " + meta.getName());
            } catch (Exception e) {
                LOG.error("Exception fetching remote POM: " + url + "; skipping.", e);
            }
        } else {
            if (LOG.isDebugEnabled()) {
                LOG.debug("No Version Information Found in Maven Central for: " + sha1Hash);
            }
        }
    } catch (Exception e) {
        LOG.error("Exception creating API call to Central Repo for POM: " + meta.getName() + "; skipping.", e);
    }
}