Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package consometdsiws;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.URL;
- import model.Marca;
- public class ConsometdsiWS {
- private static final String targetURL =
- "http://localhost:8080/tdsiWS/webresources/tdsi/listarmarca";
- public static void main(String[] args) throws MalformedURLException, IOException {
- URL restServiceURL = new URL(targetURL);
- HttpURLConnection httpConnection = (HttpURLConnection) restServiceURL.openConnection();
- httpConnection.setRequestMethod("GET");
- httpConnection.setRequestProperty("Accept", "application/json");
- if (httpConnection.getResponseCode() != 200) {
- throw new RuntimeException("HTTP GET Request Failed with Error code : "
- + httpConnection.getResponseCode());
- }
- BufferedReader responseBuffer =
- new BufferedReader(new InputStreamReader((httpConnection.getInputStream())));
- String output;
- String json = new String();
- while ((output = responseBuffer.readLine()) != null) {
- json = json + output;
- }
- ObjectMapper mapper = new ObjectMapper();
- Marca marca;
- marca = mapper.readValue(json, Marca.class);
- httpConnection.disconnect();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement