164 final String path = PlatformRestAdapter.getDomain() |
164 final String path = PlatformRestAdapter.getDomain() |
165 + exchange.getRequestURI().getPath().replaceAll("/$", ""); |
165 + exchange.getRequestURI().getPath().replaceAll("/$", ""); |
166 try { |
166 try { |
167 List<ObjectName> filteredMBeans = allowedMbeans; |
167 List<ObjectName> filteredMBeans = allowedMbeans; |
168 Map<String, String> queryMap = HttpUtil.getGetRequestQueryMap(exchange); |
168 Map<String, String> queryMap = HttpUtil.getGetRequestQueryMap(exchange); |
|
169 String query = exchange.getRequestURI().getQuery(); |
|
170 if(query != null && queryMap.isEmpty()) { |
|
171 return new HttpResponse(HttpResponse.BAD_REQUEST, |
|
172 "Invalid query params : Allowed query keys [query,page]"); |
|
173 }else if(query != null && !queryMap.isEmpty()) { |
|
174 Map<String, String> newMap = new HashMap<>(queryMap); |
|
175 newMap.remove("query"); |
|
176 newMap.remove("page"); |
|
177 if(!newMap.isEmpty()) { // Invalid query params |
|
178 return new HttpResponse(HttpResponse.BAD_REQUEST, |
|
179 "Invalid query params : Allowed query keys [query,page]"); |
|
180 } |
|
181 } |
169 if (queryMap.containsKey("query")) { // Filter based on ObjectName query |
182 if (queryMap.containsKey("query")) { // Filter based on ObjectName query |
170 Set<ObjectName> queryMBeans = mBeanServer |
183 Set<ObjectName> queryMBeans = mBeanServer |
171 .queryNames(new ObjectName(queryMap.get("query")), null); |
184 .queryNames(new ObjectName(queryMap.get("query")), null); |
172 queryMBeans.retainAll(allowedMbeans); // Intersection of two lists |
185 queryMBeans.retainAll(allowedMbeans); // Intersection of two lists |
173 filteredMBeans = new ArrayList<>(queryMBeans); |
186 filteredMBeans = new ArrayList<>(queryMBeans); |
174 } |
187 } |
175 |
188 |
176 JSONObject _links = HttpUtil.getPaginationLinks(exchange, filteredMBeans, pageSize); |
189 JSONObject _links = HttpUtil.getPaginationLinks(exchange, filteredMBeans, pageSize); |
177 filteredMBeans = HttpUtil.filterByPage(exchange, filteredMBeans, pageSize); |
190 List<ObjectName> mbeanPage = HttpUtil.filterByPage(exchange, filteredMBeans, pageSize); |
178 |
191 |
179 List<Map<String, String>> items = new ArrayList<>(filteredMBeans.size()); |
192 List<Map<String, String>> items = new ArrayList<>(filteredMBeans.size()); |
180 filteredMBeans.forEach(objectName -> { |
193 mbeanPage.forEach(objectName -> { |
181 Map<String, String> item = new LinkedHashMap<>(2); |
194 Map<String, String> item = new LinkedHashMap<>(2); |
182 item.put("name", objectName.toString()); |
195 item.put("name", objectName.toString()); |
183 String href = path + "/" + objectName.toString(); |
196 String href = path + "/" + objectName.toString(); |
184 href = HttpUtil.escapeUrl(href); |
197 href = HttpUtil.escapeUrl(href); |
185 item.put("href", href); |
198 item.put("href", href); |
186 items.add(item); |
199 items.add(item); |
187 }); |
200 }); |
188 |
201 |
189 Map<String, String> properties = new HashMap<>(); |
202 Map<String, String> properties = new HashMap<>(); |
190 |
203 |
191 properties.put("mbeanCount", Integer.toString(allowedMbeans.size())); |
204 properties.put("mbeanCount", Integer.toString(filteredMBeans.size())); |
192 |
205 |
193 JSONMapper typeMapper1 = JSONMappingFactory.INSTANCE.getTypeMapper(items); |
206 JSONMapper typeMapper1 = JSONMappingFactory.INSTANCE.getTypeMapper(items); |
194 JSONMapper typeMapper2 = JSONMappingFactory.INSTANCE.getTypeMapper(properties); |
207 JSONMapper typeMapper2 = JSONMappingFactory.INSTANCE.getTypeMapper(properties); |
195 |
208 |
196 JSONElement linkElem = typeMapper1.toJsonValue(items); |
209 JSONElement linkElem = typeMapper1.toJsonValue(items); |