Clover coverage report - CRISPY - 1.1.1
Coverage timestamp: Mi Nov 15 2006 13:09:46 CET
file stats: LOC: 72   Methods: 3
NCLOC: 46   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
HttpExecutor.java 100% 90,5% 100% 92,3%
coverage coverage
 1    package net.sf.crispy.impl;
 2   
 3    import java.lang.reflect.Method;
 4   
 5    import net.sf.crispy.ExceptionWrapper;
 6    import net.sf.crispy.InvocationException;
 7    import net.sf.crispy.InvocationStrategy;
 8    import net.sf.crispy.impl.http.Serializer;
 9    import net.sf.crispy.strategy.RestInvocationStrategy;
 10   
 11    import org.apache.commons.httpclient.Header;
 12    import org.apache.commons.httpclient.HttpStatus;
 13    import org.apache.commons.httpclient.HttpVersion;
 14    import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
 15    import org.apache.commons.httpclient.methods.PostMethod;
 16    import org.apache.commons.httpclient.params.HttpMethodParams;
 17   
 18   
 19    /**
 20    * Remote-Call with serialize Java Objects about HTTP protocoll.
 21    * If Java classes not implement the interface <code>java.io.Serializable</code>,
 22    * then cann object convert with <code>net.sf.crispy.util.Converter</code>.
 23    *
 24    *
 25    * @author Linke
 26    *
 27    */
 28    public class HttpExecutor extends AbstractHttpExecutor {
 29   
 30    public final static String DEFAULT_URL_AND_PORT = "http://localhost:8111/crispy/httpserializer";
 31   
 32   
 33  96 public String getDefaultUrlAndPort() { return DEFAULT_URL_AND_PORT; }
 34   
 35  59 public InvocationStrategy getDefaultInvocationStrategy() { return new RestInvocationStrategy(); }
 36   
 37  59 public Object execute(Class pvProxyClass, Object pvProxy, Method pvMethod, Object[] pvArgs) throws Exception {
 38  59 Object lvResult = super.execute(pvProxyClass, pvProxy, pvMethod, pvArgs);
 39  59 PostMethod lvMethod = new PostMethod(url);
 40  59 try {
 41  59 lvMethod.setRequestHeader(new Header("Content-Type", "application/x-java-serialized-object"));
 42   
 43  59 HttpMethodParams lvHttpMethodParams = new HttpMethodParams();
 44  59 lvHttpMethodParams.setVersion(HttpVersion.HTTP_1_1);
 45   
 46  59 lvMethod.setParams(lvHttpMethodParams);
 47  59 lvMethod.setRequestEntity(new ByteArrayRequestEntity(Serializer.serialize(pvArgs)));
 48  59 lvMethod.setRequestHeader(new Header("User-Agent","Crispy-Http"));
 49  59 int stat = httpClient.executeMethod(lvMethod);
 50  59 if (stat == HttpStatus.SC_OK) {
 51  58 lvResult = Serializer.deserialize(lvMethod.getResponseBodyAsStream());
 52    } else {
 53  1 throw new InvocationException("Invalid HttpStatus in HttpExecutor: " + lvMethod.getStatusText() + " (" + stat + ")");
 54    }
 55   
 56    } catch (InvocationException e) {
 57  1 throw e;
 58    } catch (Exception e) {
 59  0 e.printStackTrace();
 60  0 throw new InvocationException("Error in Crispy-Http-Executor.", e);
 61    }
 62    finally {
 63  59 lvMethod.releaseConnection();
 64    }
 65   
 66  58 lvResult = ExceptionWrapper.isResultExceptionThanThrowIt(lvResult);
 67   
 68  55 return lvResult;
 69    }
 70   
 71   
 72    }