[jboss-cvs] contrib/varia/src/main/org/jboss/jaxr/juddi ...

Anil Saldhana anil.saldhana at jboss.com
Thu Jul 20 13:12:40 EDT 2006


  User: asaldhana
  Date: 06/07/20 13:12:40

  Modified:    varia/src/main/org/jboss/jaxr/juddi    JUDDIService.java
                        JUDDIServiceMBean.java
  Added:       varia/src/main/org/jboss/jaxr/juddi    JUDDIServlet.java
  Log:
  JBAS-2621: JAXR to HEAD
  
  Revision  Changes    Path
  1.3       +86 -49    contrib/varia/src/main/org/jboss/jaxr/juddi/JUDDIService.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JUDDIService.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/jaxr/juddi/JUDDIService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JUDDIService.java	30 Oct 2005 00:07:20 -0000	1.2
  +++ JUDDIService.java	20 Jul 2006 17:12:40 -0000	1.3
  @@ -21,21 +21,20 @@
   */
   package org.jboss.jaxr.juddi;
   
  -import org.jboss.system.ServiceMBeanSupport;
   import org.apache.ws.scout.registry.ConnectionFactoryImpl;
  +import org.jboss.system.ServiceMBeanSupport;
   
  -import javax.sql.DataSource;
  -import javax.naming.NamingException;
   import javax.naming.InitialContext;
  -import javax.naming.Context;
  +import javax.naming.NamingException;
  +import javax.sql.DataSource;
   import javax.xml.registry.ConnectionFactory;
  -import java.sql.Connection;
  -import java.sql.SQLException;
  -import java.sql.Statement;
  +import java.io.BufferedReader;
   import java.io.IOException;
   import java.io.InputStream;
  -import java.io.BufferedReader;
   import java.io.InputStreamReader;
  +import java.sql.Connection;
  +import java.sql.SQLException;
  +import java.sql.Statement;
   
   
   /**
  @@ -44,7 +43,6 @@
    * for J2EE 1.4 compliance
    *
    * @author <mailto:Anil.Saldhana at jboss.org>Anil Saldhana
  - * @jmx.mbean name="jboss:service=juddi"
    * extends="org.jboss.system.ServiceMBean"
    * @since Nov 8, 2004
    */
  @@ -67,6 +65,8 @@
       protected boolean shouldBindJaxr = true;
       protected boolean dropDB = false;
   
  +    private boolean jndiAlreadyBound = false;
  +
       protected Connection getConnection()
               throws SQLException, NamingException
       {
  @@ -109,7 +109,7 @@
       {
           log.debug("JUDDIService: Inside locateScript");
           InputStream input =
  -                getClass().getClassLoader().getResourceAsStream("META-INF/" + name);
  +                getClass().getClassLoader().getResourceAsStream("META-INF/ddl/" + name);
           if (input != null)
           {
               try
  @@ -128,11 +128,12 @@
           boolean firstError = true;
           BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
   
  +        Connection connection = null;
           try
           {
  -            Connection connection = this.getConnection();
  +            connection = this.getConnection();
               if (connection != null)
  -                log.debug("HaHa!  Obtained the Connection");
  +                log.debug("Obtained the Connection");
               Statement statement = connection.createStatement();
               try
               {
  @@ -157,7 +158,9 @@
   
                               if (firstError)
                               {
  -                                log.warn(err + e.getLocalizedMessage()+" "+nextStatement);
  +                                log.debug(err + e.getLocalizedMessage() + " " + nextStatement);
  +                                log.debug("Your settings are:dropOnStart =" + dropOnStart + ";createOnStart =" + createOnStart);
  +                                log.debug("dropOnStop = " + dropOnStop);
   
                                   firstError = false;
                               }
  @@ -176,12 +179,14 @@
                           statement.execute(nextStatement);
                       } catch (SQLException e)
                       {
  -                        log.warn("Could not execute last statement of a juddi init script: " + e.getLocalizedMessage());
  +                        log.debug("Could not execute last statement of a juddi init script: " + e.getLocalizedMessage());
  +                        log.debug("Your settings are:dropOnStart =" + dropOnStart + ";createOnStart =" + createOnStart);
  +                        log.debug("dropOnStop = " + dropOnStop);
                       }
                   }
               } finally
               {
  -                statement.close();
  +                if (statement != null) statement.close();
               }
           } catch (NamingException nm)
           {
  @@ -189,24 +194,20 @@
               log.error(nm);
           } finally
           {
  -
  +            if (connection != null) connection.close();
           }
       }
   
       /**
  -     * starts the ebxmlrr service
  +     * starts the jUDDI service
        */
       public void startService() throws Exception
       {
           log.debug("JUDDIService: Inside startService with dropOnStart="
                   + dropOnStart + " createOnStart=" + createOnStart);
  -        if (shouldBindJaxr)
  +        if (shouldBindJaxr && !jndiAlreadyBound)
           {
  -            //Bind a ConnectionFactory object to JNDI
  -            InitialContext ctx = new InitialContext();
  -            ConnectionFactory factory = (ConnectionFactory) ConnectionFactoryImpl.newInstance();
  -
  -            bind(ctx, bindJaxr, factory);
  +            bindJAXRConnectionFactory();
           }
   
           if (dropOnStart)
  @@ -230,12 +231,12 @@
           {
               runDrop();
           }
  +        unBindJAXRConnectionFactory();
       }
   
   
       /**
        * @return boolean
  -     * @jmx:managed-attribute
        */
       public boolean isDropOnStart()
       {
  @@ -246,7 +247,6 @@
        * Sets the dropOnStart.
        *
        * @param dropOnStart The dropOnStart to set
  -     * @jmx:managed-attribute
        */
       public void setDropOnStart(boolean dropOnStart)
       {
  @@ -255,7 +255,6 @@
   
       /**
        * @return boolean
  -     * @jmx:managed-attribute
        */
       public boolean isDropOnStop()
       {
  @@ -266,7 +265,6 @@
        * Sets the dropOnStop.
        *
        * @param dropOnStop The dropOnStop to set
  -     * @jmx:managed-attribute
        */
       public void setDropOnStop(boolean dropOnStop)
       {
  @@ -275,7 +273,6 @@
   
       /**
        * @return boolean
  -     * @jmx:managed-attribute
        */
       public boolean isCreateOnStart()
       {
  @@ -286,7 +283,6 @@
        * Sets the createOnStart.
        *
        * @param createOnStart The createOnStart to set
  -     * @jmx:managed-attribute
        */
       public void setCreateOnStart(boolean createOnStart)
       {
  @@ -295,7 +291,6 @@
   
       /**
        * @return String
  -     * @jmx:managed-attribute
        */
       public String getDataSource()
       {
  @@ -306,7 +301,6 @@
        * Sets the Datasource Url.
        *
        * @param ds The datasourceurl to set
  -     * @jmx:managed-attribute
        */
       public void setDataSourceUrl(String ds)
       {
  @@ -315,7 +309,6 @@
   
       /**
        * @return String
  -     * @jmx:managed-attribute
        */
       public String getRegistryOperator()
       {
  @@ -326,7 +319,6 @@
        * Sets the RegistryOperator.
        *
        * @param ro The datasourceurl to set
  -     * @jmx:managed-attribute
        */
       public void setRegistryOperator(String ro)
       {
  @@ -335,8 +327,6 @@
   
       /**
        * gets the JAXR ConnectionFactory.
  -     *
  -     * @jmx:managed-attribute
        */
       public String getBindJaxr()
       {
  @@ -348,18 +338,20 @@
        * Sets the JAXR ConnectionFactory.
        *
        * @param str The context to bind the Jaxr factory to set
  -     * @jmx:managed-attribute
        */
       public void setBindJaxr(String str)
       {
           this.bindJaxr = str;
  +
  +        if(this.shouldBindJaxr)
  +        {
  +           bindJAXRConnectionFactory();
  +        }
       }
   
   
       /**
        * gets the JAXR ConnectionFactory.
  -     *
  -     * @jmx:managed-attribute
        */
       public boolean getShouldBindJaxr()
       {
  @@ -370,17 +362,18 @@
        * Sets the JAXR ConnectionFactory.
        *
        * @param str Should a Jaxr Connection Factory bound
  -     * @jmx:managed-attribute
        */
       public void setShouldBindJaxr(boolean str)
       {
           this.shouldBindJaxr = str;
  +        if (shouldBindJaxr)
  +        {
  +            bindJAXRConnectionFactory();
  +        }
       }
   
       /**
        * gets the JAXR ConnectionFactory.
  -     *
  -     * @jmx:managed-attribute
        */
       public boolean getDropDB()
       {
  @@ -391,25 +384,69 @@
        * Sets the JAXR ConnectionFactory.
        *
        * @param b Should a Jaxr Connection Factory bound
  -     * @jmx:managed-attribute
        */
       public void setDropDB(boolean b)
       {
           this.dropDB = b;
  -        try{
  -            if(datasource != null ) this.runDrop();
  -        }catch( Exception e)
  +        try
  +        {
  +            if (datasource != null) this.runDrop();
  +        } catch (Exception e)
           {
               log.error(e.toString());
           }
       }
   
  +    private void bindJAXRConnectionFactory()
  +    {
  +        if( this.bindJaxr == null || jndiAlreadyBound ) return;//We will wait for it to be set
  +
  +        //Bind a ConnectionFactory object to JNDI
  +        InitialContext ctx = null;
  +        try
  +        {
  +            ctx = new InitialContext();
  +        } catch (NamingException e)
  +        {
  +            log.error("JNDI InitialContext Failed");
  +            e.printStackTrace();
  +        }
  +        ConnectionFactory factory = (ConnectionFactory) ConnectionFactoryImpl.newInstance();
  +
  +        try
  +        {
  +            ctx.rebind(bindJaxr, factory);
  +            jndiAlreadyBound = true;
  +        } catch (NamingException e)
  +        {
  +            log.error("JNDI Bind Failed:" + bindJaxr);
  +            e.printStackTrace();
  +        }
   
  +    }
   
  +    private void unBindJAXRConnectionFactory()
  +    {
  +        if( this.bindJaxr == null || jndiAlreadyBound ) return;//We will wait for it to be set
   
  -    private void bind(Context ctx, String name, Object val)
  -            throws NamingException
  +        //Bind a ConnectionFactory object to JNDI
  +        InitialContext ctx = null;
  +        try
       {
  -        ctx.bind(name, val);
  +            ctx = new InitialContext();
  +        } catch (NamingException e)
  +        {
  +            log.error("JNDI InitialContext Failed");
  +            e.printStackTrace();
  +        }
  +        try
  +        {
  +            ctx.unbind(bindJaxr);
  +        } catch (NamingException e)
  +        {
  +            //Ignore
  +        }
  +
       }
   }
  +
  
  
  
  1.3       +5 -1      contrib/varia/src/main/org/jboss/jaxr/juddi/JUDDIServiceMBean.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JUDDIServiceMBean.java
  ===================================================================
  RCS file: /cvsroot/jboss/contrib/varia/src/main/org/jboss/jaxr/juddi/JUDDIServiceMBean.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- JUDDIServiceMBean.java	30 Oct 2005 00:07:20 -0000	1.2
  +++ JUDDIServiceMBean.java	20 Jul 2006 17:12:40 -0000	1.3
  @@ -21,6 +21,9 @@
   */
   package org.jboss.jaxr.juddi;
   
  +import javax.management.ObjectName;
  +import org.jboss.mx.util.ObjectNameFactory;
  +
   /**
    * MBean interface.
    * @since Nov 8, 2004
  @@ -28,7 +31,7 @@
   public interface JUDDIServiceMBean extends org.jboss.system.ServiceMBean {
   
      //default object name
  -   public static final javax.management.ObjectName OBJECT_NAME = org.jboss.mx.util.ObjectNameFactory.create("jboss:service=juddi");
  +   public static final ObjectName OBJECT_NAME = ObjectNameFactory.create("jboss:service=juddi");
   
     boolean isDropOnStart() ;
   
  @@ -104,3 +107,4 @@
     void setDropDB(boolean b) ;
   
   }
  +
  
  
  
  1.2       +401 -0    contrib/varia/src/main/org/jboss/jaxr/juddi/JUDDIServlet.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: JUDDIServlet.java
  ===================================================================
  RCS file: JUDDIServlet.java
  diff -N JUDDIServlet.java
  --- /dev/null	1 Jan 1970 00:00:00 -0000
  +++ JUDDIServlet.java	20 Jul 2006 17:12:40 -0000	1.2
  @@ -0,0 +1,401 @@
  +/*
  +* JBoss, Home of Professional Open Source
  +* Copyright 2005, JBoss Inc., and individual contributors as indicated
  +* by the @authors tag. See the copyright.txt in the distribution for a
  +* full listing of individual contributors.
  +*
  +* This is free software; you can redistribute it and/or modify it
  +* under the terms of the GNU Lesser General Public License as
  +* published by the Free Software Foundation; either version 2.1 of
  +* the License, or (at your option) any later version.
  +*
  +* This software 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 GNU
  +* Lesser General Public License for more details.
  +*
  +* You should have received a copy of the GNU Lesser General Public
  +* License along with this software; if not, write to the Free
  +* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  +* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  +*/
  +package org.jboss.jaxr.juddi;
  +
  +import org.apache.juddi.IRegistry;
  +import org.apache.juddi.datatype.RegistryObject;
  +import org.apache.juddi.datatype.response.DispositionReport;
  +import org.apache.juddi.datatype.response.ErrInfo;
  +import org.apache.juddi.datatype.response.Result;
  +import org.apache.juddi.error.BusyException;
  +import org.apache.juddi.error.FatalErrorException;
  +import org.apache.juddi.error.RegistryException;
  +import org.apache.juddi.error.UnsupportedException;
  +import org.apache.juddi.handler.HandlerMaker;
  +import org.apache.juddi.handler.IHandler;
  +import org.apache.juddi.registry.RegistryEngine;
  +import org.apache.juddi.registry.RegistryServlet;
  +import org.apache.juddi.util.Config;
  +import org.apache.juddi.util.xml.XMLUtils;
  +import org.jboss.logging.Logger;
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Element;
  +import org.w3c.dom.NamedNodeMap;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NodeList;
  +
  +import javax.servlet.ServletException;
  +import javax.servlet.http.HttpServlet;
  +import javax.servlet.http.HttpServletRequest;
  +import javax.servlet.http.HttpServletResponse;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.ParserConfigurationException;
  +import javax.xml.soap.Detail;
  +import javax.xml.soap.MessageFactory;
  +import javax.xml.soap.Name;
  +import javax.xml.soap.SOAPBody;
  +import javax.xml.soap.SOAPBodyElement;
  +import javax.xml.soap.SOAPElement;
  +import javax.xml.soap.SOAPException;
  +import javax.xml.soap.SOAPFactory;
  +import javax.xml.soap.SOAPFault;
  +import javax.xml.soap.SOAPMessage;
  +import javax.xml.soap.SOAPPart;
  +
  +import java.io.ByteArrayOutputStream;
  +import java.io.IOException;
  +import java.util.Vector;
  +
  +/**
  + * Servlet that represents the JUDDI Registry
  + * Based on the JUDDI standard servlets
  + * @author <mailto:Anil.Saldhana at jboss.org>Anil Saldhana
  + * @since May 18, 2005
  + */
  +public class JUDDIServlet extends HttpServlet
  +{
  +    /** The serialVersionUID */
  +   private static final long serialVersionUID = 8768916717023791095L;
  +
  +   // XML Document Builder
  +    private static DocumentBuilder docBuilder = null;
  +
  +    // jUDDI XML Handler maker
  +    private static HandlerMaker maker = HandlerMaker.getInstance();
  +
  +    private static Logger log = Logger.getLogger(JUDDIServlet.class);
  +
  +    /**
  +     *
  +     */
  +    public void doGet(HttpServletRequest req, HttpServletResponse res)
  +            throws ServletException, IOException
  +    {
  +        res.setHeader("Allow", "POST");
  +        res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The request " +
  +                "method 'GET' is not allowed by UDDI API.");
  +    }
  +
  +    public void doPost(HttpServletRequest req, HttpServletResponse res)
  +            throws ServletException, IOException
  +    {
  +        res.setContentType("text/xml; charset=utf-8");
  +
  +        SOAPMessage soapReq = null;
  +        SOAPMessage soapRes = null;
  +
  +        try
  +        { 
  +            MessageFactory msgFactory = MessageFactory.newInstance();
  +            soapReq = msgFactory.createMessage(null, req.getInputStream());
  +            soapRes = msgFactory.createMessage();
  +            if(log.isDebugEnabled())
  +            {
  +               ByteArrayOutputStream bs = new ByteArrayOutputStream();
  +               soapReq.writeTo(bs);
  +               log.debug("Request received::"+bs.toString()); 
  +            } 
  +
  +            SOAPBody soapReqBody = soapReq.getSOAPBody();
  +            Element uddiReq = (Element) soapReqBody.getFirstChild();
  +            if (uddiReq == null)
  +                throw new FatalErrorException("A UDDI request was not " +
  +                        "found in the SOAP message.");
  +
  +            String function = uddiReq.getLocalName();
  +            if ((function == null) || (function.trim().length() == 0))
  +                throw new FatalErrorException("The name of the UDDI request " +
  +                        "could not be identified.");
  +            IHandler requestHandler = maker.lookup(function);
  +            if (requestHandler == null)
  +                throw new UnsupportedException("The UDDI request " +
  +                        "type specified is unknown: " + function);
  +
  +            String generic = uddiReq.getAttribute("generic");
  +            if (generic == null)
  +                throw new FatalErrorException("A UDDI generic attribute " +
  +                        "value was not found for UDDI request: " + function + " (The " +
  +                        "'generic' attribute must be present)");
  +            else if (!generic.equals(IRegistry.UDDI_V2_GENERIC))
  +                throw new UnsupportedException("Currently only UDDI v2 " +
  +                        "requests are supported. The generic attribute value " +
  +                        "received was: " + generic);
  +
  +            // Unmarshal the raw xml into the appropriate jUDDI
  +            // request object.
  +
  +            RegistryObject uddiReqObj = requestHandler.unmarshal(uddiReq);
  +            if(uddiReqObj == null)
  +               throw new FatalErrorException("Uddi Request is null");
  +
  +            // Grab a reference to the shared jUDDI registry
  +            // instance (make sure it's running) and execute the
  +            // requested UDDI function.
  +
  +            RegistryObject uddiResObj = null;
  +            RegistryEngine registry = RegistryServlet.getRegistry();
  +            if ((registry != null) && (registry.isAvailable()))
  +                uddiResObj = registry.execute(uddiReqObj);
  +            else
  +                throw new BusyException("The Registry is currently unavailable.");
  +
  +            // Lookup the appropriate response handler which will
  +            // be used to marshal the UDDI object into the appropriate
  +            // xml format.
  +
  +            IHandler responseHandler = maker.lookup(uddiResObj.getClass().getName());
  +            if (responseHandler == null)
  +                throw new FatalErrorException("The response object " +
  +                        "type is unknown: " + uddiResObj.getClass().getName());
  +
  +            // Create a new 'temp' XML element to use as a container
  +            // in which to marshal the UDDI response data into.
  +
  +            DocumentBuilder docBuilder = getDocumentBuilder();
  +            Document document = docBuilder.newDocument();
  +            Element element = document.createElement("temp");
  +
  +            // Lookup the appropriate response handler and marshal
  +            // the juddi object into the appropriate xml format (we
  +            // only support UDDI v2.0 at this time).  Attach the
  +            // results to the body of the SOAP response.
  +
  +            responseHandler.marshal(uddiResObj, element);
  +            log.debug("Response that will be sent:");
  +            log.debug(XMLUtils.toString((Element) element.getFirstChild()));
  +
  +            // Grab a reference to the 'temp' element's
  +            // only child here (this has the effect of
  +            // discarding the temp element) and append
  +            // this child to the soap response body
  +
  +            /*document.appendChild(element.getFirstChild());
  +            soapRes.getSOAPBody().addDocument(document);*/ 
  +            Element el = (Element) element.getFirstChild(); 
  +            soapRes = this.createSOAPMessage(el); 
  +        } catch (Exception ex) // Catch ALL exceptions
  +        {
  +            // SOAP Fault values
  +            String faultCode = null;
  +            String faultString = null;
  +            String faultActor = null;
  +
  +            // UDDI DispositionReport values
  +            String errno = null;
  +            String errCode = null;
  +            String errMsg = null;
  +
  +            if (ex instanceof RegistryException)
  +            {
  +
  +                log.error("RegistryException::",ex);
  +
  +                RegistryException rex = (RegistryException) ex;
  +
  +                faultCode = rex.getFaultCode();  // SOAP Fault faultCode
  +                faultString = rex.getFaultString();  // SOAP Fault faultString
  +                faultActor = rex.getFaultActor();  // SOAP Fault faultActor
  +
  +                DispositionReport dispRpt = rex.getDispositionReport();
  +                if (dispRpt != null)
  +                {
  +                    Result result = null;
  +                    ErrInfo errInfo = null;
  +
  +                    Vector results = dispRpt.getResultVector();
  +                    if ((results != null) && (!results.isEmpty()))
  +                        result = (Result) results.elementAt(0);
  +
  +                    if (result != null)
  +                    {
  +                        errno = String.valueOf(result.getErrno());  // UDDI Result errno
  +                        errInfo = result.getErrInfo();
  +
  +                        if (errInfo != null)
  +                        {
  +                            errCode = errInfo.getErrCode();  // UDDI ErrInfo errCode
  +                            errMsg = errInfo.getErrMsg();  // UDDI ErrInfo errMsg
  +                        }
  +                    }
  +                }
  +            } else
  +            {
  +
  +                log.error(ex.getMessage(), ex);
  +
  +                faultCode = "Server";
  +                faultString = ex.getMessage();
  +                faultActor = null;
  +
  +
  +                errno = String.valueOf(Result.E_FATAL_ERROR);
  +                errCode = Result.lookupErrCode(Result.E_FATAL_ERROR);
  +                errMsg = Result.lookupErrText(Result.E_FATAL_ERROR);
  +            }
  +
  +            try
  +            {
  +                SOAPBody soapResBody = soapRes.getSOAPBody();
  +                SOAPFault soapFault = soapResBody.addFault();
  +                if(faultCode == null)
  +                   faultCode = "Unavailable";
  +                soapFault.setFaultCode(faultCode);
  +                soapFault.setFaultString(faultString);
  +                soapFault.setFaultActor(faultActor); 
  +
  +                Detail faultDetail = soapFault.addDetail();
  +
  +                SOAPElement dispRpt = faultDetail.addChildElement("dispositionReport", "", IRegistry.UDDI_V2_NAMESPACE);
  +                dispRpt.setAttribute("generic", IRegistry.UDDI_V2_GENERIC);
  +                dispRpt.setAttribute("operator", Config.getOperator());
  +
  +                SOAPElement result = dispRpt.addChildElement("result");
  +                result.setAttribute("errno", errno);
  +
  +                SOAPElement errInfo = result.addChildElement("errInfo");
  +                errInfo.setAttribute("errCode", errCode);
  +                errInfo.setValue(errMsg);
  +            } catch (Exception e)
  +            { // if we end up in here it's just NOT good.
  +                log.error("A serious error has occured while assembling the SOAP Fault.", e);
  +            }
  +        } finally
  +        {
  +            try
  +            {
  +               if(log.isDebugEnabled())
  +               {
  +                  ByteArrayOutputStream bs = new ByteArrayOutputStream();
  +                  soapRes.writeTo(bs);
  +                  log.debug("Response being sent::"+bs.toString()); 
  +               } 
  +               soapRes.writeTo(res.getOutputStream());
  +            } catch (SOAPException sex)
  +            {
  +                log.error("SOAPException::",sex);
  +            }
  +        }
  +    }
  +
  +    /**
  +     *
  +     */
  +    private DocumentBuilder getDocumentBuilder()
  +    {
  +        if (docBuilder == null)
  +            docBuilder = createDocumentBuilder();
  +        return docBuilder;
  +    }
  +
  +    /**
  +     *
  +     */
  +    private synchronized DocumentBuilder createDocumentBuilder()
  +    {
  +        if (docBuilder != null)
  +            return docBuilder;
  +
  +        try
  +        {
  +            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  +            factory.setNamespaceAware(true);
  +            //factory.setValidating(true);
  +
  +            docBuilder = factory.newDocumentBuilder();
  +        } catch (ParserConfigurationException pcex)
  +        {
  +           log.error("ParserConfigurationException::",pcex);
  +        }
  +
  +        return docBuilder;
  +    }
  +    
  +    private SOAPMessage createSOAPMessage(Element elem) throws Exception
  +    {
  +       String prefix = "uddi";
  +       MessageFactory msgFactory = MessageFactory.newInstance();
  +       SOAPFactory factory = SOAPFactory.newInstance();
  +       
  +       SOAPMessage message = msgFactory.createMessage();
  +       message.getSOAPHeader().detachNode();
  +       SOAPPart soapPart = message.getSOAPPart();
  +       SOAPBody soapBody = soapPart.getEnvelope().getBody(); 
  +       //Create the outer body element
  +       String uddins = IRegistry.UDDI_V2_NAMESPACE;
  +       Name bodyName = factory.createName(elem.getNodeName(), prefix, uddins);
  +       SOAPBodyElement bodyElement = soapBody.addBodyElement(bodyName);
  +       bodyElement.addNamespaceDeclaration(prefix,uddins);      
  +       appendAttributes(bodyElement, elem.getAttributes(), factory);
  +       appendElements(bodyElement,elem.getChildNodes(), factory); 
  +       return message;
  +    }
  +    
  +    private void appendAttributes(SOAPElement bodyElement, NamedNodeMap nnm,
  +          SOAPFactory factory) throws SOAPException
  +    {
  +       int len = nnm != null ? nnm.getLength() : 0;
  +       for (int i = 0; i < len; i++)
  +       {
  +           Node n = nnm.item(i);
  +           String nodename = n.getNodeName();
  +           String nodevalue = n.getNodeValue(); 
  +           if("xmlns".equals(nodename))
  +              continue; 
  +           //Special case:  xml:lang
  +           if("xml:lang".equals(nodename))
  +           {
  +              Name xmlLang = factory.createName("lang","xml",
  +                    "http://www.w3.org/TR/REC-xml/");
  +              bodyElement.addAttribute(xmlLang, nodevalue);
  +           }
  +           else
  +               bodyElement.addAttribute(factory.createName(nodename), nodevalue);
  +       } 
  +    }
  +    
  +    private void appendElements(SOAPElement bodyElement, NodeList nlist,
  +          SOAPFactory factory) 
  +    throws SOAPException
  +    {  
  +       String prefix = "uddi";
  +       String uddins = IRegistry.UDDI_V2_NAMESPACE;
  +       int len = nlist != null ? nlist.getLength() : 0;
  +
  +       for (int i = 0; i < len; i++)
  +       {
  +           Node node = nlist.item(i);
  +           short nodeType = node != null ? node.getNodeType() : -100;
  +           if (Node.ELEMENT_NODE == nodeType)
  +           {
  +              Element el = (Element)node;
  +              Name name = factory.createName(el.getNodeName(), prefix,uddins);
  +              SOAPElement attachedEl = bodyElement.addChildElement(name);
  +              appendAttributes(attachedEl, el.getAttributes(), factory);
  +              appendElements(attachedEl, el.getChildNodes(), factory);
  +           } else if (nodeType == Node.TEXT_NODE)
  +           {
  +               bodyElement.addTextNode(node.getNodeValue());
  +           } 
  +       } 
  +    } 
  +}
  
  
  



More information about the jboss-cvs-commits mailing list