Coverage Report - org.apache.ws.scout.transport.AxisTransport
 
Classes in this File Line Coverage Branch Coverage Complexity
AxisTransport
4%
2/50
0%
0/4
7
 
 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.ws.scout.transport;
 17  
 
 18  
 import java.io.ByteArrayInputStream;
 19  
 import java.net.URI;
 20  
 import java.util.Vector;
 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.w3c.dom.Element;
 31  
 
 32  
 /**
 33  
  * Message transport class.
 34  
  * 
 35  
  * <p><i>Borrowed from jUDDI project.</i></p>
 36  
  * 
 37  
  * @author Steve Viens (sviens@apache.org)
 38  
  */
 39  12
 public class AxisTransport implements Transport
 40  
 {
 41  
   // private reference to the jUDDI logger
 42  6
   private static Log log = LogFactory.getLog(AxisTransport.class);
 43  
 
 44  
   public Element send(Element request,URI endpointURL)
 45  
     throws TransportException
 46  
   {    
 47  0
     Service service = null;
 48  0
     Call call = null;
 49  0
     Element response = null;
 50  
 
 51  0
     if (log.isDebugEnabled()) {
 52  0
         log.debug("\nRequest message:\n" + XMLUtils.ElementToString(request));
 53  0
         log.debug(endpointURL.toString());
 54  
     }
 55  
 
 56  
     try {
 57  0
       service = new Service();
 58  0
       call = (Call)service.createCall();
 59  0
       call.setTargetEndpointAddress(endpointURL.toURL());
 60  
       
 61  0
       String requestString = XMLUtils.ElementToString(request);
 62  0
       SOAPBodyElement body = new SOAPBodyElement(new ByteArrayInputStream(requestString.getBytes("UTF-8")));
 63  0
       Object[] soapBodies = new Object[] { body };
 64  
 
 65  0
       Vector result = (Vector)call.invoke(soapBodies);
 66  0
       response = ((SOAPBodyElement)result.elementAt(0)).getAsDOM();
 67  
     }
 68  0
     catch (AxisFault fault) {
 69  
 
 70  
       try {
 71  0
         Message msg = call.getResponseMessage();
 72  0
         response = msg.getSOAPEnvelope().getFirstBody().getAsDOM();
 73  
       }
 74  0
       catch (Exception ex) {
 75  0
         throw new TransportException(ex);
 76  0
       }
 77  
     }
 78  0
     catch (Exception ex) {
 79  0
       throw new TransportException(ex);
 80  0
     }
 81  
 
 82  0
     if (log.isDebugEnabled()) {
 83  0
         log.debug("\nResponse message:\n" + XMLUtils.ElementToString(response));
 84  
     }
 85  
 
 86  
 
 87  0
     return response;
 88  
   }
 89  
   
 90  
   public String send(String request,URI endpointURL)
 91  
     throws TransportException
 92  
   {    
 93  0
     Service service = null;
 94  0
     Call call = null;
 95  0
     String response = null;
 96  
 
 97  0
     log.debug("\nRequest message:\n" + request);
 98  
 
 99  
     try {
 100  
         
 101  0
       service = new Service();
 102  0
       call = (Call)service.createCall();
 103  0
       call.setTargetEndpointAddress(endpointURL.toURL());
 104  
     
 105  0
       SOAPBodyElement body = new SOAPBodyElement(new ByteArrayInputStream(request.getBytes("UTF-8")));
 106  0
       Object[] soapBodies = new Object[] { body };
 107  
     
 108  0
       Vector result = (Vector)call.invoke(soapBodies);
 109  0
       response = ((SOAPBodyElement)result.elementAt(0)).getAsString();
 110  
     }
 111  0
     catch (AxisFault fault) {
 112  
 
 113  
       try {
 114  0
         Message msg = call.getResponseMessage();
 115  0
         response = msg.getSOAPEnvelope().getFirstBody().getAsString();
 116  
       }
 117  0
       catch (Exception ex) {
 118  0
         throw new TransportException(ex);
 119  0
       }
 120  
     }
 121  0
     catch (Exception ex) {
 122  0
       throw new TransportException(ex);
 123  0
     }
 124  
 
 125  0
     log.debug("\nResponse message:\n" + response);
 126  
 
 127  0
     return response;
 128  
   }
 129  
 }