[wsas-java-dev] svn commit r3641 -
trunk/wsas/java/modules/core/src/org/wso2/wsas/transport
svn at wso2.org
svn at wso2.org
Sun Jun 10 22:03:19 PDT 2007
Author: saminda
Date: Sun Jun 10 22:03:08 2007
New Revision: 3641
Modified:
trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/UIInitializerServlet.java
Log:
Obtaining the values of servicepath , httpsport , httpport from the given axis2.xml, without creating a
AxisConfiguration.
Modified: trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/UIInitializerServlet.java
==============================================================================
--- trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/UIInitializerServlet.java (original)
+++ trunk/wsas/java/modules/core/src/org/wso2/wsas/transport/UIInitializerServlet.java Sun Jun 10 22:03:08 2007
@@ -15,26 +15,35 @@
*/
package org.wso2.wsas.transport;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.context.ConfigurationContextFactory;
-import org.apache.axis2.AxisFault;
+import org.jaxen.JaxenException;
+import org.jaxen.XPath;
+import org.wso2.adminui.AdminUIServletFilter;
import org.wso2.adminui.UIProcessingException;
import org.wso2.adminui.UIProcessor;
-import org.wso2.adminui.AdminUIServletFilter;
-import org.wso2.wsas.ServerConstants;
-import org.wso2.wsas.ServerManager;
-import org.wso2.wsas.util.Utils;
import org.wso2.utils.ServerConfiguration;
+import org.wso2.wsas.util.Utils;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Hashtable;
import java.util.Map;
-import java.io.File;
/**
@@ -55,8 +64,7 @@
UIProcessor.createPages(resourceBase, "ui-extensions-config.xml", files);
- ConfigurationContext configurationContext = initConfigContext();
- initFilters(servletConfig.getServletContext(), files, configurationContext);
+ initFilters(servletConfig.getServletContext(), files, getAxis2XMLInfo());
} catch (UIProcessingException e) {
log.error(e);
@@ -64,46 +72,99 @@
} catch (AxisFault e) {
log.error(e);
throw new ServletException(e);
+ } catch (JaxenException e) {
+ log.error(e);
+ throw new ServletException(e);
+ } catch (IOException e) {
+ log.error(e);
+ throw new ServletException(e);
+ } catch (XMLStreamException e) {
+ log.error(e);
+ throw new ServletException(e);
}
}
- private void initFilters(ServletContext servletContext, Map filesMap,
- ConfigurationContext configurationContext)
+ private void initFilters(ServletContext servletContext, Map filesMap, Axis2XMLInfo axis2XMLInfo)
throws ServletException {
- //TODO THIS WILL WORK ONLY IN WSAS STANDALONE EDITION
AdminUIServletFilter adminUIServletFilter =
((AdminUIServletFilter) servletContext
.getAttribute(AdminUIServletFilter.class.getName()));
if (adminUIServletFilter != null) {
adminUIServletFilter.init(filesMap,
Utils.isAdminConsoleEnabled(),
- ServerManager.httpsPort,
- ServerManager.httpPort,
- configurationContext.getServicePath());
+ axis2XMLInfo.httpsPort,
+ axis2XMLInfo.httpPort,
+ axis2XMLInfo.servicePath);
}
}
- private ConfigurationContext initConfigContext() throws AxisFault {
+ private Axis2XMLInfo getAxis2XMLInfo() throws IOException, XMLStreamException,
+ JaxenException {
ServerConfiguration serverConfiguration = ServerConfiguration.getInstance();
- String repository = serverConfiguration
- .getFirstProperty(ServerConfiguration.AXIS2_CONFIG_REPO_LOCATION);
String axis2XML = serverConfiguration.getFirstProperty("Axis2Config.ConfigurationFile");
- if (repository != null && axis2XML != null) {
- return ConfigurationContextFactory
- .createConfigurationContextFromFileSystem(repository, axis2XML);
+ InputStream axis2XMLInStream;
+ boolean isURl = isURL(axis2XML);
+ if (isURl) {
+ axis2XMLInStream = new URL(axis2XML).openStream();
+ } else {
+ axis2XMLInStream = new FileInputStream(new File(axis2XML));
}
- //AS a last resort
- repository = System.getProperty(ServerConstants.WSO2WSAS_HOME) + File.separator +
- "repository";
- axis2XML = System.getProperty(ServerConstants.WSO2WSAS_HOME) + File.separator +
- "conf" + File.separator + "axis2.xml";
- return ConfigurationContextFactory
- .createConfigurationContextFromFileSystem(repository, axis2XML);
+ XMLStreamReader xmlStreamReader =
+ XMLInputFactory.newInstance().createXMLStreamReader(axis2XMLInStream);
+ StAXOMBuilder builder = new StAXOMBuilder(xmlStreamReader);
+
+ String servicePath = "/services";
+ XPath xp = new AXIOMXPath("/axisconfig/parameter[@name='servicePath']");
+ OMElement documentElement = builder.getDocumentElement();
+ OMElement servicePathEle = (OMElement) xp.selectSingleNode(documentElement);
+ if (servicePathEle != null) {
+ String text = servicePathEle.getText();
+ if (text == null) {
+ } else {
+ if (text.startsWith("/")) {
+ servicePath = text;
+ } else {
+ servicePath = "/" + text;
+ }
+ }
+
+ }
+
+ xp = new AXIOMXPath("/axisconfig/transportReceiver[@name='http']/parameter[@name='port']");
+ OMElement httpPortEle = (OMElement) xp.selectSingleNode(documentElement);
+
+ xp = new AXIOMXPath("/axisconfig/transportReceiver[@name='https']/parameter[@name='port']");
+ OMElement httpsPortEle = (OMElement) xp.selectSingleNode(documentElement);
+
+ return new Axis2XMLInfo(servicePath, Integer.parseInt(httpsPortEle.getText()),
+ Integer.parseInt(httpPortEle.getText()));
+
+ }
+
+ private boolean isURL(String axis2XMLLocation) {
+ try {
+ new URL(axis2XMLLocation);
+ return true;
+ } catch (MalformedURLException e) {
+ return false;
+ }
+ }
+
+ private class Axis2XMLInfo {
+ private String servicePath;
+ private int httpsPort;
+ private int httpPort;
+
+ public Axis2XMLInfo(String servicePath, int httpsPort, int httpPort) {
+ this.servicePath = servicePath;
+ this.httpsPort = httpsPort;
+ this.httpPort = httpPort;
+ }
}
}
\ No newline at end of file
More information about the Wsas-java-dev
mailing list