001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: ListServicesServlet.java 8954 2007-09-05 20:23:47Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.component.http.server;
025:
026: import java.io.IOException;
027: import java.util.Map;
028: import java.util.Set;
029:
030: import javax.servlet.ServletException;
031: import javax.servlet.ServletOutputStream;
032: import javax.servlet.ServletRequest;
033: import javax.servlet.ServletResponse;
034: import javax.servlet.http.HttpServlet;
035: import javax.xml.namespace.QName;
036:
037: import org.apache.axis2.context.ConfigurationContext;
038: import org.apache.axis2.description.AxisService;
039:
040: public class ListServicesServlet extends HttpServlet {
041:
042: /**
043: * The HTML title string
044: */
045: private static final String HTML_TITLE = "<html><head><title>List Services</title></head><body>";
046:
047: /**
048: * The axis2 configuration context used to get services list
049: */
050: private ConfigurationContext configContext;
051:
052: /**
053: * Creates a new instance of ListServicesServlet
054: *
055: * @param configurationContext
056: * @param active
057: */
058: public ListServicesServlet(ConfigurationContext configurationContext) {
059: this .configContext = configurationContext;
060: }
061:
062: @Override
063: public void service(ServletRequest request, ServletResponse response)
064: throws ServletException, IOException {
065: ServletOutputStream out = response.getOutputStream();
066: this .printServicesList(out, request.getLocalAddr());
067: }
068:
069: /**
070: * Print the list of services with links to their WSDL description
071: *
072: * @param out
073: * @throws IOException
074: */
075: private void printServicesList(ServletOutputStream out,
076: String localAddr) throws IOException {
077: Map services = this .configContext.getAxisConfiguration()
078: .getServices();
079: Set keys = services.keySet();
080:
081: boolean foundService = false;
082:
083: out.write(ListServicesServlet.HTML_TITLE.getBytes());
084: out.write("<h2>Available Services</h2>".getBytes());
085: if (keys.size() > 0) {
086: for (Object key : keys) {
087: AxisService service = (AxisService) services.get(key);
088: String serviceName = service.getName();
089: //A service is being created from the SU wsdl
090: //that I can't figure out why. So, just don't
091: //display it until I can find where its coming from.
092: //The bogus service starts with a namespace surounded by {}
093: if (!serviceName.startsWith("{")) {
094: out.write("<li><a href='".getBytes());
095: out.write(("services/" + serviceName).getBytes());
096: out.write("?wsdl'>".getBytes());
097: out.write(serviceName.getBytes());
098: out.write("</a></li>".getBytes());
099: foundService = true;
100: }
101: }
102: }
103: if (!foundService) {
104: out.write("No service".getBytes());
105: }
106: out.write("</body></html>".getBytes());
107: out.flush();
108: out.close();
109: }
110:
111: protected QName StringToQName(String qnameString) {
112: if (qnameString.startsWith("{")) {
113: int index = qnameString.indexOf("}");
114: String namespace = qnameString.substring(1, index);
115: String localname = qnameString.substring(index + 1);
116: return new QName(namespace, localname);
117: }
118: return new QName(null, qnameString);
119: }
120:
121: }
|