You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2006/09/15 05:58:09 UTC
svn commit: r446505 - in
/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2:
transport/http/AxisServlet.java util/JavaUtils.java
Author: dims
Date: Thu Sep 14 20:58:08 2006
New Revision: 446505
URL: http://svn.apache.org/viewvc?view=rev&rev=446505
Log:
Remove the HACK as it does not work in Weblogic. Use HttpServletRequest.getContextPath to compute the root.
Modified:
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java?view=diff&rev=446505&r1=446504&r2=446505
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/transport/http/AxisServlet.java Thu Sep 14 20:58:08 2006
@@ -68,7 +68,7 @@
protected transient ServletConfig servletConfig;
private transient ListingAgent agent;
- private String contextRoot;
+ private String contextRoot = null;
protected boolean enableRESTInAxis2MainServlet = false;
protected boolean disableREST = false;
@@ -117,6 +117,29 @@
}
+ /**
+ * Set the context root if it is not set already.
+ *
+ * @param req
+ */
+ public void initContextRoot(HttpServletRequest req) {
+ if (contextRoot == null) {
+ String [] parts = JavaUtils.split(req.getContextPath(), '/');
+ if (parts != null) {
+ for (int i = 0; i < parts.length; i++) {
+ if (parts[i].length() > 0) {
+ contextRoot = parts[i];
+ break;
+ }
+ }
+ }
+ if (contextRoot == null || req.getContextPath().equals("/")) {
+ contextRoot = "/";
+ }
+ configContext.setContextRoot(contextRoot);
+ }
+ }
+
/*
* (non-Javadoc)
* @see javax.servlet.http.HttpServlet#doPost(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
@@ -125,6 +148,9 @@
protected void doGet(HttpServletRequest req,
HttpServletResponse resp) throws ServletException, IOException {
+
+ initContextRoot(req);
+
// this method is also used to serve for the listServices request.
String requestURI = req.getRequestURI();
@@ -175,6 +201,8 @@
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
+ initContextRoot(req);
+
MessageContext msgContext;
OutputStream out = res.getOutputStream();
@@ -315,18 +343,6 @@
if (parameter != null) {
disableSeperateEndpointForREST = !JavaUtils.isFalseExplicitly(parameter.getValue());
}
-
- // HACK ALERT!!! - Is there a better way to get the webapp name?
- try {
- String[] array = servletConfig.getServletContext().getResource("/").toString().split("/");
- contextRoot = array[array.length - 1];
- configContext.setContextRoot(contextRoot);
- } catch (Exception e) {
- }
- if (contextRoot == null) {
- contextRoot = "axis2";
- }
- this.configContext.setContextRoot(contextRoot);
}
public void init() throws ServletException {
Modified: webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java?view=diff&rev=446505&r1=446504&r2=446505
==============================================================================
--- webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java (original)
+++ webservices/axis2/trunk/java/modules/kernel/src/org/apache/axis2/util/JavaUtils.java Thu Sep 14 20:58:08 2006
@@ -18,7 +18,8 @@
import java.text.Collator;
import java.util.Arrays;
import java.util.Locale;
-
+import java.util.List;
+import java.util.ArrayList;
/**
* JavaUtils
*/
@@ -317,5 +318,63 @@
if (!Character.isJavaIdentifierPart(id.charAt(i)))
return false;
return true;
+ }
+
+ /**
+ * An empty immutable <code>String</code> array.
+ */
+ public static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+ /**
+ * <p>Splits the provided text into an array, separator specified.
+ * This is an alternative to using StringTokenizer.</p>
+ * <p/>
+ * <p>The separator is not included in the returned String array.
+ * Adjacent separators are treated as one separator.</p>
+ * <p/>
+ * <p>A <code>null</code> input String returns <code>null</code>.</p>
+ * <p/>
+ * <pre>
+ * StringUtils.split(null, *) = null
+ * StringUtils.split("", *) = []
+ * StringUtils.split("a.b.c", '.') = ["a", "b", "c"]
+ * StringUtils.split("a..b.c", '.') = ["a", "b", "c"]
+ * StringUtils.split("a:b:c", '.') = ["a:b:c"]
+ * StringUtils.split("a\tb\nc", null) = ["a", "b", "c"]
+ * StringUtils.split("a b c", ' ') = ["a", "b", "c"]
+ * </pre>
+ *
+ * @param str the String to parse, may be null
+ * @param separatorChar the character used as the delimiter,
+ * <code>null</code> splits on whitespace
+ * @return an array of parsed Strings, <code>null</code> if null String input
+ */
+ public static String[] split(String str, char separatorChar) {
+ if (str == null) {
+ return null;
+ }
+ int len = str.length();
+ if (len == 0) {
+ return EMPTY_STRING_ARRAY;
+ }
+ List list = new ArrayList();
+ int i = 0, start = 0;
+ boolean match = false;
+ while (i < len) {
+ if (str.charAt(i) == separatorChar) {
+ if (match) {
+ list.add(str.substring(start, i));
+ match = false;
+ }
+ start = ++i;
+ continue;
+ }
+ match = true;
+ i++;
+ }
+ if (match) {
+ list.add(str.substring(start, i));
+ }
+ return (String[]) list.toArray(new String[list.size()]);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org