super(config);
host = config.getAttribute(SERVER_HOST_TAG);
try {
address = InetAddress.getByName(host).getHostAddress();
}catch (Exception e) {
throw new ConfigurationException("Invalid host configuration");
}
port = config.getAttribute(SERVER_PORT_TAG);
httpContext = config.getAttribute(REQUEST_CONTEXT_TAG);
serviceCategory = config.getAttribute(ListenerTagNames.TARGET_SERVICE_CATEGORY_TAG);
serviceName = config.getAttribute(ListenerTagNames.TARGET_SERVICE_NAME_TAG);
if (config.getAttribute(DISPATCH_SERVLET_CLASS) != null) {
dispatchServletClassName = config.getAttribute(DISPATCH_SERVLET_CLASS);
}
boolean synchronous = !config.getAttribute("synchronous", "true").equalsIgnoreCase("false");
if (!synchronous) {
String asyncResponse = config.getAttribute("asyncResponse");
if (asyncResponse != null) {
if (ClassUtil.getResourceAsStream(asyncResponse, getClass()) == null) {
throw new ConfigurationException("Asynchronous response resource file '" + asyncResponse
+ "' not found on classpath.");
}
}
}
//validate allow http method configuration
if (config.getAttribute(ALLOW_HTTP_METHOD) != null) {
String allowMethods = config.getAttribute(ALLOW_HTTP_METHOD);
String[] methods = allowMethods.split(",");
List<String> standardMesthods = new ArrayList<String>();
standardMesthods.add("GET");
standardMesthods.add("POST");
standardMesthods.add("DELETE");
standardMesthods.add("PUT");
standardMesthods.add("OPTIONS");
standardMesthods.add("HEAD");
standardMesthods.add("TRACE");
for (String method : methods) {
if (!standardMesthods.contains(method.toUpperCase())) {
throw new ConfigurationException("Invalid allow http method configuration, please specify the specify method list with comma-separated(e.g. POST,GET,PUT,DELETE");
}
}
}
try {
Set ports = HttpServerDelegate.getInstance().queryObjects("jboss.web:port="+ port+",type=Connector,*");
if (ports.size() > 0) {
//When this gateway stared on JBoss default port 8080 or 80, the configured host will be ignored
Set contexts = HttpServerDelegate.getInstance().queryObjects("jboss.web:host=localhost" + ",path=" + httpContext + ",*");
if (contexts.size() > 0) {
throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
}
logger.info("This http gateway listener [" + config.getAttribute(ListenerTagNames.NAME_TAG) + "] will be started on JBoss default port " + port + " and the configured host will be ignored.");
//the created context will be attached jboss.web domain
useJBossWebServletEngine = true;
} else {
//if the port is not the jboss.web used, check if the http context name is duplicate
Set contexts = HttpServerDelegate.getInstance().queryObjects(HttpServerDelegate.DOMAIN_NAME + ":host=" + HttpServerDelegate.defaultVHost + ",path=" + httpContext + ",*");
if (contexts.size() > 0) {
throw new ConfigurationException("There is already an http context named " + httpContext + ", choose another one");
}
}
} catch (Exception e) {
throw new ConfigurationException(e);
}
//Check the http security configuration
if (config.getAttribute(AUTH_METHOD) != null) {
if (config.getAttribute(SECURITY_DOMAIN) == null) {
throw new ConfigurationException("Security domain configuration for this context not found for http authentication method " + config.getAttribute(AUTH_METHOD));
}
if (config.getAttribute(SECURITY_ROLE) == null) {
throw new ConfigurationException("Security role configuration for this context not found for http authentication method " + config.getAttribute(AUTH_METHOD));
}
}
}