You are viewing a plain text version of this content. The canonical link for it is here.
Posted to soap-dev@xml.apache.org by sa...@locus.apache.org on 2000/09/01 04:46:25 UTC
cvs commit: xml-soap/java/samples/messaging DeploymentDescriptor.xml POProcessor.java README SendMessage.java msg1.xml msg2.xml msg3.xml po.xml
sanjiva 00/08/31 19:46:25
Added: java/samples/messaging DeploymentDescriptor.xml
POProcessor.java README SendMessage.java msg1.xml
msg2.xml msg3.xml po.xml
Log:
new sample for testing messaging stuff
Revision Changes Path
1.1 xml-soap/java/samples/messaging/DeploymentDescriptor.xml
Index: DeploymentDescriptor.xml
===================================================================
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment"
id="urn:po-processor" type="message">
<isd:provider type="java"
scope="Application"
methods="purchaseOrder bustedRequest XXX">
<isd:java class="samples.messaging.POProcessor" static="false"/>
</isd:provider>
</isd:service>
1.1 xml-soap/java/samples/messaging/POProcessor.java
Index: POProcessor.java
===================================================================
package samples.messaging;
import java.io.*;
import org.apache.soap.*;
/**
* This class receives the PO via a "purchaseOrder" method and does
* something with it.
*
* @author Sanjiva Weerawarana <sa...@watson.ibm.com>
*/
public class POProcessor {
public void purchaseOrder (Envelope env, PrintWriter out) {
out.println ("OK thanks, got the PO; we'll contact you when ready.");
}
public void bustedRequest (Envelope env, PrintWriter out) throws Exception {
throw new IllegalArgumentException ("Huh?");
}
}
1.1 xml-soap/java/samples/messaging/README
Index: README
===================================================================
This sample shows how the messaging stuff works. First deploy the
message handler by deploying DeploymentDescriptor.xml:
java org.apache.soap.server.ServiceManagerClient rpc-router-URL \
DeploymentDescriptor.xml
where rpc-router-URL is the URL of the RPC router servlet (typically
http://hostname:port/soap-context-name/servlet/rpcrouter).
Now run:
java samples.messaging.SendMessage message-router-URL filename
where message-router-URL is the URL of the message router servlet
(typically http://hostname:port/soap-context-name/servlet/messagerouter)
and filename is one of msg*.xml.
msg1.xml: contains a valid message
msg2.xml: contains a valid message to a handler that throws an exception
msg3.xml: contains a valid message to the bogus handler that was listed
in the deployment file, but doesn't exist.
1.1 xml-soap/java/samples/messaging/SendMessage.java
Index: SendMessage.java
===================================================================
package samples.messaging;
import java.io.*;
import java.net.*;
import org.w3c.dom.*;
import org.apache.soap.*;
import org.apache.soap.message.*;
import org.apache.soap.transport.*;
import org.apache.soap.util.xml.*;
/**
* This class sends a message by taking in an XML file that has a full
* SOAP envelope in it and dumping it to the given message router URL.
* Any content from the response is dumped to stdout.
*
* @author Sanjiva Weerawarana <sa...@watson.ibm.com>
*/
public class SendMessage {
public static void main (String[] args) throws Exception {
if (args.length != 2) {
System.err.println ("Usage: java " + SendMessage.class.getName () +
" SOAP-router-URL envelope-file");
System.exit (1);
}
// get the envelope to send
FileReader fr = new FileReader (args[1]);
XMLParserLiaison xpl = new XercesParserLiaison ();
Document doc = xpl.read ("- SOAP HTTP Envelope -", fr);
if (doc == null) {
throw new SOAPException (Constants.FAULT_CODE_CLIENT, "parsing error");
}
Envelope msgEnv = Envelope.unmarshall (doc.getDocumentElement ());
// send the message
Message msg = new Message ();
msg.send (new URL (args[0]), "urn:this-is-the-action-uri", msgEnv);
// receive whatever from the transport and dump it to the screen
System.out.println ("RESPONSE:");
System.out.println ("--------");
SOAPTransport st = msg.getSOAPTransport ();
BufferedReader br = st.receive ();
String line;
while ((line = br.readLine ()) != null) {
System.out.println (line);
}
}
}
1.1 xml-soap/java/samples/messaging/msg1.xml
Index: msg1.xml
===================================================================
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<purchaseOrder xmlns="urn:po-processor" orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<price>148.95</price>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<price>39.98</price>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>
</s:Body>
</s:Envelope>
1.1 xml-soap/java/samples/messaging/msg2.xml
Index: msg2.xml
===================================================================
<!-- the handler of this message throws an exception -->
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<bustedRequest xmlns="urn:po-processor">
<stuff/>
</bustedRequest>
</s:Body>
</s:Envelope>
1.1 xml-soap/java/samples/messaging/msg3.xml
Index: msg3.xml
===================================================================
<!-- this is a buggy message .. the method name is unknown -->
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body>
<XXX xmlns="urn:po-processor">
<stuff/>
</XXX>
</s:Body>
</s:Envelope>
1.1 xml-soap/java/samples/messaging/po.xml
Index: po.xml
===================================================================
<purchaseOrder xmlns="urn:po-processor" orderDate="1999-10-20">
<shipTo country="US">
<name>Alice Smith</name>
<street>123 Maple Street</street>
<city>Mill Valley</city>
<state>CA</state>
<zip>90952</zip>
</shipTo>
<billTo country="US">
<name>Robert Smith</name>
<street>8 Oak Avenue</street>
<city>Old Town</city>
<state>PA</state>
<zip>95819</zip>
</billTo>
<comment>Hurry, my lawn is going wild!</comment>
<items>
<item partNum="872-AA">
<productName>Lawnmower</productName>
<quantity>1</quantity>
<price>148.95</price>
<comment>Confirm this is electric</comment>
</item>
<item partNum="926-AA">
<productName>Baby Monitor</productName>
<quantity>1</quantity>
<price>39.98</price>
<shipDate>1999-05-21</shipDate>
</item>
</items>
</purchaseOrder>