From: Sasha Sherstnev Date: Mon, 30 Sep 2013 13:28:19 +0000 (+0100) Subject: test WS on internal server in the case of proxying X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ec9601b59af0d33fb562f3a580cce47bc61debd4;hp=a3c9dabc9438b34a939bd41b2bee97531724580d;p=jabaws.git test WS on internal server in the case of proxying --- diff --git a/statpages/ServicesStatus.jsp b/statpages/ServicesStatus.jsp index 67255a3..98d0ab6 100644 --- a/statpages/ServicesStatus.jsp +++ b/statpages/ServicesStatus.jsp @@ -20,11 +20,16 @@ TODO refactor
diff --git a/webservices/compbio/stat/servlet/ServiceStatus.java b/webservices/compbio/stat/servlet/ServiceStatus.java index a0f5516..93df9f5 100644 --- a/webservices/compbio/stat/servlet/ServiceStatus.java +++ b/webservices/compbio/stat/servlet/ServiceStatus.java @@ -1,22 +1,52 @@ +/* Copyright (c) 2013 Alexander Sherstnev + * Copyright (c) 2011 Peter Troshin + * + * JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0 + * + * This library is free software; you can redistribute it and/or modify it under the terms of the + * Apache License version 2 as published by the Apache Software Foundation + * + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without + * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache + * License for more details. + * + * A copy of the license is in apache_license.txt. It is also available here: + * @see: http://www.apache.org/licenses/LICENSE-2.0.txt + * + * Any republication or derived work distributed in source code form + * must include this copyright and license notice. + */ + package compbio.stat.servlet; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.management.ManagementFactory; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; +import java.util.Set; import java.util.Collections; +import javax.management.AttributeNotFoundException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanException; +import javax.management.MBeanServer; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.Query; +import javax.management.ReflectionException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.ServletContext; import org.apache.log4j.Logger; -import compbio.stat.servlet.util.Totals; import compbio.ws.client.Services; import compbio.ws.client.WSTester; @@ -29,66 +59,73 @@ import compbio.ws.client.WSTester; * @author pvtroshin * */ + public class ServiceStatus extends HttpServlet { private final static Logger log = Logger.getLogger(ServiceStatus.class); - - private static String getURL(HttpServletRequest req) { - String scheme = req.getScheme(); // http - String serverName = req.getServerName(); // hostname.com - int serverPort = req.getServerPort(); // 80 - String contextPath = req.getContextPath(); // /mywebapp - String servletPath = req.getServletPath(); // /servlet/MyServlet - String pathInfo = req.getPathInfo(); // /a/b;c=123 - String queryString = req.getQueryString(); // d=789 - - // Reconstruct original requesting URL - StringBuffer url = new StringBuffer(); - url.append(scheme).append("://").append(serverName); - - if ((serverPort != 80) && (serverPort != 443)) { - url.append(":").append(serverPort); + private List getEndPoints() throws MalformedObjectNameException, NullPointerException, UnknownHostException, + AttributeNotFoundException, InstanceNotFoundException, MBeanException, ReflectionException { + MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); + Set objs = mbs.queryNames(new ObjectName("*:type=Connector,*"), + Query.match(Query.attr("protocol"), Query.value("HTTP/1.1"))); + List endPoints = new ArrayList(); + for (Iterator i = objs.iterator(); i.hasNext();) { + ObjectName obj = i.next(); + String scheme = mbs.getAttribute(obj, "scheme").toString(); + String port = obj.getKeyProperty("port"); + String hostname = InetAddress.getLocalHost().getHostName(); + endPoints.add(scheme + "://" + hostname + ":" + port); } + return endPoints; + } - url.append(contextPath).append(servletPath); - - if (pathInfo != null) { - url.append(pathInfo); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + /** + * // PROBLEM: the code tries to test not WS endpoints on an internal + * Tomcat, but on an external // endpoints with wrong info on the + * proxing StringBuffer jabawspath = req.getRequestURL(); jabawspath = + * jabawspath.delete(jabawspath.lastIndexOf("/"), jabawspath.length()); + * String serverPath = jabawspath.toString(); + */ + List eps = new ArrayList(); + try { + eps = getEndPoints(); + } catch (MalformedObjectNameException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (AttributeNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (InstanceNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (NullPointerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (MBeanException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ReflectionException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - if (queryString != null) { - url.append("?").append(queryString); + if (1 != eps.size()) { + log.info(eps.size() + "EndPoints found"); + //System.out.println(" " + eps.size() + " EndPoints found"); + for (String endpoint : eps) { + log.info(eps.size() + "EndPoint is " + endpoint); + //System.out.println(" EndPoint is " + endpoint); + } } - return url.toString(); - } - @Override - protected void doGet(HttpServletRequest req, HttpServletResponse resp) - throws ServletException, IOException { - StringBuffer jabawspath = req.getRequestURL(); - jabawspath = jabawspath.delete(jabawspath.lastIndexOf("/"), jabawspath.length()); - String serverPath = jabawspath.toString(); -/** - String host = java.net.InetAddress.getLocalHost().getCanonicalHostName(); - System.out.println("Testing services at " + req.getRequestURL()); - System.out.println("Really: Testing services at " + serverPath); - System.out.println(" serverPath2 is " + getURL(req)); - System.out.println(" Context Path is " + req.getContextPath()); - System.out.println(" Host is " + host); - System.out.println(" Request URI is " + req.getRequestURI()); - System.out.println(" Servlet Path is " + req.getServletPath()); - System.out.println(" Path Info is " + req.getPathInfo()); - System.out.println(" Local Port is " + req.getLocalPort()); - System.out.println(" Remote Port is " + req.getRemotePort()); - System.out.println(" Local address is " + req.getLocalAddr()); - System.out.println(" Remote address is " + req.getRemoteAddr()); - @SuppressWarnings("unchecked") - List list = Collections.list(req.getHeaderNames()); - System.out.println(" HTTP header names are " + list.toString()); - for (String hdr : list) { - System.out.println(" " + hdr + " header is " + req.getHeader(hdr)); + String serverPath = new String(); + for (String endpoint : eps) { + serverPath = endpoint + req.getContextPath(); } -*/ + //System.out.println("Testing services at " + serverPath); + List testResults = new ArrayList(); long startTime = System.nanoTime(); for (Services service : Services.values()) {