package org.codehaus.xfire.client;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.codehaus.xfire.aegis.AbstractXFireAegisTest;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.invoker.BeanInvoker;
import org.codehaus.xfire.transport.local.LocalTransport;
import org.codehaus.xfire.util.LoggingHandler;
import org.codehaus.xfire.util.dom.DOMOutHandler;

public class ConcatClientTest
    extends AbstractXFireAegisTest
{
    public void testDynamicClient() throws Exception
    {
        Service s = getServiceFactory().create(ConcatService.class);
        s.setInvoker(new BeanInvoker(new ConcatService()
        {
            public String concat(String s1, String s2)
            {
                return s1 + s2;
            }
        }));

        getServiceRegistry().register(s);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        s.getWSDLWriter().write(bos);
        Client client = new Client(new ByteArrayInputStream(bos.toByteArray()), null);
        client.setXFire(getXFire());
        client.setUrl("xfire.local://ConcatService");
        client.setTransport(getTransportManager().getTransport(LocalTransport.BINDING_ID));
        
        client.addOutHandler(new LoggingHandler());
        client.addOutHandler(new DOMOutHandler());
        
        Object[] res = client.invoke("concat", new Object[]{"1", "2"});
        
        assertEquals("12", res[0]);
    }

    public static interface ConcatService
    {
        String concat(String s1, String s2);
    }
}

@@ -329,107 +329,8 @@
 rt;%0D
-%0Aimport org.codehaus.xfire.util.LoggingHandler;%0D%0Aimport org.codehaus.xfire.util.dom.DOMOutHandler;%0D
 %0A%0D%0Ap
@@ -716,16 +716,167 @@
       %7D%0D
+%0A%0D%0A            public String concat(String s1, String s2, String s3)%0D%0A            %7B%0D%0A                return s1 + s2 + s3;%0D%0A            %7D%0D%0A            %0D
 %0A       
@@ -1304,32 +1304,34 @@
 DING_ID));%0D%0A
+%0D%0A
         
 %0D%0A        cl
@@ -1322,111 +1322,116 @@
     
-%0D%0A        client.addOutHandler(new LoggingHandler());%0D%0A        client.addOutHandler(new DOMOutHandler()
+Object%5B%5D res = client.invoke(%22concat%22, new Object%5B%5D%7B%221%22, %222%22%7D);%0D%0A        %0D%0A        assertEquals(%2212%22, res%5B0%5D
 );%0D%0A
@@ -1443,33 +1443,24 @@
    %0D%0A       
- Object%5B%5D
  res = clien
@@ -1467,32 +1467,33 @@
 t.invoke(%22concat
+1
 %22, new Object%5B%5D%7B
@@ -1492,32 +1492,37 @@
 bject%5B%5D%7B%221%22, %222%22
+, %223%22
 %7D);%0D%0A        %0D%0A 
@@ -1536,32 +1536,33 @@
 assertEquals(%2212
+3
 %22, res%5B0%5D);%0D%0A   
@@ -1659,22 +1659,89 @@
 tring s2);%0D%0A
+        %0D%0A        String concat(String s1, String s2, String s3);%0D%0A
     %7D%0D%0A%7D%0D%0A

extend the test case a bit more to try and reproduce errors...