Clover Coverage Report - ARESTC 0.1.5
Coverage timestamp: Tue Aug 10 2010 10:22:22 CEST
../../../../../img/srcFileCovDistChart7.png 69% of files have more coverage
28   111   8   9.33
2   61   0.29   3
3     2.67  
1    
 
  CallServer       Line # 41 28 0% 8 11 66.7% 0.6666667
 
  (15)
 
1    /*
2    *
3    * (C)opyright 2010, Nikolaos Georgosopoulos
4    *
5    * This file is part of ARESTC.
6   
7    ARESTC is free software: you can redistribute it and/or modify
8    it under the terms of the Lesser General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11   
12    ARESTC is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    GNU General Public License for more details.
16   
17    You should have received a copy of the Lesser General Public License
18    along with ARESTC. If not, see <http://www.gnu.org/licenses/>.
19   
20    */
21    package net.sf.arestc.core.commands;
22   
23    import java.io.IOException;
24   
25    import net.sf.arestc.core.BaseCommand;
26    import net.sf.arestc.core.BaseError;
27    import net.sf.arestc.core.CommandException;
28    import net.sf.arestc.core.ConnectorCommand;
29    import net.sf.arestc.core.ConnectorContext;
30    import net.sf.arestc.core.ConnectorRequest;
31   
32    import org.apache.commons.httpclient.HttpException;
33    import org.apache.commons.httpclient.HttpMethod;
34    import org.apache.log4j.Logger;
35   
36    /**
37    * The Class CallServer.
38    *
39    * @author georgosn
40    */
 
41    public class CallServer extends BaseCommand {
42   
43    /** The Constant LOGGER. */
44    private static final Logger LOGGER = Logger.getLogger(CallServer.class
45    .getName());
46   
47    /** The Constant WEB_ERROR_CODE. */
48    private static final int WEB_ERROR_CODE = 300;
49   
 
50  0 toggle public CallServer() {
51  0 super();
52    }
53   
 
54  17 toggle public CallServer(final ConnectorCommand next) {
55  17 super(next);
56    }
57   
58    /*
59    * (non-Javadoc)
60    *
61    * @see
62    * net.sf.arestc.core.BaseCommand#process(net.sf.arestc.core.ConnectorRequest
63    * , net.sf.arestc.core.ConnectorContext)
64    */
 
65  10 toggle @Override
66    public ConnectorContext process(final ConnectorRequest request,
67    final ConnectorContext context) throws CommandException {
68   
69  10 try {
70  10 final HttpMethod method = context.getMethod();
71   
72  10 final int retCode = context.getClient().executeMethod(method);
73  10 if (WEB_ERROR_CODE <= retCode) {
74  0 context.add(new BaseError(-1, this, "HttpConnection error",
75    context.getService()));
76   
77  0 return context;
78    } else {
79  10 switch (context.getService().getReturnedType()) {
80  1 case STREAM:
81  1 context.setReturnedBody(method.getResponseBodyAsStream());
82  1 context.setReturnStream(Boolean.TRUE);
83  1 break;
84  1 case NOBODY:
85  1 context.setReturnedHeader(method.getResponseHeaders());
86  1 context.setReturnedBody(null);
87  1 break;
88  8 default:
89  8 context.setReturnedBody(method.getResponseBodyAsString());
90  8 context.setReturnedHeader(method.getResponseHeaders());
91  8 break;
92    }
93   
94    }
95    } catch (final HttpException e) {
96   
97  0 context.add(new BaseError(-1, this, "HttpConnection error", context
98    .getService()));
99  0 LOGGER.error("Error occured in process:", e);
100   
101  0 return context;
102    } catch (final IOException e) {
103  0 context.add(new BaseError(-1, this, "IO Exception error", context
104    .getService()));
105  0 LOGGER.error("Error occured in process:", e);
106   
107  0 return context;
108    }
109  10 return super.process(request, context);
110    }
111    }