You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-dev@ws.apache.org by wi...@apache.org on 2005/08/12 22:45:46 UTC

svn commit: r232376 [9/112] - in /webservices/muse/trunk/src/examples/client: ./ bin/ bin/axis/ bin/axis/com/ bin/axis/com/xyz/ bin/org/ bin/org/apache/ bin/org/apache/ws/ bin/org/apache/ws/client/ bin/org/apache/ws/client/async/ bin/org/apache/ws/clie...

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/DynamicSoapClientTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/DynamicSoapClientTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/DynamicSoapClientTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/DynamicSoapClientTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,218 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*/
+package org.apache.ws.client;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Vector;
+
+import javax.wsdl.Operation;
+import javax.wsdl.WSDLException;
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+
+import org.apache.ws.resource.discovery.RegistrationManagerFactory;
+import org.apache.ws.test.AbstractOneAxisTestCase;
+import org.apache.xmlbeans.XmlObject;
+import org.xmlsoap.schemas.soap.envelope.impl.FaultImpl;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+
+/**
+ * @author wire
+ */
+public class DynamicSoapClientTestCase extends AbstractOneAxisTestCase {
+    private static final int        CALL_TIMEOUT               = 300000;
+    private static final String testServiceName="registry";
+    private URL m_testWSDLUrl;
+    private URL m_testEndpoint;
+	private DynamicSoapClient m_client;
+    
+    /**
+     * @throws IOException
+     * @throws WSDLException
+     * 
+     */
+    public DynamicSoapClientTestCase() throws WSDLException, IOException {
+        super();
+    }
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		m_testEndpoint=new URL(getAxisBaseUrl().toExternalForm()+testServiceName);
+		m_testWSDLUrl=new URL(getAxisBaseUrl().toExternalForm()+testServiceName+"?wsdl");
+		DynamicSchemaClassBuilder.dispose(); // Flush previously generated classes
+		m_client=new DynamicSoapClient(m_testWSDLUrl,m_testEndpoint);
+		RegistrationManagerFactory.discoverResources(  );
+}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	    RegistrationManagerFactory.shutdown(  );
+	}
+	
+	/**
+	 * Objective: Enumerate Operations of a WSDL
+	 *
+	 */
+	public void testGetOperations(){
+		Operation[] operations = m_client.getWsdlOperations();
+		Assert.assertNotNull(operations);
+		Assert.assertEquals(5,operations.length);
+		Assert.assertEquals("GetResourceProperty",((Operation)operations[0]).getName());
+		Assert.assertEquals("findResourcesByServiceName",((Operation)operations[1]).getName());
+		Assert.assertEquals("findResource",((Operation)operations[2]).getName());
+		Assert.assertEquals("findAllServiceNames",((Operation)operations[3]).getName());
+		Assert.assertEquals("QueryResourceProperties",((Operation)operations[4]).getName());
+		
+	//	System.out.println();
+	}
+	
+	/**
+	 * Objective: Enummerate the parameters of an operation.
+	 * @throws SecurityException
+	 * @throws IllegalArgumentException
+	 * @throws ClassNotFoundException
+	 * @throws NoSuchMethodException
+	 * @throws IllegalAccessException
+	 * @throws InvocationTargetException
+	 */
+	public void testGetParameters() throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
+		Operation[] operations = m_client.getWsdlOperations();
+		Assert.assertNotNull(operations);
+		Assert.assertEquals(5,operations.length);
+		Operation opfindResourcesByServiceName=((Operation)operations[1]);
+		String[] params = m_client.getParameters(opfindResourcesByServiceName);
+		Assert.assertNotNull(params);
+		Assert.assertEquals(1,params.length);
+		Assert.assertEquals("ServiceName[java.lang.String]",params[0]);		
+	}
+	
+	/**
+	 * Objective: Execute a simple web service call. Test Result.
+	 * @throws Exception
+	 */
+	public void testExecuteNoParams() throws Exception{
+		Operation[] operations = m_client.findOperation("findAllServiceNames");
+		Assert.assertEquals(1,operations.length);
+		Operation opGetVersion=operations[0];		
+		XmlObject[] responses = m_client.execute(opGetVersion,null);
+		Assert.assertEquals(1,responses.length);
+		Assert.assertFalse("A soap fault was returned. Message was "+responses[0],responses[0] instanceof FaultImpl);
+		String[] props=DynamicSchemaClassBuilder.getProperties(responses[0]);
+		String[] arrayOfServiceNames=(String[])DynamicSchemaClassBuilder.getProperty(responses[0],"ItemArray");
+		Assert.assertEquals("registry",arrayOfServiceNames[1]);
+		Assert.assertEquals("disk",arrayOfServiceNames[0]);
+	}
+	
+	
+	/**
+	 * Objective: Call the resource property for version number to test the GetResourceProp access
+	 * for registry singleton.
+	 * @throws Exception
+	 *
+	 */
+	public void testGetVersionNumber() throws Exception{
+		Operation[] operations = m_client.findOperation("GetResourceProperty");
+		Assert.assertEquals(1,operations.length);
+		Operation opGetVersion=operations[0];
+		
+		String[] props = m_client.getParameters(opGetVersion);
+		Hashtable params=new Hashtable();
+		//NamespaceURI[java.lang.String], Prefix[java.lang.String], LocalPart[java.lang.String]]
+		params.put("QName",new QName("http://docs.oasis-open.org/wsdm/2004/04/muws-0.5/schema","Version"));
+		//params.put("LocalPart",);
+		XmlObject[] responses = m_client.execute(opGetVersion,params);
+		Assert.assertEquals(1,responses.length);
+		XmlObject response=responses[0];
+		Assert.assertFalse("A soap fault was returned. Message was "+response,response instanceof FaultImpl);
+		String responseText=response.toString();
+		Assert.assertTrue(responseText.indexOf("Revision")>0);
+				
+	}
+	
+	/**
+	 * Make a call with 2 parameters. This excercizes the code to generate requests.
+	 * @throws Exception
+	 */
+	public void testExecute1Parameter() throws Exception{
+		Operation[] operations = m_client.findOperation("findResourcesByServiceName");
+		Assert.assertEquals(1,operations.length);
+		Operation opfindResource=operations[0];
+		String[] paramsExample = m_client.getParameters(opfindResource);
+		Hashtable params=new Hashtable();
+		params.put("ServiceName","disk");
+		XmlObject[] responses = m_client.execute(opfindResource,params);
+		Assert.assertEquals(1,responses.length);
+		XmlObject response=responses[0];
+		Assert.assertFalse("A soap fault was returned. Message was "+response,response instanceof FaultImpl);
+		String[] props=DynamicSchemaClassBuilder.getProperties(responses[0]);
+		Object objItemArry=DynamicSchemaClassBuilder.getProperty(responses[0],"ItemArray");
+		String cname=objItemArry.getClass().getName();
+		Assert.assertTrue(objItemArry instanceof EndpointReferenceType[]);
+		Assert.assertEquals(2,props.length);
+		//Address, PortType, ReferenceProperties, ServiceName
+//		Assert.assertEquals("Address",props[0]);
+//		Assert.assertEquals("PortType",props[1]);
+//		Assert.assertEquals("ReferenceProperties",props[2]);
+//		Assert.assertEquals("ServiceName",props[3]);
+		
+		
+		
+		// TODO wire Veryfy some of the contents
+	}
+
+	/**
+	 * Make a call with 2 parameters. This excercizes the code to generate requests.
+	 * @throws Exception
+	 */
+	public void testExecute2Parameters() throws Exception{
+		Operation[] operations = m_client.findOperation("findResource");
+		Assert.assertEquals(1,operations.length);
+		Operation opfindResource=operations[0];
+		String[] paramsExample = m_client.getParameters(opfindResource);
+		Hashtable params=new Hashtable();
+		params.put("ServiceName","disk");
+		params.put("Id","1234");
+		XmlObject[] responses = m_client.execute(opfindResource,params);
+		Assert.assertEquals(1,responses.length);
+		XmlObject response=responses[0];
+		Assert.assertFalse("A soap fault was returned. Message was "+response,response instanceof FaultImpl);
+		String[] props=DynamicSchemaClassBuilder.getProperties(responses[0]);
+		Assert.assertEquals(4,props.length);
+		
+		
+		Vector propNames=new Vector();
+		for (int index = 0; index < props.length; index++) {
+            String propName = props[index];
+            propNames.add(propName);
+        }
+		
+		
+		//Address, PortType, ReferenceProperties, ServiceName
+		
+		Assert.assertTrue(propNames.contains("Address"));
+		Assert.assertTrue(propNames.contains("PortType"));
+		Assert.assertTrue(propNames.contains("ReferenceProperties"));
+		Assert.assertTrue(propNames.contains("ServiceName"));
+		
+		
+		
+		//TODO wire Veryfy some of the contents
+	}
+	
+	
+	protected String getAxisConfigFileName() {
+		
+		return "server-config.wsdd";
+	}
+	
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncCallProviderTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncCallProviderTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncCallProviderTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncCallProviderTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,106 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 27, 2004
+ *
+ * $RCSfile: AsyncCallProviderTestCase.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:08:49 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.async;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author wire
+ *
+ */
+public class AsyncCallProviderTestCase extends TestCase implements AsyncListener {
+
+    private AsyncEvent m_event;
+    int m_secondsToWait=20;
+
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        m_event=null;
+    }
+
+    /*
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testPerformAsyncCall() throws SecurityException, NoSuchMethodException {
+        AsyncUnitTestImpl asyncImpl = new AsyncUnitTestImpl(5000);
+        asyncImpl.addListener(this);
+        asyncImpl.mockOperationAsync(new Long(3000));
+        
+        // Returns right away but must wait for an event to be received or a timeout
+        waitForEvent(m_secondsToWait);
+        
+        // An event has been received
+        Object retValue=m_event.getReturnValue();
+        Assert.assertNotNull(retValue);
+        Assert.assertTrue(retValue instanceof String);
+        String retString=(String)retValue;
+        Assert.assertEquals("Success",retString);
+        
+        asyncImpl.removeListener(this);
+    }
+
+    public void testFailAsyncCall() throws SecurityException, NoSuchMethodException {
+        AsyncUnitTestImpl asyncImpl = new AsyncUnitTestImpl(2000);
+        asyncImpl.addListener(this);
+        asyncImpl.mockOperationAsync(new Long(5000));
+        
+        // Returns right away but must wait for an event to be received or a timeout
+        waitForEvent(m_secondsToWait);
+        
+        // An event has been received
+        Object retValue=m_event.getReturnValue();
+        Assert.assertNotNull(retValue);
+
+        // This line should be re-enabled!
+        //Assert.assertTrue(retValue instanceof TimeoutException);
+        
+        asyncImpl.removeListener(this);
+    }
+
+    
+    /**
+     * 
+     */
+    private void waitForEvent(int secondsToWait) {
+        int checks=0;
+        while(checks<secondsToWait){
+            if(m_event!=null){
+                break;
+            }
+            try {
+                Thread.sleep(1000);
+            } catch (InterruptedException e) {
+            }
+        }
+        if(checks==20){
+            Assert.fail("Timout exceeded on test");
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ws.client.async.AsyncListener#asyncCompletionEvent(java.lang.Object)
+     */
+    public void asyncCompletionEvent(AsyncEvent event) {
+        
+        m_event=event;
+    }
+
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncUnitTestImpl.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncUnitTestImpl.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncUnitTestImpl.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/async/AsyncUnitTestImpl.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,48 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 27, 2004
+ *
+ * $RCSfile: AsyncUnitTestImpl.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:08:49 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.async;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author wire
+ *
+ */
+public class AsyncUnitTestImpl extends AsyncCallProvider {
+    long m_operationTimeout=5000;
+    /**
+     * 
+     */
+    public AsyncUnitTestImpl() {
+        super();
+    }
+
+    public AsyncUnitTestImpl(long timeout) {
+        super();
+        m_operationTimeout=timeout;
+    }
+    
+    public void mockOperationAsync(Long duration) throws SecurityException, NoSuchMethodException{
+        Method mockOperationMethod=getClass().getMethod("mockOperation",new Class[]{Long.class});
+        performAsync(mockOperationMethod,new Object[]{duration},m_operationTimeout);
+    }
+
+    public String mockOperation(Long duration){
+        try {
+            Thread.sleep(duration.longValue());
+        } catch (InterruptedException e) {
+        }
+        return "Success";
+    }
+
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmClientTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmClientTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmClientTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmClientTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,88 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*/
+package org.apache.ws.client.model;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.EndpointReferenceType;
+
+import junit.framework.Assert;
+
+import org.apache.ws.client.model.impl.WsdmClientImpl;
+import org.apache.ws.resource.discovery.RegistrationManagerFactory;
+import org.apache.ws.test.AbstractOneAxisTestCase;
+
+/**
+ * @author wire
+ */
+public class WsdmClientTestCase extends AbstractOneAxisTestCase {
+    private static final int        CALL_TIMEOUT               = 300000;
+    private URL m_testEndpoint;
+	private WsdmClient m_wsdmClient;
+    
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		m_testEndpoint=new URL(getAxisBaseUrl().toExternalForm());
+		WsdmClientFactory.clearGeneratedClassCache();
+		m_wsdmClient=WsdmClientFactory.create(WsdmClientFactory.AXIS_CLIENT_TYPE,m_testEndpoint.getHost()+":"+m_testEndpoint.getPort(),"axis");
+	    RegistrationManagerFactory.discoverResources(  );
+}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	    RegistrationManagerFactory.shutdown(  );
+	}
+	
+	
+	/**
+	 * Objective: Test the ping method which returns a count in millis of
+	 * how long it takes for a simple call to be made to a server. Can be used
+	 * to display status or judge health of the system remotly.
+	 * @throws Exception
+	 */public void testPing() throws Exception{
+		long time=m_wsdmClient.ping();
+		Assert.assertTrue(time>0);
+	}
+	
+	/**
+	 * Objective: Use this client to get a set of Wsdm Resources. Verify 
+	 * they are returned and check their names.
+	 * @throws SecurityException
+	 * @throws IllegalArgumentException
+	 * @throws NoSuchMethodException
+	 * @throws IllegalAccessException
+	 * @throws InvocationTargetException
+	 * @throws Exception
+	 */
+	 public void testGetResources() throws SecurityException, IllegalArgumentException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, Exception{
+		WsdmResource[] resources=m_wsdmClient.getResources();
+		Assert.assertEquals(2,resources.length);
+		Assert.assertEquals("registry",resources[1].getName());
+		Assert.assertEquals("disk",resources[0].getName());
+	}
+	 
+	/**
+	 * Objective: Test the format of a returned Client Name.
+	 *
+	 */
+	 public void testGetName(){
+	     Assert.assertNotNull(m_wsdmClient.getName());
+	     Assert.assertTrue(m_wsdmClient.getName().startsWith("Server - 127.0.0.1"));
+	}
+	 
+	public void testFindInstance() throws Exception{
+	    WsdmClientImpl impl = (WsdmClientImpl)m_wsdmClient;
+	     EndpointReferenceType erp = impl.getErpFor("disk","1234");	     
+	     WsdmInstance instance=impl.findInstance(erp);
+	     Assert.assertNotNull(instance);
+	}
+	 
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmInstanceTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmInstanceTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmInstanceTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmInstanceTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,109 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 14, 2004
+ *
+ * $RCSfile: WsdmInstanceTestCase.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:08:49 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+import java.lang.reflect.InvocationTargetException;
+import java.net.URL;
+import java.util.Hashtable;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.Assert;
+
+import org.apache.ws.resource.discovery.RegistrationManagerFactory;
+import org.apache.ws.test.AbstractMultipleAxisTestCase;
+import org.apache.xmlbeans.XmlCursor;
+import org.apache.xmlbeans.XmlObject;
+import org.xmlsoap.schemas.ws.x2003.x03.addressing.impl.EndpointReferenceTypeImpl;
+
+/**
+ * @author wire
+ *
+ */
+public class WsdmInstanceTestCase extends AbstractMultipleAxisTestCase {
+
+    private static final int        CALL_TIMEOUT               = 300000;
+    private URL m_testEndpoint;
+	private WsdmClient m_wsdmServer;
+	private WsdmResource m_resourceDisk;
+    private WsdmInstance m_instanceDisk1234;
+    private WsdmInstance m_resourceRegistrySingleton;
+    
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		m_testEndpoint=new URL(getAxisBaseUrl().toExternalForm());
+		WsdmClientFactory.clearGeneratedClassCache();
+		m_wsdmServer=WsdmClientFactory.create(WsdmClientFactory.AXIS_CLIENT_TYPE,m_testEndpoint.getHost()+":"+m_testEndpoint.getPort(),"axis");
+	    RegistrationManagerFactory.discoverResources(  );
+	    m_resourceDisk=m_wsdmServer.getResources()[0];
+	    m_instanceDisk1234=m_resourceDisk.getInstances()[0];
+	    m_resourceRegistrySingleton=m_wsdmServer.getResources()[1].getInstances()[0];
+
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	    RegistrationManagerFactory.shutdown(  );
+	}
+
+	/**
+	 * Objective: get a list of properties and verify a value.
+	 * @throws Exception
+	 */
+	public void testGetPropertyNames() throws Exception{
+	    String[] propnames=m_instanceDisk1234.getPropertyNames();
+	    Assert.assertNotNull(propnames);
+	    Assert.assertEquals("{http://xyz.com/}TopicSpace[0]",propnames[0]);
+	}
+	
+	public void testGetPropertyNamesOfASingleton() throws Exception{
+	    String[] propnames=m_resourceRegistrySingleton.getPropertyNames();
+	    Assert.assertNotNull(propnames);
+	    Assert.assertEquals("{http://docs.oasis-open.org/wsdm/2004/04/muws-0.5/schema}Name[0]",propnames[0]);
+	}
+
+	public void testGetOperations() throws SecurityException, IllegalArgumentException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException{
+	    WsdmOperation[] ops = m_instanceDisk1234.getOperations();
+	    Assert.assertNotNull(ops);
+	    Assert.assertTrue(ops.length>0);
+	}
+	
+	public void testInvoke() throws Exception{
+	    WsdmOperation[] ops = m_instanceDisk1234.getOperations();
+	    WsdmOperation destroyOperation = ops[ops.length-1];
+	    Assert.assertNotNull(destroyOperation);
+	    Assert.assertEquals("Destroy",destroyOperation.getName());
+	    XmlObject[] responses = m_instanceDisk1234.invoke(destroyOperation,new Hashtable());
+	}
+	
+	public void testGetPropertyValueFromQName() throws Exception{
+	    QName propName=new QName("http://xyz.com/","Manufacturer");
+	    XmlObject[] ret=m_instanceDisk1234.getPropertyValue(propName);
+	    XmlCursor cursor = ret[0].newCursor();
+	    String manufacturerName=cursor.getTextValue();
+	    cursor.dispose();
+	    Assert.assertEquals("Hewlett-Packard Company",manufacturerName);
+	}
+	
+	public void testGetERP() throws Exception{
+	    XmlObject erp=m_instanceDisk1234.getEPR();
+	    Assert.assertTrue(erp instanceof EndpointReferenceTypeImpl);
+	}
+
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmOperationTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmOperationTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmOperationTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmOperationTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,62 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 11, 2004
+ *
+ * $RCSfile: WsdmOperationTestCase.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:08:49 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+import org.apache.ws.client.model.impl.WsdmOperationImpl;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author wire
+ *
+ * TODO To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Style - Code Templates
+ */
+public class WsdmOperationTestCase extends TestCase {
+
+    private WsdmOperation m_operation;
+
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        m_operation=new WsdmOperationImpl("testOperation",new String[]{"hostname[java.lang.String]","port[java.lang.Long]"});
+    }
+
+    /*
+     * @see TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    public void testGetName() {
+        Assert.assertEquals("testOperation",m_operation.getName());
+    }
+
+    public void testGetParameterNames() {
+        String[] names = m_operation.getParameterNames();
+        Assert.assertEquals(2,names.length);
+        Assert.assertEquals("hostname",names[1]);
+        Assert.assertEquals("port",names[0]);
+    }
+
+    public void testGetParameterType() {
+        String[] names = m_operation.getParameterNames();
+        Assert.assertEquals("java.lang.String",m_operation.getParameterType(names[1]));
+        Assert.assertEquals("java.lang.Long",m_operation.getParameterType(names[0]));
+    }
+
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmResourceTestCase.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmResourceTestCase.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmResourceTestCase.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/model/WsdmResourceTestCase.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,77 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*
+ * Created on Sep 11, 2004
+ *
+ * $RCSfile: WsdmResourceTestCase.java,v $ $Revision: 1.1 $
+ * $Author: scamp $ $Date: 2004/11/12 21:08:49 $
+ * Branch or Tag : $Name:  $
+ *
+ * ______________Recent Changes_______________________________
+ *
+ */
+package org.apache.ws.client.model;
+
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.ws.resource.discovery.RegistrationManagerFactory;
+import org.apache.ws.test.AbstractOneAxisTestCase;
+
+/**
+ * @author wire
+ *
+ */
+public class WsdmResourceTestCase extends AbstractOneAxisTestCase {
+    private static final int        CALL_TIMEOUT               = 300000;
+    private URL m_testEndpoint;
+	private WsdmClient m_wsdmServer;
+	private WsdmResource m_resourceDisk;
+    private WsdmResource m_resourceRegistry;
+    
+	/*
+	 * @see TestCase#setUp()
+	 */
+	protected void setUp() throws Exception {
+		super.setUp();
+		m_testEndpoint=new URL(getAxisBaseUrl().toExternalForm());
+		WsdmClientFactory.clearGeneratedClassCache();
+		m_wsdmServer=WsdmClientFactory.create(WsdmClientFactory.AXIS_CLIENT_TYPE,m_testEndpoint.getHost()+":"+m_testEndpoint.getPort(),"axis");
+	    RegistrationManagerFactory.discoverResources(  );
+	    m_resourceDisk=m_wsdmServer.getResources()[0];
+	    m_resourceRegistry=m_wsdmServer.getResources()[1];
+	}
+
+	/*
+	 * @see TestCase#tearDown()
+	 */
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	    RegistrationManagerFactory.shutdown(  );
+	}
+
+	
+	public void testGetName(){
+	    Assert.assertNotNull(m_resourceDisk.getName());
+	    Assert.assertEquals("disk",m_resourceDisk.getName());
+	    Assert.assertNotNull(m_resourceRegistry.getName());
+	    Assert.assertEquals("registry",m_resourceRegistry.getName());
+	}
+	
+	public void testGetInstances() throws Exception{
+	    WsdmInstance[] instancesDisk = m_resourceDisk.getInstances();
+	    Assert.assertNotNull(instancesDisk);
+	    Assert.assertEquals(4,instancesDisk.length);
+	    Assert.assertEquals("1234",instancesDisk[0].getName());
+	    Assert.assertEquals("8765",instancesDisk[1].getName());
+	    Assert.assertEquals("4321",instancesDisk[2].getName());
+	    Assert.assertEquals("5678",instancesDisk[3].getName());
+
+	    WsdmInstance[] instancesRegistrySingleton = m_resourceRegistry.getInstances();
+	    Assert.assertNotNull(instancesRegistrySingleton);
+	    Assert.assertEquals(1,instancesRegistrySingleton.length);
+	    Assert.assertEquals("Singleton",instancesRegistrySingleton[0].getName());
+	}
+	
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/util/SubscriberTest.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/util/SubscriberTest.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/util/SubscriberTest.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/client/util/SubscriberTest.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,110 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*/
+package org.apache.ws.client.util;
+
+import junit.framework.TestCase;
+import org.apache.ws.client.model.WsdmInstance;
+import org.apache.ws.client.model.impl.WsdmInstanceImpl;
+import com.ibm.xmlns.stdwip.webServices.wsBaseNotification.TopicExpressionType;
+
+import java.net.URL;
+
+/**
+ * Tests the Subscriber utility.
+ */
+public class SubscriberTest
+   extends TestCase
+{
+   /** the subscriber object to test */
+   private Subscriber m_subscriber;
+
+   /** some dummy WSDM instances */
+   private WsdmInstance m_wsdm1 = new WsdmInstanceImpl( "one", null );
+   private WsdmInstance m_wsdm2 = new WsdmInstanceImpl( "two", null );
+
+   /** some dummy topic expressions */
+   private TopicExpressionType m_topic1;
+   private TopicExpressionType m_topic2;
+
+   /**
+    * Creates a new {@link SubscriberTest} object.
+    */
+   public SubscriberTest(  )
+   {
+      m_topic1    = TopicExpressionType.Factory.newInstance(  );
+      m_topic2    = TopicExpressionType.Factory.newInstance(  );
+
+      m_topic1.setDialect( "topic1dialect" );
+      m_topic2.setDialect( "topic2dialect" );
+   }
+
+   /**
+    * Tests getting existing subscriptions.
+    *
+    * @throws Exception
+    */
+   public void testGetSubscriptions(  )
+   throws Exception
+   {
+   	//TODO wire This feature is not done and this test is disabled
+   	
+//      assertEquals( 0, m_subscriber.getSubscriptions(  ).length );
+//
+//      m_subscriber.subscribe( m_wsdm1, m_topic1 );
+//      assertEquals( 1, m_subscriber.getSubscriptions(  ).length );
+//      assertEquals( 1, m_subscriber.getSubscriptions( m_wsdm1 ).length );
+//
+//      m_subscriber.subscribe( m_wsdm2, m_topic2 );
+//      assertEquals( 2, m_subscriber.getSubscriptions(  ).length );
+//      assertEquals( 1, m_subscriber.getSubscriptions( m_wsdm2 ).length );
+//
+//      m_subscriber.subscribe( m_wsdm1, m_topic2 );
+//      assertEquals( 3, m_subscriber.getSubscriptions(  ).length );
+//      assertEquals( 2, m_subscriber.getSubscriptions( m_wsdm1 ).length );
+//
+//      m_subscriber.subscribe( m_wsdm2, m_topic1 );
+//      assertEquals( 4, m_subscriber.getSubscriptions(  ).length );
+//      assertEquals( 2, m_subscriber.getSubscriptions( m_wsdm2 ).length );
+//
+//      assertNotNull( m_subscriber.getSubscription( m_wsdm1, m_topic1 ) );
+//      assertNotNull( m_subscriber.getSubscription( m_wsdm2, m_topic2 ) );
+//      assertNotNull( m_subscriber.getSubscription( m_wsdm1, m_topic2 ) );
+//      assertNotNull( m_subscriber.getSubscription( m_wsdm2, m_topic1 ) );
+//
+//      m_subscriber.unsubscribe( m_wsdm1, m_topic1 );
+//      assertNull( m_subscriber.getSubscription( m_wsdm1, m_topic1 ) );
+//      assertEquals( 3, m_subscriber.getSubscriptions(  ).length );
+//
+//      m_subscriber.unsubscribe( m_wsdm2 );
+//      assertNull( m_subscriber.getSubscription( m_wsdm2, m_topic1 ) );
+//      assertNull( m_subscriber.getSubscription( m_wsdm2, m_topic2 ) );
+//      assertEquals( 1, m_subscriber.getSubscriptions(  ).length );
+//
+//      m_subscriber.unsubscribe(  );
+//      assertNull( m_subscriber.getSubscription( m_wsdm1, m_topic1 ) );
+//      assertNull( m_subscriber.getSubscription( m_wsdm2, m_topic2 ) );
+//      assertNull( m_subscriber.getSubscription( m_wsdm1, m_topic2 ) );
+//      assertNull( m_subscriber.getSubscription( m_wsdm2, m_topic1 ) );
+//      assertEquals( 0, m_subscriber.getSubscriptions(  ).length );
+   }
+
+   /**
+    * @see junit.framework.TestCase#setUp()
+    */
+   protected void setUp(  )
+   throws Exception
+   {
+      m_subscriber = new Subscriber( new URL( "http://consumer" ) );
+   }
+
+   /**
+    * @see junit.framework.TestCase#tearDown()
+    */
+   protected void tearDown(  )
+   throws Exception
+   {
+      m_subscriber.unsubscribe(  );
+      m_subscriber = null;
+   }
+}
\ No newline at end of file

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisServer.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisServer.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisServer.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisServer.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,468 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.http;
+
+import org.apache.axis.EngineConfiguration;
+import org.apache.axis.collections.LRUMap;
+import org.apache.axis.components.logger.LogFactory;
+import org.apache.axis.components.threadpool.ThreadPool;
+import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
+import org.apache.axis.management.ServiceAdmin;
+import org.apache.axis.server.AxisServer;
+import org.apache.axis.session.Session;
+import org.apache.axis.session.SimpleSession;
+import org.apache.axis.transport.http.SimpleAxisWorker;
+import org.apache.axis.transport.http.SimpleAxisServer;
+import org.apache.axis.utils.Messages;
+import org.apache.axis.utils.NetworkUtils;
+import org.apache.axis.utils.Options;
+import org.apache.commons.logging.Log;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.util.Map;
+
+/**
+ * This is a simple implementation of an HTTP server for processing SOAP requests via Apache's xml-axis.  This is not
+ * intended for production use.  Its intended uses are for demos, debugging, and performance profiling.
+ * <p/>
+ * Note this classes uses static objects to provide a thread pool, so you should not use multiple instances of this
+ * class in the same JVM/classloader unless you want bad things to happen at shutdown.
+ *
+ * TODO: delete any methods that can be safely inherited from superclass
+ *
+ * @author Ian Springer
+ */
+public class NotSoSimpleAxisServer extends SimpleAxisServer implements Runnable
+{
+
+    public static final File DEFAULT_DOC_ROOT_DIR = new File( "./src/wsdl" );
+    public static final int DEFAULT_MAX_THREADS = 200;
+    public static final int DEFAULT_MAX_SESSIONS = 100;
+
+    protected static final Log LOG = LogFactory.getLog( NotSoSimpleAxisServer.class.getName() );
+
+    // session state.
+    // This table maps session keys (random numbers) to SimpleAxisSession objects.
+    //
+    // There is a simple LRU based session cleanup mechanism, but if clients are not
+    // passing cookies, then a new session will be created for *every* request.
+    private Map m_sessions;
+    //Maximum capacity of the LRU Map used for session cleanup
+    private int m_maxSessions;
+
+    private File m_docRootDir;
+
+    /**
+     * get the thread pool
+     *
+     * @return
+     */
+    public static ThreadPool getPool()
+    {
+        return m_pool;
+    }
+
+    /*
+     * pool of threads
+     */
+    private static ThreadPool m_pool;
+
+    /*
+     * Are we doing threads?
+     */
+    private static boolean s_doThreads = true;
+
+    /*
+     * Are we doing sessions? Set this to false if you don't want any session overhead.
+     */
+    private static boolean s_doSessions = true;
+
+    /**
+     * Create a server with default options.
+     */
+    public NotSoSimpleAxisServer()
+    {
+        this( DEFAULT_DOC_ROOT_DIR );
+    }
+
+    /**
+     * Create a server with the specified docRoot.
+     */
+    public NotSoSimpleAxisServer( File docRootDir )
+    {
+        this( docRootDir, DEFAULT_MAX_THREADS );
+    }
+
+    /**
+     * Create a server with the specified docRoot and max threads.
+     */
+    public NotSoSimpleAxisServer( File docRootDir, int maxPoolSize )
+    {
+        this( docRootDir, maxPoolSize, DEFAULT_MAX_SESSIONS );
+    }
+
+    /**
+     * Create a server with the specified docRoot, max threads, and max sessions.
+     */
+    public NotSoSimpleAxisServer( File docRootDir, int maxPoolSize, int maxSessions )
+    {
+        m_docRootDir = docRootDir;
+        m_pool = new ThreadPool( maxPoolSize );
+        m_sessions = new LRUMap( maxSessions );
+    }
+
+    /**
+     * stop the server if not already told to.
+     *
+     * @throws Throwable
+     */
+    protected void finalize() throws Throwable
+    {
+        stop();
+        super.finalize();
+    }
+
+    /**
+     * get max session count
+     *
+     * @return
+     */
+    public int getMaxSessions()
+    {
+        return m_maxSessions;
+    }
+
+    /**
+     * Resize the session map
+     *
+     * @param maxSessions maximum sessions
+     */
+    public void setMaxSessions( int maxSessions )
+    {
+        this.m_maxSessions = maxSessions;
+        ( (LRUMap) m_sessions ).setMaximumSize( maxSessions );
+    }
+    //---------------------------------------------------
+
+    protected boolean isSessionUsed()
+    {
+        return s_doSessions;
+    }
+
+    /**
+     * turn threading on or off. This sets a static value
+     *
+     * @param value
+     */
+    public void setDoThreads( boolean value )
+    {
+        s_doThreads = value;
+    }
+
+    public boolean getDoThreads()
+    {
+        return s_doThreads;
+    }
+
+    public EngineConfiguration getMyConfig()
+    {
+        return m_myConfig;
+    }
+
+    public void setMyConfig( EngineConfiguration myConfig )
+    {
+        m_myConfig = myConfig;
+    }
+
+    /**
+     * demand create a session if there is not already one for the string
+     *
+     * @param cooky
+     *
+     * @return a session.
+     */
+    protected Session createSession( String cooky )
+    {
+
+        // is there a session already?
+        Session session = null;
+        if ( m_sessions.containsKey( cooky ) )
+        {
+            session = (Session) m_sessions.get( cooky );
+        }
+        else
+        {
+            // no session for this cooky, bummer
+            session = new SimpleSession();
+
+            // ADD CLEANUP LOGIC HERE if needed
+            m_sessions.put( cooky, session );
+        }
+        return session;
+    }
+
+    // What is our current session index?
+    // This is a monotonically increasing, non-thread-safe integer
+    // (thread safety not considered crucial here)
+    public static int sessionIndex = 0;
+
+    // Axis server (shared between instances)
+    private static AxisServer myAxisServer = null;
+
+    private EngineConfiguration m_myConfig = null;
+
+    /**
+     * demand create an axis server; return an existing one if one exists. The configuration for the axis server is
+     * derived from #myConfig if not null, the default config otherwise.
+     *
+     * @return
+     */
+    public synchronized AxisServer getAxisServer()
+    {
+        if ( myAxisServer == null )
+        {
+            if ( m_myConfig == null )
+            {
+                m_myConfig = EngineConfigurationFactoryFinder.newFactory().getServerEngineConfig();
+            }
+            myAxisServer = new AxisServer( m_myConfig );
+            ServiceAdmin.setEngine( myAxisServer, NetworkUtils.getLocalHostname() + "@" + m_serverSocket.getLocalPort() );
+        }
+        return myAxisServer;
+    }
+
+    /**
+     * are we stopped? latch to true if stop() is called
+     */
+    private boolean stopped = false;
+
+    /**
+     * Accept requests from a given TCP port and send them through the Axis engine for processing.
+     */
+    public void run()
+    {
+        LOG.info( Messages.getMessage( "start01", "SimpleAxisServer",
+                new Integer( getServerSocket().getLocalPort() ).toString(), getCurrentDirectory() ) );
+
+        // Accept and process requests from the socket
+        while ( !stopped )
+        {
+            Socket socket = null;
+            try
+            {
+                socket = m_serverSocket.accept();
+            }
+            catch ( java.io.InterruptedIOException iie )
+            {
+            }
+            catch ( Exception e )
+            {
+                LOG.debug( Messages.getMessage( "exception00" ), e );
+                break;
+            }
+            if ( socket != null )
+            {
+                SimpleAxisWorker worker = new NotSoSimpleAxisWorker( this, socket, m_docRootDir );
+                if ( s_doThreads )
+                {
+                    m_pool.addWorker( worker );
+                }
+                else
+                {
+                    worker.run();
+                }
+            }
+        }
+        LOG.info( Messages.getMessage( "quit00", "SimpleAxisServer" ) );
+    }
+
+    /**
+     * Gets the current directory
+     *
+     * @return current directory
+     */
+    private String getCurrentDirectory()
+    {
+        return System.getProperty( "user.dir" );
+    }
+
+    // per thread socket information
+    private ServerSocket m_serverSocket;
+
+    /**
+     * Obtain the serverSocket that that SimpleAxisServer is listening on.
+     */
+    public ServerSocket getServerSocket()
+    {
+        return m_serverSocket;
+    }
+
+    /**
+     * Set the serverSocket this server should listen on. (note : changing this will not affect a running server, but if
+     * you stop() and then start() the server, the new socket will be used).
+     */
+    public void setServerSocket( ServerSocket serverSocket )
+    {
+        m_serverSocket = serverSocket;
+    }
+
+    /**
+     * Start this server.
+     * <p/>
+     * Spawns a worker thread to listen for HTTP requests.
+     *
+     * @param daemon a boolean indicating if the thread should be a daemon.
+     */
+    public void start( boolean daemon ) throws Exception
+    {
+        stopped = false;
+        if ( s_doThreads )
+        {
+            Thread thread = new Thread( this );
+            thread.setDaemon( daemon );
+            thread.start();
+        }
+        else
+        {
+            run();
+        }
+    }
+
+    /**
+     * Start this server as a NON-daemon.
+     */
+    public void start() throws Exception
+    {
+        start( false );
+    }
+
+    /**
+     * Stop this server. Can be called safely if the system is already stopped, or if it was never started.
+     * <p/>
+     * This will interrupt any pending accept().
+     */
+    public void stop()
+    {
+        //recognise use before we are live
+        if ( stopped )
+        {
+            return;
+        }
+        /*
+         * Close the server socket cleanly, but avoid fresh accepts while
+         * the socket is closing.
+         */
+        stopped = true;
+
+        try
+        {
+            if ( m_serverSocket != null )
+            {
+                m_serverSocket.close();
+            }
+        }
+        catch ( IOException e )
+        {
+            LOG.info( Messages.getMessage( "exception00" ), e );
+        }
+        finally
+        {
+            m_serverSocket = null;
+        }
+
+        LOG.info( Messages.getMessage( "quit00", "SimpleAxisServer" ) );
+
+        //shut down the pool
+        m_pool.shutdown();
+    }
+
+    /**
+     * Server process.
+     */
+    public static void main( String args[] )
+    {
+
+        Options opts = null;
+        try
+        {
+            opts = new Options( args );
+        }
+        catch ( MalformedURLException e )
+        {
+            LOG.error( Messages.getMessage( "malformedURLException00" ), e );
+            return;
+        }
+
+        String maxPoolSize = opts.isValueSet( 't' );
+        if ( maxPoolSize == null )
+        {
+            maxPoolSize = ThreadPool.DEFAULT_MAX_THREADS + "";
+        }
+
+        String maxSessions = opts.isValueSet( 'm' );
+        if ( maxSessions == null )
+        {
+            maxSessions = DEFAULT_MAX_SESSIONS + "";
+        }
+
+        String[] nonOptionArgs = opts.getRemainingArgs();
+        NotSoSimpleAxisServer server = new NotSoSimpleAxisServer( new File( nonOptionArgs[0] ), Integer.parseInt( maxPoolSize ),
+                Integer.parseInt( maxSessions ) );
+
+        try
+        {
+            s_doThreads = ( opts.isFlagSet( 't' ) > 0 );
+
+            int port = opts.getPort();
+            ServerSocket ss = null;
+            // Try five times
+            final int retries = 5;
+            for ( int i = 0; i < retries; i++ )
+            {
+                try
+                {
+                    ss = new ServerSocket( port );
+                    break;
+                }
+                catch ( java.net.BindException be )
+                {
+                    LOG.debug( Messages.getMessage( "exception00" ), be );
+                    if ( i < ( retries - 1 ) )
+                    {
+                        // At 3 second intervals.
+                        Thread.sleep( 3000 );
+                    }
+                    else
+                    {
+                        throw new Exception( Messages.getMessage( "unableToStartServer00",
+                                Integer.toString( port ) ) );
+                    }
+                }
+            }
+            server.setServerSocket( ss );
+            server.start();
+        }
+        catch ( Exception e )
+        {
+            LOG.error( Messages.getMessage( "exception00" ), e );
+            return;
+        }
+    }
+}

Added: webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisWorker.java
URL: http://svn.apache.org/viewcvs/webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisWorker.java?rev=232376&view=auto
==============================================================================
--- webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisWorker.java (added)
+++ webservices/muse/trunk/src/examples/client/src/test/org/apache/ws/http/NotSoSimpleAxisWorker.java Fri Aug 12 13:38:04 2005
@@ -0,0 +1,956 @@
+/*=============================================================================*
+ *  Confidential Copyright (c) 2004 Hewlett-Packard Development Company, L.P.  *
+ *=============================================================================*/
+package org.apache.ws.http;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.Socket;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.MimeHeader;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPMessage;
+
+import org.apache.axis.AxisFault;
+import org.apache.axis.Constants;
+import org.apache.axis.Message;
+import org.apache.axis.MessageContext;
+import org.apache.axis.description.OperationDesc;
+import org.apache.axis.description.ServiceDesc;
+import org.apache.axis.encoding.Base64;
+import org.apache.axis.message.SOAPEnvelope;
+import org.apache.axis.message.SOAPFault;
+import org.apache.axis.server.AxisServer;
+import org.apache.axis.transport.http.HTTPConstants;
+import org.apache.axis.transport.http.NonBlockingBufferedInputStream;
+import org.apache.axis.transport.http.SimpleAxisServer;
+import org.apache.axis.transport.http.SimpleAxisWorker;
+import org.apache.axis.utils.Messages;
+import org.apache.axis.utils.XMLUtils;
+import org.apache.commons.io.IoUtils;
+import org.w3c.dom.Document;
+
+/**
+ * Web server that supports SOAP POST requests and arbitrary GET requests.
+ * 
+ * @author Ian P. Springer
+ */
+public class NotSoSimpleAxisWorker
+      extends SimpleAxisWorker
+{
+   private static final byte[] TO_LOWER = new byte[256];
+
+   static
+   {
+      for ( int i = 0; i < 256; i++ )
+      {
+         TO_LOWER[i] = (byte) i;
+      }
+
+      for ( int lc = 'a'; lc <= 'z'; lc++ )
+      {
+         TO_LOWER[( lc + 'A' ) - 'a'] = (byte) lc;
+      }
+   }
+
+   // buffer for IO
+   private static final int BUFSIZ = 4096;
+
+   // Axis specific constants
+   private static String TRANSPORT_NAME = "SimpleHTTP";
+
+   // header ender
+   private static final byte[] HEADER_ENDER = ": ".getBytes();
+
+   // HTTP status codes
+   private static byte[] OK = ( "200 " + Messages.getMessage( "ok00" ) ).getBytes();
+   private static byte[] NOCONTENT = ( "202 " + Messages.getMessage( "ok00" ) + "\n\n" ).getBytes();
+   private static byte[] UNAUTH = ( "401 " + Messages.getMessage( "unauth00" ) ).getBytes();
+   private static byte[] SENDER = "400".getBytes();
+   private static byte[] ISE = ( "500 " + Messages.getMessage( "internalError01" ) ).getBytes();
+
+   // HTTP prefix
+   private static byte[] HTTP = "HTTP/1.0 ".getBytes();
+
+   // Standard MIME headers for XML payload
+   private static byte[] XML_MIME_STUFF =
+         ( "\r\nContent-Type: text/xml; charset=utf-8\r\n" + "Content-Length: " ).getBytes();
+
+   // Standard MIME headers for HTML payload
+   private static byte[] HTML_MIME_STUFF =
+         ( "\r\nContent-Type: text/html; charset=utf-8\r\n" + "Content-Length: " ).getBytes();
+
+   // Mime/Content separator
+   private static byte[] SEPARATOR = "\r\n\r\n".getBytes();
+
+   // mime header for content length
+   private static final byte[] lenHeader = "content-length: ".getBytes();
+   private static final int lenLen = lenHeader.length;
+
+   // mime header for content type
+   private static final byte[] typeHeader =
+         ( HTTPConstants.HEADER_CONTENT_TYPE.toLowerCase() + ": " ).getBytes();
+   private static final int typeLen = typeHeader.length;
+
+   // mime header for content location
+   private static final byte[] locationHeader =
+         ( HTTPConstants.HEADER_CONTENT_LOCATION.toLowerCase() + ": " ).getBytes();
+   private static final int locationLen = locationHeader.length;
+
+   // mime header for soap action
+   private static final byte[] actionHeader = "soapaction: ".getBytes();
+   private static final int actionLen = actionHeader.length;
+
+   // mime header for cookie
+   private static final byte[] cookieHeader = "cookie: ".getBytes();
+   private static final int cookieLen = cookieHeader.length;
+
+   // mime header for cookie2
+   private static final byte[] cookie2Header = "cookie2: ".getBytes();
+   private static final int cookie2Len = cookie2Header.length;
+
+   // HTTP header for authentication
+   private static final byte[] authHeader = "authorization: ".getBytes();
+   private static final int authLen = authHeader.length;
+
+   // mime header for GET
+   private static final byte[] getHeader = "GET".getBytes();
+
+   // mime header for POST
+   private static final byte[] postHeader = "POST".getBytes();
+
+   // header ender
+   private static final byte[] headerEnder = ": ".getBytes();
+
+   // "Basic" auth string
+   private static final byte[] basicAuth = "basic ".getBytes();
+   private File m_docRootDir;
+   private NotSoSimpleAxisServer m_server;
+   private Socket m_socket;
+
+   /**
+    * Creates a new {@link NotSoSimpleAxisWorker} object.
+    *
+    * @param server     DOCUMENT_ME
+    * @param socket     DOCUMENT_ME
+    * @param docRootDir DOCUMENT_ME
+    */
+   public NotSoSimpleAxisWorker( NotSoSimpleAxisServer server,
+                                 Socket socket,
+                                 File docRootDir )
+   {
+      super( server, socket );
+      m_server = server;
+      m_socket = socket;
+      m_docRootDir = docRootDir;
+   }
+
+   /**
+    * The main workhorse method.
+    */
+   public void execute()
+   {
+      byte buf[] = new byte[BUFSIZ];
+      // create an Axis server
+      AxisServer engine = m_server.getAxisServer();
+
+      // create and initialize a message context
+      MessageContext msgContext = new MessageContext( engine );
+      Message requestMsg = null;
+
+      // Reusuable, buffered, content length controlled, InputStream
+      NonBlockingBufferedInputStream is =
+            new NonBlockingBufferedInputStream();
+
+      // buffers for the headers we care about
+      StringBuffer soapAction = new StringBuffer();
+      StringBuffer httpRequest = new StringBuffer();
+      StringBuffer fileName = new StringBuffer();
+      StringBuffer cookie = new StringBuffer();
+      StringBuffer cookie2 = new StringBuffer();
+      StringBuffer authInfo = new StringBuffer();
+      StringBuffer contentType = new StringBuffer();
+      StringBuffer contentLocation = new StringBuffer();
+
+      Message responseMsg = null;
+
+      // prepare request (do as much as possible while waiting for the
+      // next connection).  Note the next two statements are commented
+      // out.  Uncomment them if you experience any problems with not
+      // resetting state between requests:
+      //   msgContext = new MessageContext();
+      //   requestMsg = new Message("", "String");
+      //msgContext.setProperty("transport", "HTTPTransport");
+      msgContext.setTransportName( TRANSPORT_NAME );
+
+      responseMsg = null;
+
+      try
+      {
+         // assume the best
+         byte[] status = OK;
+
+         // assume we're not getting WSDL
+         boolean doWsdl = false;
+
+         // cookie for this session, if any
+         String cooky = null;
+
+         String methodName = null;
+
+         try
+         {
+            // wipe cookies if we're doing sessions
+            if ( m_server.isSessionUsed() )
+            {
+               cookie.delete( 0, cookie.length() );
+               cookie2.delete( 0, cookie2.length() );
+            }
+            authInfo.delete( 0, authInfo.length() );
+
+            // read headers
+            is.setInputStream( m_socket.getInputStream() );
+            // parse all headers into hashtable
+            MimeHeaders requestHeaders = new MimeHeaders();
+            int contentLength = parseHeaders( is, buf, contentType,
+                  contentLocation, soapAction,
+                  httpRequest, fileName,
+                  cookie, cookie2, authInfo, requestHeaders );
+            is.setContentLength( contentLength );
+
+            int paramIdx = fileName.toString().indexOf( '?' );
+            if ( paramIdx != -1 )
+            {
+               // Got params
+               String params = fileName.substring( paramIdx + 1 );
+               fileName.setLength( paramIdx );
+
+               log.debug( Messages.getMessage( "filename00",
+                     fileName.toString() ) );
+               log.debug( Messages.getMessage( "params00",
+                     params ) );
+
+               if ( "wsdl".equalsIgnoreCase( params ) )
+               {
+                  doWsdl = true;
+               }
+
+               if ( params.startsWith( "method=" ) )
+               {
+                  methodName = params.substring( 7 );
+               }
+            }
+
+            // Real and relative paths are the same for the
+            // SimpleAxisServer
+            msgContext.setProperty( Constants.MC_REALPATH,
+                  fileName.toString() );
+            msgContext.setProperty( Constants.MC_RELATIVE_PATH,
+                  fileName.toString() );
+            msgContext.setProperty( Constants.MC_JWS_CLASSDIR,
+                  "jwsClasses" );
+            msgContext.setProperty( Constants.MC_HOME_DIR, "." );
+
+            // !!! Fix string concatenation
+            String url = "http://" + getLocalHost() + ":" +
+                  m_server.getServerSocket().getLocalPort() + "/" +
+                  fileName.toString();
+            msgContext.setProperty( MessageContext.TRANS_URL, url );
+
+            String filePart = fileName.toString();
+            if ( filePart.startsWith( "axis/services/" ) )
+            {
+               String servicePart = filePart.substring( 14 );
+               int separator = servicePart.indexOf( '/' );
+               if ( separator > -1 )
+               {
+                  msgContext.setProperty( "objectID",
+                        servicePart.substring( separator + 1 ) );
+                  servicePart = servicePart.substring( 0, separator );
+               }
+               msgContext.setTargetService( servicePart );
+            }
+
+            if ( authInfo.length() > 0 )
+            {
+               // Process authentication info
+               //authInfo = new StringBuffer("dXNlcjE6cGFzczE=");
+               byte[] decoded = Base64.decode( authInfo.toString() );
+               StringBuffer userBuf = new StringBuffer();
+               StringBuffer pwBuf = new StringBuffer();
+               StringBuffer authBuf = userBuf;
+               for ( int i = 0; i < decoded.length; i++ )
+               {
+                  if ( (char) ( decoded[i] & 0x7f ) == ':' )
+                  {
+                     authBuf = pwBuf;
+                     continue;
+                  }
+                  authBuf.append( (char) ( decoded[i] & 0x7f ) );
+               }
+
+               if ( log.isDebugEnabled() )
+               {
+                  log.debug( Messages.getMessage( "user00",
+                        userBuf.toString() ) );
+               }
+
+               msgContext.setUsername( userBuf.toString() );
+               msgContext.setPassword( pwBuf.toString() );
+            }
+
+            // if get, then return simpleton document as response
+            if ( httpRequest.toString().equals( "GET" ) )
+            {
+
+               OutputStream out = m_socket.getOutputStream();
+               out.write( HTTP );
+               if ( fileName.length() == 0 )
+               {
+                  out.write( "301 Redirect\nLocation: /axis/\n\n".getBytes() );
+                  out.flush();
+                  return;
+               }
+               out.write( status );
+
+               if ( methodName != null )
+               {
+                  String body =
+                        "<" + methodName + ">" +
+//                               args +
+                        "</" + methodName + ">";
+                  String msgtxt =
+                        "<SOAP-ENV:Envelope" +
+                        " xmlns:SOAP-ENV=\"" + Constants.URI_SOAP12_ENV + "\">" +
+                        "<SOAP-ENV:Body>" + body + "</SOAP-ENV:Body>" +
+                        "</SOAP-ENV:Envelope>";
+
+                  ByteArrayInputStream istream =
+                        new ByteArrayInputStream( msgtxt.getBytes() );
+                  requestMsg = new Message( istream );
+               }
+               else if ( doWsdl )
+               {
+                  engine.generateWSDL( msgContext );
+
+                  Document doc = (Document) msgContext.getProperty( "WSDL" );
+                  if ( doc != null )
+                  {
+                     XMLUtils.normalize( doc.getDocumentElement() );
+                     String response = XMLUtils.PrettyDocumentToString( doc );
+                     byte[] respBytes = response.getBytes();
+
+                     out.write( XML_MIME_STUFF );
+                     putInt( buf, out, respBytes.length );
+                     out.write( SEPARATOR );
+                     out.write( respBytes );
+                     out.flush();
+                     return;
+                  }
+               }
+               else if ( fileName.equals( "/" ) )
+               {
+                  StringBuffer sb = new StringBuffer();
+                  sb.append( "<h2>And now... Some Services</h2>\n" );
+                  Iterator i = engine.getConfig().getDeployedServices();
+                  sb.append( "<ul>\n" );
+                  while ( i.hasNext() )
+                  {
+                     ServiceDesc sd = (ServiceDesc) i.next();
+                     sb.append( "<li>\n" );
+                     sb.append( sd.getName() );
+                     sb.append( " <a href=\"services/" );
+                     sb.append( sd.getName() );
+                     sb.append( "?wsdl\"><i>(wsdl)</i></a></li>\n" );
+                     ArrayList operations = sd.getOperations();
+                     if ( !operations.isEmpty() )
+                     {
+                        sb.append( "<ul>\n" );
+                        for ( Iterator it = operations.iterator(); it.hasNext(); )
+                        {
+                           OperationDesc desc = (OperationDesc) it.next();
+                           sb.append( "<li>" + desc.getName() );
+                        }
+                        sb.append( "</ul>\n" );
+                     }
+                  }
+                  sb.append( "</ul>\n" );
+
+                  byte[] bytes = sb.toString().getBytes();
+
+                  out.write( HTML_MIME_STUFF );
+                  putInt( buf, out, bytes.length );
+                  out.write( SEPARATOR );
+                  out.write( bytes );
+                  out.flush();
+                  return;
+               }
+               else
+               {
+                   String filePath = fileName.toString();
+                   if ( filePath.startsWith( "/" ) )
+                   {
+                      filePath = filePath.substring( 1 );
+                   }
+                   File realPath = new File( m_docRootDir, filePath );
+                   System.out.println( "Attemping to serving up " + realPath + " ..." );
+                   InputStream in = new BufferedInputStream( new FileInputStream( realPath ) );
+                   out.write( XML_MIME_STUFF );
+                   putInt( buf, out, in.available() );
+                   out.write( SEPARATOR );
+                   //out.write( respBytes );
+                   System.out.println( "Served up " + realPath + " on a silver platter." );
+
+                   
+                   IoUtils.copy( in, out );
+                   in.close();
+                   out.flush();
+                   return;
+               }
+            }
+            else
+            {
+
+               // this may be "" if either SOAPAction: "" or if no SOAPAction at all.
+               // for now, do not complain if no SOAPAction at all
+               String soapActionString = soapAction.toString();
+               if ( soapActionString != null )
+               {
+                  msgContext.setUseSOAPAction( true );
+                  msgContext.setSOAPActionURI( soapActionString );
+               }
+               requestMsg = new Message( is,
+                     false,
+                     contentType.toString(),
+                     contentLocation.toString() );
+            }
+
+            // Transfer HTTP headers to MIME headers for request message.
+            MimeHeaders requestMimeHeaders = requestMsg.getMimeHeaders();
+            for ( Iterator i = requestHeaders.getAllHeaders(); i.hasNext(); )
+            {
+               MimeHeader requestHeader = (MimeHeader) i.next();
+               requestMimeHeaders.addHeader( requestHeader.getName(), requestHeader.getValue() );
+            }
+            msgContext.setRequestMessage( requestMsg );
+            // put character encoding of request to message context
+            // in order to reuse it during the whole process.
+            String requestEncoding = (String) requestMsg.getProperty( SOAPMessage.CHARACTER_SET_ENCODING );
+            if ( requestEncoding != null )
+            {
+               msgContext.setProperty( SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding );
+            }
+
+            // set up session, if any
+            if ( m_server.isSessionUsed() )
+            {
+               // did we get a cookie?
+               if ( cookie.length() > 0 )
+               {
+                  cooky = cookie.toString().trim();
+               }
+               else if ( cookie2.length() > 0 )
+               {
+                  cooky = cookie2.toString().trim();
+               }
+
+               // if cooky is null, cook up a cooky
+               if ( cooky == null )
+               {
+                  // fake one up!
+                  // make it be an arbitrarily increasing number
+                  // (no this is not thread safe because ++ isn't atomic)
+                  int i = SimpleAxisServer.sessionIndex++;
+                  cooky = "" + i;
+               }
+
+               msgContext.setSession( m_server.createSession( cooky ) );
+            }
+
+            // invoke the Axis engine
+            engine.invoke( msgContext );
+
+            // Retrieve the response from Axis
+            responseMsg = msgContext.getResponseMessage();
+
+            if ( responseMsg == null )
+            {
+               status = NOCONTENT;
+            }
+         }
+         catch ( Exception e )
+         {
+            AxisFault af;
+            if ( e instanceof AxisFault )
+            {
+               af = (AxisFault) e;
+               log.debug( Messages.getMessage( "serverFault00" ), af );
+               QName faultCode = af.getFaultCode();
+               if ( Constants.FAULT_SOAP12_SENDER.equals( faultCode ) )
+               {
+                  status = SENDER;
+               }
+               else if ( "Server.Unauthorized".equals( af.getFaultCode().getLocalPart() ) )
+               {
+                  status = UNAUTH; // SC_UNAUTHORIZED
+               }
+               else
+               {
+                  status = ISE; // SC_INTERNAL_SERVER_ERROR
+               }
+            }
+            else
+            {
+               status = ISE; // SC_INTERNAL_SERVER_ERROR
+               af = AxisFault.makeFault( e );
+            }
+
+            // There may be headers we want to preserve in the
+            // response message - so if it's there, just add the
+            // FaultElement to it.  Otherwise, make a new one.
+            responseMsg = msgContext.getResponseMessage();
+            if ( responseMsg == null )
+            {
+               responseMsg = new Message( af );
+               responseMsg.setMessageContext( msgContext );
+            }
+            else
+            {
+               try
+               {
+                  SOAPEnvelope env = responseMsg.getSOAPEnvelope();
+                  env.clearBody();
+                  env.addBodyElement( new SOAPFault( (AxisFault) e ) );
+               }
+               catch ( AxisFault fault )
+               {
+                  // Should never reach here!
+               }
+            }
+         }
+
+         // synchronize the character encoding of request and response
+         String responseEncoding = (String) msgContext.getProperty( SOAPMessage.CHARACTER_SET_ENCODING );
+         if ( responseEncoding != null && responseMsg != null )
+         {
+            responseMsg.setProperty( SOAPMessage.CHARACTER_SET_ENCODING, responseEncoding );
+         }
+         // Send it on its way...
+         OutputStream out = m_socket.getOutputStream();
+         out.write( HTTP );
+         out.write( status );
+
+         if ( responseMsg != null )
+         {
+            if ( m_server.isSessionUsed() && null != cooky &&
+                  0 != cooky.trim().length() )
+            {
+               // write cookie headers, if any
+               // don't sweat efficiency *too* badly
+               // optimize at will
+               StringBuffer cookieOut = new StringBuffer();
+               cookieOut.append( "\r\nSet-Cookie: " )
+                     .append( cooky )
+                     .append( "\r\nSet-Cookie2: " )
+                     .append( cooky );
+               // OH, THE HUMILITY!  yes this is inefficient.
+               out.write( cookieOut.toString().getBytes() );
+            }
+
+            //out.write(XML_MIME_STUFF);
+            out.write(
+                  ( "\r\n" + HTTPConstants.HEADER_CONTENT_TYPE + ": " +
+                  responseMsg.getContentType( msgContext.getSOAPConstants() ) ).getBytes() );
+            // Writing the length causes the entire message to be decoded twice.
+            //out.write(("\r\n" + HTTPConstants.HEADER_CONTENT_LENGTH + ": " + responseMsg.getContentLength()).getBytes());
+            // putInt(out, response.length);
+
+            // Transfer MIME headers to HTTP headers for response message.
+            for ( Iterator i = responseMsg.getMimeHeaders().getAllHeaders(); i.hasNext(); )
+            {
+               MimeHeader responseHeader = (MimeHeader) i.next();
+               out.write( '\r' );
+               out.write( '\n' );
+               out.write( responseHeader.getName().getBytes() );
+               out.write( headerEnder );
+               out.write( responseHeader.getValue().getBytes() );
+            }
+
+            out.write( SEPARATOR );
+            responseMsg.writeTo( out );
+         }
+
+         // out.write(response);
+         out.flush();
+      }
+      catch ( Exception e )
+      {
+         log.info( Messages.getMessage( "exception00" ), e );
+      }
+      finally
+      {
+         try
+         {
+            if ( m_socket != null )
+            {
+               m_socket.close();
+            }
+         }
+         catch ( Exception e )
+         {
+         }
+      }
+      if ( msgContext.getProperty( MessageContext.QUIT_REQUESTED ) != null )
+      {
+         // why then, quit!
+         try
+         {
+            m_server.stop();
+         }
+         catch ( Exception e )
+         {
+         }
+      }
+
+   }
+
+   /**
+    * Read all mime headers, returning the value of Content-Length and SOAPAction.
+    *
+    * @param is              InputStream to read from
+    * @param contentType     The content type.
+    * @param contentLocation The content location
+    * @param soapAction      StringBuffer to return the soapAction into
+    * @param httpRequest     StringBuffer for GET / POST
+    * @param cookie          first cookie header (if doSessions)
+    * @param cookie2         second cookie header (if doSessions)
+    * @param headers         HTTP headers to transfer to MIME headers
+    *
+    * @return Content-Length
+    */
+   private int parseHeaders( NonBlockingBufferedInputStream is,
+                             byte[] buf,
+                             StringBuffer contentType,
+                             StringBuffer contentLocation,
+                             StringBuffer soapAction,
+                             StringBuffer httpRequest,
+                             StringBuffer fileName,
+                             StringBuffer cookie,
+                             StringBuffer cookie2,
+                             StringBuffer authInfo,
+                             MimeHeaders headers )
+         throws java.io.IOException
+   {
+      int n;
+      int len = 0;
+
+      // parse first line as GET or POST
+      n = this.readLine( is, buf, 0, buf.length );
+
+      if ( n < 0 )
+      {
+         // nothing!
+         throw new java.io.IOException( Messages.getMessage( "unexpectedEOS00" ) );
+      }
+
+      // which does it begin with?
+      httpRequest.delete( 0,
+            httpRequest.length() );
+      fileName.delete( 0,
+            fileName.length() );
+      contentType.delete( 0,
+            contentType.length() );
+      contentLocation.delete( 0,
+            contentLocation.length() );
+
+      if ( buf[0] == getHeader[0] )
+      {
+         httpRequest.append( "GET" );
+
+         for ( int i = 0; i < ( n - 5 ); i++ )
+         {
+            char c = (char) ( buf[i + 5] & 0x7f );
+
+            if ( c == ' ' )
+            {
+               break;
+            }
+
+            fileName.append( c );
+         }
+
+         log.debug( Messages.getMessage( "filename01",
+               "SimpleAxisServer",
+               fileName.toString() ) );
+
+         return 0;
+      }
+      else if ( buf[0] == postHeader[0] )
+      {
+         httpRequest.append( "POST" );
+
+         for ( int i = 0; i < ( n - 6 ); i++ )
+         {
+            char c = (char) ( buf[i + 6] & 0x7f );
+
+            if ( c == ' ' )
+            {
+               break;
+            }
+
+            fileName.append( c );
+         }
+
+         log.debug( Messages.getMessage( "filename01",
+               "SimpleAxisServer",
+               fileName.toString() ) );
+      }
+      else
+      {
+         throw new java.io.IOException( Messages.getMessage( "badRequest00" ) );
+      }
+
+      while ( ( n = readLine( is, buf, 0, buf.length ) ) > 0 )
+      {
+         if ( ( n <= 2 ) && ( ( buf[0] == '\n' ) || ( buf[0] == '\r' ) ) && ( len > 0 ) )
+         {
+            break;
+         }
+
+         // RobJ gutted the previous logic; it was too hard to extend for more headers.
+         // Now, all it does is search forwards for ": " in the buf,
+         // then do a length / byte compare.
+         // Hopefully this is still somewhat efficient (Sam is watching!).
+         // First, search forwards for ": "
+         int endHeaderIndex = 0;
+
+         while ( ( endHeaderIndex < n ) && ( TO_LOWER[buf[endHeaderIndex]] != headerEnder[0] ) )
+         {
+            endHeaderIndex++;
+         }
+
+         endHeaderIndex += 2;
+
+         // endHeaderIndex now points _just past_ the ": ", and is
+         // comparable to the various lenLen, actionLen, etc. values
+         // convenience; i gets pre-incremented, so initialize it to one less
+         int i = endHeaderIndex - 1;
+
+         // which header did we find?
+         if ( ( endHeaderIndex == lenLen ) && matches( buf, lenHeader ) )
+         {
+            // parse content length
+            while ( ( ++i < n ) && ( buf[i] >= '0' ) && ( buf[i] <= '9' ) )
+            {
+               len = ( len * 10 ) + ( buf[i] - '0' );
+            }
+
+            headers.addHeader( HTTPConstants.HEADER_CONTENT_LENGTH,
+                  String.valueOf( len ) );
+         }
+         else if ( ( endHeaderIndex == actionLen ) && matches( buf, actionHeader ) )
+         {
+            soapAction.delete( 0,
+                  soapAction.length() );
+
+            // skip initial '"'
+            i++;
+
+            while ( ( ++i < n ) && ( buf[i] != '"' ) )
+            {
+               soapAction.append( (char) ( buf[i] & 0x7f ) );
+            }
+
+            headers.addHeader( HTTPConstants.HEADER_SOAP_ACTION, "\"" + soapAction.toString() + "\"" );
+         }
+         else if ( m_server.isSessionUsed() && ( endHeaderIndex == cookieLen ) && matches( buf, cookieHeader ) )
+         {
+            // keep everything up to first ;
+            while ( ( ++i < n ) && ( buf[i] != ';' ) && ( buf[i] != '\r' ) && ( buf[i] != '\n' ) )
+            {
+               cookie.append( (char) ( buf[i] & 0x7f ) );
+            }
+
+            headers.addHeader( "Set-Cookie",
+                  cookie.toString() );
+         }
+         else if ( m_server.isSessionUsed() && ( endHeaderIndex == cookie2Len ) && matches( buf, cookie2Header ) )
+         {
+            // keep everything up to first ;
+            while ( ( ++i < n ) && ( buf[i] != ';' ) && ( buf[i] != '\r' ) && ( buf[i] != '\n' ) )
+            {
+               cookie2.append( (char) ( buf[i] & 0x7f ) );
+            }
+
+            headers.addHeader( "Set-Cookie2",
+                  cookie.toString() );
+         }
+         else if ( ( endHeaderIndex == authLen ) && matches( buf, authHeader ) )
+         {
+            if ( matches( buf, endHeaderIndex, basicAuth ) )
+            {
+               i += basicAuth.length;
+
+               while ( ( ++i < n ) && ( buf[i] != '\r' ) && ( buf[i] != '\n' ) )
+               {
+                  if ( buf[i] == ' ' )
+                  {
+                     continue;
+                  }
+
+                  authInfo.append( (char) ( buf[i] & 0x7f ) );
+               }
+
+               headers.addHeader( HTTPConstants.HEADER_AUTHORIZATION,
+                     new String( basicAuth ) + authInfo.toString() );
+            }
+            else
+            {
+               throw new java.io.IOException( Messages.getMessage( "badAuth00" ) );
+            }
+         }
+         else if ( ( endHeaderIndex == locationLen ) && matches( buf, locationHeader ) )
+         {
+            while ( ( ++i < n ) && ( buf[i] != '\r' ) && ( buf[i] != '\n' ) )
+            {
+               if ( buf[i] == ' ' )
+               {
+                  continue;
+               }
+
+               contentLocation.append( (char) ( buf[i] & 0x7f ) );
+            }
+
+            headers.addHeader( HTTPConstants.HEADER_CONTENT_LOCATION,
+                  contentLocation.toString() );
+         }
+         else if ( ( endHeaderIndex == typeLen ) && matches( buf, typeHeader ) )
+         {
+            while ( ( ++i < n ) && ( buf[i] != '\r' ) && ( buf[i] != '\n' ) )
+            {
+               if ( buf[i] == ' ' )
+               {
+                  continue;
+               }
+
+               contentType.append( (char) ( buf[i] & 0x7f ) );
+            }
+
+            headers.addHeader( HTTPConstants.HEADER_CONTENT_TYPE,
+                  contentLocation.toString() );
+         }
+         else
+         {
+            String customHeaderName = new String( buf, 0, endHeaderIndex - 2 );
+            StringBuffer customHeaderValue = new StringBuffer();
+
+            while ( ( ++i < n ) && ( buf[i] != '\r' ) && ( buf[i] != '\n' ) )
+            {
+               if ( buf[i] == ' ' )
+               {
+                  continue;
+               }
+
+               customHeaderValue.append( (char) ( buf[i] & 0x7f ) );
+            }
+
+            headers.addHeader( customHeaderName,
+                  customHeaderValue.toString() );
+         }
+      }
+
+      return len;
+   }
+
+   /**
+    * output an integer into the output stream
+    *
+    * @param out   OutputStream to be written to
+    * @param value Integer value to be written.
+    */
+   private void putInt( byte[] buf,
+                        OutputStream out,
+                        int value )
+         throws java.io.IOException
+   {
+      int len = 0;
+      int offset = buf.length;
+
+      // negative numbers
+      if ( value < 0 )
+      {
+         buf[--offset] = (byte) '-';
+         value = -value;
+         len++;
+      }
+
+      // zero
+      if ( value == 0 )
+      {
+         buf[--offset] = (byte) '0';
+         len++;
+      }
+
+      // positive numbers
+      while ( value > 0 )
+      {
+         buf[--offset] = (byte) ( ( value % 10 ) + '0' );
+         value = value / 10;
+         len++;
+      }
+
+      // write the result
+      out.write( buf, offset, len );
+   }
+
+   /**
+    * Read a single line from the input stream
+    *
+    * @param is  inputstream to read from
+    * @param b   byte array to read into
+    * @param off starting offset into the byte array
+    * @param len maximum number of bytes to read
+    */
+   private int readLine( NonBlockingBufferedInputStream is,
+                         byte[] b,
+                         int off,
+                         int len )
+         throws java.io.IOException
+   {
+      int count = 0;
+      int c;
+
+      while ( ( c = is.read() ) != -1 )
+      {
+         if ( ( c != '\n' ) && ( c != '\r' ) )
+         {
+            b[off++] = (byte) c;
+            count++;
+         }
+
+         if ( count == len )
+         {
+            break;
+         }
+
+         if ( '\n' == c )
+         {
+            int peek = is.peek(); //If the next line begins with tab or space then this is a continuation.
+
+            if ( ( peek != ' ' ) && ( peek != '\t' ) )
+            {
+               break;
+            }
+         }
+      }
+
+      return ( count > 0 ) ? count : ( -1 );
+   }
+}
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: muse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-dev-help@ws.apache.org