Author: asankha
Date: Tue Jul 4 19:35:24 2006
New Revision: 419139
URL: http://svn.apache.org/viewvc?rev=419139&view=rev
Log:
add files which I have missed in the last commit
Added:
incubator/synapse/trunk/java/modules/samples/src/samples/common/
incubator/synapse/trunk/java/modules/samples/src/samples/common/InvesbotHandler.java
incubator/synapse/trunk/java/modules/samples/src/samples/common/Util.java
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/JMSProxySend.java
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/ProxyStockQuoteClient.java
Added:
incubator/synapse/trunk/java/modules/samples/src/samples/common/InvesbotHandler.java
URL:
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/samples/src/samples/common/InvesbotHandler.java?rev=419139&view=auto
==============================================================================
---
incubator/synapse/trunk/java/modules/samples/src/samples/common/InvesbotHandler.java
(added)
+++
incubator/synapse/trunk/java/modules/samples/src/samples/common/InvesbotHandler.java
Tue Jul 4 19:35:24 2006
@@ -0,0 +1,142 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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 samples.common;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+
+import javax.xml.namespace.QName;
+
+/**
+ * A class that can create messages to, and parse replies from the
+ * invesbot stock quote service at http://ws.invesbot.com/stockquotes.asmx
+ */
+public class InvesbotHandler {
+ /**
+ * Create a new custom stock quote request with a body as follows
+ * <m0:CheckPriceRequest xmlns:m0="http://www.apache-synapse.org/test">
+ * <m0:Code>symbol</m0:Code>
+ * </m0:CheckPriceRequest>
+ * @param symbol the stock symbol
+ * @return OMElement for SOAP body
+ */
+ public static OMElement createCustomRequestPayload(String symbol) {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace(
+ "http://www.apache-synapse.org/test", "m0");
+ OMElement chkPrice = factory.createOMElement("CheckPriceRequest", ns);
+ OMElement code = factory.createOMElement("Code", ns);
+ chkPrice.addChild(code);
+ code.setText(symbol);
+ return chkPrice;
+ }
+
+ /**
+ * Create a new erroneous custom stock quote request with a body as follows
+ * <m0:CheckPriceRequest xmlns:m0="http://www.apache-synapse.org/test">
+ * <m0:Symbol>symbol</m0:Symbol>
+ * </m0:CheckPriceRequest>
+ * @param symbol the stock symbol
+ * @return OMElement for SOAP body
+ */
+ public static OMElement createErroneousCustomRequestPayload(String symbol)
{
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace ns = factory.createOMNamespace(
+ "http://www.apache-synapse.org/test", "m0");
+ OMElement chkPrice = factory.createOMElement("CheckPriceRequest", ns);
+ OMElement code = factory.createOMElement("Symbol", ns);
+ chkPrice.addChild(code);
+ code.setText(symbol);
+ return chkPrice;
+ }
+
+ /**
+ * Create a new custom stock quote request with a body as follows
+ * <m:GetQuote xmlns:m="http://ws.invesbot.com/">
+ * <m:symbol>IBM</m:symbol>
+ * </m:GetQuote>
+ * @param symbol the stock symbol
+ * @return OMElement for SOAP body
+ */
+ public static OMElement createStandardRequestPayload(String symbol) {
+ OMFactory factory = OMAbstractFactory.getOMFactory();
+ OMNamespace ns =
factory.createOMNamespace("http://ws.invesbot.com/", "m0");
+ OMElement getQuote = factory.createOMElement("GetQuote", ns);
+ OMElement symb = factory.createOMElement("symbol", ns);
+ getQuote.addChild(symb);
+ symb.setText(symbol);
+ return getQuote;
+ }
+
+ /**
+ * Digests the standard StockQuote response and extracts the last trade
price
+ * @param result
+ * @return
+ * @throws javax.xml.stream.XMLStreamException
+ *
+ * <GetQuoteResponse xmlns="http://ws.invesbot.com/">
+ * <GetQuoteResult>
+ * <StockQuote xmlns="">
+ * <Symbol>IBM</Symbol>
+ * ...
+ * <Price>82.47</Price>
+ * .......
+ * </StockQuote>
+ * </GetQuoteResult>
+ * </GetQuoteResponse>
+ */
+ public static String parseStandardResponsePayload(OMElement result) throws
Exception {
+
+ OMElement getQResp = result.getFirstChildWithName(
+ new QName("http://ws.invesbot.com/", "StockQuote"));
+ if (getQResp != null) {
+ OMElement price = getQResp.getFirstChildWithName(
+ new QName("http://ws.invesbot.com/", "Price"));
+ return price.getText();
+ } else {
+ throw new Exception("Unexpected response : " + result);
+ }
+ }
+
+ /**
+ * Digests the custom quote response and extracts the last trade price
+ * @param result
+ * @return
+ * @throws javax.xml.stream.XMLStreamException
+ *
+ * <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
+ * <soap:Body>
+ * <CheckPriceResponse xmlns="http://ws.invesbot.com/" >
+ * <Code>IBM</Code>
+ * <Price>82.90</Price>
+ * </CheckPriceResponse>
+ * </soap:Body>
+ * </soap:Envelope>
+ */
+ public static String parseCustomResponsePayload(OMElement result) throws
Exception {
+
+ OMElement chkPResp = result.getFirstChildWithName(
+ new QName("http://www.apache-synapse.org/test",
"CheckPriceResponse"));
+ if (chkPResp != null) {
+ OMElement price = chkPResp.getFirstChildWithName(new
QName("http://www.apache-synapse.org/test", "Price"));
+ return price.getText();
+ } else {
+ throw new Exception("Unexpected response : " + result);
+ }
+ }
+}
Added: incubator/synapse/trunk/java/modules/samples/src/samples/common/Util.java
URL:
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/samples/src/samples/common/Util.java?rev=419139&view=auto
==============================================================================
--- incubator/synapse/trunk/java/modules/samples/src/samples/common/Util.java
(added)
+++ incubator/synapse/trunk/java/modules/samples/src/samples/common/Util.java
Tue Jul 4 19:35:24 2006
@@ -0,0 +1,129 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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 samples.common;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.MessageContextConstants;
+import org.apache.axis2.AxisFault;
+
+public class Util {
+
+ public static void testStandardQuote(
+ String symbol, String soapAction, String xurl, String turl) {
+
+ try {
+ OMElement getQuote =
InvesbotHandler.createStandardRequestPayload(symbol);
+
+ Options options = new Options();
+ if (xurl != null)
+ options.setTo(new EndpointReference(xurl));
+ if (turl != null)
+ options.setProperty(MessageContextConstants.TRANSPORT_URL,
turl);
+ options.setAction(soapAction);
+
+ ServiceClient serviceClient = new ServiceClient();
+ serviceClient.setOptions(options);
+
+ OMElement result =
serviceClient.sendReceive(getQuote).getFirstElement();
+ System.out.println("Standard :: Stock price = $" +
+ InvesbotHandler.parseStandardResponsePayload(result));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void testCustomQuote(
+ String symbol, String soapAction, String xurl, String turl) {
+
+ try {
+ OMElement getQuote =
InvesbotHandler.createCustomRequestPayload(symbol);
+
+ Options options = new Options();
+ if (xurl != null)
+ options.setTo(new EndpointReference(xurl));
+ if (turl != null)
+ options.setProperty(MessageContextConstants.TRANSPORT_URL,
turl);
+ options.setAction(soapAction);
+
+ ServiceClient serviceClient = new ServiceClient();
+ serviceClient.setOptions(options);
+
+ OMElement result =
serviceClient.sendReceive(getQuote).getFirstElement();
+ System.out.println("Custom :: Stock price = $" +
+ InvesbotHandler.parseCustomResponsePayload(result));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void testAdvancedQuote(
+ String symbol, String soapAction, String xurl, String turl) {
+ try {
+ OMElement getQuote =
InvesbotHandler.createCustomRequestPayload(symbol);
+
+ Options options = new Options();
+ if (xurl != null)
+ options.setTo(new EndpointReference(xurl));
+ if (turl != null)
+ options.setProperty(MessageContextConstants.TRANSPORT_URL,
turl);
+ options.setAction(soapAction);
+
+ ServiceClient serviceClient = new ServiceClient();
+ serviceClient.setOptions(options);
+
+ OMElement result = serviceClient.sendReceive(getQuote);
+ System.out.println("Custom :: Stock price = $" +
+
InvesbotHandler.parseCustomResponsePayload(result.getFirstElement()));
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void testErroneousQuote(
+ String symbol, String soapAction, String xurl, String turl) {
+ try {
+ OMElement getQuote =
InvesbotHandler.createErroneousCustomRequestPayload(symbol);
+
+ Options options = new Options();
+ if (xurl != null)
+ options.setTo(new EndpointReference(xurl));
+ if (turl != null)
+ options.setProperty(MessageContextConstants.TRANSPORT_URL,
turl);
+ options.setAction(soapAction);
+
+ ServiceClient serviceClient = new ServiceClient();
+ serviceClient.setOptions(options);
+
+ OMElement result = serviceClient.sendReceive(getQuote);
+ System.out.println("Error :: Stock price = $" +
+
InvesbotHandler.parseCustomResponsePayload(result.getFirstElement()));
+
+ } catch (Exception e) {
+ if (e instanceof AxisFault) {
+ System.out.println("Fault : " +
((AxisFault)e).getFaultElements());
+ } else {
+ e.printStackTrace();
+ }
+ }
+ }
+
+}
Added:
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/JMSProxySend.java
URL:
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/samples/src/samples/proxy/JMSProxySend.java?rev=419139&view=auto
==============================================================================
---
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/JMSProxySend.java
(added)
+++
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/JMSProxySend.java
Tue Jul 4 19:35:24 2006
@@ -0,0 +1,36 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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 samples.proxy;
+
+import org.apache.axiom.om.OMFactory;
+import samples.common.Util;
+
+public class JMSProxySend {
+
+ public static void main(String[] args) {
+ String symbol = "IBM";
+ String xurl = "http://ws.invesbot.com/stockquotes.asmx";
+ String turl =
"jms:/JMSInvesbotSequenceProxy?transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url=tcp://localhost:61616";
+ String sAction = "http://ws.invesbot.com/GetQuote";
+
+ if (args.length > 0) symbol = args[0];
+ if (args.length > 1) xurl = args[1];
+ if (args.length > 2) turl = args[2];
+
+ Util.testStandardQuote(symbol, sAction, xurl, turl);
+ }
+
+}
Added:
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/ProxyStockQuoteClient.java
URL:
http://svn.apache.org/viewvc/incubator/synapse/trunk/java/modules/samples/src/samples/proxy/ProxyStockQuoteClient.java?rev=419139&view=auto
==============================================================================
---
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/ProxyStockQuoteClient.java
(added)
+++
incubator/synapse/trunk/java/modules/samples/src/samples/proxy/ProxyStockQuoteClient.java
Tue Jul 4 19:35:24 2006
@@ -0,0 +1,44 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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 samples.mediation;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.client.Options;
+import org.apache.axis2.client.ServiceClient;
+import org.apache.axis2.context.MessageContextConstants;
+import samples.common.InvesbotHandler;
+import samples.common.Util;
+
+public class ProxyStockQuoteClient {
+
+ public static void main(String[] args) {
+
+ String symbol = "IBM";
+ String fwdProxy =
"http://localhost:8080/axis2/services/InvesbotForwardProxy";
+ String defProxy =
"http://localhost:8080/axis2/services/InvesbotDefaultProxy";
+ String seqProxy =
"http://localhost:8080/axis2/services/InvesbotSequenceProxy";
+ String sAction = "http://ws.invesbot.com/GetQuote";
+
+ if (args.length > 0) symbol = args[0];
+ if (args.length > 1) fwdProxy = args[1];
+ if (args.length > 2) defProxy = args[2];
+ if (args.length > 2) seqProxy = args[3];
+
+ Util.testStandardQuote(symbol, sAction, null, fwdProxy);
+ Util.testStandardQuote(symbol, sAction, null, defProxy);
+ Util.testStandardQuote(symbol, sAction, null, seqProxy);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]