Clover coverage report - ActiveSOAP - 1.0-SNAPSHOT
Coverage timestamp: Wed May 18 2005 17:30:15 BST
file stats: LOC: 176   Methods: 20
NCLOC: 98   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
RestClient.java 50% 68.3% 70% 68.3%
coverage coverage
 1   
 /** 
 2   
  * 
 3   
  * Copyright 2004 Protique Ltd
 4   
  * 
 5   
  * Licensed under the Apache License, Version 2.0 (the "License"); 
 6   
  * you may not use this file except in compliance with the License. 
 7   
  * You may obtain a copy of the License at 
 8   
  * 
 9   
  * http://www.apache.org/licenses/LICENSE-2.0
 10   
  * 
 11   
  * Unless required by applicable law or agreed to in writing, software
 12   
  * distributed under the License is distributed on an "AS IS" BASIS, 
 13   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 14   
  * See the License for the specific language governing permissions and 
 15   
  * limitations under the License. 
 16   
  * 
 17   
  **/
 18   
 package org.codehaus.activesoap;
 19   
 
 20   
 import org.codehaus.activesoap.impl.ClientHandler;
 21   
 import org.codehaus.activesoap.impl.ClientProxy;
 22   
 import org.codehaus.activesoap.transport.Invocation;
 23   
 import org.codehaus.activesoap.transport.LocalTransportClient;
 24   
 import org.codehaus.activesoap.transport.TransportClient;
 25   
 
 26   
 import javax.xml.stream.XMLStreamReader;
 27   
 import javax.xml.stream.XMLStreamWriter;
 28   
 import java.lang.reflect.Proxy;
 29   
 
 30   
 /**
 31   
  * Represents a client interface to REST services
 32   
  *
 33   
  * @version $Revision: 1.8 $
 34   
  */
 35   
 public class RestClient {
 36   
     private RestService service;
 37   
     private TransportClient transport;
 38   
     private ClientHandler clientHandler;
 39   
 
 40   
     /**
 41   
      * Factory method to create a new client to an in memory RestService
 42   
      */
 43  0
     public static RestClient newLocalClient(RestService restService) {
 44  0
         return new RestClient(new LocalTransportClient(restService), restService);
 45   
     }
 46   
 
 47  15
     public RestClient(TransportClient transport, RestService service) {
 48  15
         this.transport = transport;
 49  15
         this.service = service;
 50   
     }
 51   
 
 52  1
     public MessageExchange createMessageExchange() {
 53  1
         return new MessageExchange(service, null, null);
 54   
     }
 55   
 
 56  13
     public MessageExchange createMessageExchange(XMLStreamReader in, XMLStreamWriter out) {
 57  13
         return new MessageExchange(service, in, out);
 58   
     }
 59   
 
 60  0
     public void invokeOneWay(Handler generateBodyHandler) throws Exception {
 61  0
         MessageExchange exchange = createMessageExchange(null, null);
 62  0
         invokeOneWay(exchange, generateBodyHandler);
 63   
     }
 64   
 
 65  0
     public void invokeOneWay(MessageExchange exchange, Handler generateBodyHandler) throws Exception {
 66  0
         Invocation request = transport.createInvocation();
 67  0
         XMLStreamWriter out = request.getOut();
 68  0
         processBody(exchange, out, generateBodyHandler);
 69  0
         request.invokeOneWay();
 70   
     }
 71   
 
 72  13
     public XMLStreamReader invokeRequestReply(Handler generateBodyHandler) throws Exception {
 73  13
         Invocation request = transport.createInvocation();
 74  13
         XMLStreamWriter out = request.getOut();
 75  13
         MessageExchange exchange = createMessageExchange(null, out);
 76   
 
 77  13
         return invokeRequestReply(exchange, out, generateBodyHandler, request);
 78   
     }
 79   
 
 80  1
     public XMLStreamReader invokeRequestReply(MessageExchange exchange, Handler generateBodyHandler) throws Exception {
 81  1
         Invocation request = transport.createInvocation();
 82  1
         XMLStreamWriter out = request.getOut();
 83   
 
 84  1
         return invokeRequestReply(exchange, out, generateBodyHandler, request);
 85   
     }
 86   
 
 87   
     /**
 88   
      * Performs a request using a generic message object
 89   
      */
 90  0
     public void invokeOneWay(Object object) throws Exception {
 91  0
         checkClientHandler();
 92  0
         Handler handler = clientHandler.createBodyHandler(object);
 93  0
         invokeOneWay(handler);
 94   
     }
 95   
 
 96   
     /**
 97   
      * Performs a request-response using a generic message object API
 98   
      */
 99  4
     public Object invokeRequestReply(Object argument) throws Exception {
 100  4
         checkClientHandler();
 101  4
         Handler handler = clientHandler.createBodyHandler(argument);
 102  4
         XMLStreamReader in = invokeRequestReply(handler);
 103  4
         return parseResponse(in);
 104   
     }
 105   
 
 106   
     /**
 107   
      * Performs a request-response using a generic message object API
 108   
      */
 109  1
     public Object invokeRequestReply(MessageExchange exchange, Object argument) throws Exception {
 110  1
         checkClientHandler();
 111  1
         Handler handler = clientHandler.createBodyHandler(argument);
 112  1
         XMLStreamReader in = invokeRequestReply(exchange, handler);
 113  1
         return parseResponse(in);
 114   
     }
 115   
 
 116   
     /**
 117   
      * Creates a dynamic proxy of the given interface which when invoked
 118   
      * will perform a web services invocation.
 119   
      *
 120   
      * @param interfaceClass is the interface of the proxy to create
 121   
      * @return
 122   
      */
 123  9
     public Object createProxy(Class interfaceClass) {
 124  9
         checkClientHandler();
 125  9
         return Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
 126   
                 new Class[]{interfaceClass},
 127   
                 new ClientProxy(this, clientHandler));
 128   
     }
 129   
 
 130   
     /**
 131   
      * Internal method used to process a SOAP response
 132   
      */
 133  14
     public Object parseResponse(XMLStreamReader in) throws Exception {
 134  14
         return clientHandler.parseResponse(in);
 135   
     }
 136   
 
 137   
     /**
 138   
      * Closes down the client freeing any resources
 139   
      */
 140  0
     public void close() throws Exception {
 141  0
         transport.close();
 142   
     }
 143   
 
 144   
     // Properties
 145   
     //-------------------------------------------------------------------------
 146  0
     public ClientHandler getClientHandler() {
 147  0
         return clientHandler;
 148   
     }
 149   
 
 150  15
     public void setClientHandler(ClientHandler clientHandler) {
 151  15
         this.clientHandler = clientHandler;
 152   
     }
 153   
 
 154   
     // Implementation methods
 155   
     //-------------------------------------------------------------------------
 156  7
     public RestService getService() {
 157  7
         return service;
 158   
     }
 159   
 
 160  14
     protected void checkClientHandler() {
 161  14
         if (clientHandler == null) {
 162  0
             throw new IllegalArgumentException("Cannot create a dyamic proxy without configuring the 'clientHandler' property");
 163   
         }
 164   
     }
 165   
 
 166  14
     protected XMLStreamReader invokeRequestReply(MessageExchange exchange, XMLStreamWriter out, Handler generateBodyHandler, Invocation request) throws Exception {
 167  14
         processBody(exchange, out, generateBodyHandler);
 168  14
         return request.invokeRequest();
 169   
     }
 170   
 
 171  14
     protected void processBody(MessageExchange exchange, XMLStreamWriter out, Handler generateBodyHandler) throws Exception {
 172  14
         generateBodyHandler.invoke(exchange.newInstance(null, out));
 173   
     }
 174   
 
 175   
 }
 176