1 20 package org.apache.cactus.internal.server; 21 22 import javax.servlet.ServletException ; 23 import javax.servlet.http.HttpServletRequest ; 24 25 import org.apache.cactus.internal.HttpServiceDefinition; 26 import org.apache.cactus.internal.ServiceEnumeration; 27 import org.apache.cactus.spi.server.ImplicitObjects; 28 import org.apache.cactus.spi.server.TestController; 29 import org.apache.commons.logging.Log; 30 import org.apache.commons.logging.LogFactory; 31 32 40 public abstract class AbstractWebTestController implements TestController 41 { 42 45 private static final Log LOGGER = 46 LogFactory.getLog(AbstractWebTestController.class); 47 48 52 protected abstract AbstractWebTestCaller getTestCaller( 53 WebImplicitObjects theObjects); 54 55 64 public void handleRequest(ImplicitObjects theObjects) 65 throws ServletException 66 { 67 WebImplicitObjects webImplicitObjects = (WebImplicitObjects) theObjects; 68 69 try 79 { 80 String serviceName = 81 getServiceName(webImplicitObjects.getHttpServletRequest()); 82 83 AbstractWebTestCaller caller = getTestCaller(webImplicitObjects); 84 85 87 ServiceEnumeration service = 88 ServiceEnumeration.valueOf(serviceName); 89 90 if (service == ServiceEnumeration.CALL_TEST_SERVICE) 92 { 93 caller.doTest(); 94 } 95 else if (service == ServiceEnumeration.GET_RESULTS_SERVICE) 97 { 98 caller.doGetResults(); 99 } 100 else if (service == ServiceEnumeration.RUN_TEST_SERVICE) 104 { 105 caller.doRunTest(); 106 } 107 else if (service == ServiceEnumeration.CREATE_SESSION_SERVICE) 109 { 110 caller.doCreateSession(); 111 } 112 else if (service == ServiceEnumeration.GET_VERSION_SERVICE) 113 { 114 caller.doGetVersion(); 115 } 116 else 117 { 118 String message = "Unknown service [" + serviceName 119 + "] in HTTP request."; 120 121 LOGGER.error(message); 122 throw new ServletException (message); 123 } 124 } 125 catch (NoClassDefFoundError e) 126 { 127 if (e.getMessage().startsWith("junit/framework")) 129 { 130 String message = "You must put the JUnit jar in " 131 + "your server classpath (in WEB-INF/lib for example)"; 132 133 LOGGER.error(message, e); 134 throw new ServletException (message, e); 135 } 136 else 137 { 138 String message = "You are missing a jar in your " 139 + "classpath (class [" + e.getMessage() 140 + "] could not " + "be found"; 141 142 LOGGER.error(message, e); 143 throw new ServletException (message, e); 144 } 145 } 146 } 147 148 155 private String getServiceName(HttpServletRequest theRequest) 156 throws ServletException 157 { 158 String queryString = theRequest.getQueryString(); 160 String serviceName = ServletUtil.getQueryStringParameter(queryString, 161 HttpServiceDefinition.SERVICE_NAME_PARAM); 162 163 if (serviceName == null) 164 { 165 String message = "Missing service name parameter [" 166 + HttpServiceDefinition.SERVICE_NAME_PARAM 167 + "] in HTTP request. Received query string is [" 168 + queryString + "]."; 169 170 LOGGER.debug(message); 171 throw new ServletException (message); 172 } 173 174 LOGGER.debug("Service to call = " + serviceName); 175 176 return serviceName; 177 } 178 } 179 | Popular Tags |