Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
../../../../img/srcFileCovDistChart9.png 41% of files have more coverage
20   92   5   20
4   46   0.25   1
1     5  
1    
 
  Ticketer       Line # 36 20 0% 5 4 84% 0.84
 
  (1)
 
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.util.HashMap;
22    import java.util.Map;
23   
24    import net.sf.arestc.core.bodytransformations.ReturnTransformationTypes;
25   
26    import org.apache.commons.configuration.ConfigurationException;
27    import org.apache.log4j.Logger;
28    import org.w3c.dom.Document;
29   
30    // TODO: Auto-generated Javadoc
31    /**
32    * The Class Ticketer.
33    *
34    * @author georgosn
35    */
 
36    public class Ticketer {
37   
38    /** The Constant LOGGER. */
39    private static final Logger LOGGER = Logger.getLogger(Ticketer.class
40    .getName());
41   
42    // This is not the job of the Context
43    /**
44    * Gets the ticket.
45    *
46    * @param context
47    * the context
48    * @param username
49    * the username
50    * @param password
51    * the password
52    * @return the ticket
53    */
 
54  1 toggle public String getTicket(final ConnectorContext context,
55    final String username, final String password) {
56  1 final Map<String, Object> myParams = new HashMap<String, Object>();
57  1 myParams.put("u", username);
58  1 myParams.put("pw", password);
59  1 ARESTConnector connector = null;
60  1 Document doc = null;
61   
62  1 String ret = "NOTICKET";
63  1 try {
64  1 connector = new ARESTConnector(ConnectorTypes.STANDARD);
65   
66  1 connector.setClient(context.getClient());
67  1 final ConnectorRequest request = new StandardConnectorRequest(
68    "login", myParams, ReturnTransformationTypes.DOM, "UTF-8");
69   
70  1 final ConnectorResponse resp = connector.serve(request);
71  1 doc = (Document) resp.getResponseBody();
72  1 if (doc != null) {
73  1 doc.getDocumentElement().normalize();
74  1 ret = doc.getDocumentElement().getChildNodes().item(0)
75    .getNodeValue();
76    }
77    } catch (final ConfigurationException e) {
78  0 LOGGER.error(
79    "This should never occur, configuration should be fine by now",
80    e);
81    } catch (final CommandException e) {
82  0 LOGGER.error(
83    "This should never occur, configuration should be fine by now",
84    e);
85    } finally {
86  1 if (null != connector) {
87  1 connector.shutdown();
88    }
89    }
90  1 return ret;
91    }
92    }