31917eee65b9b37f43e9febd592cfc1586e49f87
[vtn.git] /
1 /**
2  * Copyright (c) 2014 NEC Corporation
3  * All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this
7  * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.vtn.app.run.config.rest.parser;
11
12 import java.util.HashMap;
13 import java.util.Map;
14 import java.util.Map.Entry;
15
16 public class RestRequest {
17
18     /**
19      * Json Response Start Delimiter.
20      */
21
22     public static final String PARAM_DELIM_START = " {";
23
24     /**
25      * Json Response End Delimiter.
26      */
27     public static final String PARAM_DELIM_END = "}";
28
29     /**
30      * REST Service server URL address.
31      */
32     private String url = null;
33
34     /**
35      * Response string value received from the request.
36      */
37     private String response = null;
38
39     /**
40      * Map of Response parameters.
41      */
42     private Map<String, String> params = null;
43
44     /**
45      * Default contructor
46      */
47     public RestRequest() {
48         params = new HashMap<String, String>();
49     }
50
51     /**
52      * getUrl - to get the server URL.
53      * @return {@link String}
54      */
55     public String getUrl() {
56         return url;
57     }
58
59     /**
60      * setUrl - to set the server URL.
61      *  @param url
62      */
63     public void setUrl(String url) {
64         this.url = url;
65     }
66
67     /**
68      * getParams - to get the response parameter.
69      * @return {@link String}
70      */
71     public Map<String, String> getParams() {
72         return params;
73     }
74
75     /**
76      * setParams - to set the response parameter.
77      * @param params
78      */
79     public void setParams(Map<String, String> params) {
80         this.params = params;
81     }
82
83     /**
84      * getResponse - to get the response .
85      * @return {@link Map<String, String>}
86      */
87     public String getResponse() {
88         return response;
89     }
90
91     /**
92      * setResponse - to set the response.
93      * @param response.
94      */
95     public void setResponse(String response) {
96         this.response = response;
97     }
98
99     /**
100      * setResponse - to set the URL parameters.
101      *
102      */
103     public void setURLParams() {
104         for (Entry<String, String> entry : params.entrySet()) {
105             setURLParam(entry.getKey(), entry.getValue());
106         }
107     }
108
109     /**
110      * setResponse - to set the response.
111      * @param paramName, paramValue
112      */
113     public void setURLParam(String paramName, String paramValue) {
114         if (url.contains(PARAM_DELIM_START + paramName + PARAM_DELIM_END)) {
115             url = url.replace(PARAM_DELIM_START + paramName + PARAM_DELIM_END,
116                     paramValue);
117         }
118     }
119 }