32 lines
2.7 KiB
HTML
32 lines
2.7 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>UserService.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">Client</a> > <a href="index.source.html" class="el_package">gogreen.client.rest</a> > <span class="el_source">UserService.java</span></div><h1>UserService.java</h1><pre class="source lang-java linenums">package gogreen.client.rest;
|
|
|
|
import gogreen.common.UserDTO;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.web.client.RestTemplateBuilder;
|
|
import org.springframework.context.annotation.Bean;
|
|
import org.springframework.http.*;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
@Component
|
|
<span class="fc" id="L13">public class UserService {</span>
|
|
@Autowired
|
|
RestTemplate restTemplate;
|
|
|
|
@Bean
|
|
public RestTemplate restTemplate(RestTemplateBuilder builder) {
|
|
<span class="nc" id="L19"> return builder.build();</span>
|
|
}
|
|
|
|
public UserDTO registerUser(String name, String password) {
|
|
<span class="fc" id="L23"> HttpHeaders headers = new HttpHeaders();</span>
|
|
<span class="fc" id="L24"> headers.set("Accept", MediaType.APPLICATION_JSON_VALUE);</span>
|
|
<span class="fc" id="L25"> UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl("http://localhost:8080/registerUser")</span>
|
|
<span class="fc" id="L26"> .queryParam("name", name)</span>
|
|
<span class="fc" id="L27"> .queryParam("password", password);</span>
|
|
<span class="fc" id="L28"> HttpEntity<?> entity = new HttpEntity<>(headers);</span>
|
|
<span class="fc" id="L29"> return this.restTemplate.getForObject(builder.build().encode().toUri(), UserDTO.class);</span>
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.2.201808211720</span></div></body></html> |