Advanced Customization > Info*Engine User’s Guide > SOAP Services > Example Standalone Java SOAP Client > Putting It All Together
  
Putting It All Together
The simple Java SOAP client
/home/user/src/org/myOrg/client/Test.java
illustrates how to interact with Info*Engine using SOAP from a standalone application:
package org.myOrg.client;

import org.myOrg.Math.MathDAO;

import com.infoengine.connector.IeConnectionSpec;

import java.util.Hashtable;
import javax.resource.ResourceException;
import javax.resource.cci.Connection;
import javax.resource.cci.ConnectionFactory;
import javax.naming.InitialContext;
import javax.naming.NamingException;

// only used in undesirable local configured and created
// ConnectionFactory situation
import com.infoengine.connector.IeManagedConnectionFactory;
import java.beans.PropertyVetoException;
import java.io.FileInputStream;
import java.io.IOException;

public class Test {

private static ConnectionFactory getLDAPFactory ()
throws NamingException {

Hashtable env = new Hashtable ( 5 );
env.put ( "java.naming.factory.initial",
"com.sun.jndi.ldap.LdapCtxFactory" );
env.put ( "java.naming.provider.url",
"ldap://ldap.mycompany.com/o=MyCompany" );
env.put ( "java.naming.security.authentication", "simple" );
env.put ( "java.naming.security.principal", "cn=Manager" );
env.put ( "java.naming.security.credentials", "admin" );
InitialContext ctx = new InitialContext ( env );
return (ConnectionFactory)ctx.lookup (
"cn=cxFactory.HTTP " );
}

private static ConnectionFactory getManualFactory ()
throws PropertyVetoException,IOException,ResourceException {

IeManagedConnectionFactory mcf =
new IeManagedConnectionFactory ();
// following optional since HTTPConnection is the default
mcf.setConnectionImplementation (
"com.infoengine.connector.HTTPConnection" );
// configure from properties file
mcf.loadConnectionProperties (
new FileInputStream ( "./http.properties" ) );
// or via method call
// mcf.setConnectionProperties (
// "ConnectionURL=http://localhost/Windchill/servlet/RPC" );
return (ConnectionFactory)mcf.createConnectionFactory ();
}

private static String formatArray ( double [] arr ) {
StringBuffer sb = new StringBuffer ();
for ( int i = 0; i < arr.length; i++ )
sb.append ( arr[i] )
.append ( ( (i+1) < arr.length ) ? " + " : "" );
return sb.toString ();

}
public static void main ( String [] args ) throws Exception {
ConnectionFactory cxf = getLDAPFactory ();
//ConnectionFactory cxf = getManualFactory ();

Connection cx = null;
try {
// get connection with credentials
IeConnectionSpec cxSpec = new IeConnectionSpec ();
cxSpec.setUserName ( "wcadmin" );
cxSpec.setPassword ( "wcadmin" );
cx = cxf.getConnection ( cxSpec );

// or anonymous
//cx = cxf.getConnection ();

MathDAO dao = new MathDAO ( cx, cxf.getRecordFactory () );

int fourAndFive = dao.sum ( 4, 5 );
System.out.println (
"4 + 5 = " + fourAndFive );

double [] nums = new double [] { 4, 5, 6, 7 };
double avg = dao.average ( nums );
System.out.println (
"average of " + formatArray ( nums ) + " = " + avg );

} finally {
if ( cx != null ) cx.close ();
System.exit ( 0 );
}
}
}