Clover icon

Magnolia REST Client Module 1.0.1

  1. Project Clover database Fri Dec 5 2014 14:52:06 EST
  2. Package info.magnolia.rest.client.call

File AbstractRestCall.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
0% of files have more coverage

Code metrics

0
10
1
1
123
66
1
0.1
10
1
1
68.6% of code in this file is excluded from these metrics.

Classes

Class Line # Actions
AbstractRestCall 49 10 68.6% 1 11
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2014 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.rest.client.call;
35   
36    import java.util.HashMap;
37    import java.util.Map;
38   
39    import javax.ws.rs.client.Invocation;
40    import javax.ws.rs.client.WebTarget;
41   
42    import org.apache.commons.lang3.StringUtils;
43   
44    /**
45    * Base class for all rest calls (GET, POST, HEAD, PUT, DELETE).<br/>
46    *
47    * @param <T> Bean class to which response is mapped after call execution.
48    */
 
49    public abstract class AbstractRestCall<T> {
50   
51    private String path;
52    private Class<T> entityClass;
53    private Map<String, String> queryParams = new HashMap<String, String>();
54    private Map<String, String> cookies = new HashMap<String, String>();
55    private Map<String, Object> headers = new HashMap<String, Object>();
56    private Map<String, Object> templateValues = new HashMap<String, Object>();
57   
58    public abstract <T> T doCall(WebTarget target);
59   
 
60  0 toggle protected Invocation.Builder buildCall(WebTarget target) {
61  0 WebTarget webTarget = target.path(getPath());
62  0 for (Map.Entry<String, String> entry: getQueryParams().entrySet()) {
63  0 webTarget = webTarget.queryParam(entry.getKey(), StringUtils.split(entry.getValue(), ", "));
64    }
65  0 webTarget = webTarget.resolveTemplates(getTemplateValues());
66  0 Invocation.Builder builder = webTarget.request();
67  0 for (Map.Entry<String, Object> entry : getHeaders().entrySet()) {
68  0 builder.header(entry.getKey(), entry.getValue());
69    }
70  0 for (Map.Entry<String, String> entry : getQueryParams().entrySet()) {
71  0 builder.cookie(entry.getKey(), entry.getValue());
72    }
73  0 return builder;
74    }
75   
 
76    toggle public void setPath(String path) {
77    this.path = path;
78    }
79   
 
80    toggle public String getPath() {
81    return path;
82    }
83   
 
84    toggle public void setEntityClass(Class<T> entityClass) {
85    this.entityClass = entityClass;
86    }
87   
 
88    toggle public Class<T> getEntityClass() {
89    return entityClass;
90    }
91   
 
92    toggle public Map<String, String> getQueryParams() {
93    return queryParams;
94    }
95   
 
96    toggle public void setQueryParams(Map<String, String> queryParams) {
97    this.queryParams = queryParams;
98    }
99   
 
100    toggle public Map<String, Object> getHeaders() {
101    return headers;
102    }
103   
 
104    toggle public void setHeaders(Map<String, Object> headers) {
105    this.headers = headers;
106    }
107   
 
108    toggle public Map<String, Object> getTemplateValues() {
109    return templateValues;
110    }
111   
 
112    toggle public void setTemplateValues(Map<String, Object> templateValues) {
113    this.templateValues = templateValues;
114    }
115   
 
116    toggle public Map<String, String> getCookies() {
117    return cookies;
118    }
119   
 
120    toggle public void setCookies(Map<String, String> cookies) {
121    this.cookies = cookies;
122    }
123    }