KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.objectweb.petals.binding.axis2.client;
2
3 import java.io.StringWriter JavaDoc;
4 import java.util.Set JavaDoc;
5
6 import javax.activation.DataHandler JavaDoc;
7 import javax.xml.namespace.QName JavaDoc;
8 import javax.xml.transform.Transformer JavaDoc;
9 import javax.xml.transform.TransformerFactory JavaDoc;
10 import javax.xml.transform.dom.DOMSource JavaDoc;
11 import javax.xml.transform.stream.StreamResult JavaDoc;
12
13 import org.apache.axiom.soap.SOAPEnvelope;
14 import org.objectweb.petals.component.common.util.WSDLHelper;
15 import org.w3c.dom.Document JavaDoc;
16
17 public final class SOAPClient {
18
19     private SOAPClient() {
20     }
21
22     /**
23      * Calls a Request-response web service
24      * @param callEnv The call envelop
25      * @param qnameService Name of the service to be called
26      * @param opName Name of the operation to be called
27      * @param serviceDef Service description, the WSDL file as a dom document
28      * @param portName Name of the port to be called
29      * @return A soap envelop containing response from remote web service
30      * @throws Exception
31      */

32     public static SOAPEnvelope callInOutWS(SOAPEnvelope callEnv,
33             QName JavaDoc serviceName, String JavaDoc opName, Document JavaDoc serviceDesc,
34             String JavaDoc portName, Set JavaDoc<DataHandler JavaDoc> attachments) throws Exception JavaDoc {
35         DOMSource JavaDoc domSource = new DOMSource JavaDoc(serviceDesc);
36         StringWriter JavaDoc writer = new StringWriter JavaDoc();
37         StreamResult JavaDoc result = new StreamResult JavaDoc(writer);
38         TransformerFactory JavaDoc tf = TransformerFactory.newInstance();
39         Transformer JavaDoc transformer = tf.newTransformer();
40         transformer.transform(domSource, result);
41 // FIXME
42
//String stringResult = writer.toString();
43
//ByteArrayInputStream inputStream = new ByteArrayInputStream(stringResult.getBytes());
44
//String targetNS = getTargetNamespace(serviceDesc);
45
//org.apache.axis.client.Service service = new org.apache.axis.client.Service(inputStream, serviceName);
46
//org.apache.axis.client.Call call = new org.apache.axis.client.Call(service);
47
//call.setOperation(new QName(targetNS, portName), opName);
48

49         // attachments
50
// for (DataHandler dh : attachments){
51
// call.addAttachmentPart(dh);
52
//}
53
// SOAPEnvelope outEnv = null;
54
SOAPEnvelope outEnv = null;//FIXME call.invoke(callEnv);
55

56         /*
57          String response = null;
58          Call foo = new Call();
59          foo.setMethodName(opName);
60          foo.setTargetObjectURI(WSDLHelper.getServiceAddressFromWSDLDocument(serviceDesc, serviceName));
61          foo.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
62          for (DataHandler dh : attachments){
63          MimeBodyPart mimePart = new MimeBodyPart();
64          mimePart.setDataHandler(dh);
65          mimePart.setHeader(org.apache.soap.Constants.HEADER_CONTENT_LOCATION, "Attachment-1");
66          foo.addBodyPart(mimePart);
67          }
68          Response res = foo.invoke(new URL(foo.getTargetObjectURI()), "");
69          if (!res.generatedFault()) {
70          response = (String) res.getReturnValue().getValue();
71          } else {
72          response = res.getFault().getFaultString();
73          }
74          */

75         return outEnv;
76     }
77
78     protected static String JavaDoc getTargetNamespace(Document JavaDoc serviceDesc)
79         throws Exception JavaDoc {
80         return WSDLHelper.getTargetNSFromWSDLDocument(serviceDesc);
81     }
82 }
83
Popular Tags