1 7 package org.jboss.test.remoting.transport.http; 8 9 import java.util.HashMap ; 10 import java.util.Map ; 11 import java.util.Properties ; 12 import org.apache.log4j.Level; 13 import org.jboss.remoting.Client; 14 import org.jboss.remoting.InvokerLocator; 15 16 import junit.framework.TestCase; 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 83 Properties headerProps = new Properties (); 84 headerProps.put("SOAPAction", ""); 85 headerProps.put("Content-type", "text/xml; charset=UTF-8"); 86 87 metadata.put("HEADER", headerProps); 88 89 90 HTTPInvokerClientTestCase client = new HTTPInvokerClientTestCase(); 91 92 String result = client.makeInvocationCall(testURL, xml, metadata); 93 assertEquals(getExpectedWeatherResult().substring(0, 380), result.substring(0, 380)); 95 96 } 97 98 public void testCitiesByCountryHTTPInvocation() throws Throwable 99 { 100 101 org.apache.log4j.BasicConfigurator.configure(); 102 org.apache.log4j.Category.getRoot().setLevel(Level.INFO); 103 org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO); 104 org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG); 105 org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG); 106 107 108 String testURL = "http://www.webserviceX.NET/globalweather.asmx?op=GetCitiesByCountry"; 109 110 String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + 111 "<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" + 112 " <soap:Body>\n" + 113 " <GetCitiesByCountry xmlns=\"http://www.webserviceX.NET\">\n" + 114 " <CountryName>Germany</CountryName>\n" + 115 " </GetCitiesByCountry>\n" + 116 " </soap:Body>\n" + 117 "</soap:Envelope>"; 118 119 Map metadata = new HashMap (); 120 metadata.put(Client.RAW, Boolean.TRUE); 121 metadata.put("TYPE", "POST"); 122 123 129 Properties headerProps = new Properties (); 130 headerProps.put("SOAPAction", "http://www.webserviceX.NET/GetCitiesByCountry"); 131 headerProps.put("Content-type", "text/xml; charset=UTF-8"); 132 133 metadata.put("HEADER", headerProps); 134 135 136 HTTPInvokerClientTestCase client = new HTTPInvokerClientTestCase(); 137 138 String result = client.makeInvocationCall(testURL, xml, metadata); 139 assertEquals(getExpectedCityResult().substring(0, 2000), result.substring(0, 2000)); 141 142 } 143 144 145 private String getExpectedWeatherResult() 146 { 147 return "<?xml version='1.0' encoding='UTF-8'?>" + 148 "<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\">" + 149 "<SOAP-ENV:Body>" + 150 "<ns1:getTempResponse xmlns:ns1=\"urn:xmethods-Temperature\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + 151 "<return xsi:type=\"xsd:float\">60.0</return>" + 152 "</ns1:getTempResponse>" + 153 "\n" + 154 "</SOAP-ENV:Body>\n" + 155 "</SOAP-ENV:Envelope>"; 156 } 157 158 private String getExpectedCityResult() 159 { 160 return "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 161 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" + 162 "<soap:Body><GetCitiesByCountryResponse xmlns=\"http://www.webserviceX.NET\"><GetCitiesByCountryResult><NewDataSet> " + 163 "<Table> <Country>Germany</Country> <City>Berlin-Schoenefeld</City> </Table> <Table> " + 164 "<Country>Germany</Country> <City>Dresden-Klotzsche</City> </Table> <Table> " + 165 " <Country>Germany</Country> <City>Erfurt-Bindersleben</City> </Table> <Table> " + 166 " <Country>Germany</Country> <City>Frankfurt / M-Flughafen</City> </Table> <Table> " + 167 "<Country>Germany</Country> <City>Muenster / Osnabrueck</City> </Table> <Table> " + 168 "<Country>Germany</Country> <City>Hamburg-Fuhlsbuettel</City> </Table> <Table> " + 169 " <Country>Germany</Country> <City>Berlin-Tempelhof</City> </Table> <Table> " + 170 "<Country>Germany</Country> <City>Koeln / Bonn</City> </Table> <Table> " + 171 "<Country>Germany</Country> <City>Duesseldorf</City> </Table> <Table> " + 172 " <Country>Germany</Country> <City>Munich / Riem</City> </Table> <Table> " + 173 " <Country>Germany</Country> <City>Nuernberg</City> </Table> <Table> " + 174 " <Country>Germany</Country> <City>Leipzig-Schkeuditz</City> </Table> <Table> " + 175 " <Country>Germany</Country> <City>Saarbruecken / Ensheim</City> </Table> <Table> " + 176 "<Country>Germany</Country> <City>Stuttgart-Echterdingen</City> </Table> <Table> " + 177 " <Country>Germany</Country> <City>Berlin-Tegel</City> </Table> <Table> " + 178 "<Country>Germany</Country> <City>Hannover</City> </Table> <Table> " + 179 "<Country>Germany</Country> <City>Bremen</City> </Table> <Table> " + 180 " <Country>Germany</Country> <City>Hahn</City> </Table> <Table>" + 181 " <Country>Germany</Country> <City>Baden Wurttemberg, Neuostheim</"; 182 } 183 184 190 } | Popular Tags |