Skip to main content
Mitratech Success Center

Client Support Center

Need help? Click a product group below to select your application and get access to knowledge articles, webinars, training content, and release notes or to contact our support team.

Authorized users - log in to create a ticket, view tickets status and check your success plan details.

 

Client Application Sample Code

The following code sample illustrates concepts described in Putting Components Together in a Client Application of the Getting Started section. The code is an excerpt from a client application that creates a client proxy for the contactRepository.

The following code sample illustrates concepts described in Putting Components Together in a Client Application of the Getting Started section. The code is an excerpt from a client application that creates a client proxy for the contactRepository.

It is important to note that when you instantiate the client proxy using the createWSProxy method, you would type cast the resulting object according to the entityName you had passed in. For example, if you passed in the entityName, Contact, then you'd type cast the returned object as ContactRepository. For the entityName, Document, then you'd type cast the returned object as DocumentRepository.

It is also important to note that you add the interceptor for the message security headers only one time to the client proxy. Afterward, when messages are generated for the client application requests, the corresponding security headers will be automatically inserted in each message. See the code like: WSSecurityHeadersHelper.applySecurityHeaders(contactRepository)

package com.mitratech.teamconnect; import java.util.Date;
import java.util.List;
import com.mitratech.teamconnect.webservice.contactrepository.ContactRepository; 
import com.mitratech.teamconnect.webservice.type.Category;
import com.mitratech.teamconnect.webservice.type.ContAddressCreate; 
import com.mitratech.teamconnect.webservice.type.ContAddressUpdate; 
import com.mitratech.teamconnect.webservice.type.Contact;
import com.mitratech.teamconnect.webservice.type.FieldSearchClause;
import com.mitratech.teamconnect.webservice.type.LegacySearchFieldPathExpression; 
import com.mitratech.teamconnect.webservice.type.LogicOperator;
import com.mitratech.teamconnect.webservice.type.Person; 
import com.mitratech.teamconnect.webservice.type.PersonCreate; 
import com.mitratech.teamconnect.webservice.type.PersonUpdate;
import com.mitratech.teamconnect.webservice.type.StringComparator; 
import com.mitratech.teamconnect.webservice.type.StringFieldCriterion; 
import com.mitratech.teamconnect.webservice.type.TextCustomField; public class WSContactClient extends AbstractWSClient
{
    private ContactRepository contactRepository; 
    public WSContactClient() {
        contactRepository = (ContactRepository)createWSProxy("Contact");
        WSSecurityHeadersHelper.applySecurityHeaders(contactRepository); 
        fieldNames.add("firstName"); 
        fieldNames.add("addresses.uniqueKey"); 
        fieldNames.add("addresses.type.name"); 
        fieldNames.add("addresses.city"); 
        fieldNames.add("addresses.state"); 
        fieldNames.add("addresses.countryCode.name"); 
        fieldNames.add("categories");
    }
    public static void main(String[] args) throws Exception { 
        WSContactClient contactClient = new WSContactClient(); 
        String uniqueKey = contactClient.insertContact();
        Person person = contactClient.readContactByKey(uniqueKey); 
        contactClient.updateContact(uniqueKey);
        person = contactClient.readContactByKey(uniqueKey);
        List<Contact> contacts = contactClient.readContactsByFirstName(person.getFirstName());
        contacts = contactClient.readContactsByPrimaryLanguage("English"); 
        contacts = contactClient.readContactsByPrimaryLanguage("French"); 
        contactClient.deletePerson(uniqueKey);
        person = contactClient.readContactByKey(uniqueKey); 
        System.out.println("done");
    }
    private String insertContact() throws Exception {
        String uniqueKey = contactRepository.insertContact(createPerson()); 
        return uniqueKey;
    }
    private Person readContactByKey(String uniqueKey) throws Exception
    {
        Person person = (Person)contactRepository.readContact(uniqueKey, fieldNames);
        return person;
    }
    private PersonCreate createPerson() { 
        String now = "" + new Date().getTime();
        PersonCreate person = new PersonCreate(); 
        person.setFirstName("first name " + now); 
        person.getAddressCreates().add(createContAddress()); 
        ContAddressCreate anotherAddress = createContAddress(); 
        anotherAddress.setCity("San Jose"); 
        person.getAddressCreates().add(anotherAddress); 
        Category cat = new Category(); 
        cat.setUniqueKey("CONT");
        TextCustomField primaryLanguage = new TextCustomField(); 
        primaryLanguage.setFieldName("primaryLanguage");
        primaryLanguage.setValue("English"); 
        cat.getTextCustomFields().add(primaryLanguage); 
        person.getCategories().add(cat);
        return person;
    }
    private ContAddressCreate createContAddress() { 
        ContAddressCreate address = new ContAddressCreate(); 
        address.setTypeUniqueKey("ADDR_HOME"); 
        address.setCity("Los Angeles"); 
        address.setState("CA"); 
        address.setCountryCodeUniqueKey("COUN_0002");
        return address;
    }
}
  • Was this article helpful?