PT #160302607: WebFlux RMs JMX beans format + NPE for WebFlux symbols

This commit is contained in:
BoykoAlex
2018-09-05 19:02:25 -04:00
parent 238e176c90
commit 19d680bbb7
3 changed files with 93 additions and 48 deletions

View File

@@ -26,15 +26,21 @@ public class RequestMappingsParser20 {
//Contains 3 different keys now ('dispatcherServlets', 'servletFilters' and 'servlets'.
// Each with their own kind of data inside. Looks like 'dispatcherServlets' contains stuff similar to what we
// know from Boot 1.x but in slighly different form. We only parse that stuff for now.
JSONObject dispatcherServlets = obj
JSONObject mappings = obj
.getJSONObject(contextId)
.getJSONObject("mappings")
.getJSONObject("dispatcherServlets");
for (String servletId : dispatcherServlets.keySet()) {
JSONArray servlets = dispatcherServlets.getJSONArray(servletId);
for (Object _servlet : servlets) {
JSONObject servlet = (JSONObject)_servlet;
result.add(new Boot20DispatcherServletMapping(servlet));
.getJSONObject("mappings");
JSONArray rmArray = null;
if (mappings.has("dispatcherServlets")) {
// Regular Web starter endpoints RMs JMX beans format
rmArray = mappings.getJSONObject("dispatcherServlets").getJSONArray("dispatcherServlet");
} else if (mappings.has("dispatcherHandlers")) {
// WebFlux endpoints RMs JMX bean format
rmArray = mappings.getJSONObject("dispatcherHandlers").getJSONArray("webHandler");
}
if (rmArray != null) {
for (Object e : rmArray) {
JSONObject rm = (JSONObject)e;
result.add(new Boot20DispatcherServletMapping(rm));
}
}
}

View File

@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2018 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.commons.boot.app.cli;
import static org.junit.Assert.assertEquals;
import java.util.Collection;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.junit.Test;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMapping;
import org.springframework.ide.vscode.commons.boot.app.cli.requestmappings.RequestMappingsParser20;
public class Boot2xRequestMappingsTest {
@Test
public void testWebRms() throws Exception {
String json = IOUtils.toString(Boot2xRequestMappingsTest.class.getResourceAsStream("/live-rm-beans/rms-boot2-web.json"));
Collection<RequestMapping> rms = RequestMappingsParser20.parse(new JSONObject(json));
assertEquals(10, rms.size());
}
@Test
public void testWebFluxAnnotationRms() throws Exception {
String json = IOUtils.toString(Boot2xRequestMappingsTest.class.getResourceAsStream("/live-rm-beans/rms-boot2-webflux.json"));
Collection<RequestMapping> rms = RequestMappingsParser20.parse(new JSONObject(json));
assertEquals(7, rms.size());
}
}