|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| GETTransformer | Line # 37 | 20 | 0% | 8 | 3 | 90% |
0.9
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (9) | |||
| Result | |||
|
0.8333333
|
net.sf.arestc.core.OverallDesignTest.testTicketRetrievalWithTicketer
net.sf.arestc.core.OverallDesignTest.testTicketRetrievalWithTicketer
|
1 PASS | |
|
0.8333333
|
net.sf.arestc.core.OverallDesignTest.testTicketRetrieval
net.sf.arestc.core.OverallDesignTest.testTicketRetrieval
|
1 PASS | |
|
0.6333333
|
net.sf.arestc.core.OverallDesignTest.testFileDownload
net.sf.arestc.core.OverallDesignTest.testFileDownload
|
1 PASS | |
|
0.6333333
|
net.sf.arestc.core.OverallDesignTest.testRepositoryRetrieval
net.sf.arestc.core.OverallDesignTest.testRepositoryRetrieval
|
1 PASS | |
|
0.6333333
|
net.sf.arestc.core.OverallDesignTest.testRepositoryDelete
net.sf.arestc.core.OverallDesignTest.testRepositoryDelete
|
1 PASS | |
|
0.06666667
|
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForNodeRetrieve
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForNodeRetrieve
|
1 PASS | |
|
0.06666667
|
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForDownloadFile
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForDownloadFile
|
1 PASS | |
|
0.06666667
|
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForLogin
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForLogin
|
1 PASS | |
|
0.06666667
|
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForNodeDelete
net.sf.arestc.core.commands.ChainBuilderTest.testGetDefaultChainForNodeDelete
|
1 PASS | |
| 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.text.MessageFormat; | |
| 22 | import java.util.Collection; | |
| 23 | import java.util.Iterator; | |
| 24 | import java.util.Map; | |
| 25 | ||
| 26 | ||
| 27 | import org.apache.commons.collections.CollectionUtils; | |
| 28 | import org.apache.commons.configuration.ConfigurationException; | |
| 29 | import org.apache.log4j.Logger; | |
| 30 | ||
| 31 | // TODO: Auto-generated Javadoc | |
| 32 | /** | |
| 33 | * The Class TransformForGET. | |
| 34 | * | |
| 35 | * @author georgosn | |
| 36 | */ | |
| 37 | public class GETTransformer extends BaseRequestTransformer { | |
| 38 | ||
| 39 | /** The Constant LOGGER. */ | |
| 40 | private static final Logger LOGGER = Logger.getLogger(POSTTransformer.class | |
| 41 | .getName()); | |
| 42 | ||
| 43 | /** The Constant QUERY_FORMAT. */ | |
| 44 | private final static String QUERY_FORMAT = "{0}={1}"; | |
| 45 | ||
| 46 | /** | |
| 47 | * Instantiates a new gets the transformer. | |
| 48 | * | |
| 49 | * @param com the com | |
| 50 | */ | |
| 51 | 11 |
public GETTransformer(final ConnectorCommand com) { |
| 52 | 11 | super(com); |
| 53 | } | |
| 54 | ||
| 55 | /** | |
| 56 | * Format query parameters. | |
| 57 | * | |
| 58 | * @param urlParameternames the url parameternames | |
| 59 | * @param params the params | |
| 60 | * @return the string | |
| 61 | */ | |
| 62 | 7 |
protected String formatQueryParameters( |
| 63 | final Collection<String> urlParameternames, | |
| 64 | final Map<String, Object> params) { | |
| 65 | 7 | final StringBuilder queryParammeters = new StringBuilder(); |
| 66 | ||
| 67 | 7 | final Iterator<String> paramNames = CollectionUtils.disjunction( |
| 68 | params.keySet(), urlParameternames).iterator(); | |
| 69 | 15 | while (paramNames.hasNext()) { |
| 70 | 8 | final String name = paramNames.next(); |
| 71 | 8 | queryParammeters.append(MessageFormat.format(QUERY_FORMAT, |
| 72 | new Object[] { name, params.get(name) })); | |
| 73 | 8 | if (paramNames.hasNext()) { |
| 74 | 4 | queryParammeters.append("&"); |
| 75 | } | |
| 76 | } | |
| 77 | 7 | return queryParammeters.toString(); |
| 78 | } | |
| 79 | ||
| 80 | /** | |
| 81 | * Prepare query. | |
| 82 | * | |
| 83 | * @param request the request | |
| 84 | * @param context the context | |
| 85 | * @param args the args | |
| 86 | * @throws CommandException the command exception | |
| 87 | */ | |
| 88 | 7 |
@Override |
| 89 | public void prepareUri(final ConnectorRequest request, | |
| 90 | final ConnectorContext context, final Object[] args) | |
| 91 | throws CommandException { | |
| 92 | ||
| 93 | 7 | try { |
| 94 | 7 | final Object[] arguments = new Object[] { |
| 95 | context.getService().getServiceURL(request.getParameters()), | |
| 96 | formatQueryParameters(context.getService() | |
| 97 | .getURLParameters(), request.getParameters()) }; | |
| 98 | 7 | super.prepareUri(request, context, arguments); |
| 99 | ||
| 100 | } catch (final ConfigurationException e) { | |
| 101 | 0 | LOGGER.error("Error preparing query", e); |
| 102 | 0 | addError(context, "Configuration of service contains errors"); |
| 103 | 0 | throw new CommandException("Error preparing query", e); |
| 104 | } | |
| 105 | } | |
| 106 | ||
| 107 | /* (non-Javadoc) | |
| 108 | * @see net.sf.arestc.core.commands.RequestTransformer#transform(net.sf.arestc.core.ConnectorRequest, net.sf.arestc.core.ConnectorContext) | |
| 109 | */ | |
| 110 | 7 |
public void transform(final ConnectorRequest request, |
| 111 | final ConnectorContext context) throws CommandException { | |
| 112 | ||
| 113 | 7 | prepareUri(request, context, null); |
| 114 | ||
| 115 | 7 | context.setMethod(context.getService().getMethod() |
| 116 | .getMethod(context.getServiceUri().toString())); | |
| 117 | 7 | if (context.getService().isAuthenticationRequired()) { |
| 118 | 3 | super.authenticate(request, context); |
| 119 | } | |
| 120 | ||
| 121 | 7 | return; |
| 122 | } | |
| 123 | } | |
|
||||||||||||