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
9   111   5   2.25
0   45   0.56   4
4     1.25  
1    
 
  BaseRequestTransformer       Line # 33 9 0% 5 5 61.5% 0.61538464
 
  (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 it under the
8    * terms of the Lesser General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10    * version.
11    *
12    * ARESTC is distributed in the hope that it will be useful, but WITHOUT ANY
13    * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14    * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15    *
16    * You should have received a copy of the Lesser General Public License along
17    * with ARESTC. If not, see <http://www.gnu.org/licenses/>.
18    */
19    package net.sf.arestc.core;
20   
21    import java.net.URI;
22    import java.net.URISyntaxException;
23    import java.text.MessageFormat;
24   
25   
26    import org.apache.commons.httpclient.auth.AuthScope;
27    import org.apache.log4j.Logger;
28   
29    // TODO: Auto-generated Javadoc
30    /**
31    * The Class BaseRequestTransformer.
32    */
 
33    public abstract class BaseRequestTransformer implements RequestTransformer {
34   
35    /** The Constant ERROR_OCCURED_IN_PROCESS. */
36    private static final String ERROR_OCCURED_IN_PROCESS = "Error occured in process:";
37    /** The Constant ERROR_WHILE_TRYING_TO_CREATE_URI_FOR_THE_SERVICE. */
38    private static final String ERROR_WHILE_TRYING_TO_CREATE_URI_FOR_THE_SERVICE = "Error while trying to create URI for the service";
39   
40    /** The Constant LOGGER. */
41    private static final Logger LOGGER = Logger.getLogger(BaseRequestTransformer.class
42    .getName());
43   
44    /** The command. */
45    private final ConnectorCommand command;
46   
47    /**
48    * Instantiates a new base request transformer.
49    *
50    * @param com
51    * the com
52    */
 
53  17 toggle public BaseRequestTransformer(final ConnectorCommand com) {
54  17 command = com;
55    }
56   
57    /*
58    * (non-Javadoc)
59    *
60    * @see
61    * net.sf.arestc.core.commands.RequestTransformer#addError(net.sf.arestc
62    * .core.ConnectorContext, java.lang.String)
63    */
 
64  0 toggle public void addError(final ConnectorContext context, final String ErrorMsg) {
65  0 context.getErrors().add(
66    new BaseError(-1, command, ErrorMsg, context.getService()));
67    }
68   
69    /*
70    * (non-Javadoc)
71    *
72    * @see
73    * net.sf.arestc.core.commands.RequestTransformer#authenticate(net.sf.arestc
74    * .core.ConnectorRequest, net.sf.arestc.core.ConnectorContext)
75    */
 
76  6 toggle public void authenticate(final ConnectorRequest request,
77    final ConnectorContext context) {
78  6 request.setCredentials(context.getAdminAuthentication(context
79    .getService()));
80  6 context.getClient()
81    .getState()
82    .setCredentials(
83    new AuthScope(context.getServiceUri().getHost(),
84    context.getServiceUri().getPort(),
85    AuthScope.ANY_REALM, context.getServiceUri()
86    .getScheme()), request.getCredentials());
87    }
88   
89    /*
90    * (non-Javadoc)
91    *
92    * @see
93    * net.sf.arestc.core.commands.RequestTransformer#prepareUri(net.sf.arestc
94    * .core.ConnectorRequest, net.sf.arestc.core.ConnectorContext,
95    * java.lang.Object[])
96    */
 
97  10 toggle public void prepareUri(final ConnectorRequest request,
98    final ConnectorContext context, final Object[] params)
99    throws CommandException {
100  10 try {
101  10 context.setServiceUri(new URI(MessageFormat.format(context
102    .getService().getMethod().getURLPattern(), params)));
103    } catch (final URISyntaxException e) {
104  0 LOGGER.error(ERROR_OCCURED_IN_PROCESS, e);
105  0 addError(context, "URI Syntax for the service was wrong");
106  0 throw new CommandException(
107    ERROR_WHILE_TRYING_TO_CREATE_URI_FOR_THE_SERVICE, e);
108    }
109    }
110   
111    }