KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > soap > SOAPConnectionImpl


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2002-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55 package org.jboss.axis.soap;
56
57 import org.jboss.axis.AxisFault;
58 import org.jboss.axis.Constants;
59 import org.jboss.axis.Message;
60 import org.jboss.axis.attachments.Attachments;
61 import org.jboss.axis.client.Call;
62 import org.jboss.axis.message.SOAPEnvelopeAxisImpl;
63 import org.jboss.axis.transport.http.HTTPConstants;
64 import org.jboss.axis.utils.Messages;
65 import org.jboss.logging.Logger;
66 import org.w3c.dom.Element JavaDoc;
67
68 import javax.xml.soap.MimeHeader JavaDoc;
69 import javax.xml.soap.MimeHeaders JavaDoc;
70 import javax.xml.soap.SOAPException JavaDoc;
71 import javax.xml.soap.SOAPMessage JavaDoc;
72 import java.net.MalformedURLException JavaDoc;
73 import java.util.Hashtable JavaDoc;
74 import java.util.Iterator JavaDoc;
75
76 /**
77  * SOAP Connection implementation
78  *
79  * @author Davanum Srinivas (dims@yahoo.com)
80  */

81 public class SOAPConnectionImpl extends javax.xml.soap.SOAPConnection JavaDoc
82 {
83    boolean closed = false;
84
85    private static Logger log = Logger.getLogger(SOAPConnectionImpl.class.getName());
86
87    /**
88     * Sends the given message to the specified endpoint and
89     * blocks until it has returned the response.
90     *
91     * @param request the <CODE>SOAPMessage</CODE>
92     * object to be sent
93     * @param endpoint a <CODE>URLEndpoint</CODE>
94     * object giving the URL to which the message should be
95     * sent
96     * @return the <CODE>SOAPMessage</CODE> object that is the
97     * response to the message that was sent
98     * @throws SOAPException if there is a SOAP error
99     */

100    public SOAPMessage JavaDoc call(SOAPMessage JavaDoc request, Object JavaDoc endpoint)
101            throws SOAPException JavaDoc
102    {
103       if (closed)
104       {
105          throw new SOAPException JavaDoc(Messages.getMessage("connectionClosed00"));
106       }
107       try
108       {
109          Call call = createCall(endpoint);
110          ((org.jboss.axis.Message)request).setMessageContext(call.getMessageContext());
111          SOAPEnvelopeAxisImpl env = ((org.jboss.axis.Message)request).getSOAPEnvelope();
112          Attachments attachments = ((org.jboss.axis.Message)
113                  request).getAttachmentsImpl();
114          if (attachments != null)
115          {
116             Iterator JavaDoc iterator = attachments.getAttachments().iterator();
117             while (iterator.hasNext())
118             {
119                Object JavaDoc attachment = iterator.next();
120                call.addAttachmentPart(attachment);
121             }
122          }
123
124          call.setReturnClass(SOAPMessage JavaDoc.class);
125          call.invoke(env, request.getMimeHeaders());
126          return call.getResponseMessage();
127       }
128       catch (java.net.MalformedURLException JavaDoc mue)
129       {
130          throw new SOAPException JavaDoc(mue);
131       }
132       catch (org.jboss.axis.AxisFault af)
133       {
134          processAxisFault(af);
135          Message msg = new Message(af);
136          msg.setProperty(SOAPMessage.WRITE_XML_DECLARATION, "true");
137          msg.setMessageContext(((org.jboss.axis.Message)request).getMessageContext());
138          return msg;
139 // throw new SOAPException(af);
140
}
141       catch (java.rmi.RemoteException JavaDoc re)
142       {
143          throw new SOAPException JavaDoc(re);
144       }
145    }
146
147    /**
148     * routine called whenever an axis fault is caught; where they
149     * are logged and any other business. The method may modify the fault
150     * in the process
151     *
152     * @param fault what went wrong.
153     */

154    protected void processAxisFault(AxisFault fault)
155    {
156       //log the fault
157
Element JavaDoc runtimeException = fault.lookupFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE);
158       if (runtimeException != null)
159       {
160          //strip runtime details
161
fault.removeFaultDetail(Constants.QNAME_FAULTDETAIL_STACKTRACE);
162       }
163    }
164
165    /**
166     * Stubbed out to allow subclassing
167     */

168    protected Call createCall(Object JavaDoc endpoint) throws MalformedURLException JavaDoc
169    {
170       Call call = new Call(endpoint.toString());
171       return call;
172    }
173
174    /**
175     * Closes this <CODE>SOAPConnection</CODE> object.
176     *
177     * @throws SOAPException if there is a SOAP error
178     */

179    public void close() throws SOAPException JavaDoc
180    {
181       if (closed)
182       {
183          throw new SOAPException JavaDoc(Messages.getMessage("connectionClosed00"));
184       }
185       closed = true;
186    }
187 }
188
Popular Tags