[ThorFramework-devel] SF.net SVN: thorframework: [31] trunk/thor/src/org/y2k1/thor/core
Status: Planning
Brought to you by:
denniskempin
|
From: <den...@us...> - 2006-02-27 16:24:59
|
Revision: 31 Author: denniskempin Date: 2006-02-27 08:24:45 -0800 (Mon, 27 Feb 2006) ViewCVS: http://svn.sourceforge.net/thorframework/?rev=31&view=rev Log Message: ----------- added Server/System/client information classes Modified Paths: -------------- trunk/thor/src/org/y2k1/thor/core/CommonBaseInitializer.java trunk/thor/src/org/y2k1/thor/core/Request.java trunk/thor/src/org/y2k1/thor/core/ThorContext.java trunk/thor/src/org/y2k1/thor/core/ThorHttpServlet.java Added Paths: ----------- trunk/thor/src/org/y2k1/thor/core/ClientInfo.java trunk/thor/src/org/y2k1/thor/core/ServerInfo.java trunk/thor/src/org/y2k1/thor/core/SystemInfo.java Added: trunk/thor/src/org/y2k1/thor/core/ClientInfo.java =================================================================== --- trunk/thor/src/org/y2k1/thor/core/ClientInfo.java (rev 0) +++ trunk/thor/src/org/y2k1/thor/core/ClientInfo.java 2006-02-27 16:24:45 UTC (rev 31) @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.y2k1.thor.core; + +import javax.servlet.http.HttpServletRequest; + +public final class ClientInfo +{ + private HttpServletRequest request; + + ClientInfo(HttpServletRequest request) + { + this.request = request; + } + + public String getHost() + { + return this.request.getRemoteHost(); + } + + public String getAddress() + { + return this.request.getRemoteAddr(); + } + + public String getUser() + { + return this.request.getRemoteUser(); + } + + public String getUserAgent() + { + return this.request.getHeader("User-Agent"); + } +} Modified: trunk/thor/src/org/y2k1/thor/core/CommonBaseInitializer.java =================================================================== --- trunk/thor/src/org/y2k1/thor/core/CommonBaseInitializer.java 2006-02-26 21:56:16 UTC (rev 30) +++ trunk/thor/src/org/y2k1/thor/core/CommonBaseInitializer.java 2006-02-27 16:24:45 UTC (rev 31) @@ -128,4 +128,14 @@ { return this.context; } + + public final SystemInfo getSystemInfo() + { + return this.context.getSystemInfo(); + } + + public final ServerInfo getServerInfo() + { + return this.context.getServerInfo(); + } } Modified: trunk/thor/src/org/y2k1/thor/core/Request.java =================================================================== --- trunk/thor/src/org/y2k1/thor/core/Request.java 2006-02-26 21:56:16 UTC (rev 30) +++ trunk/thor/src/org/y2k1/thor/core/Request.java 2006-02-27 16:24:45 UTC (rev 31) @@ -39,21 +39,24 @@ */ private HttpServletRequest request; - private ServletContext context; + private ThorContext context; private StringMap parameter; private Map<String, Object> session; + private ClientInfo clientInfo; + /** * This will create a new Request object * @param request The httpRequest Object to wrap */ @SuppressWarnings("unchecked") - Request(HttpServletRequest request, ServletContext context) + Request(HttpServletRequest request, ThorContext context) { this.request = request; this.context = context; + this.clientInfo = new ClientInfo(request); this.parameter = new StringMap(); for(Entry<String, String[]> entry : (Set<Entry<String, String[]>>) request.getParameterMap().entrySet()) @@ -81,24 +84,6 @@ this.parameter = request.parameter; } - /*public final String getAttribute(String name) - { - return request.getAttribute(name).toString(); - } - - public final StringMap getAttributeMap() - { - Enumeration enumeration = request.getAttributeNames(); - StringMap map = new StringMap(); - - while(enumeration.hasMoreElements()) - { - String name = (String)enumeration.nextElement(); - map.put(name, request.getAttribute(name).toString()); - } - return map; - }*/ - /** * @return the request URI send by the client */ @@ -211,4 +196,19 @@ { return this.parameter; } + + public final SystemInfo getSystemInfo() + { + return this.context.getSystemInfo(); + } + + public final ServerInfo getServerInfo() + { + return this.context.getServerInfo(); + } + + public final ClientInfo getClientInfo() + { + return this.clientInfo; + } } Added: trunk/thor/src/org/y2k1/thor/core/ServerInfo.java =================================================================== --- trunk/thor/src/org/y2k1/thor/core/ServerInfo.java (rev 0) +++ trunk/thor/src/org/y2k1/thor/core/ServerInfo.java 2006-02-27 16:24:45 UTC (rev 31) @@ -0,0 +1,43 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.y2k1.thor.core; + +import javax.servlet.ServletContext; + +public final class ServerInfo +{ + private ServletContext context; + + ServerInfo(ServletContext context) + { + this.context = context; + } + + public String getServerName() + { + return this.context.getServerInfo(); + } + + public String getServletContextName() + { + return this.context.getServletContextName(); + } + + public String getServletVersion() + { + return this.context.getMajorVersion()+"."+this.context.getMinorVersion(); + } +} Added: trunk/thor/src/org/y2k1/thor/core/SystemInfo.java =================================================================== --- trunk/thor/src/org/y2k1/thor/core/SystemInfo.java (rev 0) +++ trunk/thor/src/org/y2k1/thor/core/SystemInfo.java 2006-02-27 16:24:45 UTC (rev 31) @@ -0,0 +1,79 @@ +/* + * Copyright 2002-2006 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.y2k1.thor.core; + +public final class SystemInfo +{ + SystemInfo() + { + + } + + public String getVMVersion() + { + return System.getProperty("java.vm.version"); + } + + public String getVMName() + { + return System.getProperty("java.vm.name"); + } + + public String getVMVendor() + { + return System.getProperty("java.vm.vendor"); + } + + public String getRuntimeVersion() + { + return System.getProperty("java.runtime.version"); + } + + public String getRuntimeName() + { + return System.getProperty("java.runtime.name"); + } + + public String getOSVersion() + { + return System.getProperty("os.version"); + } + + public String getOSName() + { + return System.getProperty("os.name"); + } + + public String getOSArch() + { + return System.getProperty("os.arch"); + } + + public long getMaxMemory() + { + return Runtime.getRuntime().maxMemory(); + } + + public long getTotalMemory() + { + return Runtime.getRuntime().totalMemory(); + } + + public long getFreeMemory() + { + return Runtime.getRuntime().freeMemory(); + } +} \ No newline at end of file Modified: trunk/thor/src/org/y2k1/thor/core/ThorContext.java =================================================================== --- trunk/thor/src/org/y2k1/thor/core/ThorContext.java 2006-02-26 21:56:16 UTC (rev 30) +++ trunk/thor/src/org/y2k1/thor/core/ThorContext.java 2006-02-27 16:24:45 UTC (rev 31) @@ -47,15 +47,24 @@ private List<String> imports; private ServletContext context; - + + private ServerInfo serverInfo; + + private SystemInfo systemInfo; + ThorContext(ServletContext context, String resourceName, ErrorReport report) { try { this.context = context; + this.serverInfo = new ServerInfo(context); + this.systemInfo = new SystemInfo(); + SAXReader reader = new SAXReader(true); reader.setFeature("http://apache.org/xml/features/validation/schema", true); - + reader.setProperty("http://apache.org/xml/properties/schema/" + + "external-schemaLocation","http://www.y2k1.org/thor/config xsd/config.xsd"); + Document document = reader.read(context.getResource(resourceName)); this.imports = parseImports(document.getRootElement()); @@ -69,11 +78,11 @@ } catch(SAXException e) { - throw new RuntimeException("TODO"); + throw new RuntimeException(e); } catch(MalformedURLException e) { - throw new RuntimeException("TODO"); + throw new RuntimeException(e); } report.info("thorconfig", "finished reading " + resourceName); } @@ -218,4 +227,14 @@ { return this.errorPages; } + + SystemInfo getSystemInfo() + { + return this.systemInfo; + } + + ServerInfo getServerInfo() + { + return this.serverInfo; + } } Modified: trunk/thor/src/org/y2k1/thor/core/ThorHttpServlet.java =================================================================== --- trunk/thor/src/org/y2k1/thor/core/ThorHttpServlet.java 2006-02-26 21:56:16 UTC (rev 30) +++ trunk/thor/src/org/y2k1/thor/core/ThorHttpServlet.java 2006-02-27 16:24:45 UTC (rev 31) @@ -78,8 +78,11 @@ initReport.setSectionCaption("thorconfig", "Thor configuration file"); this.context = new ThorContext(getServletContext(), "/WEB-INF/thor.xml", initReport); - this.moduleManager = new ModuleManager(this.context, initReport); - this.servletManager = new ServletManager(this.context, this.moduleManager, initReport); + if(!initReport.containsError("thorconfig")) + { + this.moduleManager = new ModuleManager(this.context, initReport); + this.servletManager = new ServletManager(this.context, this.moduleManager, initReport); + } this.configBroken = initReport.containsError("thorconfig"); @@ -115,7 +118,7 @@ System.out.println(httpRequest.getRequestURI() + " requested"); long startTime = System.nanoTime(); - Request request = new Request(httpRequest, getServletContext()); + Request request = new Request(httpRequest, this.context); Response response = new Response(httpRequest, httpResponse); String uri = httpRequest.getRequestURI(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |