Listing 1

package examples;

import java.net.*;
import java.util.*;
import java.lang.reflect.*;


public class ThinClient {

    public static void main(String[] args) {
        try
        {

            // set the context class loader to a URL ClassLoader
            ClassLoader classLoader;
            Thread.currentThread().setContextClassLoader(
                classLoader = new URLClassLoader(
                    new URL[] {
                        new 

URL("http://localhost:7001/classloader/ClassLoaderServlet/")
                    }
                )
            );
 
            // setup the InitialContext information
            Hashtable env = new Hashtable();
            env.put("java.naming.factory.initial", 

"weblogic.jndi.WLInitialContextFactory");
   env.put("java.naming.provider.url", "t3://localhost:7001");
 
            // equivalent of ctx = new InitialContext();
            Class ctxClass = classLoader.loadClass("javax.naming.InitialContext");
            Constructor ctxConstructor = ctxClass.getConstructor(new Class[] 

{Class.forName("java.util.Hashtable")});
            Object ctx = ctxConstructor.newInstance(new Object[] { env });
            System.out.println("Context is: " + ctx);

            // equivalent of home = ctx.lookup("HelloWorldHome");
            Method method_lookup = ctx.getClass().getDeclaredMethod("lookup", new 

Class[] { Class.forName("java.lang.String") });
            Object home = method_lookup.invoke(ctx, new Object[] { "HelloWorldHome" 

});
            System.out.println("Home is: " + home);
 
            // equivalent of remote = home.create();
            Method method_create = home.getClass().getDeclaredMethod("create", 

null);
            Object remote = method_create.invoke(home, null);
 
            // get sayHello and remove methods
            Method method_sayHello  = remote.getClass().getDeclaredMethod(
                "sayHello",
                new Class[] { Class.forName("java.lang.String") });
 
            Method method_remove = remote.getClass().getDeclaredMethod(
                "remove",
                null);
 

   // equivalent of calling remote.sayHello("Test");
            method_sayHello.invoke(remote, new Object[] { "Test" });
 

            // remove the remote object
            System.out.println("Removing the Hello World Bean");
            method_remove.invoke(remote, null);
 
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Listing 2

package limaye.servlet;

import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ClassLoaderServlet extends HttpServlet {

	public void service(HttpServletRequest request,
						HttpServletResponse response)
						throws IOException, ServletException {

		doGet(request, response);
	}

	public void doGet(HttpServletRequest request,
					  HttpServletResponse response)
	        		  throws IOException {

		String pathInfo = request.getPathInfo();
		if (pathInfo != null) {
			if (pathInfo.charAt(0) == '/') {
				pathInfo = pathInfo.substring(1, pathInfo.length());
			}
			ClassLoader classLoader = ClassLoaderServlet.class.getClassLoader();
			if (classLoader != null) {
				InputStream inputStream = classLoader.getResourceAsStream(pathInfo);
				if (inputStream != null) {
					try
					{
						sendResource(inputStream, response);
						return;
					} catch (IOException io) {
						io.printStackTrace();
						response.sendError(404);
					}
					finally
					{
						inputStream.close();
					}
				}
				else
				{
					response.sendError(404);
				}
			}
		}
	}

	private void sendResource(InputStream inputStream,
	                          HttpServletResponse response)
	                          throws IOException {

		if ( (inputStream != null) && (response != null) ) {
			OutputStream outputStream = response.getOutputStream();
			byte[] buffer = new byte[4096];
			int bytes_read;
			while ( (bytes_read = inputStream.read(buffer)) != -1) {
				outputStream.write(buffer, 0, bytes_read);
			}
		}
	}
}

Listing 3

// setup the InitialContext information
            Hashtable env = new Hashtable();
            env.put("java.naming.factory.initial",
                    "weblogic.jndi.WLInitialContextFactory");
            env.put("java.naming.provider.url", "t3://localhost:7001");
 
            // equivalent of ctx = new InitialContext();
            Class ctxClass = classLoader.loadClass("javax.naming.InitialContext");
            Constructor ctxConstructor = ctxClass.getConstructor(new Class[] 

{Class.forName("java.util.Hashtable")});
            Object ctx = ctxConstructor.newInstance(new Object[] { env });
            System.out.println("Context is: " + ctx);

            // equivalent of home = ctx.lookup("HelloWorldHome");
            Method method_lookup = ctx.getClass().getDeclaredMethod("lookup", new 

Class[] { Class.forName("java.lang.String") });
            Object home = method_lookup.invoke(ctx, new Object[] { "HelloWorldHome" 

});

Listing 4

            // equivalent of remote = home.create();
            Method method_create = home.getClass().getDeclaredMethod("create", 

null);
            Object remote = method_create.invoke(home, null);
 
            // get sayHello and remove methods
            Method method_sayHello  = remote.getClass().getDeclaredMethod(
                "sayHello",
                new Class[] { Class.forName("java.lang.String") });
 
            Method method_remove = remote.getClass().getDeclaredMethod(
                "remove",
                null);
 

   // equivalent of calling remote.sayHello("Test");
            method_sayHello.invoke(remote, new Object[] { "Test" });
 

            // remove the remote object
            System.out.println("Removing the Hello World Bean");
            method_remove.invoke(remote, null);

Listing 5

import java.net.URL;

import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Service;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;

public class ThinClientWS{

  public static void main(String[] args) throws Exception {

    // Setup the global JAXM message factory
    System.setProperty("javax.xml.soap.MessageFactory",
      "weblogic.webservice.core.soap.MessageFactoryImpl");
    // Setup the global JAX-RPC service factory
    System.setProperty( "javax.xml.rpc.ServiceFactory",
      "weblogic.webservice.core.rpc.ServiceFactoryImpl");

    // create service factory
    ServiceFactory factory = ServiceFactory.newInstance();

    // define qnames
    String targetNamespace = 
      "http://localhost:7001/" 
      + "wsdl/test.HelloWorld/";

    QName serviceName = 
      new QName(targetNamespace, 
                "test.HelloWorldService");

    QName portName = 
      new QName(targetNamespace, 
                "test.HelloWorldPort");

    QName operationName = new QName("urn:test-helloworld", 
                                    "sayHello");

    URL wsdlLocation = 
      new URL("http://localhost:7001/soap/urn:test-helloworld.wsdl");

    // create service
    Service service = factory.createService(wsdlLocation, serviceName);

    // create call
    Call call = service.createCall(portName, operationName);

    // invoke the remote web service
    call.invoke(new Object[] {
      "Test"
    });

  } 

}