|
|
|
Java demo
This code shows how to use RecogniContact/Web in a Java
project.
Demo project download
http://address-parser.com/DemoJava.zip
This demo project contains
- a complete Java demo project ready to compile and run
- all required packages
NOTE! You will need a valid RecogniContact license to run
this demo.
Before running the demo, please insert the license key in the
source code where indicated.
Demo source code
package wsif.client;
import javax.xml.namespace.QName;
import org.apache.wsif.WSIFException;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFPort;
import org.apache.wsif.WSIFService;
import org.apache.wsif.WSIFServiceFactory;
import RecogniContactWebServiceIntf.LicenseInfo;
import RecogniContactWebServiceIntf.ParsingResult;
import RecogniContactWebServiceIntf.UsageStats;
import RecogniContactWebServiceIntf.VersionInfo;
public class WSIFClient {
public static void main(String[] args) throws Exception {
String licenseKey="(License Key)";
String textToParse =
"Dr. Walter W. Wagoner - Exhibition Manager\n"+
"The Museum of Modern Art\n"+
"Address: 11 West 53 Street, New York, NY 10019\n"+
"Phone: (212) 708-9400\n"+
"Email: info@moma.org\n"+
"Web: www.moma.org\n";
try {
WSIFPort port = GetWSIFPort();
System.out.println("LICENSE INFORMATION\n");
LicenseInfo myLicenseInfo = getLicenseInfo(port, licenseKey);
System.out.println(
"\nLicenseExpiryDateAsString= " + myLicenseInfo.getLicenseExpiryDateAsString()+
"\nMaxParsings= " + myLicenseInfo.getMaxParsings().toString()+
"\nMaxParsingsPerDay= " + myLicenseInfo.getMaxParsingsPerDay().toString()+
"\nMaxParsingsPerWeek= " + myLicenseInfo.getMaxParsingsPerWeek().toString()+
"\nMaxParsingsPerMonth= " + myLicenseInfo.getMaxParsingsPerMonth().toString()+
"\nMaxParsingsPerQuarter= " + myLicenseInfo.getMaxParsingsPerQuarter().toString()+
"\nMaxParsingsPerYear= " + myLicenseInfo.getMaxParsingsPerYear().toString()+
"\nCallerIPRange= " + myLicenseInfo.getCallerIPRange()+
"\nParserCountries= " + myLicenseInfo.getParserCountries()+
"\nUserName= " + myLicenseInfo.getUserName()+
"\nUserInfo= " + myLicenseInfo.getUserInfo());
System.out.println("\n\nUSAGE STATISTICS\n");
UsageStats myUsageStats = getUsageStats(port, licenseKey);
System.out.println(
"\nNumberParsings= "+myUsageStats.getNumberParsings().toString()+
"\nNumberParsingsToday= "+myUsageStats.getNumberParsingsToday().toString()+
"\nNumberParsingsThisWeek= "+myUsageStats.getNumberParsingsThisWeek().toString()+
"\nNumberParsingsThisMonth= "+myUsageStats.getNumberParsingsThisMonth().toString()+
"\nNumberParsingsThisQuarter= "+myUsageStats.getNumberParsingsThisQuarter().toString()+
"\nNumberParsingsThisYear= "+myUsageStats.getNumberParsingsThisYear().toString());
System.out.println("\n\nVERSION INFORMATION\n");
System.out.println("ParserVersionAsString= "+getParserVersionAsString(port)+"\n");
System.out.println("InterfaceVersionAsString()="+getInterfaceVersionAsString(port)+"\n");
ParsingResult myParsingResult = parse(port, licenseKey, textToParse);
System.out.println("\n\nPARSING RESULT\n");
System.out.println(
"Prefix= "+myParsingResult.getPrefix()+
"\nFirstName= "+myParsingResult.getFirstName()+
"\nMiddleName= "+myParsingResult.getMiddleName()+
"\nLastName= "+myParsingResult.getLastName()+
"\nSuffix= "+myParsingResult.getSuffix()+
"\nCompany= "+myParsingResult.getCompany()+
"\nCompany2= "+myParsingResult.getCompany2()+
"\nPosition= "+myParsingResult.getPosition()+
"\nStreetAddress1= "+myParsingResult.getStreetAddress1()+
"\nStreetAddress2= "+myParsingResult.getStreetAddress2()+
"\nPostboxAddress= "+myParsingResult.getPostboxAddress()+
"\nPostboxPostCode="+myParsingResult.getPostboxPostCode()+
"\nPostCode= "+myParsingResult.getPostCode()+
"\nPlaceName= "+myParsingResult.getPlaceName()+
"\nProvince= "+myParsingResult.getProvince()+
"\nCountry= "+myParsingResult.getCountry()+
"\nPhone1= "+myParsingResult.getPhone1()+
"\nPhone2= "+myParsingResult.getPhone2()+
"\nMobile= "+myParsingResult.getMobile()+
"\nFax= "+myParsingResult.getFax()+
"\nEmail= "+myParsingResult.getEmail()+
"\nUrl= "+myParsingResult.getUrl()+
"\nGender= "+myParsingResult.getGender()+
"\nCountryIsoCode= "+myParsingResult.getCountryIsoCode());
String[] unrecognized= myParsingResult.getUnrecognizedItems().split("\\|");
System.out.println(unrecognized.length+" unrecognized item(s)");
for (int i=0;i<unrecognized.length;i++) {
System.out.println("Item "+i+": "+unrecognized[i]);
}
} catch(Throwable tx) {
tx.printStackTrace();
}
}
public static WSIFPort GetWSIFPort() throws WSIFException {
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service =
factory.getService(
"http://loquisoft.net/cgi-bin/RecogniContactWebService.exe/wsdl/IRecogniContactWebService",
null,
null,
"http://loquisoft.net/",
"IRecogniContactWebService");
service.mapType(
new QName("urn:RecogniContactWebServiceIntf", "ParsingResult"),
RecogniContactWebServiceIntf.ParsingResult.class);
service.mapType(
new QName("urn:RecogniContactWebServiceIntf", "UsageStats"),
RecogniContactWebServiceIntf.UsageStats.class);
service.mapType(
new QName("urn:RecogniContactWebServiceIntf", "VersionInfo"),
RecogniContactWebServiceIntf.VersionInfo.class);
service.mapType(
new QName("urn:RecogniContactWebServiceIntf", "LicenseInfo"),
RecogniContactWebServiceIntf.LicenseInfo.class);
return service.getPort();
}
private static VersionInfo getParserVersion(WSIFPort port) throws WSIFException {
WSIFOperation operation = port.createOperation("GetParserVersion");
WSIFMessage input = operation.createInputMessage();
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
if (operation.executeRequestResponseOperation(input, output, fault)) {
return (VersionInfo) output.getObjectPart("return");
} else {
return null;
}
}
private static String getParserVersionAsString(WSIFPort port) throws WSIFException {
WSIFOperation operation = port.createOperation("GetParserVersionAsString");
WSIFMessage input = operation.createInputMessage();
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
if (operation.executeRequestResponseOperation(input, output, fault)) {
return (String) output.getObjectPart("return");
} else {
return null;
}
}
private static VersionInfo getInterfaceVersion(WSIFPort port) throws WSIFException {
WSIFOperation operation = port.createOperation("GetInterfaceVersion");
WSIFMessage input = operation.createInputMessage();
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
if (operation.executeRequestResponseOperation(input, output, fault)) {
return (VersionInfo) output.getObjectPart("return");
} else {
return null;
}
}
private static String getInterfaceVersionAsString(WSIFPort port) throws WSIFException {
WSIFOperation operation = port.createOperation("GetInterfaceVersionAsString");
WSIFMessage input = operation.createInputMessage();
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
if (operation.executeRequestResponseOperation(input, output, fault)) {
return (String) output.getObjectPart("return");
} else {
return null;
}
}
private static LicenseInfo getLicenseInfo(WSIFPort port, String licenseKey) throws WSIFException {
WSIFOperation operation = port.createOperation("GetLicenseInfo");
WSIFMessage input = operation.createInputMessage();
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
input.setObjectPart("licenseKey", licenseKey);
if (operation.executeRequestResponseOperation(input, output, fault)) {
return (LicenseInfo) output.getObjectPart("return");
} else {
return null;
}
}
private static UsageStats getUsageStats(WSIFPort port, String licenseKey) throws WSIFException {
WSIFOperation operation = port.createOperation("GetUsageStats");
WSIFMessage input = operation.createInputMessage();
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
input.setObjectPart("licenseKey", licenseKey);
if (operation.executeRequestResponseOperation(input, output, fault)) {
return (UsageStats) output.getObjectPart("return");
} else {
return null;
}
}
private static ParsingResult parse(WSIFPort port, String licenseKey, String textToParse) throws WSIFException {
WSIFOperation operation = port.createOperation("Parse");
WSIFMessage input = operation.createInputMessage();
WSIFMessage output = operation.createOutputMessage();
WSIFMessage fault = operation.createFaultMessage();
input.setObjectPart("licenseKey", licenseKey);
input.setObjectPart("stringToParse", textToParse);
if (operation.executeRequestResponseOperation(input, output, fault)) {
return (ParsingResult) output.getObjectPart("return");
} else {
return null;
}
}
}
|