1 7 package org.jboss.test.remoting.marshall.http.metadata; 8 9 import java.util.HashMap ; 10 import java.util.List ; 11 import java.util.Map ; 12 import java.util.Properties ; 13 import org.apache.log4j.Level; 14 import org.jboss.remoting.Client; 15 import org.jboss.remoting.InvokerLocator; 16 17 import junit.framework.TestCase; 18 19 25 public class HTTPUnMarshallerMetadataTestCase extends TestCase 26 { 27 private Client client; 28 29 public void init(String httpTargetURL, HTTPUnMarshallerMock unmarshaller) 30 { 31 try 32 { 33 InvokerLocator locator = new InvokerLocator(httpTargetURL); 34 client = new Client(locator, null); 35 client.setUnMarshaller(unmarshaller); 36 client.connect(); 37 } 38 catch(Exception e) 39 { 40 e.printStackTrace(); 41 } 42 } 43 44 public String makeInvocationCall(String httpTargetURL, String payload, Map metadata, HTTPUnMarshallerMock unmarshaller) throws Throwable 45 { 46 init(httpTargetURL, unmarshaller); 47 48 Object obj = client.invoke(payload, metadata); 49 50 System.out.println("invoke returned" + obj); 51 52 return (String ) obj; 53 } 54 55 public void testWeatherHTTPInvocation() throws Throwable 56 { 57 58 org.apache.log4j.BasicConfigurator.configure(); 59 org.apache.log4j.Category.getRoot().setLevel(Level.INFO); 60 org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO); 61 org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG); 62 org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG); 63 64 65 String testURL = "http://services.xmethods.net:80/soap/servlet/rpcrouter"; 66 67 String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 68 "<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" + 69 " <soap:Body soap:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\n" + 70 " <mrns0:getTemp>\n" + 71 " <zipcode xsi:type=\"xs:string\">30106</zipcode>\n" + 72 " </mrns0:getTemp>\n" + 73 " </soap:Body>\n" + 74 "</soap:Envelope>"; 75 76 Map metadata = new HashMap (); 77 metadata.put(Client.RAW, Boolean.TRUE); 78 metadata.put("TYPE", "POST"); 79 80 Properties headerProps = new Properties (); 81 headerProps.put("SOAPAction", ""); 82 headerProps.put("Content-type", "text/xml; charset=UTF-8"); 83 84 metadata.put("HEADER", headerProps); 85 86 87 HTTPUnMarshallerMetadataTestCase client = new HTTPUnMarshallerMetadataTestCase(); 88 89 HTTPUnMarshallerMock unmarshaller = new HTTPUnMarshallerMock(); 90 91 String result = client.makeInvocationCall(testURL, xml, metadata, unmarshaller); 92 93 assertNotNull(unmarshaller.getMetadata()); 95 List header = (List ) unmarshaller.getMetadata().get("Status"); 96 assertEquals("200", header.get(0)); 97 98 assertEquals(getExpectedWeatherResult().substring(0, 380), result.substring(0, 380)); 100 101 } 102 103 private String getExpectedWeatherResult() 104 { 105 return "<?xml version='1.0' encoding='UTF-8'?>" + 106 "<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\">" + 107 "<SOAP-ENV:Body>" + 108 "<ns1:getTempResponse xmlns:ns1=\"urn:xmethods-Temperature\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" + 109 "<return xsi:type=\"xsd:float\">60.0</return>" + 110 "</ns1:getTempResponse>" + 111 "\n" + 112 "</SOAP-ENV:Body>\n" + 113 "</SOAP-ENV:Envelope>"; 114 } 115 116 117 } | Popular Tags |