| FileTopicHandler.java |
1 /*
2 * Copyright (C) 2003 robert rowntree
3
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13
14 * ref. http://www.gnu.org/copyleft/gpl.html
15*/
16
17/** CLIENT-SIDE - decoupled pattern for "data producer" & "data consumer"
18 * is being used. Producer and consumer are located on different host
19 * machines (possibly at diffent companies ). This implemnents Publish.
20 * ALL Subscribe activity is totally de-coupled...
21 * ( separate thread-pool used to distribute data to subscribers ).
22 * * * * * * * * * *
23 * * * * * * * * * *
24 * Semantic Details:
25 * 1. Data has been produced on the client machine.
26 * 2. Client has generated an "I-JUST-CREATED-DATA" event.
27 * 3. The event "knows" what files or data it has to distribute.
28 * 3. The event "knows" what "Topic" governs the data distribution.
29 * 4. A "handler" or implementation for the event must exist
30 * 5. That handler will trigger the actual PUBLISH activity
31 * 6. Event and Data will be "sent" to a POST-OFFICE on a remote machine
32 * 8. Subscriber maintenance and Publishing both occur on a Remote VM.
33 *
34 * This class implements Publish for data just created
35 * This implementation uses following API's to PUSH data to Remote:
36 * HTTP, SOAP, Apache AXIS, JAX-RPC, SAAJ or SwA.
37 *
38 * In a JAXRPC implementation, the SOAP MEP is "sychronous".
39 * This implementation is much more appropriate for lower volume data
40 * interchange activity where data in files needs to be passed to
41 * other applications.
42 *
43 * Although you could do it with this implementation, it would be LESS
44 * appropriate for hi-volume interchange of small snips of XML
45 * between applications.
46 *
47 * For hi-volume messages on small XML snips, a non-blocking,
48 * non-JAXRPC implementation would be recommended.
49 * * * * * * * * * *
50 * * * * * * * * * *
51 * <p> Class Responsibilities:
52 * Handler for client action event where event contains properties:
53 * (Topic, TopicAction, FileSet ).
54 * The Fileset was just created by a DataProducer and may need to distributed
55 * to DataConsumer(s).
56 * </p><p>
57 * Semantic is that this collection of file(s) has just been created and that
58 * the FileSet belongs to a Publishable Topic. Therefor, on the event, all that
59 * is necessary is to get a Connection and Transport protocal between the
60 * nodes where:
61 * data-is-created
62 * data-is-distributed
63 * </p><p>
64 * RPC and SOAP Body - Spec requires that the Server-side method Name
65 * in the Java impl be the same string as "soap.rpc.methodname.attachment"
66 * in the code below.
67 * So, over on the server, THERE MUST be a method in the class which provides
68 * imple of the service. This class is pointed to by "wsdl.service.addr.port.name".
69 * @param Event to signal "move a fileSet up to the PO from client" ...
70 * @return there is not really a return arg BUT:
71 * look at the "response" message after the call on the SoapConnection
72 * the SOAP Response msg is dumped to SysOUT...
73 * So, when you run the client, SysOUT receives the SOAP response
74 * message as a chunk of xml for an <exchangeSession> Node. Wrapped
75 * by the response are the "commands" to exhange data that will
76 * process in another thread and that will transfer the data to subscribers.
77 * * * * * * * * * *
78 * * * * * * * * * *
79 * <A HREF="http://aWebAppContext/po_1_2/xsd/ftp.xsd">SOAP Message Response Details</A>
80 *
81 */
82
83/** Java class "FileTopicHandler.java" generated from Poseidon for UML.
84 * Poseidon for UML is developed by <A HREF="http://www.gentleware.com">Gentleware</A>.
85 * Generated with <A HREF="http://jakarta.apache.org/velocity/">velocity</A> template engine.
86 */
87package com.borneo.po.event;
88
89import java.awt.event.ActionEvent;
90import java.awt.event.ActionListener;
91import java.io.IOException;
92
93import javax.xml.soap.SOAPException;
94
95import org.apache.axis.AxisFault;
96import org.apache.axis.Message;
97import org.apache.axis.MessageContext;
98import org.apache.axis.client.Service;
99import org.apache.axis.message.RPCElement;
00import org.apache.axis.message.SOAPEnvelope;
01import org.apache.axis.session.Session;
02import org.apache.axis.soap.SOAPConnectionFactoryImpl;
03import org.apache.log4j.Logger;
04import org.apache.log4j.PropertyConfigurator;
05
06import com.borneo.net.soap.SAAJCallMgr;
07import com.borneo.util.FileUtil;
08import com.borneo.util.POProperty;
09
10/**
11 * <p>
12 *
13 * </p>
14 */
15public class FileTopicHandler implements ActionListener {
16 protected static Logger log;
17 ///////////////////////////////////////
18 // operations
19
20 private Exception _failure = null;
21
22 public void actionPerformed(ActionEvent event) {
23 //TODO the collaboration belo with class=SAAJCalMgr needs to be UNCOUPLED.
24 // Put it behind an Interface like PubDataCreate
25 // Then, this would be a SOAP implementation for the client...
26 SAAJCallMgr mgr = new SAAJCallMgr();
27 mgr.setMessageContext(new MessageContext(new Service().getEngine()));
28 // get new SOAPenvelope that will hold all attachments
29 mgr.setRequestEnvelope(
30 new SOAPEnvelope(
31 mgr.getMessageContext().getSOAPConstants(),
32 mgr.getMessageContext().getSchemaVersion()));
33 // Event hasA: FileSet. I "just-created-this-data" asCollection of Files
34 // get new RPCelement with FileSet to DataHandler[] to RPCParam[]
35 // rev - add Str topicnm as first param.
36 // see api for RPCElement in Axis implementation
37 /*
38 * TODO new Interface below that is parent to FileTopic would be great!
39 * WSDL excerpt belo is important in design of new parent interface
40* <operation name="postFile" returnQName="returnqname" returnType="ns1:StreamSource" >
41* <parameter name="topicname" type="xsd:string"/>
42* <parameter name="attachments" type="ns1:ArrayOf_apachesoap_DataHandler"/>
43* </operation>
44 *
45 * new Parent Interface to have "getter methods" for the WSDL's 2 operation parms
46 * In that way, we can "Plug" any implementation in here. We do NOT have to bind
47 * to single implementation of "filetopics" or "googleSearchTask". Anyone can plug
48 * here as long as they returns Objects for the construction
49 * ofthe RPC element w/ the 2 parms enumerated below...
50 * new call to set RPCEle would be:
51 * ( get port...
52 * , get method...
53 * , mgrsetParams( (superintrfce).getTopicname(), (superintrfce).getAttachments() )
54 */
55 RPCElement myRpcEl = new RPCElement(
56 POProperty.get("wsdl.service.addr.port.name")
57 , POProperty.get("soap.rpc.methodname.attachment")
58 , mgr.setParams(
59 ( (FileTopic) event.getSource()).getTopic()
60 , new FileUtil().setDataHandler(
61 ((FileTopic) event.getSource()).getFiles()
62 )
63 )
64 );
65 //log.debug("using encode style : " + mgr.getMessageContext().getSOAPConstants().getEncodingURI());
66 try {
67 myRpcEl.setEncodingStyle(
68 mgr.getMessageContext().getSOAPConstants().getEncodingURI());
69 // envelope hasA bodyElement and a ref to a Context
70 mgr.getRequestEnvelope().addBodyElement(myRpcEl);
71 mgr.getRequestEnvelope().setMessageType(Message.REQUEST);
72 mgr.getMessageContext().setTargetService(
73 mgr.getRequestEnvelope().getFirstBody().getNamespaceURI());
74 // get the required SOAPconnection
75 mgr.setConnection(
76 SOAPConnectionFactoryImpl.newInstance().createConnection());
77 } catch (UnsupportedOperationException e) {
78 // TODO Auto-generated catch block
79 e.printStackTrace();
80 } catch (SOAPException e) {
81 // TODO Auto-generated catch block
82 e.printStackTrace();
83 } catch (AxisFault e) {
84 // TODO Auto-generated catch block
85 e.printStackTrace();
86 }
87
88 // call on the SOAPconnection with parm of new message
89 mgr.setReqMessage(new Message(mgr.getRequestEnvelope()));
90 mgr.getReqMessage().setMessageContext(mgr.getMessageContext());
91 // rcr line belo test
92 //Session reqsess = mgr.getReqMessage().getMessageContext().getSession();
93 //System.out.println("reqsns : " +reqsess.toString());
94 Message response = (Message) mgr.call(mgr.getReqMessage());
95 Session rspsess = response.getMessageContext().getSession();
96 //System.out.println("reqsns : " +rspsess.toString());
97 try {
98 // response.writeTo(System.out);
99 if (response == null) throw new NullPointerException("WSDL HostAddr not found");
00 log.debug("attachment cnt : " + new Integer(response.countAttachments()).toString());
01 response.getAttachmentsImpl().writeContentToStream(System.out);
02// use below to get a sax source on the response
03// for (Iterator i = response.getAttachments(); i.hasNext();) {
04// AttachmentPart mm = (AttachmentPart)i.next() ;
05// log.debug("DS fm part : " + mm.getDataHandler().getDataSource().getInputStream().toString());
06// }
07//
08
09 } catch (IOException e1) {
10 // TODO Auto-generated catch block
11 _failure = e1;
12 e1.printStackTrace();
13 } finally {
14 mgr.close();
15 log.debug("SOAP Connection closed");
16 }
17
18 } // end actionPerformed
19
20 //TODO
21 static {
22 log = Logger.getLogger((FileTopicHandler.class).getName());
23 ClassLoader cl = FileTopicHandler.class.getClassLoader();
24 PropertyConfigurator.configure(
25 cl.getResource("config/log4j.properties"));
26 }
27 /**
28 *
29 * @return
30 */
31 public Exception getFailure() {
32 return _failure;
33 }
34
35} // end FileTopicHandler
36