001: /*
002: * CoadunationAdmin: The admin frontend for coadunation.
003: * Copyright (C) 2007 - 2008 Rift IT Contracting
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
018: *
019: * WebServiceManagerImpl.java
020: */
021:
022: package com.rift.coad.web.admin.server;
023:
024: // java imports
025: import java.util.Set;
026: import java.util.Iterator;
027: import java.util.Arrays;
028: import java.util.Vector;
029: import java.lang.reflect.Method;
030: import java.io.ByteArrayOutputStream;
031: import java.io.CharArrayWriter;
032: import java.io.PrintWriter;
033: import java.io.PrintStream;
034:
035: // import log4j
036: import org.apache.log4j.Logger;
037:
038: // gwt imports
039: import com.google.gwt.user.server.rpc.RemoteServiceServlet;
040:
041: // coadunation imports
042: import com.rift.coad.lib.deployment.webservice.WebServiceConnector;
043: import com.rift.coad.lib.deployment.webservice.WebServiceManager;
044: import com.rift.coad.lib.webservice.WebServiceWrapper;
045: import com.rift.coad.web.admin.client.WebServiceDef;
046: import com.rift.coad.web.admin.client.WebServiceException;
047:
048: /**
049: * This class implements the web service call for the web service manager.
050: *
051: * @author brett chaldecott
052: */
053: public class WebServiceManagerImpl extends RemoteServiceServlet
054: implements com.rift.coad.web.admin.client.WebServiceManager {
055:
056: // private member variables
057: private static Logger log = Logger
058: .getLogger(WebServiceManagerImpl.class);
059:
060: /**
061: * This method returns the list of web services.
062: *
063: * @return The list of web services.
064: */
065: public String[] getServices() throws WebServiceException {
066: try {
067: Set entries = WebServiceConnector.getInstance()
068: .getServices();
069: String[] result = new String[entries.size()];
070: int index = 0;
071: for (Iterator iter = entries.iterator(); iter.hasNext(); index++) {
072: result[index] = (String) iter.next();
073: }
074: Arrays.sort(result);
075: return result;
076: } catch (Exception ex) {
077: log.error("Failed to retrieve the web service list : "
078: + ex.getMessage(), ex);
079: throw new WebServiceException(
080: "Failed to retrieve the web service " + "list : "
081: + ex.getMessage());
082: }
083:
084: }
085:
086: /**
087: * This method returns a web service definition.
088: *
089: * @return The web service defintion.
090: * @param name The name of the web service.
091: */
092: public WebServiceDef getWebServiceDef(String name)
093: throws WebServiceException {
094: try {
095: WebServiceWrapper service = (WebServiceWrapper) WebServiceConnector
096: .getInstance().getService(name);
097: WebServiceDef def = new WebServiceDef();
098: def.setURL("http://"
099: + java.net.InetAddress.getLocalHost().getHostName()
100: + ":8085" + service.getPath() + "?WSDL");
101: def.setWSDL(service.generateWSDL());
102: return def;
103: } catch (Exception ex) {
104: log.error("Failed to retrieve the web service def : "
105: + ex.getMessage(), ex);
106: throw new WebServiceException(
107: "Failed to retrieve web service def : "
108: + ex.getMessage());
109: }
110: }
111: }
|