You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2008/02/12 00:25:22 UTC
svn commit: r620667 -
/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Author: lresende
Date: Mon Feb 11 15:25:16 2008
New Revision: 620667
URL: http://svn.apache.org/viewvc?rev=620667&view=rev
Log:
Updated fix for retrieve contextPath in web containers with old servlet api implementation
Modified:
incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
Modified: incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java?rev=620667&r1=620666&r2=620667&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java (original)
+++ incubator/tuscany/java/sca/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java Mon Feb 11 15:25:16 2008
@@ -240,24 +240,29 @@
public void initContextPath(ServletConfig config) {
ServletContext context = config.getServletContext();
int version = context.getMajorVersion() * 100 + context.getMinorVersion();
- //FIXME Do we really need this ? Servlet 2.4 Spec does mention getContextPath
- //if (version >= 205) {
- // The getContextPath() is introduced since Servlet 2.5
- Method m;
+
+ Method m;
+ try {
+ m = context.getClass().getMethod("getContextPath", new Class[] {});
try {
- m = context.getClass().getMethod("getContextPath", new Class[] {});
- try {
- contextPath = (String)m.invoke(context, new Object[] {});
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- } catch (NoSuchMethodException e) {
- throw new IllegalStateException(
- "'contextPath' init parameter must be set for pre-2.5 servlet container");
+ contextPath = (String)m.invoke(context, new Object[] {});
+ } catch (Exception e) {
+ throw new RuntimeException(e);
}
- //} else {
- // contextPath = config.getInitParameter("contextPath");
- //}
+ } catch (NoSuchMethodException e) {
+ throw new IllegalStateException("'contextPath' init parameter must be set for pre-2.5 servlet container");
+ }
+
+ // Fall back for containers using old Servlet APIs
+ if (contextPath == null) {
+ contextPath = config.getInitParameter("contextPath");
+ }
+
+ // contextPath == null => throw proper exception
+ if (contextPath == null) {
+ throw new IllegalArgumentException("Could not retrieve webapp contextPath either from servletContext or init Parameter");
+ }
+
logger.info("initContextPath: " + contextPath);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org