Tuesday, June 10, 2014

package com.ntrs.wad.test;
import java.io.InputStream;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import com.ntrs.wad.common.ErrorMessages;
import com.ntrs.wad.common.exceptions.WADBusinessException;
import com.ntrs.wad.common.exceptions.WADException;
import com.ntrs.wad.common.exceptions.WADNotFoundException;
import com.ntrs.wad.common.exceptions.WADSystemException;
import com.ntrs.wad.provider.session.AdminProviderStatefulRemote;
import com.ntrs.wad.user.info.UserInfo;
public class TestClient {
private static final String WAD_CLIENT_PROPERTIES = "wad-client.properties";
private static final String JNDI = "wad.ap.jndi.home.name.1";

public static void main(String[] args) {
AdminProviderStatefulRemote ap = null;

try {
   ap = getAdminProviderStatefulRemote();
//    ap.newEJBCreate("TNT", "TLAADMPROVIDER", "password");
   UserInfo user = new UserInfo("HPOTTER", "TNT", "Harry", "Potter", Boolean.FALSE);
   ap.createUser(user);
}
catch (WADException e) {
System.out.println(e);// handle exception
}
finally {
//   if (ap != null) {
 //      try {
 //        ap.close();
 //      }
 //      catch (WADException e) {
        //    ignore
 //      }
//   }
}
}

private static AdminProviderStatefulRemote getAdminProviderStatefulRemote()
   throws WADBusinessException, WADNotFoundException, WADSystemException
{
   try
   {
    Properties p = new Properties();
try {
InputStream inputStream = TestClient.class.getClassLoader().getResourceAsStream(WAD_CLIENT_PROPERTIES);
p.load(inputStream);
} catch (Exception e) {
System.out.println(e);// handle exception
}

    Context ic =null;
ic = new InitialContext(p);
    Object ref = ic.lookup(p.getProperty(JNDI));
    AdminProviderStatefulRemote remote = (AdminProviderStatefulRemote) PortableRemoteObject.narrow(ref, AdminProviderStatefulRemote.class);
   
    return remote;
   }
   catch( NamingException ne )
   {
    System.out.println(ne);
       throw new WADSystemException(ErrorMessages.ADMIN_BEAN_NOT_FOUND, ne);
   }
}
}


No comments:

Post a Comment