axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject cvs commit: xml-axis/addons/wsil README
Date Fri, 07 Feb 2003 19:50:11 GMT
jmsnell     2003/02/07 11:50:11

  Added:       addons/wsil/src/org/apache/axis/components/wsil
                        InspectionServlet.java
               addons/wsil README
  Log:
  Simple WS-Inspection servlet that lists all of the services deployed 
  in the Axis registry as an inspection.wsil file.  Requires Apache WSIL. 
  Tested with Axis 1.0 and 1.1beta.
  
  Revision  Changes    Path
  1.1                  xml-axis/addons/wsil/src/org/apache/axis/components/wsil/InspectionServlet.java
  
  Index: InspectionServlet.java
  ===================================================================
  package org.apache.axis.components.wsil;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  import javax.servlet.ServletContext;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.apache.wsil.Abstract;
  import org.apache.wsil.Description;
  import org.apache.wsil.Service;
  import org.apache.wsil.ServiceName;
  import org.apache.wsil.WSILDocument;
  import org.apache.wsil.WSILDocumentFactory;
  import org.apache.wsil.WSILException;
  import org.apache.wsil.extension.wsdl.Reference;
  import org.apache.wsil.extension.wsdl.WSDLConstants;
  import org.apache.wsil.impl.extension.wsdl.WSDLExtensionBuilder;
  import org.apache.wsil.xml.XMLWriter;
  import org.apache.axis.AxisEngine;
  import org.apache.axis.AxisFault;
  import org.apache.axis.ConfigurationException;
  import org.apache.axis.EngineConfiguration;
  import org.apache.axis.configuration.EngineConfigurationFactoryFinder;
  
  import org.apache.axis.description.ServiceDesc;
  import org.apache.axis.server.AxisServer;
  
  /**
   * Generates a WS-Inspection document from the collection
   * of services deployed into the Axis server.
   * 
   * @author James M Snell <jasnell@us.ibm.com>
   */
  public class InspectionServlet
    extends HttpServlet {
    
    private AxisServer axisServer;
    protected static final String ATTR_AXIS_ENGINE =
        "AxisEngine" ;
    
    protected void doGet(
      HttpServletRequest request, 
      HttpServletResponse response)
        throws ServletException, IOException {
          try {
            WSILDocument document = generateWSILDocument();
            XMLWriter writer = new XMLWriter();
            writer.writeDocument(document, response.getOutputStream());
          } catch (WSILException e) {
            throw new ServletException(e);
          } catch (AxisFault e) {
            throw new ServletException(e);
          } catch (ConfigurationException e) {
            throw new ServletException(e);
          }
    }
  
    private WSILDocument generateWSILDocument() 
      throws WSILException, AxisFault, ConfigurationException {
      
        WSILDocumentFactory factory = WSILDocumentFactory.newInstance();
        WSILDocument document = factory.newDocument();
      
        Abstract inspectionAbstract = document.createAbstract();
        inspectionAbstract.setText("Apache Axis Deployed Services");
        document.getInspection().addAbstract(inspectionAbstract);
      
        AxisServer server = getEngine();
        for (
          Iterator i = getEngine().getConfig().getDeployedServices(); 
          i.hasNext();) {
            ServiceDesc serviceDesc = (ServiceDesc)i.next();
            
            Service wsilService = document.createService();
            ServiceName wsilServiceName = document.createServiceName();
            wsilServiceName.setText(serviceDesc.getName());
            wsilService.addServiceName(wsilServiceName);
            
            Description wsilDescription = document.createDescription();
            wsilDescription.setReferencedNamespace(
              WSDLConstants.NS_URI_WSDL);
            wsilDescription.setLocation(
              serviceDesc.getName() + "?WSDL");
              
            WSDLExtensionBuilder builder = 
              (WSDLExtensionBuilder) document.getExtensionRegistry().
                  getBuilder(WSDLConstants.NS_URI_WSIL_WSDL);
            
            Reference reference = (Reference)builder.createElement(
              Reference.QNAME);
            reference.setEndpointPresent(new Boolean(true));
            
            wsilDescription.setExtensionElement(reference);
            wsilService.addDescription(wsilDescription);
            
            document.getInspection().addService(wsilService);
        }
      
        return document;
    }
    
      
    public AxisServer getEngine() throws AxisFault {
        if (axisServer == null)
            axisServer = getEngine(this);
        return axisServer;
    }
  
    public static AxisServer getEngine(HttpServlet servlet) throws AxisFault
    {
        AxisServer engine = null;
        ServletContext context = servlet.getServletContext();
        synchronized (context) {
            engine = retrieveEngine(context);
            if (engine == null) {
                Map environment = getEngineEnvironment(servlet);
                engine = AxisServer.getServer(environment);
                storeEngine(context, engine);
            }
        }
        return engine;
    }
  
    private static void storeEngine(ServletContext context, AxisServer engine) {
        if (engine == null) {
            context.removeAttribute(ATTR_AXIS_ENGINE);
        } else {
            context.setAttribute(ATTR_AXIS_ENGINE, engine);
        }
    }
  
    private static AxisServer retrieveEngine(ServletContext context) {
        Object contextObject = context.getAttribute(ATTR_AXIS_ENGINE);
        if (contextObject instanceof AxisServer) {
            return (AxisServer) contextObject;
        }
        else {
            return null;
        }
     }
  
  
    protected static Map getEngineEnvironment(HttpServlet servlet) {
        Map environment = new HashMap();
        String attdir= servlet.getInitParameter(AxisEngine.ENV_ATTACHMENT_DIR);
        if (attdir != null)
            environment.put(AxisEngine.ENV_ATTACHMENT_DIR, attdir);
        ServletContext context = servlet.getServletContext();
        environment.put(AxisEngine.ENV_SERVLET_CONTEXT, context);
        String webInfPath = context.getRealPath("/WEB-INF");
        if (webInfPath != null)
            environment.put(AxisEngine.ENV_SERVLET_REALPATH,
                            webInfPath + File.separator + "attachments");
        EngineConfiguration config =
            EngineConfigurationFactoryFinder.newFactory(context)
                    .getServerEngineConfig();
        if (config != null) {
            environment.put(EngineConfiguration.PROPERTY_NAME, config);
        }
        return environment;
    }
  }
  
  
  
  1.1                  xml-axis/addons/wsil/README
  
  Index: README
  ===================================================================
  
  Simple Http Servlet that generates a WS-Inspection document listing the
  collection of services in the Axis service deployment registry.
  
  The servlet assumes the following basic mapping configuration:
  
  <servlet>
    <servlet-name>AxisWsil</servlet-name>
    <servlet-class>org.apache.axis.components.wsil.InspectionServlet</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>Axis</servlet-name>
    <servlet-class>org.apache.axis.transport.http.HttpServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisWsil</servlet-name>
    <url-pattern>/services/inspection.wsil</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Axis</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  
  This is just an initial drop of the code. There is definitely room for 
  improvement in this component.
  
  

Mime
View raw message