KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > petals > binding > axis2 > client > AxisGUIClient


1 /**
2  * PETALS - PETALS Services Platform.
3  * Copyright (c) 2006 EBM Websourcing, http://www.ebmwebsourcing.com/
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * -------------------------------------------------------------------------
19  * $Id: Axis2BCListener.java 154 19 avr. 2006 wjoseph $
20  * -------------------------------------------------------------------------
21  */

22 package org.objectweb.petals.binding.axis2.client;
23
24 import java.awt.GridLayout JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27
28 import javax.swing.BorderFactory JavaDoc;
29 import javax.swing.JButton JavaDoc;
30 import javax.swing.JLabel JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.JScrollPane JavaDoc;
33 import javax.swing.JTextArea JavaDoc;
34 import javax.swing.JTextField JavaDoc;
35 import javax.swing.WindowConstants JavaDoc;
36 import javax.swing.border.BevelBorder JavaDoc;
37
38
39 /**
40  * Dispatcher for JBI container
41  *
42  * @version $Rev: 250 $ $Date: 2006-04-21 14:20:57 +0200 (ven, 21 avr 2006) $
43  * @since Petals 1.0
44  * @author wjoseph - EBM Websourcing
45  *
46  */

47 public class AxisGUIClient extends javax.swing.JFrame JavaDoc {
48
49     private static final long serialVersionUID = -10075363478608221L;
50
51     private JPanel JavaDoc jPanel1;
52
53     private JPanel JavaDoc jPanel4;
54
55     private JScrollPane JavaDoc jScrollPane1;
56
57     private JTextArea JavaDoc out;
58
59     private JTextArea JavaDoc in;
60
61     private JTextField JavaDoc operation;
62
63     private JTextField JavaDoc service;
64
65     private JTextField JavaDoc host;
66
67     private JTextField JavaDoc port;
68
69     private JButton JavaDoc jButton1;
70
71     private JLabel JavaDoc jLabel2;
72
73     private JLabel JavaDoc jLabel1;
74
75     private JLabel JavaDoc jLabel3;
76
77     private JLabel JavaDoc jLabel4;
78
79     private JPanel JavaDoc jPanel2;
80
81     public AxisGUIClient() {
82         super();
83         initGUI();
84     }
85
86     public static void main(String JavaDoc[] args) {
87         AxisGUIClient inst = new AxisGUIClient();
88         inst.setVisible(true);
89     }
90
91     /**
92      *
93      * @param host
94      * distant host
95      * @param port
96      * distant port
97      * @param service
98      * distant service
99      * @param operation
100      * distant operation
101      * @param msg
102      * message content
103      * @return Response to call
104      */

105     public static String JavaDoc send(String JavaDoc host, String JavaDoc port, String JavaDoc service,
106             String JavaDoc operation, Object JavaDoc[] parameters) {
107
108         /*
109         String bodyNamespace = "urn:Foo";
110         String encodingStyleProperty = "javax.xml.rpc.encodingstyle.namespace.uri";
111         String xsdNamespace = "http://www.w3.org/2001/XMLSchema";
112         String encodingUri = "http://schemas.xmlsoap.org/soap/encoding/";
113 */

114         String JavaDoc result = new String JavaDoc();
115
116         try {
117             /*
118             ServiceFactory factory = ServiceFactory.newInstance();
119             Service serviceCalled = factory.createService(new QName(service));
120
121             QName portName = new QName(service);
122
123             javax.xml.rpc.Call call = serviceCalled.createCall(portName);
124             call.setTargetEndpointAddress("http://" + host + ":" + port + "/"
125                     + service);
126
127             call.setProperty(javax.xml.rpc.Call.SOAPACTION_USE_PROPERTY,
128                     true);
129             call.setProperty(javax.xml.rpc.Call.SOAPACTION_URI_PROPERTY, "");
130             call.setProperty(encodingStyleProperty, encodingUri);
131             QName stringTypeQname = new QName(xsdNamespace, "string");
132             call.setReturnType(stringTypeQname);
133
134             call.setOperationName(new QName(bodyNamespace, operation));
135             call.addParameter(operation + "Request", stringTypeQname,
136                     ParameterMode.IN);
137             String[] params = new String[parameters.length];
138             int i = 0;
139             for (Object param : parameters) {
140                 params[i++] = (String) param;
141             }
142             result = (String) call.invoke(params);
143             return result;
144             */

145
146         } catch (Exception JavaDoc ex) {
147             ex.printStackTrace();
148             return ex.toString();
149         }
150
151
152         /*
153          String response = null;
154          Call foo = new Call();
155          foo.setMethodName(operation);
156          foo.setTargetObjectURI("http://" + host + ":" + port + "/" + service);
157          foo.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
158          if (parameters != null) {
159          Vector<Parameter> params = new Vector<Parameter>();
160          for (Object param : parameters) {
161          params.add(new Parameter("arg", param.getClass(), param
162          .toString(), null));
163          }
164          foo.setParams(params);
165          }
166          try {
167          Response res = foo.invoke(new URL(foo.getTargetObjectURI()), "coucou");
168          if (!res.generatedFault()) {
169          response = (String) res.getReturnValue().getValue();
170          } else {
171          response = res.getFault().getFaultString();
172          }
173          } catch (MalformedURLException excurl) {
174          System.out.println("The URL Exception is : " + excurl.toString());
175          } catch (SOAPException soe) {
176          System.out.println("The SOAP Exception is : " + soe.toString());
177          }
178          return response;
179          */

180         return result;
181     }
182
183     public void setResponse(String JavaDoc text) {
184         out.append(text + "\n");
185     }
186
187     /**
188      * Initiates the GUI
189      *
190      */

191     private void initGUI() {
192         try {
193             GridLayout JavaDoc thisLayout = new GridLayout JavaDoc(3, 1);
194             thisLayout.setHgap(5);
195             thisLayout.setVgap(5);
196             thisLayout.setColumns(1);
197             thisLayout.setRows(3);
198             getContentPane().setLayout(thisLayout);
199             setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
200             this.setPreferredSize(new java.awt.Dimension JavaDoc(490, 316));
201             jPanel1 = new JPanel JavaDoc();
202             GridLayout JavaDoc jPanel1Layout = new GridLayout JavaDoc(5, 2);
203             jPanel1Layout.setHgap(5);
204             jPanel1Layout.setVgap(5);
205             jPanel1Layout.setColumns(2);
206             jPanel1Layout.setRows(5);
207             jPanel1.setLayout(jPanel1Layout);
208             getContentPane().add(jPanel1);
209             jPanel1.setSize(500, 400);
210             jPanel1.setBorder(BorderFactory
211                     .createEtchedBorder(BevelBorder.LOWERED));
212             jPanel1.setPreferredSize(new java.awt.Dimension JavaDoc(490, 400));
213             jLabel1 = new JLabel JavaDoc();
214             jPanel1.add(jLabel1);
215             jLabel1.setText("service");
216             jLabel1.setPreferredSize(new java.awt.Dimension JavaDoc(113, 39));
217             service = new JTextField JavaDoc();
218             jLabel1.add(service);
219             service.setText("{http://petals.objectweb.org/}HelloworldService");
220             service.setBounds(245, 0, 231, 21);
221             jLabel2 = new JLabel JavaDoc();
222             jPanel1.add(jLabel2);
223             jLabel2.setText("operation");
224             jLabel2.setPreferredSize(new java.awt.Dimension JavaDoc(132, 39));
225             operation = new JTextField JavaDoc();
226             jLabel2.add(operation);
227             operation.setText("printMessage");
228             operation.setBounds(245, 0, 231, 21);
229             jLabel3 = new JLabel JavaDoc();
230             jPanel1.add(jLabel3);
231             jLabel3.setText("host");
232             jLabel3.setPreferredSize(new java.awt.Dimension JavaDoc(113, 39));
233             host = new JTextField JavaDoc();
234             jLabel3.add(host);
235             host.setText("127.0.0.1");
236             host.setBounds(245, 0, 231, 21);
237             jLabel4 = new JLabel JavaDoc();
238             jPanel1.add(jLabel4);
239             jLabel4.setText("port");
240             jLabel4.setPreferredSize(new java.awt.Dimension JavaDoc(113, 39));
241             port = new JTextField JavaDoc();
242             jLabel4.add(port);
243             port.setText("8084");
244             port.setBounds(245, 0, 231, 21);
245             jPanel4 = new JPanel JavaDoc();
246             getContentPane().add(jPanel4);
247             jPanel4.setBorder(BorderFactory
248                     .createEtchedBorder(BevelBorder.LOWERED));
249             jPanel4.setPreferredSize(new java.awt.Dimension JavaDoc(490, 130));
250             jButton1 = new JButton JavaDoc();
251             jPanel4.add(jButton1);
252             jButton1.setText("Send request)");
253             jButton1.setPreferredSize(new java.awt.Dimension JavaDoc(197, 39));
254             jButton1.addActionListener(new ActionListener JavaDoc() {
255                 public void actionPerformed(ActionEvent JavaDoc evt) {
256                     send();
257                 }
258             });
259             jPanel2 = new JPanel JavaDoc();
260             GridLayout JavaDoc jPanel2Layout = new GridLayout JavaDoc(1, 1);
261             jPanel2Layout.setHgap(5);
262             jPanel2Layout.setVgap(5);
263             jPanel2Layout.setColumns(1);
264             jPanel2Layout.setRows(1);
265             jPanel2.setLayout(jPanel2Layout);
266             getContentPane().add(jPanel2);
267             jPanel2.setBorder(BorderFactory
268                     .createEtchedBorder(BevelBorder.LOWERED));
269             jPanel2.setSize(492, 150);
270             jPanel2.setPreferredSize(new java.awt.Dimension JavaDoc(480, 100));
271             jScrollPane1 = new JScrollPane JavaDoc();
272             jPanel2.add(jScrollPane1);
273             in = new JTextArea JavaDoc();
274             jScrollPane1.setPreferredSize(new java.awt.Dimension JavaDoc(392, 200));
275             jScrollPane1.setViewportView(in);
276             pack();
277             this.setSize(490, 316);
278         } catch (Exception JavaDoc e) {
279             e.printStackTrace();
280         }
281     }
282
283     /**
284      * Call distant operation
285      *
286      */

287     private void send() {
288
289         Object JavaDoc[] params = {"coucou"};
290         in.setText(AxisGUIClient.send(host.getText(), port.getText(), service
291                 .getText(), operation.getText(), params));
292     }
293
294     /*
295      public static void main(String[] args){
296      try {
297      
298      DataSource ds = new FileDataSource("/home/wjoseph/.mailcap");
299      DataSource ds2 = new FileDataSource("/home/wjoseph/.dmrc");
300      DataHandler dh = new DataHandler(ds);
301      DataHandler dh2 = new DataHandler(ds2);
302      MimeBodyPart mimePart = new MimeBodyPart();
303      MimeBodyPart mimePart2 = new MimeBodyPart();
304      mimePart.setDataHandler(dh);
305      mimePart2.setDataHandler(dh2);
306      mimePart.setHeader(org.apache.soap.Constants.HEADER_CONTENT_LOCATION, "Attachment-1");
307      mimePart2.setHeader(org.apache.soap.Constants.HEADER_CONTENT_LOCATION, "Attachment-2");
308      mimePart.setContentID("001");
309      mimePart2.setContentID("002");
310      dh2.getContent();
311      String response = null;
312      Call foo = new Call();
313      foo.setMethodName("coucou");
314      foo.setTargetObjectURI("http://127.0.0.1:8083//foo");
315      foo.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
316      foo.addBodyPart(mimePart);
317      foo.addBodyPart(mimePart2);
318      
319      Response res = foo.invoke(new URL(foo.getTargetObjectURI()), "");
320      if (!res.generatedFault()) {
321      response = (String) res.getReturnValue().getValue();
322      } else {
323      response = res.getFault().getFaultString();
324      }
325      System.out.println(response);
326      }catch (Exception excurl) {
327      System.out.println("The URL Exception is : " + excurl.toString());
328      }
329      }
330      */

331 }
332
Popular Tags