PAVv3 JAVA

From CDYNE Wiki
Jump to navigation Jump to search

Verify Address

 1 import java.io.ByteArrayOutputStream;
 2 import java.io.InputStream;
 3 import java.net.URI;
 4 import java.net.URL;
 5 import java.net.MalformedURLException;
 6 import java.net.URISyntaxException;
 7 import java.util.Map;
 8 import java.util.Properties;
 9 
10 import javax.xml.namespace.QName;
11 import javax.xml.transform.OutputKeys;
12 import javax.xml.transform.Source;
13 import javax.xml.transform.Transformer;
14 import javax.xml.transform.TransformerFactory;
15 import javax.xml.transform.dom.DOMSource;
16 import javax.xml.transform.stream.StreamResult;
17 import javax.xml.transform.stream.StreamSource;
18 import javax.xml.ws.Dispatch;
19 import javax.xml.ws.Service;
20 import javax.xml.ws.handler.MessageContext;
21 import javax.xml.ws.http.HTTPBinding;
22 
23 import org.w3c.dom.Document;
24 
25 public final class VerifyAddress{
26 
27     public static void main(String[] args) {
28 
29 	String LicenseKey = "(Your License Key)";
30 
31 	try{
32 		URL url = new URL("http://pav3.cdyne.com/PavService.svc/VerifyAddress?FirmOrRecipient=Cdyne+Corporation&PrimaryAddressLine=2125+Smith+Ave&SecondaryAddressLine=&Urbanization=&CityName=Chesapeake&State=VA&ZipCode=23320&LicenseKey="+LicenseKey);		
33 		try{
34 			InputStream in = url.openStream();
35 
36 			StreamSource source = new StreamSource(in);
37 
38 			printResult(source);
39 	
40 		}catch(java.io.IOException e){
41 			e.printStackTrace();
42 		}
43 	
44 	}catch (MalformedURLException e){
45 		e.printStackTrace();
46 	}
47 
48     }
49 
50     private static void printResult(Source source) {
51         try {
52             ByteArrayOutputStream bos = new ByteArrayOutputStream();
53             StreamResult sr = new StreamResult(bos);
54             Transformer trans = TransformerFactory.newInstance().newTransformer();
55             Properties oprops = new Properties();
56             oprops.put(OutputKeys.OMIT_XML_DECLARATION, "yes");
57             trans.setOutputProperties(oprops);
58             trans.transform(source, sr);
59             System.out.println("**** Response ******");
60             System.out.println(bos.toString());
61             bos.close();
62             System.out.println();
63         } catch (Exception e) {
64             e.printStackTrace();
65         }
66     }
67 }