- C#
- Java
Address Detective International C# Rest Code Snippet
string primaryurl = "https://trial.serviceobjects.com/adi/api.svc/" + format + "/FindBestCountry?CompanyName=" + companyName + "&FullName=" + fullName + "&FirstName=" + firstName + "&LastName=" + lastName + "&Address1=" + address1 + "&Address2=" + address2 + "&Address3=" + address3 + "&Address4=" + address4 + "&Address5=" + address5 + "&Address6=" + address6 + "&Address7=" + address7 + "&Address8=" + address8 + "&Locality=" + locality + "&AdminArea=" + adminArea + "&PostalCode=" + postalCode + "&Phone1=" + phone1 + "&Phone2=" + phone2 + "&Phone3=" + phone3 + "&Email=" + email + "&IPAddress=" + ipAddress + "&LicenseKey=" + licensekey;
string backupurl = "https://trial.serviceobjects.com/adi/api.svc/" + format + "/FindBestCountry?CompanyName=" + companyName + "&FullName=" + fullName + "&FirstName=" + firstName + "&LastName=" + lastName + "&Address1=" + address1 + "&Address2=" + address2 + "&Address3=" + address3 + "&Address4=" + address4 + "&Address5=" + address5 + "&Address6=" + address6 + "&Address7=" + address7 + "&Address8=" + address8 + "&Locality=" + locality + "&AdminArea=" + adminArea + "&PostalCode=" + postalCode + "&Phone1=" + phone1 + "&Phone2=" + phone2 + "&Phone3=" + phone3 + "&Email=" + email + "&IPAddress=" + ipAddress + "&LicenseKey=" + licensekey;
try
{
wsresponse = httpGet(primaryurl);
//checks if a response was returned from the service, uses the backup url if response is null or a fatal error occured.
if (wsresponse == null || (wsresponse.Error != null && wsresponse.Error.TypeCode == "3"))
{
throw new Exception("Primary Call Received an Unhandled erros");
}
}
catch (Exception ex)
{
try
{
wsresponse = httpGet(backupurl);
}
catch (Exception err)
{
//Displays the relevant error mesasge if both backup and primary urls failed. You will likely want to log this somewhere
StatusLabel.Text = err.Message;
StatusLabel.Visible = true;
}
//Displays the relevant error mesasge if both backup and primary urls failed.
StatusLabel.Text = ex.Message;
StatusLabel.Visible = true;
}
if (wsresponse.Error != null)
{
ProcessErrorResponse(wsresponse.Error);
}
else
{
ProcessSuccessfulResponse(wsresponse);
}
private CountryDetectionResponse httpGet(string url)
{
try
{
//NOTE: URL encoding occurs automatically when creating the web request
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Timeout = 15000;//timeout for get operation
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).",
response.StatusCode,
response.StatusDescription));
//parses XML response into the AVIResponse object
XmlSerializer serializer = new XmlSerializer(typeof(CountryDetectionResponse));
StreamReader reader = new StreamReader(response.GetResponseStream());
CountryDetectionResponse output = new CountryDetectionResponse();
output = (CountryDetectionResponse)serializer.Deserialize(reader);
return output;
}
}
catch (Exception e)
{
throw e;
}
}
private void ProcessSuccessfulResponse(CountryDetectionResponse outputs)
{
DataTable dtoutput = new DataTable();
dtoutput.Columns.Add("Outputs", typeof(string));
dtoutput.Columns.Add("Values", typeof(string));
dtoutput.Rows.Add("Status", outputs.CountryDetection.Status);
dtoutput.Rows.Add("TotalScore", outputs.CountryDetection.TotalScore);
dtoutput.Rows.Add("Notes", outputs.CountryDetection.Notes);
dtoutput.Rows.Add("NotesDesc", outputs.CountryDetection.NotesDesc);
dtoutput.Rows.Add("Warnings", outputs.CountryDetection.Warnings);
dtoutput.Rows.Add("WarningsDesc", outputs.CountryDetection.WarningsDesc);
.
.
.
dtoutput.Rows.Add("Email_CountryISO2", outputs.CountryDetection.Email_CountryISO2);
dtoutput.Rows.Add("Email_CountryISO3", outputs.CountryDetection.Email_CountryISO3);
dtoutput.Rows.Add("Email_AllCountriesFoundISO2", outputs.CountryDetection.Email_AllCountriesFoundISO2);
//Checks for the existence of the Information Compoents object and then prints the resulting values if they arise.
ResultGrid.Visible = true;
StatusLabel.Visible = true;
ResultGrid.DataSource = new DataView(dtoutput);
ResultGrid.DataBind();
}
private void ProcessErrorResponse(Error errorResponse)
{
DataTable dtError = new DataTable();
dtError.Columns.Add("Outputs", typeof(string));
dtError.Columns.Add("Values", typeof(string));
dtError.Rows.Add("Type", errorResponse.Type);
dtError.Rows.Add("TypeCode", errorResponse.TypeCode);
dtError.Rows.Add("Desc", errorResponse.Desc);
dtError.Rows.Add("DescCode", errorResponse.DescCode);
ResultGrid.Visible = true;
StatusLabel.Visible = true;
ResultGrid.DataSource = new DataView(dtError);
ResultGrid.DataBind();
}
string primaryurl = "https://trial.serviceobjects.com/adi/api.svc/" + format + "/FindBestCountry?CompanyName=" + companyName + "&FullName=" + fullName + "&FirstName=" + firstName + "&LastName=" + lastName + "&Address1=" + address1 + "&Address2=" + address2 + "&Address3=" + address3 + "&Address4=" + address4 + "&Address5=" + address5 + "&Address6=" + address6 + "&Address7=" + address7 + "&Address8=" + address8 + "&Locality=" + locality + "&AdminArea=" + adminArea + "&PostalCode=" + postalCode + "&Phone1=" + phone1 + "&Phone2=" + phone2 + "&Phone3=" + phone3 + "&Email=" + email + "&IPAddress=" + ipAddress + "&LicenseKey=" + licensekey;
string backupurl = "https://trial.serviceobjects.com/adi/api.svc/" + format + "/FindBestCountry?CompanyName=" + companyName + "&FullName=" + fullName + "&FirstName=" + firstName + "&LastName=" + lastName + "&Address1=" + address1 + "&Address2=" + address2 + "&Address3=" + address3 + "&Address4=" + address4 + "&Address5=" + address5 + "&Address6=" + address6 + "&Address7=" + address7 + "&Address8=" + address8 + "&Locality=" + locality + "&AdminArea=" + adminArea + "&PostalCode=" + postalCode + "&Phone1=" + phone1 + "&Phone2=" + phone2 + "&Phone3=" + phone3 + "&Email=" + email + "&IPAddress=" + ipAddress + "&LicenseKey=" + licensekey;
try
{
wsresponse = httpGet(primaryurl);
//checks if a response was returned from the service, uses the backup url if response is null or a fatal error occured.
if (wsresponse == null || (wsresponse.Error != null && wsresponse.Error.TypeCode == "3"))
{
throw new Exception("Primary Call Received an Unhandled erros");
}
}
catch (Exception ex)
{
try
{
wsresponse = httpGet(backupurl);
}
catch (Exception err)
{
//Displays the relevant error mesasge if both backup and primary urls failed. You will likely want to log this somewhere
StatusLabel.Text = err.Message;
StatusLabel.Visible = true;
}
//Displays the relevant error mesasge if both backup and primary urls failed.
StatusLabel.Text = ex.Message;
StatusLabel.Visible = true;
}
if (wsresponse.Error != null)
{
ProcessErrorResponse(wsresponse.Error);
}
else
{
ProcessSuccessfulResponse(wsresponse);
}
private CountryDetectionResponse httpGet(string url)
{
try
{
//NOTE: URL encoding occurs automatically when creating the web request
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Timeout = 15000;//timeout for get operation
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
if (response.StatusCode != HttpStatusCode.OK)
throw new Exception(String.Format(
"Server error (HTTP {0}: {1}).",
response.StatusCode,
response.StatusDescription));
//parses XML response into the AVIResponse object
XmlSerializer serializer = new XmlSerializer(typeof(CountryDetectionResponse));
StreamReader reader = new StreamReader(response.GetResponseStream());
CountryDetectionResponse output = new CountryDetectionResponse();
output = (CountryDetectionResponse)serializer.Deserialize(reader);
return output;
}
}
catch (Exception e)
{
throw e;
}
}
private void ProcessSuccessfulResponse(CountryDetectionResponse outputs)
{
DataTable dtoutput = new DataTable();
dtoutput.Columns.Add("Outputs", typeof(string));
dtoutput.Columns.Add("Values", typeof(string));
dtoutput.Rows.Add("Status", outputs.CountryDetection.Status);
dtoutput.Rows.Add("TotalScore", outputs.CountryDetection.TotalScore);
dtoutput.Rows.Add("Notes", outputs.CountryDetection.Notes);
dtoutput.Rows.Add("NotesDesc", outputs.CountryDetection.NotesDesc);
dtoutput.Rows.Add("Warnings", outputs.CountryDetection.Warnings);
dtoutput.Rows.Add("WarningsDesc", outputs.CountryDetection.WarningsDesc);
.
.
.
dtoutput.Rows.Add("Email_CountryISO2", outputs.CountryDetection.Email_CountryISO2);
dtoutput.Rows.Add("Email_CountryISO3", outputs.CountryDetection.Email_CountryISO3);
dtoutput.Rows.Add("Email_AllCountriesFoundISO2", outputs.CountryDetection.Email_AllCountriesFoundISO2);
//Checks for the existence of the Information Compoents object and then prints the resulting values if they arise.
ResultGrid.Visible = true;
StatusLabel.Visible = true;
ResultGrid.DataSource = new DataView(dtoutput);
ResultGrid.DataBind();
}
private void ProcessErrorResponse(Error errorResponse)
{
DataTable dtError = new DataTable();
dtError.Columns.Add("Outputs", typeof(string));
dtError.Columns.Add("Values", typeof(string));
dtError.Rows.Add("Type", errorResponse.Type);
dtError.Rows.Add("TypeCode", errorResponse.TypeCode);
dtError.Rows.Add("Desc", errorResponse.Desc);
dtError.Rows.Add("DescCode", errorResponse.DescCode);
ResultGrid.Visible = true;
StatusLabel.Visible = true;
ResultGrid.DataSource = new DataView(dtError);
ResultGrid.DataBind();
}
string primaryurl = "https://trial.serviceobjects.com/adi/api.svc/" + format + "/FindBestCountry?CompanyName=" + companyName + "&FullName=" + fullName + "&FirstName=" + firstName + "&LastName=" + lastName + "&Address1=" + address1 + "&Address2=" + address2 + "&Address3=" + address3 + "&Address4=" + address4 + "&Address5=" + address5 + "&Address6=" + address6 + "&Address7=" + address7 + "&Address8=" + address8 + "&Locality=" + locality + "&AdminArea=" + adminArea + "&PostalCode=" + postalCode + "&Phone1=" + phone1 + "&Phone2=" + phone2 + "&Phone3=" + phone3 + "&Email=" + email + "&IPAddress=" + ipAddress + "&LicenseKey=" + licensekey; string backupurl = "https://trial.serviceobjects.com/adi/api.svc/" + format + "/FindBestCountry?CompanyName=" + companyName + "&FullName=" + fullName + "&FirstName=" + firstName + "&LastName=" + lastName + "&Address1=" + address1 + "&Address2=" + address2 + "&Address3=" + address3 + "&Address4=" + address4 + "&Address5=" + address5 + "&Address6=" + address6 + "&Address7=" + address7 + "&Address8=" + address8 + "&Locality=" + locality + "&AdminArea=" + adminArea + "&PostalCode=" + postalCode + "&Phone1=" + phone1 + "&Phone2=" + phone2 + "&Phone3=" + phone3 + "&Email=" + email + "&IPAddress=" + ipAddress + "&LicenseKey=" + licensekey; try { wsresponse = httpGet(primaryurl); //checks if a response was returned from the service, uses the backup url if response is null or a fatal error occured. if (wsresponse == null || (wsresponse.Error != null && wsresponse.Error.TypeCode == "3")) { throw new Exception("Primary Call Received an Unhandled erros"); } } catch (Exception ex) { try { wsresponse = httpGet(backupurl); } catch (Exception err) { //Displays the relevant error mesasge if both backup and primary urls failed. You will likely want to log this somewhere StatusLabel.Text = err.Message; StatusLabel.Visible = true; } //Displays the relevant error mesasge if both backup and primary urls failed. StatusLabel.Text = ex.Message; StatusLabel.Visible = true; } if (wsresponse.Error != null) { ProcessErrorResponse(wsresponse.Error); } else { ProcessSuccessfulResponse(wsresponse); } private CountryDetectionResponse httpGet(string url) { try { //NOTE: URL encoding occurs automatically when creating the web request HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Timeout = 15000;//timeout for get operation using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) throw new Exception(String.Format( "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); //parses XML response into the AVIResponse object XmlSerializer serializer = new XmlSerializer(typeof(CountryDetectionResponse)); StreamReader reader = new StreamReader(response.GetResponseStream()); CountryDetectionResponse output = new CountryDetectionResponse(); output = (CountryDetectionResponse)serializer.Deserialize(reader); return output; } } catch (Exception e) { throw e; } } private void ProcessSuccessfulResponse(CountryDetectionResponse outputs) { DataTable dtoutput = new DataTable(); dtoutput.Columns.Add("Outputs", typeof(string)); dtoutput.Columns.Add("Values", typeof(string)); dtoutput.Rows.Add("Status", outputs.CountryDetection.Status); dtoutput.Rows.Add("TotalScore", outputs.CountryDetection.TotalScore); dtoutput.Rows.Add("Notes", outputs.CountryDetection.Notes); dtoutput.Rows.Add("NotesDesc", outputs.CountryDetection.NotesDesc); dtoutput.Rows.Add("Warnings", outputs.CountryDetection.Warnings); dtoutput.Rows.Add("WarningsDesc", outputs.CountryDetection.WarningsDesc); . . . dtoutput.Rows.Add("Email_CountryISO2", outputs.CountryDetection.Email_CountryISO2); dtoutput.Rows.Add("Email_CountryISO3", outputs.CountryDetection.Email_CountryISO3); dtoutput.Rows.Add("Email_AllCountriesFoundISO2", outputs.CountryDetection.Email_AllCountriesFoundISO2); //Checks for the existence of the Information Compoents object and then prints the resulting values if they arise. ResultGrid.Visible = true; StatusLabel.Visible = true; ResultGrid.DataSource = new DataView(dtoutput); ResultGrid.DataBind(); } private void ProcessErrorResponse(Error errorResponse) { DataTable dtError = new DataTable(); dtError.Columns.Add("Outputs", typeof(string)); dtError.Columns.Add("Values", typeof(string)); dtError.Rows.Add("Type", errorResponse.Type); dtError.Rows.Add("TypeCode", errorResponse.TypeCode); dtError.Rows.Add("Desc", errorResponse.Desc); dtError.Rows.Add("DescCode", errorResponse.DescCode); ResultGrid.Visible = true; StatusLabel.Visible = true; ResultGrid.DataSource = new DataView(dtError); ResultGrid.DataBind(); }
Address Detective International Java Rest Code Snippet
//We'll pull these values from the input form
String Address1 = request.getParameter("address1");
String Address2 = request.getParameter("address2");
String Address3 = request.getParameter("address3");
String Address4 = request.getParameter("address4");
String Address5 = request.getParameter("address5");
String Address6 = request.getParameter("address6");
String Address7 = request.getParameter("address7");
String Address8 = request.getParameter("address8");
String Locality = request.getParameter("locality");
String AdminArea = request.getParameter("adminarea");
String PostalCode = request.getParameter("postalcode");
String Phone1 = request.getParameter("phone1");
String Phone2 = request.getParameter("phone2");
String Phone3 = request.getParameter("phone3");
String Email = request.getParameter("email");
String IPAddress = request.getParameter("ipaddress");
String Domain = request.getParameter("domain");
String LicenseKey = request.getParameter("licensekey");
Address1 = URLEncoder.encode(Address1,"UTF-8").replaceAll("+", "%20");
Address2 = URLEncoder.encode(Address2,"UTF-8").replaceAll("+", "%20");
Address3 = URLEncoder.encode(Address3,"UTF-8").replaceAll("+", "%20");
Address4 = URLEncoder.encode(Address4,"UTF-8").replaceAll("+", "%20");
Address5 = URLEncoder.encode(Address5,"UTF-8").replaceAll("+", "%20");
Address6 = URLEncoder.encode(Address6,"UTF-8").replaceAll("+", "%20");
Address7 = URLEncoder.encode(Address7,"UTF-8").replaceAll("+", "%20");
Address8 = URLEncoder.encode(Address8,"UTF-8").replaceAll("+", "%20");
Locality = URLEncoder.encode(Locality,"UTF-8").replaceAll("+", "%20");
AdminArea = URLEncoder.encode(AdminArea,"UTF-8").replaceAll("+", "%20");
PostalCode = URLEncoder.encode(PostalCode,"UTF-8").replaceAll("+", "%20");
Phone1 = URLEncoder.encode(Phone1,"UTF-8").replaceAll("+", "%20");
Phone2 = URLEncoder.encode(Phone2,"UTF-8").replaceAll("+", "%20");
Phone3 = URLEncoder.encode(Phone3,"UTF-8").replaceAll("+", "%20");
Email = URLEncoder.encode(Email,"UTF-8").replaceAll("+", "%20");
IPAddress = URLEncoder.encode(IPAddress,"UTF-8").replaceAll("+", "%20");
Domain = URLEncoder.encode(Domain,"UTF-8").replaceAll("+", "%20");
LicenseKey = URLEncoder.encode(LicenseKey,"UTF-8").replaceAll("+", "%20");
//Set the primary and backup URLs as necessary. In production, the primary endpoint should be pointed to sws.serviceobjects.com and the backup should be pointed to swsbackup.serviceobjects.com
String mainUrl = "https://trial.serviceobjects.com/adi/api.svc/XML/FindBestCountry?CompanyName=" + CompanyName + "&FullName=" + FullName+ "&FirstName=" + FirstName + "&LastName=" + LastName + "&Address1=" + Address1 + "&Address2=" + Address2 + "&Address3=" + Address3 + "&Address4=" + Address4 + "&Address5=" + Address5 + "&Address6=" + Address6 + "&Address7=" + Address7 + "&Address8=" + Address8 + "&Locality=" + Locality + "&AdminArea=" + AdminArea + "&PostalCode=" +PostalCode + "&Phone1=" + Phone1 + "&Phone2=" + Phone2 + "&Phone3=" + Phone3 +"&Email=" + Email + "&IPAddress=" + IPAddress + "&Domain=" + Domain + "&LicenseKey=" + LicenseKey;
String backupUrl = "https://trial.serviceobjects.com//adi/api.svc/XML/FindBestCountry?CompanyName=" + CompanyName + "&FullName=" + FullName+ "&FirstName=" + FirstName + "&LastName=" + LastName + "&Address1=" + Address1 + "&Address2=" + Address2 + "&Address3=" + Address3 + "&Address4=" + Address4 + "&Address5=" + Address5 + "&Address6=" + Address6 + "&Address7=" + Address7 + "&Address8=" + Address8 + "&Locality=" + Locality + "&AdminArea=" + AdminArea + "&PostalCode=" +PostalCode + "&Phone1=" + Phone1 + "&Phone2=" + Phone2 + "&Phone3=" + Phone3 +"&Email=" + Email + "&IPAddress=" + IPAddress + "&Domain=" + Domain + "&LicenseKey=" + LicenseKey;
ADIRest adirestClient = new ADIRest();
JSONObject results = new JSONObject();
results = adirestClient.AddressResponse(mainUrl, backupUrl);
if (results.getJSONObject("CountryDetectionResponse").has("Error") )
{
JSONObject errorResponse = results.getJSONObject("CountryDetectionResponse").getJSONObject("Error") ;
string Type = errorResponse.get("Type");
.
.
.
}else{
JSONObject validresponse = results.getJSONObject("CountryDetectionResponse").getJSONObject("CountryDetection");
string status = validresponse.get("Status");
.
.
.
string totalScore = validresponse.get("TotalScore");
}
//We'll pull these values from the input form
String Address1 = request.getParameter("address1");
String Address2 = request.getParameter("address2");
String Address3 = request.getParameter("address3");
String Address4 = request.getParameter("address4");
String Address5 = request.getParameter("address5");
String Address6 = request.getParameter("address6");
String Address7 = request.getParameter("address7");
String Address8 = request.getParameter("address8");
String Locality = request.getParameter("locality");
String AdminArea = request.getParameter("adminarea");
String PostalCode = request.getParameter("postalcode");
String Phone1 = request.getParameter("phone1");
String Phone2 = request.getParameter("phone2");
String Phone3 = request.getParameter("phone3");
String Email = request.getParameter("email");
String IPAddress = request.getParameter("ipaddress");
String Domain = request.getParameter("domain");
String LicenseKey = request.getParameter("licensekey");
Address1 = URLEncoder.encode(Address1,"UTF-8").replaceAll("+", "%20");
Address2 = URLEncoder.encode(Address2,"UTF-8").replaceAll("+", "%20");
Address3 = URLEncoder.encode(Address3,"UTF-8").replaceAll("+", "%20");
Address4 = URLEncoder.encode(Address4,"UTF-8").replaceAll("+", "%20");
Address5 = URLEncoder.encode(Address5,"UTF-8").replaceAll("+", "%20");
Address6 = URLEncoder.encode(Address6,"UTF-8").replaceAll("+", "%20");
Address7 = URLEncoder.encode(Address7,"UTF-8").replaceAll("+", "%20");
Address8 = URLEncoder.encode(Address8,"UTF-8").replaceAll("+", "%20");
Locality = URLEncoder.encode(Locality,"UTF-8").replaceAll("+", "%20");
AdminArea = URLEncoder.encode(AdminArea,"UTF-8").replaceAll("+", "%20");
PostalCode = URLEncoder.encode(PostalCode,"UTF-8").replaceAll("+", "%20");
Phone1 = URLEncoder.encode(Phone1,"UTF-8").replaceAll("+", "%20");
Phone2 = URLEncoder.encode(Phone2,"UTF-8").replaceAll("+", "%20");
Phone3 = URLEncoder.encode(Phone3,"UTF-8").replaceAll("+", "%20");
Email = URLEncoder.encode(Email,"UTF-8").replaceAll("+", "%20");
IPAddress = URLEncoder.encode(IPAddress,"UTF-8").replaceAll("+", "%20");
Domain = URLEncoder.encode(Domain,"UTF-8").replaceAll("+", "%20");
LicenseKey = URLEncoder.encode(LicenseKey,"UTF-8").replaceAll("+", "%20");
//Set the primary and backup URLs as necessary. In production, the primary endpoint should be pointed to sws.serviceobjects.com and the backup should be pointed to swsbackup.serviceobjects.com
String mainUrl = "https://trial.serviceobjects.com/adi/api.svc/XML/FindBestCountry?CompanyName=" + CompanyName + "&FullName=" + FullName+ "&FirstName=" + FirstName + "&LastName=" + LastName + "&Address1=" + Address1 + "&Address2=" + Address2 + "&Address3=" + Address3 + "&Address4=" + Address4 + "&Address5=" + Address5 + "&Address6=" + Address6 + "&Address7=" + Address7 + "&Address8=" + Address8 + "&Locality=" + Locality + "&AdminArea=" + AdminArea + "&PostalCode=" +PostalCode + "&Phone1=" + Phone1 + "&Phone2=" + Phone2 + "&Phone3=" + Phone3 +"&Email=" + Email + "&IPAddress=" + IPAddress + "&Domain=" + Domain + "&LicenseKey=" + LicenseKey;
String backupUrl = "https://trial.serviceobjects.com//adi/api.svc/XML/FindBestCountry?CompanyName=" + CompanyName + "&FullName=" + FullName+ "&FirstName=" + FirstName + "&LastName=" + LastName + "&Address1=" + Address1 + "&Address2=" + Address2 + "&Address3=" + Address3 + "&Address4=" + Address4 + "&Address5=" + Address5 + "&Address6=" + Address6 + "&Address7=" + Address7 + "&Address8=" + Address8 + "&Locality=" + Locality + "&AdminArea=" + AdminArea + "&PostalCode=" +PostalCode + "&Phone1=" + Phone1 + "&Phone2=" + Phone2 + "&Phone3=" + Phone3 +"&Email=" + Email + "&IPAddress=" + IPAddress + "&Domain=" + Domain + "&LicenseKey=" + LicenseKey;
ADIRest adirestClient = new ADIRest();
JSONObject results = new JSONObject();
results = adirestClient.AddressResponse(mainUrl, backupUrl);
if (results.getJSONObject("CountryDetectionResponse").has("Error") )
{
JSONObject errorResponse = results.getJSONObject("CountryDetectionResponse").getJSONObject("Error") ;
string Type = errorResponse.get("Type");
.
.
.
}else{
JSONObject validresponse = results.getJSONObject("CountryDetectionResponse").getJSONObject("CountryDetection");
string status = validresponse.get("Status");
.
.
.
string totalScore = validresponse.get("TotalScore");
}
//We'll pull these values from the input form String Address1 = request.getParameter("address1"); String Address2 = request.getParameter("address2"); String Address3 = request.getParameter("address3"); String Address4 = request.getParameter("address4"); String Address5 = request.getParameter("address5"); String Address6 = request.getParameter("address6"); String Address7 = request.getParameter("address7"); String Address8 = request.getParameter("address8"); String Locality = request.getParameter("locality"); String AdminArea = request.getParameter("adminarea"); String PostalCode = request.getParameter("postalcode"); String Phone1 = request.getParameter("phone1"); String Phone2 = request.getParameter("phone2"); String Phone3 = request.getParameter("phone3"); String Email = request.getParameter("email"); String IPAddress = request.getParameter("ipaddress"); String Domain = request.getParameter("domain"); String LicenseKey = request.getParameter("licensekey"); Address1 = URLEncoder.encode(Address1,"UTF-8").replaceAll("+", "%20"); Address2 = URLEncoder.encode(Address2,"UTF-8").replaceAll("+", "%20"); Address3 = URLEncoder.encode(Address3,"UTF-8").replaceAll("+", "%20"); Address4 = URLEncoder.encode(Address4,"UTF-8").replaceAll("+", "%20"); Address5 = URLEncoder.encode(Address5,"UTF-8").replaceAll("+", "%20"); Address6 = URLEncoder.encode(Address6,"UTF-8").replaceAll("+", "%20"); Address7 = URLEncoder.encode(Address7,"UTF-8").replaceAll("+", "%20"); Address8 = URLEncoder.encode(Address8,"UTF-8").replaceAll("+", "%20"); Locality = URLEncoder.encode(Locality,"UTF-8").replaceAll("+", "%20"); AdminArea = URLEncoder.encode(AdminArea,"UTF-8").replaceAll("+", "%20"); PostalCode = URLEncoder.encode(PostalCode,"UTF-8").replaceAll("+", "%20"); Phone1 = URLEncoder.encode(Phone1,"UTF-8").replaceAll("+", "%20"); Phone2 = URLEncoder.encode(Phone2,"UTF-8").replaceAll("+", "%20"); Phone3 = URLEncoder.encode(Phone3,"UTF-8").replaceAll("+", "%20"); Email = URLEncoder.encode(Email,"UTF-8").replaceAll("+", "%20"); IPAddress = URLEncoder.encode(IPAddress,"UTF-8").replaceAll("+", "%20"); Domain = URLEncoder.encode(Domain,"UTF-8").replaceAll("+", "%20"); LicenseKey = URLEncoder.encode(LicenseKey,"UTF-8").replaceAll("+", "%20"); //Set the primary and backup URLs as necessary. In production, the primary endpoint should be pointed to sws.serviceobjects.com and the backup should be pointed to swsbackup.serviceobjects.com String mainUrl = "https://trial.serviceobjects.com/adi/api.svc/XML/FindBestCountry?CompanyName=" + CompanyName + "&FullName=" + FullName+ "&FirstName=" + FirstName + "&LastName=" + LastName + "&Address1=" + Address1 + "&Address2=" + Address2 + "&Address3=" + Address3 + "&Address4=" + Address4 + "&Address5=" + Address5 + "&Address6=" + Address6 + "&Address7=" + Address7 + "&Address8=" + Address8 + "&Locality=" + Locality + "&AdminArea=" + AdminArea + "&PostalCode=" +PostalCode + "&Phone1=" + Phone1 + "&Phone2=" + Phone2 + "&Phone3=" + Phone3 +"&Email=" + Email + "&IPAddress=" + IPAddress + "&Domain=" + Domain + "&LicenseKey=" + LicenseKey; String backupUrl = "https://trial.serviceobjects.com//adi/api.svc/XML/FindBestCountry?CompanyName=" + CompanyName + "&FullName=" + FullName+ "&FirstName=" + FirstName + "&LastName=" + LastName + "&Address1=" + Address1 + "&Address2=" + Address2 + "&Address3=" + Address3 + "&Address4=" + Address4 + "&Address5=" + Address5 + "&Address6=" + Address6 + "&Address7=" + Address7 + "&Address8=" + Address8 + "&Locality=" + Locality + "&AdminArea=" + AdminArea + "&PostalCode=" +PostalCode + "&Phone1=" + Phone1 + "&Phone2=" + Phone2 + "&Phone3=" + Phone3 +"&Email=" + Email + "&IPAddress=" + IPAddress + "&Domain=" + Domain + "&LicenseKey=" + LicenseKey; ADIRest adirestClient = new ADIRest(); JSONObject results = new JSONObject(); results = adirestClient.AddressResponse(mainUrl, backupUrl); if (results.getJSONObject("CountryDetectionResponse").has("Error") ) { JSONObject errorResponse = results.getJSONObject("CountryDetectionResponse").getJSONObject("Error") ; string Type = errorResponse.get("Type"); . . . }else{ JSONObject validresponse = results.getJSONObject("CountryDetectionResponse").getJSONObject("CountryDetection"); string status = validresponse.get("Status"); . . . string totalScore = validresponse.get("TotalScore"); }