[sci-flex commit] r416 - in sci-flex/trunk/java/demo: . src/main/java/demo src/main/java/demo/clients

1 view
Skip to first unread message

codesite...@google.com

unread,
Jan 22, 2009, 4:31:41 PM1/22/09
to sci-fl...@googlegroups.com
Author: senakafdo
Date: Thu Jan 22 12:01:32 2009
New Revision: 416

Added:
sci-flex/trunk/java/demo/README.txt
sci-flex/trunk/java/demo/build.xml
sci-flex/trunk/java/demo/src/main/java/demo/
sci-flex/trunk/java/demo/src/main/java/demo/clients/

sci-flex/trunk/java/demo/src/main/java/demo/clients/GenericTrafficGeneratorClient.java

Log:
Adding Client used to run demo application


Added: sci-flex/trunk/java/demo/README.txt
==============================================================================
--- (empty file)
+++ sci-flex/trunk/java/demo/README.txt Thu Jan 22 12:01:32 2009
@@ -0,0 +1,9 @@
+To run the demo client you need:
+
+ 1. Traffic Data File Name
+ 2. Transport URL
+ 3. Synapse (WSO2 ESB) Home
+ 4. Repository Location
+
+Example:
+ ant traffic -Dfile=/home/user/sample.xml
-Dtrpurl=http://localhost:8280
-Dsynapse.home=/home/user/wso2esb-2.0-SNAPSHOT/
-Drepository=/home/user/wso2esb-2.0-SNAPSHOT/samples/axis2Client/client_repo/

Added: sci-flex/trunk/java/demo/build.xml
==============================================================================
--- (empty file)
+++ sci-flex/trunk/java/demo/build.xml Thu Jan 22 12:01:32 2009
@@ -0,0 +1,87 @@
+<!--
+ ~ 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
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ 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.
+ -->
+
+<project name="samples" default="help" basedir=".">
+ <target name="help">
+ <echo>
+ ant traffic
+ A client supplies the ESB with network traffic data formatted as
XML
+
+ examples:
+ ant traffic [-Dtrpurl=http://localhost:8280]
+ [-Dfile=/home/user/sample.xml]
+ [-Daddurl=http://localhost:9000/soap/SimpleStockQuoteService]
+ [-Dprxurl=http://localhost:8280]
+ </echo>
+ </target>
+
+ <property name="addurl" value=""/>
+ <property name="trpurl" value=""/>
+ <property name="prxurl" value=""/>
+ <property name="repository" value=""/>
+ <property name="file" value=""/>
+ <property name="class.dir" value="target/classes"/>
+ <property name="synapse.home" value="../../"/>
+
+ <target name="clean">
+ <delete dir="target" quiet="true"/>
+ <delete dir="${class.dir}" quiet="true"/>
+ </target>
+
+ <target name="traffic" depends="compile">
+ <java classname="demo.clients.GenericTrafficGeneratorClient"
+ classpathref="javac.classpath" fork="true">
+ <sysproperty key="addurl" value="${addurl}"/>
+ <sysproperty key="trpurl" value="${trpurl}"/>
+ <sysproperty key="prxurl" value="${prxurl}"/>
+ <sysproperty key="repository" value="${repository}"/>
+ <sysproperty key="file" value="${file}"/>
+ <sysproperty key="java.io.tmpdir"
value="${class.dir}/work/temp/sampleClient"/>
+ </java>
+ </target>
+
+ <target name="init">
+ <mkdir dir="${class.dir}"/>
+ <mkdir dir="${class.dir}/work/temp/sampleClient"/>
+ <path id="javac.classpath">
+ <pathelement path="${class.dir}"/>
+ <pathelement
path="${synapse.home}/webapps/ROOT/WEB-INF/plugins"/>
+ <fileset dir="${synapse.home}/webapps/ROOT/WEB-INF/plugins">
+ <exclude name="synapse-module*"/>
+ <exclude name="*.ui_*.jar"/>
+ <include name="**/*.jar"/>
+ </fileset>
+ <fileset dir="${synapse.home}/lib">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="${synapse.home}/lib/extensions">
+ <include name="*.jar"/>
+ </fileset>
+ <fileset dir="${synapse.home}/repository/lib">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+ </target>
+
+ <target name="compile" depends="init" description="Compile all Java">
+ <javac srcdir="src" destdir="${class.dir}">
+ <classpath refid="javac.classpath"/>
+ </javac>
+ </target>
+</project>

Added:
sci-flex/trunk/java/demo/src/main/java/demo/clients/GenericTrafficGeneratorClient.java
==============================================================================
--- (empty file)
+++
sci-flex/trunk/java/demo/src/main/java/demo/clients/GenericTrafficGeneratorClient.java
Thu Jan 22 12:01:32 2009
@@ -0,0 +1,150 @@
+/*
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.
+ */
+
+package demo.clients;
+
+import com.ctc.wstx.exc.WstxEOFException;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMException;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.Constants;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HttpTransportProperties;
+
+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.FileNotFoundException;
+import java.net.URL;
+import java.util.Iterator;
+
+/**
+ * See build.xml for options
+ */
+public class GenericTrafficGeneratorClient {
+
+ private static String xmlFilePath = null;
+ private static ServiceClient serviceClient = null;
+ private static int count = 0;
+ private static boolean initialized = false;
+
+ private static String getProperty(String name, String def) {
+ String result = System.getProperty(name);
+ if (result == null || result.length() == 0) {
+ result = def;
+ }
+ return result;
+ }
+
+ public static void main(String[] args) {
+ try {
+ if (!initialized) {
+ xmlFilePath = getProperty("file", null);
+ setupClient();
+ initialized = true;
+ }
+ if (serviceClient == null || xmlFilePath == null) {
+ return;
+ }
+ XMLStreamReader xmlStreamReader = XMLInputFactory.newInstance()
+ .createXMLStreamReader(new
FileInputStream(xmlFilePath));
+ Iterator elems =
+ new StAXOMBuilder(OMAbstractFactory.getOMFactory(),
xmlStreamReader)
+ .getDocumentElement().getChildElements();
+ int offset = 0;
+ while (count != 0 && offset++ != count && elems.hasNext()) {
+ OMElement elem = (OMElement) elems.next();
+ }
+ while (elems.hasNext()) {
+ OMElement elem = (OMElement) elems.next();
+ serviceClient.fireAndForget(elem);
+ count++;
+ Thread.sleep(100);
+ }
+ } catch (OMException e) {
+ if (e.getCause() instanceof WstxEOFException) {
+ main(args);
+ }
+ } catch (FileNotFoundException e) {
+ return;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public static void setupClient() throws Exception {
+
+ String trpUrl = getProperty("trpurl", null);
+
+ // Optional Fields
+ String addUrl = getProperty("addurl", null);
+ String prxUrl = getProperty("prxurl", null);
+ String repo = getProperty("repository", null);
+
+ ConfigurationContext configContext = null;
+
+ Options options = new Options();
+
+ if (repo != null && !"null".equals(repo)) {
+ configContext =
+ ConfigurationContextFactory.
+ createConfigurationContextFromFileSystem(repo,
+ repo + File.separator + "conf" +
File.separator + "axis2.xml");
+ serviceClient = new ServiceClient(configContext, null);
+ } else {
+ serviceClient = new ServiceClient();
+ }
+
+ options.setAction("urn:trafficData");
+
+ if (trpUrl != null && !"null".equals(trpUrl)) {
+ options.setProperty(Constants.Configuration.TRANSPORT_URL,
trpUrl);
+ }
+
+ // Optional Field setup
+ if (addUrl != null && !"null".equals(addUrl)) {
+ serviceClient.engageModule("addressing");
+ options.setTo(new EndpointReference(addUrl));
+ }
+ if (prxUrl != null && !"null".equals(prxUrl)) {
+ HttpTransportProperties.ProxyProperties proxyProperties =
+ new HttpTransportProperties.ProxyProperties();
+ URL url = new URL(prxUrl);
+ proxyProperties.setProxyName(url.getHost());
+ proxyProperties.setProxyPort(url.getPort());
+ proxyProperties.setUserName("");
+ proxyProperties.setPassWord("");
+ proxyProperties.setDomain("");
+ options.setProperty(HTTPConstants.PROXY, proxyProperties);
+ }
+
+ serviceClient.setOptions(options);
+ }
+}

Reply all
Reply to author
Forward
0 new messages