You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by "ant elder (JIRA)" <tu...@ws.apache.org> on 2008/05/15 10:13:55 UTC

[jira] Updated: (TUSCANY-2320) The contextPath init parameter for TuscanyServletFilter.

     [ https://issues.apache.org/jira/browse/TUSCANY-2320?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

ant elder updated TUSCANY-2320:
-------------------------------

    Attachment: tuscany-host-webapp-1.2-TUSCANY-2320.jar

Thanks for finding this, it looks like a couple of conflicting changes combined to lead to the change in behaviour. I've attached a patched jar - tuscany-host-webapp-1.2-TUSCANY-2320.jar - to this JIRA, which restores the behaviour to how it worked in 1.1. Could you try this out to see if it resolves the problem ok for you?

The diff for the changes in that jar are:

Index: src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java
===================================================================
--- src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java     (revision 656535)
+++ src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java     (working copy)
@@ -26,6 +26,7 @@
 import java.net.URI;
 import java.net.URL;
 import java.net.UnknownHostException;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.logging.Logger;
@@ -206,7 +207,7 @@
     public void init(ServletConfig config) throws ServletException {
         ServletContext servletContext = config.getServletContext();

-        initContextPath(servletContext);
+        initContextPath(config);

         if (servletContext.getAttribute(SCA_DOMAIN_ATTRIBUTE) == null) {
             String domainURI = "http://localhost/" + contextPath;
@@ -266,19 +267,20 @@
      * containers use an init parameter.
      */
     @SuppressWarnings("unchecked")
-    public void initContextPath(ServletContext context) {
-        // The getContextPath() is introduced since Servlet 2.5
-        Method m;
-        try {
-            // Try to get the method anyway since some ServletContext impl has this method even before 2.5
-            m = context.getClass().getMethod("getContextPath", new Class[] {});
-            contextPath = (String)m.invoke(context, new Object[] {});
-        } catch (Exception e) {
-            contextPath = context.getInitParameter("contextPath");
-            if (contextPath == null) {
+    public void initContextPath(ServletConfig config) {
+
+        if (Collections.list(config.getInitParameterNames()).contains("contextPath")) {
+            contextPath = config.getInitParameter("contextPath");
+        } else {
+            // The getContextPath() is introduced since Servlet 2.5
+            ServletContext context = config.getServletContext();
+            try {
+                // Try to get the method anyway since some ServletContext impl has this method even before 2.5
+                Method m = context.getClass().getMethod("getContextPath", new Class[] {});
+                contextPath = (String)m.invoke(context, new Object[] {});
+            } catch (Exception e) {
                 logger.warning("Servlet level is: " + context.getMajorVersion() + "." + context.getMinorVersion());
-                throw new IllegalStateException(
-                                                "'contextPath' init parameter must be set for pre-2.5 servlet container");
+                throw new IllegalStateException("'contextPath' init parameter must be set for pre-2.5 servlet container");
             }
         }


> The contextPath init parameter for TuscanyServletFilter.
> --------------------------------------------------------
>
>                 Key: TUSCANY-2320
>                 URL: https://issues.apache.org/jira/browse/TUSCANY-2320
>             Project: Tuscany
>          Issue Type: Improvement
>          Components: Java SCA Web App Integration
>    Affects Versions: Java-SCA-1.2
>            Reporter: Ilya Kanonirov
>            Assignee: ant elder
>         Attachments: tuscany-host-webapp-1.2-TUSCANY-2320.jar
>
>
> Current version of the component requires the contextPath initialization parameter to be specified in the Servlet Context, i.e. we need the following context-param in web.xml:
> <web-app
> ...
>     <context-param>
>         <param-name>contextPath</param-name>
>         <param-value>/ctx</param-value>
>     </context-param>
> ...
> </webapp>
> while the previous Java SCA 1.1 required that parameter at the filter description level:
> <web-app
> ...
>   <filter>
>     <filter-name>tuscany</filter-name>
>     <filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>
>     <init-param>
>       <param-name>contextPath</param-name>
>       <param-value>/ctx</param-value>
>     </init-param>
>   </filter>
> ...
> </webapp>
> Is that parameter supposed to be there, defined at the Servlet Context level?
> If yes, I would suggest renaming the parameter to avoid confusing. For example, adding a package prefix might be enough.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.