synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Asankha C. Perera" <asan...@wso2.com>
Subject Re: Can we support the -p option for port and an option for repository
Date Thu, 14 Dec 2006 11:32:06 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Thanks Chathura, I will apply this patch and fix the .bat file for
Windows as well.<br>
<br>
asankha<br>
<br>
Chathura Ekanayake wrote:
<blockquote
 cite="mid80592d5b0612140250n794554e0t309f2fdf573d8544@mail.gmail.com"
 type="cite">I added functionality to specify port at the start up of
the Synapse server and sample Axis2 server.<br>
  <br>
To start synapse on a different port use:<br>
synapse.sh -port &lt;port number&gt;<br>
  <br>
If the port is not specified, default port 8080 is used.
  <br>
  <br>
To start sample Axis2 server use:<br>
axis2server.sh -port &lt;port number&gt;<br>
  <br>
If the port is not specified, default port 9000 is used.<br>
  <br>
I have attached a patch for this implementation. Please review and
apply it.
  <br>
  <br>
Chathura<br>
  <br>
  <div><span class="gmail_quote">On 12/14/06, <b
 class="gmail_sendername">Chathura Ekanayake</b> &lt;<a
 href="mailto:cce.axis@gmail.com">cce.axis@gmail.com</a>&gt; wrote:</span>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;">Hi
Rajith and All,<br>
    <br>
I also agree that we should have a method to specify the port for
synapse server.<br>
    <br>
IMHO it is also important allow users to specify the port when starting
sample Axis2 servers.<br>
Then users can start multiple Axis2 servers for testing sample
scenarios.
    <br>
    <br>
I have started working on both these issues. Will send a patch soon.<br>
    <span class="sg"><br>
Chathura</span>
    <div><span class="e" id="q_10f8043701cee379_2"><br>
    <br>
    <br>
    <div><span class="gmail_quote">On 12/2/06, <b
 class="gmail_sendername">
Asankha C. Perera</b> &lt;<a href="mailto:asankha@wso2.com"
 target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
asankha@wso2.com</a>&gt; wrote:</span>
    <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left:
1ex;">Ok..
I see your point here.. and I agree it would be useful.. Let me see
      <br>
if I can also push in this feature.. I am thinking of doing a real RC<br>
next week .. as we have a chance to fix the shapshot dependencies to<br>
revisions. Else, please open a JIRA so that we could do it for the next
      <br>
RC or the 0.90 release<br>
      <br>
thanks<br>
asankha<br>
      <br>
Rajith Attapattu wrote:<br>
&gt; Hi All,<br>
&gt;<br>
&gt; I understand that we now have port 8080 as default and if not<br>
&gt; available we keep trying a list of ports.
      <br>
&gt; Also we can change the port in the axis2.xml.<br>
&gt;<br>
&gt; However I still think it's useful to have the following feature<br>
&gt; syanpse -p[port_numer] --repo[repo_path]<br>
&gt;<br>
&gt; I understand that this was there and was removed recently.
      <br>
&gt;<br>
&gt; I think this is a very useful feature to have especially for
testing.<br>
&gt; If u need several synapse instances then we can use the -p or
--port<br>
&gt; option to start n number of instances that share the same repo or
we
      <br>
&gt; can use a --repo option to specify a different repo.<br>
&gt; This way I can start multiple instance from a single installation.<br>
&gt;<br>
&gt; thoughts ??<br>
&gt;<br>
&gt; Rajith<br>
      <br>
---------------------------------------------------------------------
      <br>
To unsubscribe, e-mail: <a
 href="mailto:synapse-dev-unsubscribe@ws.apache.org" target="_blank"
 onclick="return top.js.OpenExtLink(window,event,this)">synapse-dev-unsubscribe@ws.apache.org</a><br>
For additional commands, e-mail: <a
 href="mailto:synapse-dev-help@ws.apache.org" target="_blank"
 onclick="return top.js.OpenExtLink(window,event,this)">synapse-dev-help@ws.apache.org
      </a><br>
      <br>
    </blockquote>
    </div>
    <br>
    </span></div>
  </blockquote>
  </div>
  <br>
  <pre wrap="">
<hr size="4" width="90%">
Index: src/main/bin/synapse.sh
===================================================================
--- src/main/bin/synapse.sh	(revision 487156)
+++ src/main/bin/synapse.sh	(working copy)
@@ -109,6 +109,15 @@
 SYNAPSE_XML=-Dsynapse.xml=$SYNAPSE_HOME/repository/conf/sample/synapse_sample_$2.xml
 fi
 
+if [ "$3" == "-sample" ]; then
+SYNAPSE_XML=-Dsynapse.xml=$SYNAPSE_HOME/repository/conf/sample/synapse_sample_$4.xml
+fi
+
+PORT="-Dport=8080"
+if [ "$1" == "-port" ]; then
+  PORT="-Dport=$2"
+fi
+
 # ----- Execute The Requested Command -----------------------------------------
 
 cd $SYNAPSE_HOME
@@ -117,4 +126,4 @@
 echo "Using JAVA_HOME:       $JAVA_HOME"
 echo "Using SYNAPSE_XML:     $SYNAPSE_XML"
 
-$JAVA_HOME/bin/java $SYNAPSE_XML -Daxis2.xml=$SYNAPSE_HOME/repository/conf/axis2.xml -Djava.endorsed.dirs=$SYNAPSE_ENDORSED
-classpath $SYNAPSE_CLASSPATH org.apache.synapse.SynapseHTTPServer $SYNAPSE_HOME/repository
+$JAVA_HOME/bin/java $PORT $SYNAPSE_XML -Daxis2.xml=$SYNAPSE_HOME/repository/conf/axis2.xml
-Djava.endorsed.dirs=$SYNAPSE_ENDORSED -classpath $SYNAPSE_CLASSPATH org.apache.synapse.SynapseHTTPServer
$SYNAPSE_HOME/repository
Index: modules/samples/src/main/java/samples/util/SampleAxis2Server.java
===================================================================
--- modules/samples/src/main/java/samples/util/SampleAxis2Server.java	(revision 0)
+++ modules/samples/src/main/java/samples/util/SampleAxis2Server.java	(revision 0)
@@ -0,0 +1,132 @@
+package samples.util;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axis2.transport.http.SimpleHTTPServer;
+import org.apache.axis2.util.CommandLineOptionParser;
+import org.apache.axis2.util.OptionsValidator;
+import org.apache.axis2.util.CommandLineOption;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.engine.ListenerManager;
+import org.apache.axis2.description.TransportInDescription;
+
+import javax.xml.namespace.QName;
+import java.util.List;
+import java.util.Map;
+import java.io.File;
+import java.net.ServerSocket;
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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
+ *
+ *   <a class="moz-txt-link-freetext" href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a>
+ *
+ *  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.
+ */
+
+public class SampleAxis2Server {
+
+    private static final Log log = LogFactory.getLog(SimpleHTTPServer.class);
+
+    int port = -1;
+
+    public static int DEFAULT_PORT = 8080;
+
+
+    /**
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+		String repoLocation = null;
+		String confLocation = null;
+
+		CommandLineOptionParser optionsParser = new CommandLineOptionParser(args);
+		List invalidOptionsList = optionsParser.getInvalidOptions(new OptionsValidator() {
+			public boolean isInvalid(CommandLineOption option) {
+				String optionType = option.getOptionType();
+				return !("repo".equalsIgnoreCase(optionType) || "conf"
+						.equalsIgnoreCase(optionType));
+			}
+		});
+
+		if ((invalidOptionsList.size()&gt;0)||(args.length&gt;4))
+		{
+			printUsage();
+			return;
+		}
+
+		Map optionsMap = optionsParser.getAllOptions();
+
+		CommandLineOption repoOption = (CommandLineOption) optionsMap
+				.get("repo");
+		CommandLineOption confOption = (CommandLineOption) optionsMap
+				.get("conf");
+
+		log.info("[SimpleAxisServer] Starting");
+		if (repoOption != null) {
+			repoLocation = repoOption.getOptionValue();
+			log.info("[SimpleAxisServer] Using the Axis2 Repository"
+					+ new File(repoLocation).getAbsolutePath());
+		}
+		if (confOption != null) {
+			confLocation = confOption.getOptionValue();
+			System.out
+					.println("[SimpleAxisServer] Using the Axis2 Configuration File"
+							+ new File(confLocation).getAbsolutePath());
+		}
+
+		try {
+			ConfigurationContext configctx = ConfigurationContextFactory
+					.createConfigurationContextFromFileSystem(repoLocation,
+							confLocation);
+
+            configurePort(configctx);
+
+            ListenerManager listenerManager =  new ListenerManager();
+				listenerManager.init(configctx);
+			listenerManager.start();
+			log.info("[SimpleAxisServer] Started");
+		} catch (Throwable t) {
+            log.fatal("[SimpleAxisServer] Shutting down. Error starting SimpleAxisServer",
t);
+        }
+    }
+
+    private static void configurePort(ConfigurationContext configCtx) {
+
+        TransportInDescription trsIn = (TransportInDescription)
+            configCtx.getAxisConfiguration().getTransportsIn().get(new QName("http"));
+
+        if(trsIn != null) {
+            String port = System.getProperty("port");
+            if(port != null) {
+                try {
+                    new Integer(port);
+                    trsIn.getParameter("port").setValue(port);
+                } catch (NumberFormatException e) {
+                    log.error("Given port is not a valid integer. Using 9000 for port.");
+                    trsIn.getParameter("port").setValue("9000");
+                }
+            } else {
+                trsIn.getParameter("port").setValue("9000");
+            }
+        }
+    }
+
+    public static void printUsage() {
+        System.out.println("Usage: SampleAxisServer -repo &lt;repository&gt;  -conf
&lt;axis2 configuration file&gt;");
+        System.out.println();
+        System.exit(1);
+    }
+}
Index: modules/samples/src/main/scripts/axis2server.sh
===================================================================
--- modules/samples/src/main/scripts/axis2server.sh	(revision 487156)
+++ modules/samples/src/main/scripts/axis2server.sh	(working copy)
@@ -99,5 +99,10 @@
 echo " Using AXIS2 Repository :   $AXIS2_HOME/repository"
 echo " Using AXIS2 Configuration :   $AXIS2_HOME/repository/conf/axis2.xml"
 
-java -classpath $AXIS2_CLASSPATH org.apache.axis2.transport.SimpleAxis2Server \
--repo $AXIS2_HOME/repository -conf $AXIS2_HOME/repository/conf/axis2.xml $*
+PORT="-Dport=9000"
+if [ "$1" == "-port" ]; then
+  PORT="-Dport=$2"
+fi
+
+java $PORT -classpath $AXIS2_CLASSPATH samples.util.SampleAxis2Server \
+-repo $AXIS2_HOME/repository -conf $AXIS2_HOME/repository/conf/axis2.xml
Index: modules/core/src/main/java/org/apache/synapse/SynapseHTTPServer.java
===================================================================
--- modules/core/src/main/java/org/apache/synapse/SynapseHTTPServer.java	(revision 487156)
+++ modules/core/src/main/java/org/apache/synapse/SynapseHTTPServer.java	(working copy)
@@ -24,6 +24,8 @@
 import org.apache.axis2.context.ConfigurationContextFactory;
 import org.apache.axis2.engine.ListenerManager;
 import org.apache.axis2.description.TransportInDescription;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 import javax.xml.namespace.QName;
 import java.io.File;
@@ -36,6 +38,8 @@
  */
 public class SynapseHTTPServer {
 
+    private static final Log log = LogFactory.getLog(SynapseHTTPServer.class);
+
     public static void printUsage() {
         System.out.println("Usage: SynapseHTTPServer &lt;repository&gt;");
         System.out.println(" Opts: -? this message");
@@ -93,8 +97,23 @@
 
         if (trsIn != null) {
 
-            int port = Integer.parseInt(trsIn.getParameter("port").getValue().toString());
+            int port = 8080;
 
+            String strPort = System.getProperty("port");
+            if(strPort != null) {
+                // port is specified as a VM parameter
+                try {
+                    port = new Integer(strPort).intValue();
+                } catch (NumberFormatException e) {
+                    // user supplied parameter is not a valid integer. so use the port in
configuration.
+                    log.error("Given port is not a valid integer. Port specified in the configuration
is used for the server.");
+                    port = Integer.parseInt(trsIn.getParameter("port").getValue().toString());
+                }
+
+            } else {
+                port = Integer.parseInt(trsIn.getParameter("port").getValue().toString());
+            }
+
             while (true) {
                 ServerSocket sock = null;
                 try {
  </pre>
  <pre wrap="">
<hr size="4" width="90%">
---------------------------------------------------------------------
To unsubscribe, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:synapse-dev-unsubscribe@ws.apache.org">synapse-dev-unsubscribe@ws.apache.org</a>
For additional commands, e-mail: <a class="moz-txt-link-abbreviated" href="mailto:synapse-dev-help@ws.apache.org">synapse-dev-help@ws.apache.org</a></pre>
</blockquote>
</body>
</html>

---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org


Mime
View raw message