synapse-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p..@apache.org
Subject svn commit: r369234 - in /incubator/synapse/trunk/java/src/samples/userguide: DumbStockQuoteClient.java ProxyStockQuoteClient.java StockQuoteClient.java StockQuoteXMLHandler.java
Date Sun, 15 Jan 2006 17:22:28 GMT
Author: pzf
Date: Sun Jan 15 09:22:15 2006
New Revision: 369234

URL: http://svn.apache.org/viewcvs?rev=369234&view=rev
Log:
tidy up of sample clients and rewrite to use webservicex.net instead xmethods as more reliable

Added:
    incubator/synapse/trunk/java/src/samples/userguide/StockQuoteXMLHandler.java
Modified:
    incubator/synapse/trunk/java/src/samples/userguide/DumbStockQuoteClient.java
    incubator/synapse/trunk/java/src/samples/userguide/ProxyStockQuoteClient.java
    incubator/synapse/trunk/java/src/samples/userguide/StockQuoteClient.java

Modified: incubator/synapse/trunk/java/src/samples/userguide/DumbStockQuoteClient.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/samples/userguide/DumbStockQuoteClient.java?rev=369234&r1=369233&r2=369234&view=diff
==============================================================================
--- incubator/synapse/trunk/java/src/samples/userguide/DumbStockQuoteClient.java (original)
+++ incubator/synapse/trunk/java/src/samples/userguide/DumbStockQuoteClient.java Sun Jan 15
09:22:15 2006
@@ -2,6 +2,8 @@
 
 
 
+import java.net.URL;
+
 import javax.xml.namespace.QName;
 
 import org.apache.axis2.Constants;
@@ -24,6 +26,9 @@
 import org.apache.axis2.om.OMNamespace;
 import org.apache.axis2.om.OMText;
 import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HttpTransportProperties;
+import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;
 
 public class DumbStockQuoteClient {
 
@@ -40,7 +45,7 @@
 		if (args.length > 0 && args[0].substring(0, 1).equals("-")) {
 			System.out
 					.println("This client demonstrates Synapse as a gateway\n"
-							+ "Usage: ProxyStockQuoteClient Symbol SynapseURL");
+							+ "Usage: DumbStockQuoteClient Symbol SynapseURL");
 			System.out
 					.println("\nDefault values: IBM http://localhost:8080/StockQuote"
 							+ "\nAll examples depend on using the sample synapse.xml");
@@ -55,18 +60,11 @@
 			symb = args[0];
 		if (args.length > 1)
 			url = args[1];
-
 		try {
 
 			// step 1 - create a request payload
-			OMFactory factory = OMAbstractFactory.getOMFactory(); // access to
-			// OM
-			OMNamespace xNs = factory.createOMNamespace(
-					"urn:xmethods-delayed-quotes", "x");
-			OMElement getQuote = factory.createOMElement("getQuote", xNs);
-			OMElement symbol = factory.createOMElement("symbol", xNs);
-			getQuote.addChild(symbol);
-			symbol.setText(symb);
+			OMElement getQuote = StockQuoteXMLHandler
+					.createRequestPayload(symb);
 
 			// step 2 - set up the call object
 
@@ -74,49 +72,34 @@
 			EndpointReference targetEPR = new EndpointReference(url);
 
 			Options options = new Options();
-
 			options.setTo(targetEPR);
 
-						
-			// create a lightweight Axis Config with no addressing to demonstrate "dumb" SOAP
-			AxisConfiguration ac = new AxisConfiguration();
-			ConfigurationContext cc = new ConfigurationContext(ac);
-			AxisServiceGroup asg = new AxisServiceGroup(ac);
-			AxisService as = new AxisService("AnonymousService");
-			asg.addService(as);
-			
-			
-			AxisOperation axisOperationTemplate = new OutInAxisOperation(
-					new QName("getQuote"));
-			as.addOperation(axisOperationTemplate);
-			cc.getAxisConfiguration().addService(as);
-			TransportOutDescription tod = new TransportOutDescription(
-					new QName(Constants.TRANSPORT_HTTP));
-			tod.setSender(new CommonsHTTPTransportSender());
-			ac.addTransportOut(tod);
+			options.setSoapAction("http://www.webserviceX.NET/GetQuote");
+			// create a lightweight Axis Config with no addressing to
+			// demonstrate "dumb" SOAP
 
+			ServiceClient serviceClient = StockQuoteXMLHandler
+					.createServiceClient();
 			// make the ServiceClient
-			ServiceClient serviceClient = new ServiceClient();
 
 			serviceClient.setOptions(options);
 
 			// step 3 - Blocking invocation
-			OMElement result = serviceClient.sendReceive(getQuote);
+			OMElement result = serviceClient.sendReceive(new QName("getQuote"),
+					getQuote);
+			// System.out.println(result);
 
 			// step 4 - parse result
-			QName gQR = new QName("urn:xmethods-delayed-quotes",
-					"getQuoteResponse");
-			QName Result = new QName("Result");
-			OMElement qResp = (OMElement) result.getChildrenWithName(gQR)
-					.next();
-			OMText res = (OMText) qResp.getChildrenWithName(Result).next();
 
-			System.out.println("Stock price = $" + res.getText());
+			System.out.println("Stock price = $"
+					+ StockQuoteXMLHandler.parseResponse(result));
 
 		} catch (Exception e) {
 			e.printStackTrace();
 		}
 
+	}
+		
 	}
 
 }

Modified: incubator/synapse/trunk/java/src/samples/userguide/ProxyStockQuoteClient.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/samples/userguide/ProxyStockQuoteClient.java?rev=369234&r1=369233&r2=369234&view=diff
==============================================================================
--- incubator/synapse/trunk/java/src/samples/userguide/ProxyStockQuoteClient.java (original)
+++ incubator/synapse/trunk/java/src/samples/userguide/ProxyStockQuoteClient.java Sun Jan
15 09:22:15 2006
@@ -4,39 +4,25 @@
 
 import javax.xml.namespace.QName;
 
-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.description.AxisOperation;
-import org.apache.axis2.description.AxisService;
-import org.apache.axis2.description.AxisServiceGroup;
-import org.apache.axis2.description.OutInAxisOperation;
-import org.apache.axis2.description.TransportOutDescription;
-import org.apache.axis2.engine.AxisConfiguration;
-
-import org.apache.axis2.om.OMAbstractFactory;
-import org.apache.axis2.om.OMElement;
-import org.apache.axis2.om.OMFactory;
-import org.apache.axis2.om.OMNamespace;
-import org.apache.axis2.om.OMText;
-import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
 import org.apache.axis2.transport.http.HTTPConstants;
 import org.apache.axis2.transport.http.HttpTransportProperties;
 
+import org.apache.axis2.om.OMElement;
+
 public class ProxyStockQuoteClient {
 
 	/**
 	 * 
 	 * <p>
-	 * This is a fairly static test client for Synapse using the HTTP Proxy model.
-	 *  It makes a StockQuote request to XMethods stockquote service. There is no
-	 *  WS-Addressing To URL but we set the HTTP proxy URL to point to Synapse. 
-	 *  This results in the destination XMethods URL being embedded in the POST header. 
-	 *  Synapse will pick this out and use it to direct the message
+	 * This is a fairly static test client for Synapse using the HTTP Proxy
+	 * model. It makes a StockQuote request to XMethods stockquote service.
+	 * There is no WS-Addressing To URL but we set the HTTP proxy URL to point
+	 * to Synapse. This results in the destination XMethods URL being embedded
+	 * in the POST header. Synapse will pick this out and use it to direct the
+	 * message
 	 * 
 	 */
 	public static void main(String[] args) {
@@ -44,21 +30,21 @@
 		if (args.length > 0 && args[0].substring(0, 1).equals("-")) {
 			System.out
 					.println("This client demonstrates Synapse as a proxy\n"
-							+ "Usage: ProxyStockQuoteClient Symbol XmethodsURL ProxyURL");
+							+ "Usage: ProxyStockQuoteClient Symbol StockQuoteURL ProxyURL");
 			System.out
-					.println("\nDefault values: IBM http://64.124.140.30:9090/soap http://localhost:8080");
+					.println("\nDefault values: IBM http://www.webservicex.net/stockquote.asmx http://localhost:8080");
 			System.out
 					.println("\nThe XMethods URL will be used in the <wsa:To> header");
 			System.out.println("The Proxy URL will be used as an HTTP proxy");
 			System.out
-					.println("\nTo demonstrate Synapse virtual URLs, set the xmethods URL to urn:xmethods-delayed-quotes\n"
+					.println("\nTo demonstrate Synapse virtual URLs, set the URL to http://stockquote\n"
 							+ "\nTo demonstrate content-based behaviour, set the Symbol to MSFT\n"
 							+ "\nAll examples depend on using the sample synapse.xml");
 			System.exit(0);
 		}
 
 		String symb = "IBM";
-		String xurl = "http://64.124.140.30:9090/soap";
+		String xurl = "http://www.webservicex.net/stockquote.asmx";
 		String purl = "http://localhost:8080";
 
 		if (args.length > 0)
@@ -71,14 +57,8 @@
 		try {
 
 			// step 1 - create a request payload
-			OMFactory factory = OMAbstractFactory.getOMFactory(); // access to
-			// OM
-			OMNamespace xNs = factory.createOMNamespace(
-					"urn:xmethods-delayed-quotes", "x");
-			OMElement getQuote = factory.createOMElement("getQuote", xNs);
-			OMElement symbol = factory.createOMElement("symbol", xNs);
-			getQuote.addChild(symbol);
-			symbol.setText(symb);
+			OMElement getQuote = StockQuoteXMLHandler
+					.createRequestPayload(symb);
 
 			// step 2 - set up the call object
 
@@ -86,56 +66,42 @@
 			EndpointReference targetEPR = new EndpointReference(xurl);
 
 			Options options = new Options();
-
 			options.setTo(targetEPR);
 
 			URL url = new URL(purl);
 
-			
-			//engage HTTP Proxy
-			
+			// engage HTTP Proxy
+
 			HttpTransportProperties httpProps = new HttpTransportProperties();
+
 			HttpTransportProperties.ProxyProperties proxyProperties = httpProps.new ProxyProperties();
 			proxyProperties.setProxyName(url.getHost());
 			proxyProperties.setProxyPort(url.getPort());
+			proxyProperties.setUserName("");
+			proxyProperties.setPassWord("");
+			proxyProperties.setDomain("");
 
-			
 			options.setProperty(HTTPConstants.PROXY, proxyProperties);
 
-			
-			// create a lightweight Axis Config with no addressing to demonstrate "dumb" SOAP
-			AxisConfiguration ac = new AxisConfiguration();
-			ConfigurationContext cc = new ConfigurationContext(ac);
-			AxisServiceGroup asg = new AxisServiceGroup(ac);
-			AxisService as = new AxisService("AnonymousService");
-			asg.addService(as);
-			
-			AxisOperation axisOperationTemplate = new OutInAxisOperation(
-					new QName("getQuote"));
-			as.addOperation(axisOperationTemplate);
-			cc.getAxisConfiguration().addService(as);
-			TransportOutDescription tod = new TransportOutDescription(
-					new QName(Constants.TRANSPORT_HTTP));
-			tod.setSender(new CommonsHTTPTransportSender());
-			ac.addTransportOut(tod);
+			options.setAction("http://www.webserviceX.NET/GetQuote");
+			// create a lightweight Axis Config with no addressing to
+			// demonstrate "dumb" SOAP
 
+			ServiceClient serviceClient = StockQuoteXMLHandler
+					.createServiceClient();
 			// make the ServiceClient
-			ServiceClient serviceClient = new ServiceClient();
 
 			serviceClient.setOptions(options);
 
 			// step 3 - Blocking invocation
-			OMElement result = serviceClient.sendReceive(getQuote);
+			OMElement result = serviceClient.sendReceive(new QName("getQuote"),
+					getQuote);
+			// System.out.println(result);
 
 			// step 4 - parse result
-			QName gQR = new QName("urn:xmethods-delayed-quotes",
-					"getQuoteResponse");
-			QName Result = new QName("Result");
-			OMElement qResp = (OMElement) result.getChildrenWithName(gQR)
-					.next();
-			OMText res = (OMText) qResp.getChildrenWithName(Result).next();
 
-			System.out.println("Stock price = $" + res.getText());
+			System.out.println("Stock price = $"
+					+ StockQuoteXMLHandler.parseResponse(result));
 
 		} catch (Exception e) {
 			e.printStackTrace();

Modified: incubator/synapse/trunk/java/src/samples/userguide/StockQuoteClient.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/samples/userguide/StockQuoteClient.java?rev=369234&r1=369233&r2=369234&view=diff
==============================================================================
--- incubator/synapse/trunk/java/src/samples/userguide/StockQuoteClient.java (original)
+++ incubator/synapse/trunk/java/src/samples/userguide/StockQuoteClient.java Sun Jan 15 09:22:15
2006
@@ -1,5 +1,7 @@
 package samples.userguide;
 
+import java.net.URL;
+
 import javax.xml.namespace.QName;
 
 
@@ -13,6 +15,9 @@
 import org.apache.axis2.om.OMFactory;
 import org.apache.axis2.om.OMNamespace;
 import org.apache.axis2.om.OMText;
+import org.apache.axis2.transport.http.HTTPConstants;
+import org.apache.axis2.transport.http.HttpTransportProperties;
+import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;
 import org.apache.axis2.Constants;
 
 public class StockQuoteClient {
@@ -21,8 +26,8 @@
      * @param args
      *            <p>
      *            This is a fairly static test client for Synapse. It makes a
-     *            StockQuote request to XMethods stockquote service. The EPR it
-     *            is sent to is for XMethods, but the actual transport URL is
+     *            StockQuote request to WebServiceX stockquote service. The EPR it
+     *            is sent to is for WebServiceX, but the actual transport URL is
      *            designed to go to the Synapse listener.
      *
      */
@@ -30,25 +35,25 @@
 
         if (args.length > 0 && args[0].substring(0, 1).equals("-")) {
             System.out
-                    .println("Usage: StockQuoteClient Symbol XmethodsURL TransportURL");
+                    .println("Usage: StockQuoteClient Symbol StockQuoteURL TransportURL");
             System.out
-                    .println("\nDefault values: IBM http://64.124.140.30:9090/soap http://localhost:8080");
+                    .println("\nDefault values: IBM http://www.webservicex.net/stockquote.asmx
http://localhost:8080");
             System.out
                     .println("\nThe XMethods URL will be used in the <wsa:To> header");
             System.out
                     .println("The Transport URL will be used as the actual address to send
to");
             System.out
-                    .println("\nTo bypass Synapse, set the transport URL to the XMethods
URL: \n"
-                            + "e.g. StockQuoteClient IBM http://64.124.140.30:9090/soap http://64.124.140.30:9090/soap\n"
-                            + "\nTo demonstrate Synapse virtual URLs, set the xmethods URL
to urn:xmethods-delayed-quotes\n"
+                    .println("\nTo bypass Synapse, set the transport URL to the WebServiceX
URL: \n"
+                            + "e.g. StockQuoteClient IBM http://www.webservicex.net/stockquote.asmx
 http://www.webservicex.net/stockquote.asmx \n"
+                            + "\nTo demonstrate Synapse virtual URLs, set the URL to http://stockquote\n"
                             + "\nTo demonstrate content-based behaviour, set the Symbol to
MSFT\n"
                             + "\nAll examples depend on using the sample synapse.xml");
             System.exit(0);
         }
 
         String symb = "IBM";
-        String xurl = "http://64.124.140.30:9090/soap";
-        String turl = "http://127.0.0.1:8080";
+        String xurl = "http://www.webservicex.net/stockquote.asmx";
+        String turl = "http://localhost:8080";
 
         if (args.length > 0)
             symb = args[0];
@@ -58,49 +63,47 @@
             turl = args[2];
 
         try {
+       
+    			// step 1 - create a request payload
+    			OMElement getQuote = StockQuoteXMLHandler
+    					.createRequestPayload(symb);
 
-            // step 1 - create a request payload
-            OMFactory factory = OMAbstractFactory.getOMFactory(); // access to
-            // OM
-            OMNamespace xNs = factory.createOMNamespace(
-                    "urn:xmethods-delayed-quotes", "x");
-            OMElement getQuote = factory.createOMElement("getQuote", xNs);
-            OMElement symbol = factory.createOMElement("symbol", xNs);
-            getQuote.addChild(symbol);
-            symbol.setText(symb);
-
-            // step 2 - set up the call object
-
-            // the wsa:To
-            EndpointReference targetEPR = new EndpointReference(xurl);
-
-            Options options = new Options();
-            options.setTo(targetEPR);
-            options.setProperty(MessageContextConstants.CHUNKED, Constants.VALUE_FALSE);
-
-            // the transport URL
-            options.setProperty(MessageContextConstants.TRANSPORT_URL, turl);
-
-            ServiceClient serviceClient = new ServiceClient();
-            serviceClient.setOptions(options);
-
-            // step 3 - Blocking invocation
-            OMElement result = serviceClient.sendReceive(getQuote);
-
-            // step 4 - parse result
-            QName gQR = new QName("urn:xmethods-delayed-quotes",
-                    "getQuoteResponse");
-            QName Result = new QName("Result");
-            OMElement qResp = (OMElement) result.getChildrenWithName(gQR)
-                    .next();
-            OMText res = (OMText) qResp.getChildrenWithName(Result).next();
+    			// step 2 - set up the call object
 
-            System.out.println("Stock price = $" + res.getText());
+    			// the wsa:To
+    			EndpointReference targetEPR = new EndpointReference(xurl);
+
+    			Options options = new Options();
+    			//options.setProperty(MessageContextConstants.TRANSPORT_URL, turl);
+    			options.setTo(targetEPR);
+
+    	
+    			options.setAction("http://www.webserviceX.NET/GetQuote");
+    			options.setSoapAction("http://www.webserviceX.NET/GetQuote");
+    			
+                // options.setProperty(MessageContextConstants.CHUNKED, Constants.VALUE_FALSE);
+    		    ServiceClient serviceClient = new ServiceClient();
+    	        
+    			serviceClient.setOptions(options);
+
+    			// step 3 - Blocking invocation
+    			OMElement result = serviceClient.sendReceive(new QName("getQuote"),
+    					getQuote);
+    			// System.out.println(result);
+
+    			// step 4 - parse result
+
+    			System.out.println("Stock price = $"
+    					+ StockQuoteXMLHandler.parseResponse(result));
+
+    		} catch (Exception e) {
+    			e.printStackTrace();
+    		}
+
+    	}
 
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
 
+           
     }
 
 }

Added: incubator/synapse/trunk/java/src/samples/userguide/StockQuoteXMLHandler.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/java/src/samples/userguide/StockQuoteXMLHandler.java?rev=369234&view=auto
==============================================================================
--- incubator/synapse/trunk/java/src/samples/userguide/StockQuoteXMLHandler.java (added)
+++ incubator/synapse/trunk/java/src/samples/userguide/StockQuoteXMLHandler.java Sun Jan 15
09:22:15 2006
@@ -0,0 +1,88 @@
+package samples.userguide;
+
+import java.io.ByteArrayInputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.OutInAxisOperation;
+import org.apache.axis2.description.TransportOutDescription;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.om.OMAbstractFactory;
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMFactory;
+import org.apache.axis2.om.OMNamespace;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
+import org.apache.axis2.transport.http.CommonsHTTPTransportSender;
+
+public class StockQuoteXMLHandler {
+
+	public static OMElement createRequestPayload(String symb) {
+		OMFactory factory = OMAbstractFactory.getOMFactory(); // access to
+		// OM
+		OMNamespace xNs = factory.createOMNamespace(
+				"http://www.webserviceX.NET/", "");
+		OMElement getQuote = factory.createOMElement("GetQuote", xNs);
+		OMElement symbol = factory.createOMElement("symbol", xNs);
+		getQuote.addChild(symbol);
+		symbol.setText(symb);
+		return getQuote;
+	}
+
+	public static String parseResponse(OMElement result) throws XMLStreamException {
+		QName gQR = new QName("http://www.webserviceX.NET/", "GetQuoteResponse");
+
+		OMElement qResp = (OMElement) result.getChildrenWithName(gQR).next();
+
+		String text = ((OMText) qResp.getFirstOMChild()).getText();
+		// this odd webservice embeds XML as a string inside other XML
+		// hmmmm can't say its useful!
+
+		
+
+		
+			StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(
+					text.getBytes()));
+
+			OMElement parse = builder.getDocumentElement();
+		
+		OMElement last = (OMElement) parse.getFirstElement().getFirstElement()
+				.getNextOMSibling();
+		OMText lastText = (OMText) last.getFirstOMChild();
+		return lastText.getText();
+		
+	}
+	
+	public static ServiceClient createServiceClient() throws AxisFault {
+		AxisConfiguration ac = new AxisConfiguration();
+		ConfigurationContext cc = new ConfigurationContext(ac);
+		AxisServiceGroup asg = new AxisServiceGroup(ac);
+		AxisService as = new AxisService("AnonymousService");
+		asg.addService(as);
+
+		AxisOperation axisOperationTemplate = new OutInAxisOperation(
+				new QName("getQuote"));
+		as.addOperation(axisOperationTemplate);
+		cc.getAxisConfiguration().addService(as);
+		TransportOutDescription tod = new TransportOutDescription(
+				new QName(Constants.TRANSPORT_HTTP));
+
+		tod.setSender(new CommonsHTTPTransportSender());
+		ac.addTransportOut(tod);
+
+		// make the ServiceClient
+
+	
+		ServiceClient serviceClient = new ServiceClient(cc, as);
+		return serviceClient;
+	}
+
+}



---------------------------------------------------------------------
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