I am new to the topic of consuming web services, and I want to consume it in Java EE.This is link I can not do it, greetings in advance
According to the link site, you have to consume this information as an XML file. The following code works, ie it connects and consumes the XML, in this case it printed the information related to santoral and currency, it is just an example.
package com.proyecto.init;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
public class Main {
public static void main(String[] args) throws IOException, ParserConfigurationException, SAXException {
// TODO Auto-generated method stub
consumir();
}
public static void imprimeLista(NodeList lista)
{
for (int index=0;index<lista.getLength();index++)
{
System.out.println(lista.item(index).getNodeName()+" "+lista.item(index).getTextContent());
}
}
public static void consumir() throws IOException, ParserConfigurationException, SAXException
{
URL url= new URL("http://indicadoresdeldia.cl/webservice/indicadores.xml");
URLConnection urlConnection = url.openConnection();
urlConnection.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
InputStream input = new BufferedInputStream(urlConnection.getInputStream());
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(input);
NodeList listaSantoral = doc.getElementsByTagName("santoral").item(0).getChildNodes();
NodeList listaMoneda=doc.getElementsByTagName("moneda").item(0).getChildNodes();
imprimeLista(listaSantoral);
imprimeLista(listaMoneda);
}
}
In the following link you find all the information about webservices, in the final part is the step by step explanation of how to consume a web service from JAVA using NetBeans:
I hope I clarify the doubts, since your question is very open.