Coverage Report - org.apache.ws.scout.transport.AxisTransport
 
Classes in this File Line Coverage Branch Coverage Complexity
AxisTransport
0%
0/52
0%
0/8
8
 
 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  0
 public class AxisTransport implements Transport
 40  
 {
 41  
   // private reference to the jUDDI logger
 42  0
   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
       if (result.size() > 0) {
 67  0
               response = ((SOAPBodyElement)result.elementAt(0)).getAsDOM();
 68  
       }
 69  
     }
 70  0
     catch (AxisFault fault) {
 71  
 
 72  
       try {
 73  0
         Message msg = call.getResponseMessage();
 74  0
         response = msg.getSOAPEnvelope().getFirstBody().getAsDOM();
 75  
       }
 76  0
       catch (Exception ex) {
 77  0
         throw new TransportException(ex);
 78  0
       }
 79  
     }
 80  0
     catch (Exception ex) {
 81  0
       throw new TransportException(ex);
 82  0
     }
 83  
 
 84  0
     if (log.isDebugEnabled()) {
 85  0
         log.debug("\nResponse message:\n" + XMLUtils.ElementToString(response));
 86  
     }
 87  
 
 88  
 
 89  0
     return response;
 90  
   }
 91  
   
 92  
   public String send(String request,URI endpointURL)
 93  
     throws TransportException
 94  
   {    
 95  0
     Service service = null;
 96  0
     Call call = null;
 97  0
     String response = null;
 98  
 
 99  0
     log.debug("\nRequest message:\n" + request);
 100  
 
 101  
     try {
 102  
         
 103  0
       service = new Service();
 104  0
       call = (Call)service.createCall();
 105  0
       call.setTargetEndpointAddress(endpointURL.toURL());
 106  
     
 107  0
       SOAPBodyElement body = new SOAPBodyElement(new ByteArrayInputStream(request.getBytes("UTF-8")));
 108  0
       Object[] soapBodies = new Object[] { body };
 109  
     
 110  0
       Vector result = (Vector)call.invoke(soapBodies);
 111  0
       if (result.size() > 0 ) {
 112  0
               response = ((SOAPBodyElement)result.elementAt(0)).getAsString();
 113  
       }
 114  
     }
 115  0
     catch (AxisFault fault) {
 116  
 
 117  
       try {
 118  0
         Message msg = call.getResponseMessage();
 119  0
         response = msg.getSOAPEnvelope().getFirstBody().getAsString();
 120  
       }
 121  0
       catch (Exception ex) {
 122  0
         throw new TransportException(ex);
 123  0
       }
 124  
     }
 125  0
     catch (Exception ex) {
 126  0
       throw new TransportException(ex);
 127  0
     }
 128  
 
 129  0
     log.debug("\nResponse message:\n" + response);
 130  
 
 131  0
     return response;
 132  
   }
 133  
 }