@@ -540,9 +540,9 @@ private void buildJEEServiceComponents(MonitorDataFrame mdf, Map<String, Object> |
540 | 540 | // get spring mvc urls |
541 | 541 | String springmvcBaseURL = getBaseURL(serviceServlets, "springmvc"); |
542 | 542 |
|
543 | | - getSpringMVCURLs(springmvcBaseURL, compServices, springMVC); |
| 543 | + getSpringMVCURLs(appurl, springmvcBaseURL, compServices, springMVC); |
544 | 544 |
|
545 | | - getSpringMVCURLs(springmvcBaseURL, compServices, springMVCRest); |
| 545 | + getSpringMVCURLs(appurl, springmvcBaseURL, compServices, springMVCRest); |
546 | 546 |
|
547 | 547 | // get struts2 urls |
548 | 548 | Map<String, Object> strutsAction = mdf.getElemInstValues(appid, "cpt", "com.opensymphony.xwork2.Action"); |
@@ -846,28 +846,41 @@ private void getJAXWSProviderURLs(String jaxwsBaseUrl, Map<String, Set<String>> |
846 | 846 | * @param spring |
847 | 847 | */ |
848 | 848 | @SuppressWarnings("unchecked") |
849 | | - private void getSpringMVCURLs(String springMVCBaseUrl, Map<String, Set<String>> compServices, |
| 849 | + private void getSpringMVCURLs(String appurl, String springMVCBaseUrl, Map<String, Set<String>> compServices, |
850 | 850 | Map<String, Object> spring) { |
851 | 851 |
|
852 | | - String realSpringMVCBaseUrl = null; |
853 | | - String suffix = ""; |
854 | | - if (springMVCBaseUrl != null) { |
| 852 | + Set<String> realSpringMVCBaseUrls = new HashSet<>(); |
| 853 | + Set<String> servletPaths = new HashSet<>(); |
855 | 854 |
|
856 | | - // NOTE: handle *.xxx,should remove *.xxx |
857 | | - realSpringMVCBaseUrl = springMVCBaseUrl; |
| 855 | + if (StringHelper.isEmpty(springMVCBaseUrl) || springMVCBaseUrl.length() < appurl.length()) { |
| 856 | + return; |
| 857 | + } |
| 858 | + |
| 859 | + String[] springMVCBaseUrls = springMVCBaseUrl.split(","); |
| 860 | + |
| 861 | + for (String url : springMVCBaseUrls) { |
| 862 | + |
| 863 | + // shouldn't happened |
| 864 | + if (url.length() < appurl.length()) { |
| 865 | + continue; |
| 866 | + } |
858 | 867 |
|
859 | | - int allIndex = realSpringMVCBaseUrl.indexOf("*"); |
| 868 | + String servletPath = url.substring(appurl.length()); |
860 | 869 |
|
| 870 | + int allIndex = servletPath.indexOf("*"); |
861 | 871 | if (allIndex > -1) { |
862 | 872 |
|
863 | 873 | // check if there is suffix, such as *.do |
864 | | - if (allIndex != realSpringMVCBaseUrl.length() - 1) { |
865 | | - suffix = realSpringMVCBaseUrl.substring(allIndex + 1, realSpringMVCBaseUrl.length() - 1); |
866 | | - } |
| 874 | + int indexOfDot = servletPath.indexOf(".", allIndex); |
| 875 | + if (indexOfDot > -1) { |
867 | 876 |
|
| 877 | + servletPath = servletPath.substring(indexOfDot, servletPath.length() - 1); |
| 878 | + } |
868 | 879 | // get the real access path |
869 | | - realSpringMVCBaseUrl = realSpringMVCBaseUrl.substring(0, allIndex); |
| 880 | + url = url.substring(0, appurl.length() + allIndex); |
870 | 881 | } |
| 882 | + servletPaths.add(servletPath); |
| 883 | + realSpringMVCBaseUrls.add(url); |
871 | 884 | } |
872 | 885 |
|
873 | 886 | for (String compId : spring.keySet()) { |
@@ -916,99 +929,100 @@ private void getSpringMVCURLs(String springMVCBaseUrl, Map<String, Set<String>> |
916 | 929 | resourceClassRelativePaths.add(""); |
917 | 930 | } |
918 | 931 |
|
919 | | - for (String resourceClassRelativePath : resourceClassRelativePaths) { |
920 | | - |
921 | | - resourceClassRelativePath = formatRelativePath(resourceClassRelativePath); |
| 932 | + // get the resource class path |
| 933 | + for (String realSpringMVCBaseUrl : realSpringMVCBaseUrls) { |
922 | 934 |
|
923 | | - // get the resource class path |
924 | | - String resourceClassPath = realSpringMVCBaseUrl + resourceClassRelativePath; |
| 935 | + for (String resourceClassRelativePath : resourceClassRelativePaths) { |
| 936 | + resourceClassRelativePath = formatRelativePath(resourceClassRelativePath); |
| 937 | + String resourceClassPath = realSpringMVCBaseUrl + resourceClassRelativePath; |
925 | 938 |
|
926 | | - // get methods path |
927 | | - Map<String, Object> compMethodInfo = (Map<String, Object>) compInfo.get("methods"); |
| 939 | + // get methods path |
| 940 | + Map<String, Object> compMethodInfo = (Map<String, Object>) compInfo.get("methods"); |
928 | 941 |
|
929 | | - for (String method : compMethodInfo.keySet()) { |
| 942 | + for (String method : compMethodInfo.keySet()) { |
930 | 943 |
|
931 | | - Map<String, Object> methodInfo = (Map<String, Object>) compMethodInfo.get(method); |
| 944 | + Map<String, Object> methodInfo = (Map<String, Object>) compMethodInfo.get(method); |
932 | 945 |
|
933 | | - if (!methodInfo.containsKey("anno")) { |
934 | | - continue; |
935 | | - } |
936 | | - |
937 | | - Map<String, Object> methodAnnoInfo = (Map<String, Object>) methodInfo.get("anno"); |
938 | | - |
939 | | - String serviceURL = formatRelativePath(resourceClassPath); |
940 | | - |
941 | | - /** |
942 | | - * each method has Path info except only one |
943 | | - */ |
944 | | - if (methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.RequestMapping") |
945 | | - || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.PostMapping") |
946 | | - || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.GetMapping") |
947 | | - || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.PutMapping") |
948 | | - || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.DeleteMapping") |
949 | | - || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.PatchMapping")) { |
950 | | - |
951 | | - Map<String, Object> pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
952 | | - .get("org.springframework.web.bind.annotation.RequestMapping"); |
953 | | - |
954 | | - if (pathAnnoInfo == null) { |
955 | | - pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
956 | | - .get("org.springframework.web.bind.annotation.PostMapping"); |
957 | | - } |
958 | | - if (pathAnnoInfo == null) { |
959 | | - pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
960 | | - .get("org.springframework.web.bind.annotation.GetMapping"); |
961 | | - } |
962 | | - if (pathAnnoInfo == null) { |
963 | | - pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
964 | | - .get("org.springframework.web.bind.annotation.PutMapping"); |
965 | | - } |
966 | | - if (pathAnnoInfo == null) { |
967 | | - pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
968 | | - .get("org.springframework.web.bind.annotation.DeleteMapping"); |
969 | | - } |
970 | | - if (pathAnnoInfo == null) { |
971 | | - pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
972 | | - .get("org.springframework.web.bind.annotation.PatchMapping"); |
| 946 | + if (!methodInfo.containsKey("anno")) { |
| 947 | + continue; |
973 | 948 | } |
974 | 949 |
|
975 | | - List<String> methodRelativePaths = (List<String>) pathAnnoInfo.get("value"); |
| 950 | + Map<String, Object> methodAnnoInfo = (Map<String, Object>) methodInfo.get("anno"); |
| 951 | + |
| 952 | + String serviceURL = formatRelativePath(resourceClassPath); |
| 953 | + |
| 954 | + /** |
| 955 | + * each method has Path info except only one |
| 956 | + */ |
| 957 | + if (methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.RequestMapping") |
| 958 | + || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.PostMapping") |
| 959 | + || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.GetMapping") |
| 960 | + || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.PutMapping") |
| 961 | + || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.DeleteMapping") |
| 962 | + || methodAnnoInfo.containsKey("org.springframework.web.bind.annotation.PatchMapping")) { |
| 963 | + |
| 964 | + Map<String, Object> pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
| 965 | + .get("org.springframework.web.bind.annotation.RequestMapping"); |
| 966 | + if (pathAnnoInfo == null) { |
| 967 | + pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
| 968 | + .get("org.springframework.web.bind.annotation.PostMapping"); |
| 969 | + } |
| 970 | + if (pathAnnoInfo == null) { |
| 971 | + pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
| 972 | + .get("org.springframework.web.bind.annotation.GetMapping"); |
| 973 | + } |
| 974 | + if (pathAnnoInfo == null) { |
| 975 | + pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
| 976 | + .get("org.springframework.web.bind.annotation.PutMapping"); |
| 977 | + } |
| 978 | + if (pathAnnoInfo == null) { |
| 979 | + pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
| 980 | + .get("org.springframework.web.bind.annotation.DeleteMapping"); |
| 981 | + } |
| 982 | + if (pathAnnoInfo == null) { |
| 983 | + pathAnnoInfo = (Map<String, Object>) methodAnnoInfo |
| 984 | + .get("org.springframework.web.bind.annotation.PatchMapping"); |
| 985 | + } |
| 986 | + List<String> methodRelativePaths = (List<String>) pathAnnoInfo.get("value"); |
976 | 987 |
|
977 | | - // try to get info from filed 'path' |
978 | | - if (methodRelativePaths == null) { |
979 | | - methodRelativePaths = (List<String>) pathAnnoInfo.get("path"); |
980 | | - } |
| 988 | + // try to get info from filed 'path' |
| 989 | + if (methodRelativePaths == null) { |
| 990 | + methodRelativePaths = (List<String>) pathAnnoInfo.get("path"); |
| 991 | + } |
981 | 992 |
|
982 | | - // FIX NPE |
983 | | - if (methodRelativePaths == null) { |
984 | | - compServicesURLs.add(serviceURL); |
985 | | - continue; |
986 | | - } |
| 993 | + // FIX NPE |
| 994 | + if (methodRelativePaths == null) { |
| 995 | + compServicesURLs.add(serviceURL); |
| 996 | + continue; |
| 997 | + } |
987 | 998 |
|
988 | | - for (String methodRelativePath : methodRelativePaths) { |
| 999 | + for (String methodRelativePath : methodRelativePaths) { |
989 | 1000 |
|
990 | | - methodRelativePath = formatRelativePath(methodRelativePath); |
| 1001 | + methodRelativePath = formatRelativePath(methodRelativePath); |
991 | 1002 |
|
992 | | - String methodServiceURL; |
| 1003 | + String methodServiceURL = formatRelativePath(serviceURL + "/" + methodRelativePath); |
| 1004 | + if (methodRelativePath.indexOf(".") > -1 || servletPaths.isEmpty()) { |
| 1005 | + compServicesURLs.add(methodServiceURL); |
| 1006 | + continue; |
| 1007 | + } |
993 | 1008 |
|
994 | | - if (methodRelativePath.endsWith(suffix)) { |
| 1009 | + for (String servletPath : servletPaths) { |
| 1010 | + int indexOfDot = servletPath.indexOf("."); |
| 1011 | + if (indexOfDot > -1) { |
| 1012 | + compServicesURLs.add(methodServiceURL + servletPath.substring(indexOfDot)); |
| 1013 | + } |
| 1014 | + else if (realSpringMVCBaseUrl.endsWith("/" + servletPath)) { |
| 1015 | + compServicesURLs.add(methodServiceURL); |
| 1016 | + } |
| 1017 | + } |
995 | 1018 |
|
996 | | - methodServiceURL = formatRelativePath(serviceURL + "/" + methodRelativePath); |
997 | 1019 | } |
998 | | - else { |
999 | | - // endwith "#" means the suffix is added from springMVCBaseUrl,should be removed while on query |
1000 | | - methodServiceURL = formatRelativePath( |
1001 | | - serviceURL + "/" + methodRelativePath + suffix + "#"); |
1002 | | - } |
1003 | | - |
1004 | | - compServicesURLs.add(methodServiceURL); |
1005 | 1020 | } |
1006 | | - } |
1007 | | - else { |
1008 | | - compServicesURLs.add(serviceURL); |
| 1021 | + else { |
| 1022 | + compServicesURLs.add(serviceURL); |
| 1023 | + } |
1009 | 1024 | } |
1010 | 1025 | } |
1011 | | - |
1012 | 1026 | } |
1013 | 1027 | } |
1014 | 1028 | } |
@@ -1390,7 +1404,13 @@ else if (engine.indexOf("jersey") > -1) { |
1390 | 1404 | serviceServlets.put("jersey", serviceURL); |
1391 | 1405 | } |
1392 | 1406 | else if (engine.indexOf("springmvc") > -1) { |
1393 | | - serviceServlets.put("springmvc", serviceURL); |
| 1407 | + // 一个servlet mapping多个URL用逗号隔开. |
| 1408 | + if (StringHelper.isEmpty(serviceServlets.get("springmvc"))) { |
| 1409 | + serviceServlets.put("springmvc", serviceURL); |
| 1410 | + } |
| 1411 | + else { |
| 1412 | + serviceServlets.put("springmvc", serviceServlets.get("springmvc") + "/," + serviceURL); |
| 1413 | + } |
1394 | 1414 | } |
1395 | 1415 | else if (engine.indexOf("jaxws-ri") > -1) { |
1396 | 1416 | serviceServlets.put("jaxws-ri", serviceURL); |
|