| FileTopicHandler.java |
1 /** CLIENT-SIDE - decoupled pattern for "data producer" & "data consumer"
2 * is being used. Producer and consumer are located on different host
3 * machines (possibly at diffent companies ). This implemnents Publish.
4 * ALL Subscribe activity is totally de-coupled...
5 * ( separate thread-pool used to distribute data to subscribers ).
6 * * * * * * * * * *
7 * * * * * * * * * *
8 * Semantic Details:
9 * 1. Data has been produced on the client machine.
10 * 2. Client has generated an "I-JUST-CREATED-DATA" event.
11 * 3. The event "knows" what files or data it has to distribute.
12 * 3. The event "knows" what "Topic" governs the data distribution.
13 * 4. A "handler" or implementation for the event must exist
14 * 5. That handler will trigger the actual PUBLISH activity
15 * 6. Event and Data will be "sent" to a POST-OFFICE on a remote machine
16 * 8. Subscriber maintenance and Publishing both occur on a Remote VM.
17 *
18 * This class implements Publish for data just created
19 * This implementation uses following API's to PUSH data to Remote:
20 * HTTP, SOAP, Apache AXIS, JAX-RPC, SAAJ or SwA.
21 *
22 * In a JAXRPC implementation, the SOAP MEP is "sychronous".
23 * This implementation is much more appropriate for lower volume data
24 * interchange activity where data in files needs to be passed to
25 * other applications.
26 *
27 * Although you could do it with this implementation, it would be LESS
28 * appropriate for hi-volume interchange of small snips of XML
29 * between applications.
30 *
31 * For hi-volume messages on small XML snips, a non-blocking,
32 * non-JAXRPC implementation would be recommended.
33 * * * * * * * * * *
34 * * * * * * * * * *
35 * <p> Class Responsibilities:
36 * Handler for client action event where event contains properties:
37 * (Topic, TopicAction, FileSet ).
38 * The Fileset was just created by a DataProducer and may need to distributed
39 * to DataConsumer(s).
40 * </p><p>
41 * Semantic is that this collection of file(s) has just been created and that
42 * the FileSet belongs to a Publishable Topic. Therefor, on the event, all that
43 * is necessary is to get a Connection and Transport protocal between the
44 * nodes where:
45 * data-is-created
46 * data-is-distributed
47 * </p><p>
48 * RPC and SOAP Body - Spec requires that the Server-side method Name
49 * in the Java impl be the same string as "soap.rpc.methodname.attachment"
50 * in the code below.
51 * So, over on the server, THERE MUST be a method in the class which provides
52 * imple of the service. This class is pointed to by "wsdl.service.addr.port.name".
53 * @param Event to signal "move a fileSet up to the PO from client" ...
54 * @return there is not really a return arg BUT:
55 * look at the "response" message after the call on the SoapConnection
56 * the SOAP Response msg is dumped to SysOUT...
57 * So, when you run the client, SysOUT receives the SOAP response
58 * message as a chunk of xml for an <exchangeSession> Node. Wrapped
59 * by the response are the "commands" to exhange data that will
60 * process in another thread and that will transfer the data to subscribers.
61 * * * * * * * * * *
62 * * * * * * * * * *
63 * <A HREF="http://aWebAppContext/po_1_2/xsd/ftp.xsd">SOAP Message Response Details</A>
64 *
65 */
66
67/** Java class "FileTopicHandler.java" generated from Poseidon for UML.
68 * Poseidon for UML is developed by <A HREF="http://www.gentleware.com">Gentleware</A>.
69 * Generated with <A HREF="http://jakarta.apache.org/velocity/">velocity</A> template engine.
70 */
71package com.borneo.po.event;
72
73import java.awt.event.ActionEvent;
74import java.awt.event.ActionListener;
75import java.io.IOException;
76
77import javax.xml.soap.SOAPException;
78import javax.xml.soap.SOAPMessage;
79
80import org.apache.axis.AxisFault;
81import org.apache.axis.Message;
82import org.apache.axis.MessageContext;
83import org.apache.axis.client.Service;
84import org.apache.axis.message.RPCElement;
85import org.apache.axis.message.SOAPEnvelope;
86import org.apache.axis.soap.SOAPConnectionFactoryImpl;
87
88import org.apache.log4j.Logger;
89import org.apache.log4j.PropertyConfigurator;
90
91import com.borneo.net.soap.SAAJCallMgr;
92import com.borneo.util.POProperty;
93
94/**
95 * <p>
96 *
97 * </p>
98 */
99public class FileTopicHandler implements ActionListener {
00 protected static Logger log;
01 ///////////////////////////////////////
02 // operations
03
04
05 public void actionPerformed(ActionEvent event) {
06//TODO the collaboration belo with class=SAAJCalMgr needs to be UNCOUPLED.
07// Put it behind an Interface like PubDataCreate
08// Then, this would be a SOAP implementation for the client...
09 SAAJCallMgr mgr = new SAAJCallMgr();
10 mgr.setMessageContext(
11 new MessageContext(
12 new Service().getEngine()
13 )
14 );
15// get new SOAPenvelope that will hold all attachments
16 mgr.setRequestEnvelope(
17 new SOAPEnvelope(
18 mgr.getMessageContext().getSOAPConstants()
19 ,mgr.getMessageContext().getSchemaVersion()
20 )
21 );
22// Event hasA: FileSet. I "just-created-this-data" asCollection of Files
23// get new RPCelement with FileSet to DataHandler[] to RPCParam[]
24
25 RPCElement myRpcEl =
26 new RPCElement(
27// "urn:EchoAttachmentsService"
28 POProperty.get(
29 "wsdl.service.addr.port.name"
30 )
31// ,"echoDir"
32 , POProperty.get(
33 "soap.rpc.methodname.attachment"
34 )
35 , mgr.setParam(
36 mgr.setDH(
37 (
38 (FileTopic)event.getSource()
39 ).getFiles()
40 )
41 )
42 );
43 log.debug("using encode style : "+
44 mgr.getMessageContext()
45 .getSOAPConstants().getEncodingURI());
46 try {
47 myRpcEl.setEncodingStyle(
48 mgr.getMessageContext(
49 ).getSOAPConstants().getEncodingURI()
50 );
51// envelope hasA bodyElement and a ref to a Context
52 mgr.getRequestEnvelope().addBodyElement(myRpcEl);
53 mgr.getRequestEnvelope().setMessageType(Message.REQUEST);
54 mgr.getMessageContext().setTargetService(
55 mgr.getRequestEnvelope()
56 .getFirstBody()
57 .getNamespaceURI()
58 );
59// get the required SOAPconnection
60 mgr.setConnection(
61 SOAPConnectionFactoryImpl.newInstance()
62 .createConnection()
63 );
64 } catch (UnsupportedOperationException e) {
65 // TODO Auto-generated catch block
66 e.printStackTrace();
67 } catch (SOAPException e) {
68 // TODO Auto-generated catch block
69 e.printStackTrace();
70 } catch (AxisFault e) {
71 // TODO Auto-generated catch block
72 e.printStackTrace();
73 }
74
75// call on the SOAPconnection with parm of new message
76 mgr.setReqMessage(
77 new Message(
78 mgr.getRequestEnvelope()
79 )
80 );
81 mgr.getReqMessage().setMessageContext(
82 mgr.getMessageContext()
83 );
84 Message response = (Message)mgr.call(mgr.getReqMessage());
85 mgr.close();
86 try {
87// response.writeTo(System.out);
88
89 response.getAttachmentsImpl().writeContentToStream(System.out);
90
91 } catch (IOException e1) {
92 // TODO Auto-generated catch block
93 e1.printStackTrace();
94 }
95
96 } // end actionPerformed
97//TODO server side SOAP msg consumer will need the TopicName
98// not just the PARM wrapper on ArrayOFDataHandlers
99
00 static
01 {
02 log = Logger.getLogger((FileTopicHandler.class).getName());
03 ClassLoader cl = FileTopicHandler.class.getClassLoader();
04 PropertyConfigurator.configure(cl.getResource(
05 "config/log4j.properties"));
06 }
07} // end FileTopicHandler
08
09
10
11