KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Jt > axis > JtAxisService


1 package Jt.axis;
2 import java.util.*;
3 import java.lang.reflect.*;
4 import java.beans.*;
5 import java.io.*;
6 import Jt.xml.*;
7 import Jt.*;
8 import org.apache.axis.*;
9 import org.apache.axis.session.*;
10
11 /**
12  * Axis Web Service used to interface with the Jt Framework.
13  */

14
15 public class JtAxisService extends JtObject {
16
17
18   JtScriptInterpreter reader = null;
19   JtXMLHelper xmlHelper = null;
20
21   public JtAxisService() {
22   }
23
24
25   // convertToXML: convert script output to XML
26

27   String JavaDoc convertToXML (Object JavaDoc scriptOutput) {
28
29     Exception JavaDoc ex;
30     JtMessage msg = new JtMessage ();
31     JtList lst;
32
33     ex = (Exception JavaDoc)
34       getValue (reader, "objException");
35
36     if (xmlHelper == null)
37       xmlHelper = new JtXMLHelper ();
38    
39     if (ex == null) {
40       msg.setMsgId ("JtCONVERT_OBJECT_TO_XML");
41       msg.setMsgContent (scriptOutput);
42       return ((String JavaDoc) sendMessage (xmlHelper, msg));
43     }
44
45     lst = new JtList ();
46
47     msg.setMsgId ("JtADD");
48     if (scriptOutput != null) {
49       msg.setMsgContent (scriptOutput);
50       //sendMessage (lst, msg);
51
lst.processMessage (msg);
52     }
53     //msg.setMsgContent (new JtException (ex.getMessage ())); // check
54
msg.setMsgContent (ex);
55     sendMessage (lst, msg);
56
57     msg.setMsgId ("JtCONVERT_OBJECT_TO_XML");
58     msg.setMsgContent (lst);
59     return ((String JavaDoc) sendMessage (xmlHelper, msg));
60
61   }
62
63
64    /**
65      * Process Jt Messages that have been previously converted to the XML format.
66      *
67      * @param xmlMessage Jt Message in XML format
68      * @return reply in XML format
69      */

70
71
72   public String JavaDoc processMessage (String JavaDoc xmlMessage) {
73   JtMessage msg;
74   Object JavaDoc scriptOutput = null;
75       MessageContext mc = MessageContext.
76          getCurrentContext();
77       Session session = mc.getSession();
78       String JavaDoc name = (String JavaDoc)session.get("name");
79
80     if (xmlMessage == null)
81       return (null);
82
83     
84
85     //System.out.println ("JtAxisService Instance:" + this);
86
//setLogFile ("c:\\log.txt");
87

88     //handleTrace ("JtAxisService.processMessage ...\n" + xmlMessage);
89

90
91     msg = new JtMessage ("JtPARSE");
92     //msg.setMsgReplyTo (this);
93

94     // Send Jt script to the Message Interpreter for execution
95

96
97     if (reader == null) {
98       reader = (JtScriptInterpreter) this.createObject ("Jt.xml.JtScriptInterpreter",
99         "root");
100       setValue (reader, "remoteInvocation", "true");
101     }
102
103     setValue (reader, "content", xmlMessage);
104     setValue (reader, "objException", null);
105     //System.out.println ("JtAxisService.processMessage:" + xmlMessage);
106

107     scriptOutput = sendMessage (reader, msg);
108
109     return (convertToXML (scriptOutput));
110
111
112   }
113
114
115  /**
116    * Unit tests all the message processed by JtAxisService.
117    */

118
119
120   public static void main(String JavaDoc[] args) {
121
122     JtObject main = new JtObject ();
123     JtMessage msg1, msg2;
124     Integer JavaDoc count;
125     JtXMLMsgReader reader; // XML reader;
126
JtAxisService adapter;
127     String JavaDoc str;
128
129     //main.setObjTrace (1);
130
//main.setLogFile ("log.txt");
131

132
133     if (args.length < 1) {
134       System.err.println ("Usage: java JtAxisService uri");
135       System.exit (1);
136     }
137
138     msg1 = new JtMessage ();
139     msg2 = new JtMessage ();
140
141
142     main.createObject ("Jt.JtFile", "file");
143     main.setValue ("file", "name", args[0]);
144     main.setValue (msg1, "msgId", "JtCONVERT_TO_STRING");
145
146     str = (String JavaDoc) main.sendMessage ("file", msg1);
147
148     msg1.setMsgId ("JtMessage1");
149     msg2.setMsgId ("JtMessage2");
150
151
152     // Create XML adapter
153

154
155     adapter = (JtAxisService) main.createObject ("Jt.axis.JtAxisService",
156      "adapter");
157
158     adapter.processMessage (str);
159       
160
161   }
162
163 }
164
165
166
Popular Tags