Saturday, February 13, 2010

In WLI, find out which Web Services are invoked by a given process

This is the first step for a Discovery and Monitoring and Testing tool:


package com.acme.integration.tools;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.net.MalformedURLException;


public class ClassLoaderTest {
   
    private static final String COM_BEA_CONTROL_SERVICE_CONTROL$_LOCATION = "com.bea.control.ServiceControl$Location";

    public static void main(String[] args) throws MalformedURLException, Exception {
        ClassLoader cl = Thread.currentThread().getContextClassLoader();
        String processName = "adjustment.CancelAdjustmentProcess";
        Class cls = cl.loadClass(processName);
        Field[] fields = cls.getDeclaredFields();
        for (Field field : fields) {
            Class type = field.getType();
            System.out.println("type " + type.getCanonicalName() + "  " + field.getName());
            for (Class iface : type.getInterfaces()) {
                for (Annotation annotation : type.getAnnotations()) {
                    String name = annotation.annotationType().getName();
                    if (name.equals(COM_BEA_CONTROL_SERVICE_CONTROL$_LOCATION)) {
                        String[] urls = ((com.bea.control.ServiceControl.Location)annotation).urls();
                        for (String url : urls) {
                            System.out.println("             url=" + url);
                        }
                    }
                }
            }
        }
    }
}



of course some jars and the src folder containing the processes must be added to the classpath

No comments: