Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
../../../../img/srcFileCovDistChart7.png 67% of files have more coverage
28   114   8   9.33
2   55   0.29   3
3     2.67  
1    
 
  CallServer       Line # 36 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;
22   
23    import java.io.IOException;
24   
25   
26    import org.apache.commons.httpclient.HttpException;
27    import org.apache.commons.httpclient.HttpMethod;
28    import org.apache.log4j.Logger;
29   
30    // TODO: Auto-generated Javadoc
31    /**
32    * The Class CallServer.
33    *
34    * @author georgosn
35    */
 
36    public class CallServer extends BaseCommand {
37   
38    /** The Constant LOGGER. */
39    private static final Logger LOGGER = Logger.getLogger(CallServer.class
40    .getName());
41   
42    /** The Constant WEB_ERROR_CODE. */
43    private static final int WEB_ERROR_CODE = 300;
44   
45    /**
46    * Instantiates a new call server.
47    */
 
48  0 toggle public CallServer() {
49  0 super();
50    }
51   
52    /**
53    * Instantiates a new call server.
54    *
55    * @param next the next
56    */
 
57  17 toggle public CallServer(final ConnectorCommand next) {
58  17 super(next);
59    }
60   
61    /*
62    * (non-Javadoc)
63    *
64    * @see
65    * net.sf.arestc.core.BaseCommand#process(net.sf.arestc.core.ConnectorRequest
66    * , net.sf.arestc.core.ConnectorContext)
67    */
 
68  10 toggle @Override
69    public ConnectorContext process(final ConnectorRequest request,
70    final ConnectorContext context) throws CommandException {
71   
72  10 try {
73  10 final HttpMethod method = context.getMethod();
74   
75  10 final int retCode = context.getClient().executeMethod(method);
76  10 if (WEB_ERROR_CODE <= retCode) {
77  0 context.add(new BaseError(-1, this, "HttpConnection error",
78    context.getService()));
79   
80  0 return context;
81    } else {
82  10 switch (context.getService().getReturnedType()) {
83  1 case STREAM:
84  1 context.setReturnedBody(method.getResponseBodyAsStream());
85  1 context.setReturnStream(Boolean.TRUE);
86  1 break;
87  1 case NOBODY:
88  1 context.setReturnedHeader(method.getResponseHeaders());
89  1 context.setReturnedBody(null);
90  1 break;
91  8 default:
92  8 context.setReturnedBody(method.getResponseBodyAsString());
93  8 context.setReturnedHeader(method.getResponseHeaders());
94  8 break;
95    }
96   
97    }
98    } catch (final HttpException e) {
99   
100  0 context.add(new BaseError(-1, this, "HttpConnection error", context
101    .getService()));
102  0 LOGGER.error("Error occured in process:", e);
103   
104  0 return context;
105    } catch (final IOException e) {
106  0 context.add(new BaseError(-1, this, "IO Exception error", context
107    .getService()));
108  0 LOGGER.error("Error occured in process:", e);
109   
110  0 return context;
111    }
112  10 return super.process(request, context);
113    }
114    }