1 package org.jboss.test.cluster.test; 2 3 import java.io.IOException ; 4 import java.net.HttpURLConnection ; 5 6 import junit.framework.Test; 7 8 import org.apache.commons.httpclient.Header; 9 import org.apache.commons.httpclient.HttpClient; 10 import org.apache.commons.httpclient.HttpState; 11 import org.apache.commons.httpclient.methods.GetMethod; 12 import org.jboss.test.JBossClusteredTestCase; 13 14 public class CrossContextCallsTestCase extends ScopedTestCase 15 { 16 17 public CrossContextCallsTestCase(String name) 18 { 19 super(name); 20 warName_ = "/http-cross-ctx-first/"; 21 22 concatenate(); 23 } 24 25 public static Test suite() throws Exception 26 { 27 Test t1 = JBossClusteredTestCase.getDeploySetup(CrossContextCallsTestCase.class, 28 "http-cross-ctx.ear"); 29 return t1; 30 } 31 32 33 36 public void testExcludeSecuritySubject() throws Exception 37 { 38 return; 39 } 40 41 44 public void testSessionBindingEvent() throws Exception 45 { 46 return; 47 } 48 49 protected String makeGet(HttpClient client, String url) 50 { 51 getLog().debug("makeGet(): trying to get from url " +url); 52 53 GetMethod method = new GetMethod(url); 54 int responseCode = 0; 55 try 56 { 57 responseCode = client.executeMethod(method); 58 } catch (IOException e) 59 { 60 e.printStackTrace(); 61 fail("HttpClient executeMethod fails." +e.toString()); 62 } 63 assertTrue("Get OK with url: " +url + " responseCode: " +responseCode 64 , responseCode == HttpURLConnection.HTTP_OK); 65 66 String response = extractResponse(method); 67 68 71 return response; 72 } 73 74 protected String getWarName() 75 { 76 return "http-cross-ctx-first"; 77 } 78 79 89 protected String makeGetWithState(HttpClient client, String url) 90 { 91 getLog().debug("makeGetWithState(): trying to get from url " +url); 92 GetMethod method = new GetMethod(url); 93 int responseCode = 0; 94 try 95 { 96 HttpState state = client.getState(); 97 responseCode = client.executeMethod(method.getHostConfiguration(), 98 method, state); 99 } catch (IOException e) 100 { 101 e.printStackTrace(); 102 fail("HttpClient executeMethod fails." +e.toString()); 103 } 104 assertTrue("Get OK with url: " +url + " responseCode: " +responseCode, 105 responseCode == HttpURLConnection.HTTP_OK); 106 107 String response = extractResponse(method); 108 109 112 return response; 113 } 114 115 private String extractResponse(GetMethod method) 116 { 117 Header header = method.getResponseHeader("FIRST"); 118 119 assertNotNull("Received FIRST header", header); 120 121 String result = header.getValue(); 122 123 assertNotNull("FIRST header not null", result); 124 125 header = method.getResponseHeader("SECOND"); 126 127 assertNotNull("Received SECOND header", header); 128 129 String second = header.getValue(); 130 131 assertNotNull("FIRST header not null", second); 132 133 result.concat(second); 134 135 byte[] responseBody = method.getResponseBody(); 137 result.concat(new String (responseBody)); 139 140 143 return result; 144 145 } 146 147 } 148 | Popular Tags |