1 16 17 package org.apache.axis2.transport; 18 19 20 import org.apache.axis2.AbstractTestCase; 21 import org.apache.axis2.engine.AxisFault; 22 import org.apache.axis2.transport.http.HTTPConstants; 23 import org.apache.axis2.transport.http.HTTPTransportReceiver; 24 25 import java.io.BufferedInputStream ; 26 import java.io.ByteArrayInputStream ; 27 import java.io.InputStream ; 28 import java.util.Map ; 29 30 public class HTTPTrasportHeaderParsingTest extends AbstractTestCase { 31 32 public HTTPTrasportHeaderParsingTest(String testName) { 33 super(testName); 34 } 35 36 public void testServerHaeders() throws Exception { 37 String message = 38 "POST /axis2/services/echo HTTP/1.0\n" 39 + "Content-Type: text/xml; charset=utf-8\n" 40 + "Accept: application/soap+xml, application/dime, multipart/related, text/*\n" 41 + "User-Agent: Axis/1.2RC1\n" 42 + "Host: 127.0.0.1:8081\n" 43 + "Cache-Control: no-cache\n" 44 + "Pragma: no-cache\n" 45 + "SOAPAction: \"\"\n" 46 + "Content-Length: 73507\n\nee rwewebtewbeww"; 47 48 InputStream reader = new ByteArrayInputStream (message.getBytes()); 49 HTTPTransportReceiver reciver = new HTTPTransportReceiver(); 50 51 Map map = reciver.parseTheHeaders(reader, true); 52 assertEquals(map.get(HTTPConstants.PROTOCOL_VERSION), "HTTP/1.0"); 53 assertEquals(map.get(HTTPConstants.REQUEST_URI), 54 "/axis2/services/echo"); 55 assertEquals(map.get("Accept"), 56 "application/soap+xml, application/dime, multipart/related, text/*"); 57 assertEquals(map.get("User-Agent"), "Axis/1.2RC1"); 58 assertEquals(map.get("Host"), "127.0.0.1:8081"); 59 assertEquals(map.get("Cache-Control"), "no-cache"); 60 assertEquals(map.get("Pragma"), "no-cache"); 61 assertEquals(map.get("Content-Length"), "73507"); 62 assertEquals(reader.read(), 'e'); 63 } 64 65 public void testClientHeaders() throws Exception { 66 String message = 67 "HTTP/1.1 200 OK\n" 68 + "Content-Type: text/xml;charset=utf-8\n" 69 + "Date: Sat, 12 Feb 2005 10:39:39 GMT\n" 70 + "Server: Apache-Coyote/1.1\n" 71 + "Connection: close\n\nA"; 72 InputStream reader = new ByteArrayInputStream (message.getBytes()); 73 HTTPTransportReceiver reciver = new HTTPTransportReceiver(); 74 75 Map map = reciver.parseTheHeaders(reader, false); 76 assertEquals(map.get(HTTPConstants.PROTOCOL_VERSION), "HTTP/1.1"); 77 assertEquals(map.get(HTTPConstants.RESPONSE_CODE), "200"); 78 assertEquals(map.get(HTTPConstants.RESPONSE_WORD), "OK"); 79 assertEquals(map.get("Content-Type"), "text/xml;charset=utf-8"); 80 assertEquals(map.get("Date"), "Sat, 12 Feb 2005 10:39:39 GMT"); 81 assertEquals(map.get("Server"), "Apache-Coyote/1.1"); 82 assertEquals(map.get("Connection"), "close"); 83 assertEquals(reader.read(), 'A'); 84 } 85 86 public void testWrongClientHeaders() throws AxisFault { 87 try { 88 String message = 89 "HTTP/1.1 200 OK\n" 90 + "Content-Type: text/xml;charset=utf-8\n" 91 + "Date: Sat, 12 Feb 2005 10:39:39 GMT\n" 92 + "Server: Apache-Coyote/1.1\n" 93 + "Connection: close"; 94 InputStream reader = new ByteArrayInputStream (message.getBytes()); 95 HTTPTransportReceiver reciver = new HTTPTransportReceiver(); 96 BufferedInputStream br = new BufferedInputStream (reader); 97 Map map = reciver.parseTheHeaders(br, false); 98 fail("test must failed as \n\n is missing"); 99 } catch (AxisFault e) { 100 } 101 } 102 103 } 104 | Popular Tags |