diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/Menu.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/Menu.java deleted file mode 100644 index 0ea64a5557..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/Menu.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Menu - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface Menu { - - String name(); - - String desc() default ""; - - int order() default 0; - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/MenuComparator.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/MenuComparator.java deleted file mode 100644 index 57b0330f61..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/MenuComparator.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page; - -import java.io.Serializable; -import java.util.Comparator; - -/** - * MenuComparator - */ -public class MenuComparator implements Comparator, Serializable { - - private static final long serialVersionUID = -3161526932904414029L; - - public int compare(PageHandler o1, PageHandler o2) { - if (o1 == null && o2 == null) { - return 0; - } - if (o1 == null) { - return -1; - } - if (o2 == null) { - return 1; - } - return o1.equals(o2) ? 0 : (o1.getClass().getAnnotation(Menu.class).order() - > o2.getClass().getAnnotation(Menu.class).order() ? 1 : -1); - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/Page.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/Page.java deleted file mode 100644 index 748fe7f886..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/Page.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -/** - * Page - */ -public class Page { - - private final String navigation; - - private final String title; - - private final List columns; - - private final List> rows; - - public Page(String navigation) { - this(navigation, (String) null, (String[]) null, (List>) null); - } - - public Page(String navigation, String title, - String column, String row) { - this(navigation, title, column == null ? null : Arrays.asList(new String[]{column}), row == null ? null : stringToList(row)); - } - - public Page(String navigation, String title, - String[] columns, List> rows) { - this(navigation, title, columns == null ? null : Arrays.asList(columns), rows); - } - - public Page(String navigation, String title, - List columns, List> rows) { - this.navigation = navigation; - this.title = title; - this.columns = columns; - this.rows = rows; - } - - private static List> stringToList(String str) { - List> rows = new ArrayList>(); - List row = new ArrayList(); - row.add(str); - rows.add(row); - return rows; - } - - public String getNavigation() { - return navigation; - } - - public String getTitle() { - return title; - } - - public List getColumns() { - return columns; - } - - public List> getRows() { - return rows; - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/PageHandler.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/PageHandler.java deleted file mode 100644 index 36590b3177..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/PageHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.SPI; - -/** - * PageHandler - */ -@SPI -public interface PageHandler { - - /** - * Handle the page. - * - * @param url - * @return the page. - */ - Page handle(URL url); - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/PageServlet.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/PageServlet.java deleted file mode 100644 index 36ec09dddd..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/PageServlet.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page; - -import com.alibaba.dubbo.common.Constants; -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.ExtensionLoader; -import com.alibaba.dubbo.common.logger.Logger; -import com.alibaba.dubbo.common.logger.LoggerFactory; -import com.alibaba.dubbo.common.utils.StringUtils; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.ConcurrentHashMap; - -/** - * PageServlet - */ -public class PageServlet extends HttpServlet { - - protected static final Logger logger = LoggerFactory.getLogger(PageServlet.class); - private static final long serialVersionUID = -8370312705453328501L; - private static PageServlet INSTANCE; - protected final Random random = new Random(); - protected final Map pages = new ConcurrentHashMap(); - protected final List menus = new ArrayList(); - - public static PageServlet getInstance() { - return INSTANCE; - } - - public List getMenus() { - return Collections.unmodifiableList(menus); - } - - @Override - public void init() throws ServletException { - super.init(); - INSTANCE = this; - String config = getServletConfig().getInitParameter("pages"); - Collection names; - if (config != null && config.length() > 0) { - names = Arrays.asList(Constants.COMMA_SPLIT_PATTERN.split(config)); - } else { - names = ExtensionLoader.getExtensionLoader(PageHandler.class).getSupportedExtensions(); - } - for (String name : names) { - PageHandler handler = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtension(name); - pages.put(ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler), handler); - Menu menu = handler.getClass().getAnnotation(Menu.class); - if (menu != null) { - menus.add(handler); - } - } - Collections.sort(menus, new MenuComparator()); - } - - @Override - protected final void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - doPost(request, response); - } - - @Override - protected final void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException { - if (!response.isCommitted()) { - PrintWriter writer = response.getWriter(); - String uri = request.getRequestURI(); - boolean isHtml = false; - if (uri == null || uri.length() == 0 || "/".equals(uri)) { - uri = "index"; - isHtml = true; - } else { - if (uri.startsWith("/")) { - uri = uri.substring(1); - } - if (uri.endsWith(".html")) { - uri = uri.substring(0, uri.length() - ".html".length()); - isHtml = true; - } - } - if (uri.endsWith("favicon.ico")) { - response.sendError(HttpServletResponse.SC_NOT_FOUND); - return; - } - ExtensionLoader pageHandlerLoader = ExtensionLoader.getExtensionLoader(PageHandler.class); - PageHandler pageHandler = pageHandlerLoader.hasExtension(uri) ? pageHandlerLoader.getExtension(uri) : null; - if (isHtml) { - writer.println("Dubbo"); - writer.println(""); - writer.println(""); - } - if (pageHandler != null) { - Page page = null; - try { - String query = request.getQueryString(); - page = pageHandler.handle(URL.valueOf(request.getRequestURL().toString() - + (query == null || query.length() == 0 ? "" : "?" + query))); - } catch (Throwable t) { - logger.warn(t.getMessage(), t); - String msg = t.getMessage(); - if (msg == null) { - msg = StringUtils.toString(t); - } - if (isHtml) { - writer.println(""); - writer.println(""); - writer.println(" "); - writer.println(" "); - writer.println(" "); - writer.println(""); - writer.println(""); - writer.println(" "); - writer.println(" "); - writer.println(" "); - writer.println(""); - writer.println("
Error
"); - writer.println(" " + msg.replace("<", "<").replace(">", "<").replace("\n", "
")); - writer.println("
"); - writer.println("
"); - } else { - writer.println(msg); - } - } - if (page != null) { - if (isHtml) { - String nav = page.getNavigation(); - if (nav == null || nav.length() == 0) { - nav = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(pageHandler); - nav = nav.substring(0, 1).toUpperCase() + nav.substring(1); - } - if (!"index".equals(uri)) { - nav = "Home > " + nav; - } - writeMenu(request, writer, nav); - writeTable(writer, page.getTitle(), page.getColumns(), - page.getRows()); - } else { - if (page.getRows().size() > 0 && page.getRows().get(0).size() > 0) { - writer.println(page.getRows().get(0).get(0)); - } - } - } - } else { - if (isHtml) { - writer.println(""); - writer.println(""); - writer.println(" "); - writer.println(" "); - writer.println(" "); - writer.println(""); - writer.println(""); - writer.println(" "); - writer.println(" "); - writer.println(" "); - writer.println(""); - writer.println("
Error
"); - writer.println(" Not found " + uri + " page. Please goto Home page."); - writer.println("
"); - writer.println("
"); - } else { - writer.println("Not found " + uri + " page."); - } - } - if (isHtml) { - writer.println(""); - } - writer.flush(); - } - } - - protected final void writeMenu(HttpServletRequest request, PrintWriter writer, String nav) { - writer.println(""); - writer.println(""); - writer.println(" "); - for (PageHandler handler : menus) { - String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler); - Menu menu = handler.getClass().getAnnotation(Menu.class); - writer.println(" "); - } - writer.println(" "); - writer.println(""); - writer.println(""); - writer.println(" "); - writer.println(" "); - writer.println(" "); - writer.println(""); - writer.println("
" + menu.name() + "
"); - writer.println(nav); - writer.println("
"); - writer.println("
"); - } - - protected final void writeTable(PrintWriter writer, String title, List columns, - List> rows) { - int n = random.nextInt(); - int c = (columns == null ? (rows == null || rows.size() == 0 ? 0 : rows.get(0).size()) - : columns.size()); - int r = (rows == null ? 0 : rows.size()); - writer.println(""); - writer.println(""); - writer.println(" "); - writer.println(" "); - writer.println(" "); - if (columns != null && columns.size() > 0) { - writer.println(" "); - for (int i = 0; i < columns.size(); i++) { - String col = columns.get(i); - if (col.endsWith(":")) { - col += " 0 && (tv.length < iv.length || tv.indexOf(iv) == -1)) { m = false; break; } } } document.getElementById('tr_" - + n - + "_' + i).style.display = (m ? '' : 'none');}\" sytle=\"width: 100%\" />"; - } - writer.println(" "); - } - writer.println(" "); - } - writer.println(""); - if (rows != null && rows.size() > 0) { - writer.println(""); - int i = 0; - for (Collection row : rows) { - writer.println(" "); - int j = 0; - for (String col : row) { - writer.println(" "); - j++; - } - writer.println(" "); - i++; - } - writer.println(""); - } - writer.println("
" + title + "
" + col + "
" + col + "
"); - writer.println("
"); - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/ResourceFilter.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/ResourceFilter.java deleted file mode 100644 index eefdafaa79..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/ResourceFilter.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page; - -import com.alibaba.dubbo.common.Constants; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; - -/** - * ResourceServlet - */ -public class ResourceFilter implements Filter { - - private static final String CLASSPATH_PREFIX = "classpath:"; - - private final long start = System.currentTimeMillis(); - - private final List resources = new ArrayList(); - - public void init(FilterConfig filterConfig) throws ServletException { - String config = filterConfig.getInitParameter("resources"); - if (config != null && config.length() > 0) { - String[] configs = Constants.COMMA_SPLIT_PATTERN.split(config); - for (String c : configs) { - if (c != null && c.length() > 0) { - c = c.replace('\\', '/'); - if (c.endsWith("/")) { - c = c.substring(0, c.length() - 1); - } - resources.add(c); - } - } - } - } - - public void destroy() { - } - - public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) - throws IOException, ServletException { - HttpServletRequest request = (HttpServletRequest) req; - HttpServletResponse response = (HttpServletResponse) res; - if (response.isCommitted()) { - return; - } - String uri = request.getRequestURI(); - String context = request.getContextPath(); - if (uri.endsWith("/favicon.ico")) { - uri = "/favicon.ico"; - } else if (context != null && !"/".equals(context)) { - uri = uri.substring(context.length()); - } - if (!uri.startsWith("/")) { - uri = "/" + uri; - } - long lastModified = getLastModified(uri); - long since = request.getDateHeader("If-Modified-Since"); - if (since >= lastModified) { - response.sendError(HttpServletResponse.SC_NOT_MODIFIED); - return; - } - byte[] data; - InputStream input = getInputStream(uri); - if (input == null) { - chain.doFilter(req, res); - return; - } - try { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - byte[] buffer = new byte[8192]; - int n = 0; - while (-1 != (n = input.read(buffer))) { - output.write(buffer, 0, n); - } - data = output.toByteArray(); - } finally { - input.close(); - } - response.setDateHeader("Last-Modified", lastModified); - OutputStream output = response.getOutputStream(); - output.write(data); - output.flush(); - } - - private boolean isFile(String path) { - return path.startsWith("/") || path.indexOf(":") <= 1; - } - - private long getLastModified(String uri) { - for (String resource : resources) { - if (resource != null && resource.length() > 0) { - String path = resource + uri; - if (isFile(path)) { - File file = new File(path); - if (file.exists()) { - return file.lastModified(); - } - } - } - } - return start; - } - - private InputStream getInputStream(String uri) { - for (String resource : resources) { - String path = resource + uri; - try { - if (isFile(path)) { - return new FileInputStream(path); - } else if (path.startsWith(CLASSPATH_PREFIX)) { - return Thread.currentThread().getContextClassLoader().getResourceAsStream(path.substring(CLASSPATH_PREFIX.length())); - } else { - return new URL(path).openStream(); - } - } catch (IOException e) { - } - } - return null; - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/HomePageHandler.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/HomePageHandler.java deleted file mode 100644 index ce3e22782f..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/HomePageHandler.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page.pages; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.ExtensionLoader; -import com.alibaba.dubbo.container.page.Menu; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; -import com.alibaba.dubbo.container.page.PageServlet; - -import java.util.ArrayList; -import java.util.List; - -/** - * HomePageHandler - */ -@Menu(name = "Home", desc = "Home page.", order = Integer.MIN_VALUE) -public class HomePageHandler implements PageHandler { - - public Page handle(URL url) { - List> rows = new ArrayList>(); - for (PageHandler handler : PageServlet.getInstance().getMenus()) { - String uri = ExtensionLoader.getExtensionLoader(PageHandler.class).getExtensionName(handler); - Menu menu = handler.getClass().getAnnotation(Menu.class); - List row = new ArrayList(); - row.add("" + menu.name() + ""); - row.add(menu.desc()); - rows.add(row); - } - return new Page("Home", "Menus", new String[]{"Menu Name", "Menu Desc"}, rows); - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/LogPageHandler.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/LogPageHandler.java deleted file mode 100644 index 5c7fecb8d7..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/LogPageHandler.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page.pages; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.container.page.Menu; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; - -import org.apache.log4j.Appender; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; -import org.apache.log4j.LogManager; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.Enumeration; -import java.util.List; - -/** - * LogPageHandler - */ -@Menu(name = "Log", desc = "Show system log.", order = Integer.MAX_VALUE - 11000) -public class LogPageHandler implements PageHandler { - - private static final int SHOW_LOG_LENGTH = 30000; - - private File file; - - @SuppressWarnings("unchecked") - public LogPageHandler() { - try { - org.apache.log4j.Logger logger = LogManager.getRootLogger(); - if (logger != null) { - Enumeration appenders = logger.getAllAppenders(); - if (appenders != null) { - while (appenders.hasMoreElements()) { - Appender appender = appenders.nextElement(); - if (appender instanceof FileAppender) { - FileAppender fileAppender = (FileAppender) appender; - String filename = fileAppender.getFile(); - file = new File(filename); - break; - } - } - } - } - } catch (Throwable t) { - } - } - - public Page handle(URL url) { - long size = 0; - String content = ""; - String modified = "Not exist"; - if (file != null && file.exists()) { - try { - FileInputStream fis = new FileInputStream(file); - FileChannel channel = fis.getChannel(); - size = channel.size(); - ByteBuffer bb; - if (size <= SHOW_LOG_LENGTH) { - bb = ByteBuffer.allocate((int) size); - channel.read(bb, 0); - } else { - int pos = (int) (size - SHOW_LOG_LENGTH); - bb = ByteBuffer.allocate(SHOW_LOG_LENGTH); - channel.read(bb, pos); - } - bb.flip(); - content = new String(bb.array()).replace("<", "<") - .replace(">", ">").replace("\n", "

"); - modified = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") - .format(new Date(file.lastModified())); - } catch (IOException e) { - } - } - Level level = LogManager.getRootLogger().getLevel(); - List> rows = new ArrayList>(); - List row = new ArrayList(); - row.add(content); - rows.add(row); - return new Page("Log", "Log", new String[]{(file == null ? "" : file.getName()) + ", " + size + " bytes, " + modified + ", " + level}, rows); - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/StatusPageHandler.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/StatusPageHandler.java deleted file mode 100644 index d3c4246092..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/StatusPageHandler.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page.pages; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.extension.ExtensionLoader; -import com.alibaba.dubbo.common.status.Status; -import com.alibaba.dubbo.common.status.StatusChecker; -import com.alibaba.dubbo.common.status.support.StatusUtils; -import com.alibaba.dubbo.container.page.Menu; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * StatusPageHandler - */ -@Menu(name = "Status", desc = "Show system status.", order = Integer.MAX_VALUE - 12000) -public class StatusPageHandler implements PageHandler { - - public Page handle(URL url) { - List> rows = new ArrayList>(); - Set names = ExtensionLoader.getExtensionLoader(StatusChecker.class).getSupportedExtensions(); - Map statuses = new HashMap(); - for (String name : names) { - StatusChecker checker = ExtensionLoader.getExtensionLoader(StatusChecker.class).getExtension(name); - List row = new ArrayList(); - row.add(name); - Status status = checker.check(); - if (status != null && !Status.Level.UNKNOWN.equals(status.getLevel())) { - statuses.put(name, status); - row.add(getLevelHtml(status.getLevel())); - row.add(status.getMessage()); - rows.add(row); - } - } - Status status = StatusUtils.getSummaryStatus(statuses); - if ("status".equals(url.getPath())) { - return new Page("", "", "", status.getLevel().toString()); - } else { - List row = new ArrayList(); - row.add("summary"); - row.add(getLevelHtml(status.getLevel())); - row.add("summary"); - rows.add(row); - return new Page("Status (summary)", "Status", new String[]{"Name", "Status", "Description"}, rows); - } - } - - private String getLevelHtml(Status.Level level) { - return "" + level.name() + ""; - } - - private String getLevelColor(Status.Level level) { - if (level == Status.Level.OK) { - return "green"; - } else if (level == Status.Level.ERROR) { - return "red"; - } else if (level == Status.Level.WARN) { - return "yellow"; - } - return "gray"; - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java b/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java deleted file mode 100644 index 24c7baf3f0..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/java/com/alibaba/dubbo/container/page/pages/SystemPageHandler.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.page.pages; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.Version; -import com.alibaba.dubbo.common.utils.NetUtils; -import com.alibaba.dubbo.container.page.Menu; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; - -import java.lang.management.ManagementFactory; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Locale; - -/** - * SystemPageHandler - */ -@Menu(name = "System", desc = "Show system environment information.", order = Integer.MAX_VALUE - 10000) -public class SystemPageHandler implements PageHandler { - - private static final long SECOND = 1000; - private static final long MINUTE = 60 * SECOND; - private static final long HOUR = 60 * MINUTE; - private static final long DAY = 24 * HOUR; - - public Page handle(URL url) { - List> rows = new ArrayList>(); - List row; - - row = new ArrayList(); - row.add("Version"); - row.add(Version.getVersion(SystemPageHandler.class, "2.0.0")); - rows.add(row); - - row = new ArrayList(); - row.add("Host"); - String address = NetUtils.getLocalHost(); - row.add(NetUtils.getHostName(address) + "/" + address); - rows.add(row); - - row = new ArrayList(); - row.add("OS"); - row.add(System.getProperty("os.name") + " " + System.getProperty("os.version")); - rows.add(row); - - row = new ArrayList(); - row.add("JVM"); - row.add(System.getProperty("java.runtime.name") + " " + System.getProperty("java.runtime.version") + ",
" + System.getProperty("java.vm.name") + " " + System.getProperty("java.vm.version") + " " + System.getProperty("java.vm.info", "")); - rows.add(row); - - row = new ArrayList(); - row.add("CPU"); - row.add(System.getProperty("os.arch", "") + ", " + String.valueOf(Runtime.getRuntime().availableProcessors()) + " cores"); - rows.add(row); - - row = new ArrayList(); - row.add("Locale"); - row.add(Locale.getDefault().toString() + "/" + System.getProperty("file.encoding")); - rows.add(row); - - row = new ArrayList(); - row.add("Uptime"); - row.add(formatUptime(ManagementFactory.getRuntimeMXBean().getUptime())); - rows.add(row); - - row = new ArrayList(); - row.add("Time"); - row.add(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS Z").format(new Date())); - rows.add(row); - - return new Page("System", "System", new String[]{ - "Property", "Value"}, rows); - } - - private String formatUptime(long uptime) { - StringBuilder buf = new StringBuilder(); - if (uptime > DAY) { - long days = (uptime - uptime % DAY) / DAY; - buf.append(days); - buf.append(" Days"); - uptime = uptime % DAY; - } - if (uptime > HOUR) { - long hours = (uptime - uptime % HOUR) / HOUR; - if (buf.length() > 0) { - buf.append(", "); - } - buf.append(hours); - buf.append(" Hours"); - uptime = uptime % HOUR; - } - if (uptime > MINUTE) { - long minutes = (uptime - uptime % MINUTE) / MINUTE; - if (buf.length() > 0) { - buf.append(", "); - } - buf.append(minutes); - buf.append(" Minutes"); - uptime = uptime % MINUTE; - } - if (uptime > SECOND) { - long seconds = (uptime - uptime % SECOND) / SECOND; - if (buf.length() > 0) { - buf.append(", "); - } - buf.append(seconds); - buf.append(" Seconds"); - uptime = uptime % SECOND; - } - if (uptime > 0) { - if (buf.length() > 0) { - buf.append(", "); - } - buf.append(uptime); - buf.append(" Milliseconds"); - } - return buf.toString(); - } -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-api/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler b/dubbo-container/dubbo-container-api/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler deleted file mode 100644 index e1c39d6ca8..0000000000 --- a/dubbo-container/dubbo-container-api/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler +++ /dev/null @@ -1,4 +0,0 @@ -index=com.alibaba.dubbo.container.page.pages.HomePageHandler -status=com.alibaba.dubbo.container.page.pages.StatusPageHandler -log=com.alibaba.dubbo.container.page.pages.LogPageHandler -system=com.alibaba.dubbo.container.page.pages.SystemPageHandler \ No newline at end of file diff --git a/dubbo-container/dubbo-container-jetty/pom.xml b/dubbo-container/dubbo-container-jetty/pom.xml deleted file mode 100644 index 0743f2cde5..0000000000 --- a/dubbo-container/dubbo-container-jetty/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - 4.0.0 - - com.alibaba - dubbo-container - 2.6.0 - - dubbo-container-jetty - jar - ${project.artifactId} - The jetty container module of dubbo project - - true - - - - com.alibaba - dubbo-container-api - ${project.parent.version} - - - \ No newline at end of file diff --git a/dubbo-container/dubbo-container-jetty/src/main/java/com/alibaba/dubbo/container/jetty/JettyContainer.java b/dubbo-container/dubbo-container-jetty/src/main/java/com/alibaba/dubbo/container/jetty/JettyContainer.java deleted file mode 100644 index 7f0563f5c3..0000000000 --- a/dubbo-container/dubbo-container-jetty/src/main/java/com/alibaba/dubbo/container/jetty/JettyContainer.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.jetty; - -import com.alibaba.dubbo.common.logger.Logger; -import com.alibaba.dubbo.common.logger.LoggerFactory; -import com.alibaba.dubbo.common.utils.ConfigUtils; -import com.alibaba.dubbo.common.utils.NetUtils; -import com.alibaba.dubbo.container.Container; -import com.alibaba.dubbo.container.page.PageServlet; -import com.alibaba.dubbo.container.page.ResourceFilter; - -import org.mortbay.jetty.Handler; -import org.mortbay.jetty.Server; -import org.mortbay.jetty.nio.SelectChannelConnector; -import org.mortbay.jetty.servlet.FilterHolder; -import org.mortbay.jetty.servlet.ServletHandler; -import org.mortbay.jetty.servlet.ServletHolder; - -/** - * JettyContainer. (SPI, Singleton, ThreadSafe) - */ -public class JettyContainer implements Container { - - public static final String JETTY_PORT = "dubbo.jetty.port"; - public static final String JETTY_DIRECTORY = "dubbo.jetty.directory"; - public static final String JETTY_PAGES = "dubbo.jetty.page"; - public static final int DEFAULT_JETTY_PORT = 8080; - private static final Logger logger = LoggerFactory.getLogger(JettyContainer.class); - SelectChannelConnector connector; - - public void start() { - String serverPort = ConfigUtils.getProperty(JETTY_PORT); - int port; - if (serverPort == null || serverPort.length() == 0) { - port = DEFAULT_JETTY_PORT; - } else { - port = Integer.parseInt(serverPort); - } - connector = new SelectChannelConnector(); - connector.setPort(port); - ServletHandler handler = new ServletHandler(); - - String resources = ConfigUtils.getProperty(JETTY_DIRECTORY); - if (resources != null && resources.length() > 0) { - FilterHolder resourceHolder = handler.addFilterWithMapping(ResourceFilter.class, "/*", Handler.DEFAULT); - resourceHolder.setInitParameter("resources", resources); - } - - ServletHolder pageHolder = handler.addServletWithMapping(PageServlet.class, "/*"); - pageHolder.setInitParameter("pages", ConfigUtils.getProperty(JETTY_PAGES)); - pageHolder.setInitOrder(2); - - Server server = new Server(); - server.addConnector(connector); - server.addHandler(handler); - try { - server.start(); - } catch (Exception e) { - throw new IllegalStateException("Failed to start jetty server on " + NetUtils.getLocalHost() + ":" + port + ", cause: " + e.getMessage(), e); - } - } - - public void stop() { - try { - if (connector != null) { - connector.close(); - connector = null; - } - } catch (Throwable e) { - logger.error(e.getMessage(), e); - } - } - -} \ No newline at end of file diff --git a/dubbo-container/dubbo-container-jetty/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.Container b/dubbo-container/dubbo-container-jetty/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.Container deleted file mode 100644 index 880fcc8754..0000000000 --- a/dubbo-container/dubbo-container-jetty/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.Container +++ /dev/null @@ -1 +0,0 @@ -jetty=com.alibaba.dubbo.container.jetty.JettyContainer \ No newline at end of file diff --git a/dubbo-container/dubbo-container-jetty/src/test/java/com/alibaba/dubbo/container/jetty/JettyContainerTest.java b/dubbo-container/dubbo-container-jetty/src/test/java/com/alibaba/dubbo/container/jetty/JettyContainerTest.java deleted file mode 100644 index 957cb50244..0000000000 --- a/dubbo-container/dubbo-container-jetty/src/test/java/com/alibaba/dubbo/container/jetty/JettyContainerTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.container.jetty; - -import com.alibaba.dubbo.common.extension.ExtensionLoader; -import com.alibaba.dubbo.container.Container; - -import org.junit.Assert; -import org.junit.Test; - -/** - * StandaloneContainerTest - */ -public class JettyContainerTest { - - @Test - public void testContainer() { - JettyContainer container = (JettyContainer) ExtensionLoader.getExtensionLoader(Container.class).getExtension("jetty"); - container.start(); - Assert.assertTrue(container.connector.isStarted()); - container.stop(); - } - -} \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegisteredPageHandler.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegisteredPageHandler.java deleted file mode 100644 index 19a08c0bf0..0000000000 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegisteredPageHandler.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.registry.pages; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; -import com.alibaba.dubbo.registry.Registry; -import com.alibaba.dubbo.registry.support.AbstractRegistry; -import com.alibaba.dubbo.registry.support.AbstractRegistryFactory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -/** - * RegisteredPageHandler - * - */ -public class RegisteredPageHandler implements PageHandler { - - public Page handle(URL url) { - String registryAddress = url.getParameter("registry", ""); - List> rows = new ArrayList>(); - Collection registries = AbstractRegistryFactory.getRegistries(); - StringBuilder select = new StringBuilder(); - Registry registry = null; - if (registries != null && registries.size() > 0) { - if (registries.size() == 1) { - registry = registries.iterator().next(); - select.append(" > " + registry.getUrl().getAddress()); - } else { - select.append(" > "); - } - } - if (registry instanceof AbstractRegistry) { - Set services = ((AbstractRegistry) registry).getRegistered(); - if (services != null && services.size() > 0) { - for (URL u : services) { - List row = new ArrayList(); - row.add(u.toFullString().replace("<", "<").replace(">", ">")); - rows.add(row); - } - } - } - return new Page("Registries" + select.toString() + " > Registered | Subscribed", "Registered (" + rows.size() + ")", - new String[]{"Provider URL:"}, rows); - } - -} \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegistriesPageHandler.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegistriesPageHandler.java deleted file mode 100644 index 8f1a88d6dd..0000000000 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/RegistriesPageHandler.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.registry.pages; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.utils.NetUtils; -import com.alibaba.dubbo.container.page.Menu; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; -import com.alibaba.dubbo.registry.Registry; -import com.alibaba.dubbo.registry.support.AbstractRegistry; -import com.alibaba.dubbo.registry.support.AbstractRegistryFactory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * RegistriesPageHandler - * - */ -@Menu(name = "Registries", desc = "Show connected registries.", order = 10000) -public class RegistriesPageHandler implements PageHandler { - - public Page handle(URL url) { - List> rows = new ArrayList>(); - Collection registries = AbstractRegistryFactory.getRegistries(); - int registeredCount = 0; - int subscribedCount = 0; - if (registries != null && registries.size() > 0) { - for (Registry registry : registries) { - String server = registry.getUrl().getAddress(); - List row = new ArrayList(); - row.add(NetUtils.getHostName(server) + "/" + server); - if (registry.isAvailable()) { - row.add("Connected"); - } else { - row.add("Disconnected"); - } - int registeredSize = 0; - int subscribedSize = 0; - if (registry instanceof AbstractRegistry) { - registeredSize = ((AbstractRegistry) registry).getRegistered().size(); - registeredCount += registeredSize; - subscribedSize = ((AbstractRegistry) registry).getSubscribed().size(); - subscribedCount += subscribedSize; - } - row.add("Registered(" + registeredSize + ")"); - row.add("Subscribed(" + subscribedSize + ")"); - rows.add(row); - } - } - return new Page("Registries", "Registries (" + rows.size() + ")", - new String[]{"Registry Address:", "Status", "Registered(" + registeredCount + ")", "Subscribed(" + subscribedCount + ")"}, rows); - } - -} \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/SubscribedPageHandler.java b/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/SubscribedPageHandler.java deleted file mode 100644 index b048eb90f8..0000000000 --- a/dubbo-registry/dubbo-registry-api/src/main/java/com/alibaba/dubbo/registry/pages/SubscribedPageHandler.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.registry.pages; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; -import com.alibaba.dubbo.registry.Registry; -import com.alibaba.dubbo.registry.support.AbstractRegistry; -import com.alibaba.dubbo.registry.support.AbstractRegistryFactory; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; - -/** - * SubscribedPageHandler - * - */ -public class SubscribedPageHandler implements PageHandler { - - public Page handle(URL url) { - String registryAddress = url.getParameter("registry", ""); - List> rows = new ArrayList>(); - Collection registries = AbstractRegistryFactory.getRegistries(); - StringBuilder select = new StringBuilder(); - Registry registry = null; - if (registries != null && registries.size() > 0) { - if (registries.size() == 1) { - registry = registries.iterator().next(); - select.append(" > " + registry.getUrl().getAddress()); - } else { - select.append(" > "); - } - } - if (registry instanceof AbstractRegistry) { - Set services = ((AbstractRegistry) registry).getSubscribed().keySet(); - if (services != null && services.size() > 0) { - for (URL u : services) { - List row = new ArrayList(); - row.add(u.toFullString().replace("<", "<").replace(">", ">")); - rows.add(row); - } - } - } - return new Page("Registries" + select.toString() + " > Registered | Subscribed", "Subscribed (" + rows.size() + ")", - new String[]{"Consumer URL:"}, rows); - } - -} \ No newline at end of file diff --git a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler b/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler deleted file mode 100644 index 8e75ea0504..0000000000 --- a/dubbo-registry/dubbo-registry-api/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler +++ /dev/null @@ -1,3 +0,0 @@ -registries=com.alibaba.dubbo.registry.pages.RegistriesPageHandler -registered=com.alibaba.dubbo.registry.pages.RegisteredPageHandler -subscribed=com.alibaba.dubbo.registry.pages.SubscribedPageHandler \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-default/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/page/ClientsPageHandler.java b/dubbo-rpc/dubbo-rpc-default/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/page/ClientsPageHandler.java deleted file mode 100644 index a841e0d2d6..0000000000 --- a/dubbo-rpc/dubbo-rpc-default/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/page/ClientsPageHandler.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.rpc.protocol.dubbo.page; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.utils.NetUtils; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; -import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; -import com.alibaba.dubbo.remoting.exchange.ExchangeServer; -import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * ClientsPageHandler - */ -public class ClientsPageHandler implements PageHandler { - - public Page handle(URL url) { - String port = url.getParameter("port"); - int p = port == null || port.length() == 0 ? 0 : Integer.parseInt(port); - Collection servers = DubboProtocol.getDubboProtocol().getServers(); - ExchangeServer server = null; - StringBuilder select = new StringBuilder(); - if (servers != null && servers.size() > 0) { - if (servers.size() == 1) { - server = servers.iterator().next(); - String address = server.getUrl().getAddress(); - select.append(" > " + NetUtils.getHostName(address) + "/" + address); - } else { - select.append(" > "); - } - } - List> rows = new ArrayList>(); - if (server != null) { - Collection channels = server.getExchangeChannels(); - for (ExchangeChannel c : channels) { - List row = new ArrayList(); - String address = NetUtils.toAddressString(c.getRemoteAddress()); - row.add(NetUtils.getHostName(address) + "/" + address); - rows.add(row); - } - } - return new Page("Servers" + select.toString() + " > Clients", "Clients (" + rows.size() + ")", new String[]{"Client Address:"}, rows); - } - -} \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-default/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/page/ServersPageHandler.java b/dubbo-rpc/dubbo-rpc-default/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/page/ServersPageHandler.java deleted file mode 100644 index b6e1c32157..0000000000 --- a/dubbo-rpc/dubbo-rpc-default/src/main/java/com/alibaba/dubbo/rpc/protocol/dubbo/page/ServersPageHandler.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.alibaba.dubbo.rpc.protocol.dubbo.page; - -import com.alibaba.dubbo.common.URL; -import com.alibaba.dubbo.common.utils.NetUtils; -import com.alibaba.dubbo.container.page.Menu; -import com.alibaba.dubbo.container.page.Page; -import com.alibaba.dubbo.container.page.PageHandler; -import com.alibaba.dubbo.remoting.exchange.ExchangeServer; -import com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -/** - * ServersPageHandler - */ -@Menu(name = "Servers", desc = "Show exported service servers.", order = 14000) -public class ServersPageHandler implements PageHandler { - - public Page handle(URL url) { - List> rows = new ArrayList>(); - Collection servers = DubboProtocol.getDubboProtocol().getServers(); - int clientCount = 0; - if (servers != null && servers.size() > 0) { - for (ExchangeServer s : servers) { - List row = new ArrayList(); - String address = s.getUrl().getAddress(); - row.add(NetUtils.getHostName(address) + "/" + address); - int clientSize = s.getExchangeChannels().size(); - clientCount += clientSize; - row.add("Clients(" + clientSize + ")"); - rows.add(row); - } - } - return new Page("Servers", "Servers (" + rows.size() + ")", new String[]{"Server Address:", "Clients(" + clientCount + ")"}, rows); - } - -} \ No newline at end of file diff --git a/dubbo-rpc/dubbo-rpc-default/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler b/dubbo-rpc/dubbo-rpc-default/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler deleted file mode 100644 index 63122b4182..0000000000 --- a/dubbo-rpc/dubbo-rpc-default/src/main/resources/META-INF/dubbo/internal/com.alibaba.dubbo.container.page.PageHandler +++ /dev/null @@ -1,2 +0,0 @@ -servers=com.alibaba.dubbo.rpc.protocol.dubbo.page.ServersPageHandler -clients=com.alibaba.dubbo.rpc.protocol.dubbo.page.ClientsPageHandler \ No newline at end of file