Created
November 11, 2011 22:57
-
-
Save lbernstein/1359580 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.net.URL; | |
| import javax.xml.bind.JAXBContext; | |
| import javax.xml.bind.Unmarshaller; | |
| import javax.xml.bind.annotation.XmlElement; | |
| import javax.xml.bind.annotation.XmlRootElement; | |
| public class IpCaller | |
| { | |
| public static void main(String[] args) throws Exception | |
| { | |
| URL api = new URL("http://api.demandbase.com/api/v2/ip.xml?key=<Your_Demandbase_Key>&query=208.92.40.133"); | |
| JAXBContext context = JAXBContext.newInstance(CompanyData.class); | |
| Unmarshaller unmarshaller = context.createUnmarshaller(); | |
| CompanyData data = (CompanyData) unmarshaller.unmarshal(api.openConnection().getInputStream()); | |
| System.out.println("Company data object from xml : \n" + data); | |
| } | |
| // Map XML to company data object fields of interest | |
| @XmlRootElement(name="result") | |
| private static class CompanyData | |
| { | |
| @XmlElement(name="demandbase-sid") | |
| public Long sid; | |
| @XmlElement(name="company-name") | |
| public String companyName; | |
| @XmlElement(name="city") | |
| public String city; | |
| @XmlElement(name="state") | |
| public String state; | |
| @XmlElement(name="country-code") | |
| public String countryCode; | |
| @XmlElement(name="isp") | |
| public Boolean isp; | |
| @Override | |
| public String toString() | |
| { | |
| return "\tsid = " + sid + "\n" + | |
| "\tCompany Name = " + companyName + "\n" + | |
| "\tCity = " + city +" \n " + | |
| "\tState = " + state + "\n" + | |
| "\tCountry Code = " + countryCode + "\n" + | |
| "\tisp = " + isp; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment