1 7 package org.jboss.remoting.transport.http; 8 9 import junit.framework.TestCase; 10 import org.apache.log4j.Level; 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 24 public class HTTPInvokerClientTestCase extends TestCase 25 { 26 private Client client; 27 28 public void init(String httpTargetURL) 29 { 30 try 31 { 32 InvokerLocator locator = new InvokerLocator(httpTargetURL); 33 client = new Client(locator, null); 34 client.connect(); 35 } 36 catch(Exception e) 37 { 38 e.printStackTrace(); 39 } 40 } 41 42 public String makeInvocationCall(String httpTargetURL, String payload, Map metadata) throws Throwable 43 { 44 init(httpTargetURL); 45 Object obj = client.invoke(payload, metadata); 46 47 System.out.println("invoke returned" + obj); 48 49 return (String ) obj; 50 } 51 52 public void testWeatherHTTPInvocation() throws Throwable 53 { 54 55 org.apache.log4j.BasicConfigurator.configure(); 56 org.apache.log4j.Category.getRoot().setLevel(Level.INFO); 57 org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO); 58 org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG); 59 org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG); 60 61 62 String testURL = "http://services.xmethods.net:80/soap/servlet/rpcrouter"; 63 64 String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 65 "<soap:Envelope xmlns:mrns0=\"urn:xmethods-Temperature\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + 66 " <soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" + 67 " <mrns0:getTemp>\n" + 68 " <zipcode xsi:type=\"xs:string\">30106</zipcode>\n" + 69 " </mrns0:getTemp>\n" + 70 " </soap:Body>\n" + 71 "</soap:Envelope>"; 72 73 Map metadata = new HashMap (); 74 metadata.put(Client.RAW, Boolean.TRUE); 75 metadata.put("TYPE", "POST"); 76 77 Properties headerProps = new Properties (); 78 headerProps.put("SOAPAction", ""); 79 headerProps.put("Content-type", "text/xml; charset=UTF-8"); 80 81 metadata.put("HEADER", headerProps); 82 83 84 HTTPInvokerClientTestCase client = new HTTPInvokerClientTestCase(); 85 86 String result = client.makeInvocationCall(testURL, xml, metadata); 87 assertEquals(getExpectedWeatherResult().substring(0, 380), result.substring(0, 380)); 89 90 } 91 92 public void testCitiesByCountryHTTPInvocation() throws Throwable 93 { 94 95 org.apache.log4j.BasicConfigurator.configure(); 96 org.apache.log4j.Category.getRoot().setLevel(Level.INFO); 97 org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO); 98 org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG); 99 org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG); 100 101 102 String testURL = "http://www.webserviceX.NET/globalweather.asmx?op=GetCitiesByCountry"; 103 104 String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 105 "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + 106 " <soap:Body>\n" + 107 " <GetCitiesByCountry xmlns=\"http://www.webserviceX.NET\">\n" + 108 " <CountryName>Germany</CountryName>\n" + 109 " </GetCitiesByCountry>\n" + 110 " </soap:Body>\n" + 111 "</soap:Envelope>"; 112 113 Map metadata = new HashMap (); 114 metadata.put(Client.RAW, Boolean.TRUE); 115 metadata.put("TYPE", "POST"); 116 117 Properties headerProps = new Properties (); 118 headerProps.put("SOAPAction", "http://www.webserviceX.NET/GetCitiesByCountry"); 119 headerProps.put("Content-type", "text/xml; charset=UTF-8"); 120 121 metadata.put("HEADER", headerProps); 122 123 124 HTTPInvokerClientTestCase client = new HTTPInvokerClientTestCase(); 125 126 String result = client.makeInvocationCall(testURL, xml, metadata); 127 assertEquals(getExpectedCityResult().substring(0, 2000), result.substring(0, 2000)); 129 130 } 131 132 133 private String getExpectedWeatherResult() 134 { 135 return "<?xml version='1.0' encoding='UTF-8'?>" + 136 "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 137 "<SOAP-ENV:Body>" + 138 "<ns1:getTempResponse xmlns:ns1=\"urn:xmethods-Temperature\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + 139 "<return xsi:type=\"xsd:float\">60.0</return>" + 140 "</ns1:getTempResponse>" + 141 "\n" + 142 "</SOAP-ENV:Body>\n" + 143 "</SOAP-ENV:Envelope>"; 144 } 145 146 private String getExpectedCityResult() 147 { 148 return "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 149 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 150 "<soap:Body><GetCitiesByCountryResponse xmlns=\"http://www.webserviceX.NET\"><GetCitiesByCountryResult><NewDataSet> " + 151 "<Table> <Country>Germany</Country> <City>Berlin-Schoenefeld</City> </Table> <Table> " + 152 "<Country>Germany</Country> <City>Dresden-Klotzsche</City> </Table> <Table> " + 153 " <Country>Germany</Country> <City>Erfurt-Bindersleben</City> </Table> <Table> " + 154 " <Country>Germany</Country> <City>Frankfurt / M-Flughafen</City> </Table> <Table> " + 155 "<Country>Germany</Country> <City>Muenster / Osnabrueck</City> </Table> <Table> " + 156 "<Country>Germany</Country> <City>Hamburg-Fuhlsbuettel</City> </Table> <Table> " + 157 " <Country>Germany</Country> <City>Berlin-Tempelhof</City> </Table> <Table> " + 158 "<Country>Germany</Country> <City>Koeln / Bonn</City> </Table> <Table> " + 159 "<Country>Germany</Country> <City>Duesseldorf</City> </Table> <Table> " + 160 " <Country>Germany</Country> <City>Munich / Riem</City> </Table> <Table> " + 161 " <Country>Germany</Country> <City>Nuernberg</City> </Table> <Table> " + 162 " <Country>Germany</Country> <City>Leipzig-Schkeuditz</City> </Table> <Table> " + 163 " <Country>Germany</Country> <City>Saarbruecken / Ensheim</City> </Table> <Table> " + 164 "<Country>Germany</Country> <City>Stuttgart-Echterdingen</City> </Table> <Table> " + 165 " <Country>Germany</Country> <City>Berlin-Tegel</City> </Table> <Table> " + 166 "<Country>Germany</Country> <City>Hannover</City> </Table> <Table> " + 167 "<Country>Germany</Country> <City>Bremen</City> </Table> <Table> " + 168 " <Country>Germany</Country> <City>Hahn</City> </Table> <Table>" + 169 " <Country>Germany</Country> <City>Baden Wurttemberg, Neuostheim</"; 170 } 171 172 178 } | Popular Tags |