KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > juddi > proxy > AxisTransport


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.juddi.proxy;
17
18 import java.io.ByteArrayInputStream JavaDoc;
19 import java.net.URL JavaDoc;
20 import java.util.Vector JavaDoc;
21
22 import org.apache.axis.AxisFault;
23 import org.apache.axis.Message;
24 import org.apache.axis.client.Call;
25 import org.apache.axis.client.Service;
26 import org.apache.axis.message.SOAPBodyElement;
27 import org.apache.axis.utils.XMLUtils;
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.juddi.error.RegistryException;
31 import org.w3c.dom.Element JavaDoc;
32
33 /**
34  * @author Steve Viens (sviens@apache.org)
35  */

36 public class AxisTransport implements Transport
37 {
38   // private reference to the jUDDI logger
39
private static Log log = LogFactory.getLog(AxisTransport.class);
40
41   public Element send(Element request,URL JavaDoc endpointURL)
42     throws RegistryException
43   {
44     Service service = null;
45     Call call = null;
46     Element response = null;
47
48     log.debug("\nRequest message:\n" + XMLUtils.ElementToString(request));
49
50     try {
51       service = new Service();
52       call = (Call)service.createCall();
53       call.setTargetEndpointAddress(endpointURL);
54
55       String JavaDoc requestString = XMLUtils.ElementToString(request);
56       SOAPBodyElement body = new SOAPBodyElement(new ByteArrayInputStream JavaDoc(requestString.getBytes("UTF-8")));
57       Object JavaDoc[] soapBodies = new Object JavaDoc[] { body };
58
59       Vector JavaDoc result = (Vector JavaDoc)call.invoke(soapBodies);
60       response = ((SOAPBodyElement)result.elementAt(0)).getAsDOM();
61     }
62     catch (AxisFault fault) {
63
64       fault.printStackTrace();
65
66       try {
67         Message msg = call.getResponseMessage();
68         response = msg.getSOAPEnvelope().getFirstBody().getAsDOM();
69       }
70       catch (Exception JavaDoc ex) {
71         throw new RegistryException(ex);
72       }
73     }
74     catch (Exception JavaDoc ex) {
75       throw new RegistryException(ex);
76     }
77
78     log.debug("\nResponse message:\n" + XMLUtils.ElementToString(response));
79
80
81     return response;
82   }
83   
84   public String JavaDoc send(String JavaDoc request,URL JavaDoc endpointURL)
85     throws RegistryException
86   {
87     Service service = null;
88     Call call = null;
89     String JavaDoc response = null;
90
91     log.debug("\nRequest message:\n" + request);
92
93     try {
94         
95       service = new Service();
96       call = (Call)service.createCall();
97       call.setTargetEndpointAddress(endpointURL);
98     
99       SOAPBodyElement body = new SOAPBodyElement(new ByteArrayInputStream JavaDoc(request.getBytes("UTF-8")));
100       Object JavaDoc[] soapBodies = new Object JavaDoc[] { body };
101     
102       Vector JavaDoc result = (Vector JavaDoc)call.invoke(soapBodies);
103       response = ((SOAPBodyElement)result.elementAt(0)).getAsString();
104     }
105     catch (AxisFault fault) {
106
107       fault.printStackTrace();
108
109       try {
110         Message msg = call.getResponseMessage();
111         response = msg.getSOAPEnvelope().getFirstBody().getAsString();
112       }
113       catch (Exception JavaDoc ex) {
114         throw new RegistryException(ex);
115       }
116     }
117     catch (Exception JavaDoc ex) {
118       throw new RegistryException(ex);
119     }
120
121     log.debug("\nResponse message:\n" + response);
122
123     return response;
124   }
125 }
126
Popular Tags