RecogniContact/Web - International Address Parser Web Service - Java demo
SOAP Methods
class ParsingResult
class VersionInfo
class LicenseInfo
class UsageStats
Exceptions
PHP demo
C# demo
Java demo

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 {
       
        //----------------------------------------------------------------
        // Set license key
        //----------------------------------------------------------------

        String licenseKey="(License Key)";  //<---REPLACE WITH YOUR 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 {
            //----------------------------------------------------------------
            //Create SOAP Client
            //----------------------------------------------------------------
                
            WSIFPort port = GetWSIFPort();

            //----------------------------------------------------------------
            // Show License Information 
            //----------------------------------------------------------------
            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());            
  
          
            //----------------------------------------------------------------
            //Show Usage Statistics 
            //----------------------------------------------------------------
            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());
  
              
            //----------------------------------------------------------------
            // Show Version Information for Parser and Parser Interface
            //----------------------------------------------------------------
            System.out.println("\n\nVERSION INFORMATION\n");
            System.out.println("ParserVersionAsString=   "+getParserVersionAsString(port)+"\n");
            System.out.println("InterfaceVersionAsString()="+getInterfaceVersionAsString(port)+"\n");
            
            
            //----------------------------------------------------------------
            // Call Parser 
            //----------------------------------------------------------------

            //NOTE!
            //  parse() tries to interpret the entire text as an address/contact data string.
            //To SEARCH a text - such as CVs, resumes, web sites - for address and contact  
            //information and parse it, use 
            //  findAndParse() 
            
            ParsingResult myParsingResult = parse(port, licenseKey, textToParse);
            //ParsingResult myParsingResult = findAndParse(port, licenseKey, textToParse);

            
            //----------------------------------------------------------------
            // Show Parsing Result
            //----------------------------------------------------------------

            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("\\|"); // the | character
              
              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 {
       
        // create a service factory
        WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
        WSIFService service =
            factory.getService(
                "http://loquisoft.net/cgi-bin/RecogniContactWebService.exe/wsdl/IRecogniContactWebService",
                null,
                null,
                "http://loquisoft.net/",
                "IRecogniContactWebService");
                
        // map types
        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);

        // get the port
        return service.getPort();
        
    }

       private static VersionInfo getParserVersion(WSIFPort port) throws WSIFException {
               // create the operation
        WSIFOperation operation = port.createOperation("GetParserVersion");

        // create the input, output and fault messages associated with this operation
        WSIFMessage input = operation.createInputMessage();
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();

        // do the invocation
        if (operation.executeRequestResponseOperation(input, output, fault)) {
            // invocation succeeded, extract information from output message
            return (VersionInfo) output.getObjectPart("return");
        } else {
            return null;
        }
       }
       
        private static String getParserVersionAsString(WSIFPort port) throws WSIFException {
               // create the operation
        WSIFOperation operation = port.createOperation("GetParserVersionAsString");

        // create the input, output and fault messages associated with this operation
        WSIFMessage input = operation.createInputMessage();
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();

        // do the invocation
        if (operation.executeRequestResponseOperation(input, output, fault)) {
            // invocation succeeded, extract information from output message
            return (String) output.getObjectPart("return");
        } else {
            return null;
        }
       }
       
        private static VersionInfo getInterfaceVersion(WSIFPort port) throws WSIFException {
               // create the operation
        WSIFOperation operation = port.createOperation("GetInterfaceVersion");

        // create the input, output and fault messages associated with this operation
        WSIFMessage input = operation.createInputMessage();
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();

        // do the invocation
        if (operation.executeRequestResponseOperation(input, output, fault)) {
            // invocation succeeded, extract information from output message
            return (VersionInfo) output.getObjectPart("return");
        } else {
            return null;
        }
       }

       private static String getInterfaceVersionAsString(WSIFPort port) throws WSIFException {
               // create the operation
        WSIFOperation operation = port.createOperation("GetInterfaceVersionAsString");

        // create the input, output and fault messages associated with this operation
        WSIFMessage input = operation.createInputMessage();
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();

        // do the invocation
        if (operation.executeRequestResponseOperation(input, output, fault)) {
            // invocation succeeded, extract information from output message
            return (String) output.getObjectPart("return");
        } else {
            return null;
        }
       }

       private static LicenseInfo getLicenseInfo(WSIFPort port, String licenseKey) throws WSIFException {
               // create the operation
        WSIFOperation operation = port.createOperation("GetLicenseInfo");

        // create the input, output and fault messages associated with this operation
        WSIFMessage input = operation.createInputMessage();
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();
        
        // populate the input message
        input.setObjectPart("licenseKey", licenseKey);

        // do the invocation
        if (operation.executeRequestResponseOperation(input, output, fault)) {
            // invocation succeeded, extract information from output message
            return (LicenseInfo) output.getObjectPart("return");
        } else {
            return null;
        }
       }

       private static UsageStats getUsageStats(WSIFPort port, String licenseKey) throws WSIFException {
               // create the operation
        WSIFOperation operation = port.createOperation("GetUsageStats");

        // create the input, output and fault messages associated with this operation
        WSIFMessage input = operation.createInputMessage();
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();
        
        // populate the input message
        input.setObjectPart("licenseKey", licenseKey);

        // do the invocation
        if (operation.executeRequestResponseOperation(input, output, fault)) {
            // invocation succeeded, extract information from output message
            return (UsageStats) output.getObjectPart("return");
        } else {
            return null;
        }
       }

       private static ParsingResult parse(WSIFPort port, String licenseKey, String textToParse) throws WSIFException {
        // create the operation
        WSIFOperation operation = port.createOperation("Parse");

        // create the input, output and fault messages associated with this operation
        WSIFMessage input = operation.createInputMessage();
        WSIFMessage output = operation.createOutputMessage();
        WSIFMessage fault = operation.createFaultMessage();

        // populate the input message
        input.setObjectPart("licenseKey", licenseKey);
        input.setObjectPart("stringToParse", textToParse);

        // do the invocation
        if (operation.executeRequestResponseOperation(input, output, fault)) {
            // invocation succeeded, extract information from output message
            return (ParsingResult) output.getObjectPart("return");
        } else {
            return null;
        }
       }
}