1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| package javaapplication11;
import java.math.BigDecimal;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import converter.ConverterRemote;
import converter.ConverterRemoteHome;
import java.util.Properties;
import java.lang.reflect.Proxy;
import java.lang.reflect.Method;
public class ClientClass {
public static void main(String[] argv) {
try {
Properties props = System.getProperties();
props.put(Context.PROVIDER_URL, URL);
props.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
Context initial = new InitialContext(props);
Object objref = initial.lookup(JNDI);
if (Proxy.isProxyClass(objref.getClass())) {
System.out.println("LA");
System.out.println(objref.getClass().getName());
Class[] interfaces = objref.getClass().getInterfaces();
for (int i=0;i<interfaces.length;i++) {
System.out.println(">> " + interfaces[i].getName());
if (!"javax.".equals(interfaces[i].getName().substring(0,6))) {
Method[] ms = interfaces[i].getMethods();
for (int j=0;j<ms.length;j++) {
System.out.println(" -- " + ms[j]);
if ("create".equals(ms[j].getName())) {
Class o = ms[j].getReturnType();
Method mo[] = o.getMethods();
for (int k=0;k<mo.length;k++) {
System.out.println(" ** " + mo[k]);
}
}
}
}
}
}
ConverterRemoteHome home =
(ConverterRemoteHome)PortableRemoteObject.narrow(objref, ConverterRemoteHome.class);
System.out.println(objref.getClass().getName());
/* Method[] m = objref.getClass().getMethods();
int nombreMethode = m.length;
int i = 0;
while(nombreMethode!=i)
{
System.out.println(m[i]);
i++;
}*/
ConverterRemote conv = home.create();
BigDecimal yenToEuro = new BigDecimal("200.000");
yenToEuro = conv.yenToEuro(yenToEuro);
System.out.println("200 yens equivaut à : "+ yenToEuro + "euros");
System.exit(0);
} catch (Exception ex) {
ex.printStackTrace();
}
}
private final static String JNDI_FACTORY = "com.sun.enterprise.naming.SerialInitContextFactory";
private final static String JNDI = "ejb/ConverterBean";
private final static String URL = "localhost:4848";
} |