1 7 package org.jboss.remoting.transport.http; 8 9 import org.jboss.dtf.MultipleTestRunner; 10 import org.jboss.remoting.AbstractInvokerTest; 11 import org.jboss.remoting.Client; 12 import org.jboss.remoting.InvokerLocator; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 import java.util.Properties ; 17 18 21 public class HTTPInvokerTestClient extends AbstractInvokerTest 22 { 23 private static String transport = "http"; 25 private static String host = "localhost"; 26 private static int port = 8888; 27 28 public HTTPInvokerTestClient(String name) 29 { 30 super(name); 31 } 32 33 public HTTPInvokerTestClient(String name, int numberOfInstances) 34 { 35 super(name, numberOfInstances); 36 } 37 38 public HTTPInvokerTestClient(String name, String transport, int port) 39 { 40 super(name, transport, port); 41 } 42 43 public HTTPInvokerTestClient(String name, String transport, int port, int numberOfInstances) 44 { 45 super(name, transport, port, numberOfInstances); 46 } 47 48 public void testInvocation() throws Exception 49 { 50 String locatorURI = transport + "://" + host + ":" + port; 51 InvokerLocator locator = new InvokerLocator(locatorURI); 52 System.out.println("Calling remoting server with locator uri of: " + locatorURI); 53 54 Client remotingClient = new Client(locator, null); 57 58 Map metadata = new HashMap (); 59 metadata.put(Client.RAW, Boolean.TRUE); 60 metadata.put("TYPE", "POST"); 61 62 Properties headerProps = new Properties (); 63 headerProps.put("SOAPAction", "http://www.example.com/fibonacci"); 64 headerProps.put("Content-type", "application/soap+xml"); 65 66 metadata.put("HEADER", headerProps); 67 68 Object response = null; 69 70 try 72 { 73 response = remotingClient.invoke(HTTPInvokerTestServer.NULL_RETURN_PARAM, metadata); 74 } 75 catch(Throwable throwable) 76 { 77 throw new Exception (throwable); 78 } 79 80 assertNull(response); 81 82 try 83 { 84 response = remotingClient.invoke("Do something", metadata); 85 } 86 catch(Throwable throwable) 87 { 88 throw new Exception (throwable); 89 } 90 91 assertEquals(HTTPInvokerTestServer.RESPONSE_VALUE, response); 92 93 headerProps.put("Content-type", HTTPServerInvoker.BINARY); 94 try 95 { 96 response = remotingClient.invoke(new ComplexObject(2, "foo", true), metadata); 97 } 98 catch(Throwable throwable) 99 { 100 throw new Exception (throwable); 101 } 102 103 assertEquals(HTTPInvokerTestServer.OBJECT_RESPONSE_VALUE, response); 104 105 } 106 107 113 public static void main(String [] args) 114 { 115 int numberOfInstances = 2; 116 117 if(args != null && args.length == 1) 118 { 119 numberOfInstances = Integer.parseInt(args[0]); 120 } 121 if(args != null && args.length == 2) 122 { 123 transport = args[0]; 124 port = Integer.parseInt(args[1]); 125 } 126 127 HTTPInvokerTestClient client = new HTTPInvokerTestClient(HTTPInvokerTestClient.class.getName(), numberOfInstances); 128 try 129 { 130 MultipleTestRunner runner = new MultipleTestRunner(); 132 runner.doRun(client, true); 133 } 134 catch(Throwable e) 135 { 136 e.printStackTrace(); 137 System.exit(1); 138 } 139 System.exit(0); 140 141 } 142 143 } | Popular Tags |