Coverage Report - org.apache.ws.scout.transport.LocalTransport
 
Classes in this File Line Coverage Branch Coverage Complexity
LocalTransport
58%
19/33
50%
2/4
0
 
 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.lang.reflect.Method;
 19  
 import java.net.URI;
 20  
 
 21  
 import javax.xml.parsers.DocumentBuilder;
 22  
 import javax.xml.parsers.DocumentBuilderFactory;
 23  
 
 24  
 import org.apache.commons.logging.Log;
 25  
 import org.apache.commons.logging.LogFactory;
 26  
 import org.apache.ws.scout.util.XMLUtils;
 27  
 import org.w3c.dom.Document;
 28  
 import org.w3c.dom.Element;
 29  
 import org.w3c.dom.Node;
 30  
 
 31  
 /**
 32  
  * Local Message transport class.
 33  
  * 
 34  
  * <p>This transpor calls jUDDI directly.</p>
 35  
  * 
 36  
  * @author Kurt Stam (kurt.stam@redhat.com)
 37  
  */
 38  336
 public class LocalTransport implements Transport
 39  
 {
 40  6
   private static Log log = LogFactory.getLog(LocalTransport.class);
 41  
 
 42  
   /** 
 43  
    * Sends an element and returns an element.
 44  
    */
 45  
   public Element send(Element request,URI endpointURI)
 46  
     throws TransportException
 47  
   {    
 48  1746
     Element response = null;
 49  
 
 50  1746
     if (log.isDebugEnabled()) {
 51  1746
             log.debug("\nRequest message:\n" + XMLUtils.convertNodeToXMLString(request));
 52  1746
             log.debug("Calling " + endpointURI + " locally");
 53  
     }
 54  
     try {
 55  1746
             String className = endpointURI.getPath();
 56  1746
             String methodName = endpointURI.getFragment();
 57  1746
             log.debug("Calling class=" + className);
 58  1746
             log.debug("Method=" + methodName);
 59  1746
             Class<?> c = Class.forName(className);
 60  1746
             Object requestHandler = c.newInstance();
 61  1746
             Method method = c.getMethod(methodName, Element.class);
 62  1746
             Node node = (Node) method.invoke(requestHandler, request);
 63  1746
             response = (Element) node.getFirstChild();
 64  
     }
 65  0
     catch (Exception ex) {
 66  0
       throw new TransportException(ex);
 67  1746
     }
 68  1746
     if (log.isDebugEnabled()) {
 69  1746
             log.debug("\nResponse message:\n" + XMLUtils.convertNodeToXMLString(response));
 70  
     }
 71  1746
     return response;
 72  
   }
 73  
   
 74  
   /**
 75  
    * Sends an XML, responds with an XML.
 76  
    */
 77  
   public String send(String request,URI endpointURI)
 78  
     throws TransportException
 79  
   {    
 80  0
     String response = null;
 81  0
     log.debug("\nRequest message:\n" + request);
 82  
     try {
 83  0
             DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
 84  0
         DocumentBuilder parser = factory.newDocumentBuilder();
 85  0
         Document document = parser.parse(request);
 86  0
         Element element = document.getDocumentElement();
 87  0
         response= XMLUtils.convertNodeToXMLString(send(element, endpointURI));
 88  0
     } catch (Exception ex) { 
 89  0
             throw new TransportException(ex);
 90  0
     }
 91  0
     log.debug("\nResponse message:\n" + response);
 92  0
     return response;
 93  
   }
 94  
   
 95  
   
 96  
 }