1 7 package org.jboss.test.remoting.transport.web; 8 9 import java.util.HashMap ; 10 import java.util.Map ; 11 import java.util.Properties ; 12 import org.jboss.remoting.Client; 13 import org.jboss.remoting.InvokerLocator; 14 import org.jboss.remoting.transport.http.HTTPServerInvoker; 15 16 import junit.framework.TestCase; 17 18 21 public abstract class WebInvokerTestClient extends TestCase 22 { 23 public abstract String getLocatorURI(); 24 25 public void testInvocation() throws Exception 26 { 27 Client remotingClient = null; 28 29 try 30 { 31 InvokerLocator locator = new InvokerLocator(getLocatorURI()); 32 System.out.println("Calling remoting server with locator uri of: " + getLocatorURI()); 33 34 remotingClient = new Client(locator); 35 36 Map metadata = new HashMap (); 37 metadata.put(Client.RAW, Boolean.TRUE); 38 metadata.put("TYPE", "POST"); 39 40 Properties headerProps = new Properties (); 41 headerProps.put("Content-type", "application/soap+xml"); 42 43 metadata.put("HEADER", headerProps); 44 45 Object response = null; 46 47 response = remotingClient.invoke(WebInvocationHandler.NULL_RETURN_PARAM, metadata); 49 System.out.println("First response should be null and was: " + response); 50 assertNull(response); 51 52 response = remotingClient.invoke("Do something", metadata); 53 System.out.println("Second response should be " + WebInvocationHandler.HTML_PAGE_RESPONSE + " and was: " + response); 54 assertEquals(WebInvocationHandler.HTML_PAGE_RESPONSE, response); 55 56 headerProps.put("Content-type", HTTPServerInvoker.BINARY); 57 response = remotingClient.invoke(new ComplexObject(2, "foo", true), metadata); 58 System.out.println("Third response should be " + WebInvocationHandler.OBJECT_RESPONSE_VALUE + " and was: " + response); 59 assertEquals(WebInvocationHandler.OBJECT_RESPONSE_VALUE, response); 60 61 response = remotingClient.invoke(WebInvocationHandler.STRING_RETURN_PARAM, metadata); 62 System.out.println("Fourth response should be " + WebInvocationHandler.RESPONSE_VALUE + " and was: " + response); 63 assertEquals(WebInvocationHandler.RESPONSE_VALUE, response); 64 65 try 66 { 67 response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata); 68 assertTrue("Should have received an exception.", false); 69 } 70 catch(Throwable throwable) 71 { 72 assertTrue("Received exception as expected", true); 73 } 75 76 remotingClient.invokeOneway("Do something", metadata, true); 77 78 remotingClient.invokeOneway("Do something", metadata, false); 79 } 80 catch(Throwable throwable) 81 { 82 throw new Exception (throwable); 83 } 84 finally 85 { 86 if(remotingClient != null) 87 { 88 remotingClient.disconnect(); 89 } 90 } 91 92 93 } 94 } | Popular Tags |