axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gdani...@apache.org
Subject cvs commit: xml-axis/java/src/org/apache/axis/utils Admin.java
Date Wed, 30 May 2001 20:00:11 GMT
gdaniels    01/05/30 13:00:10

  Modified:    java/src/org/apache/axis AxisFault.java MessageContext.java
               java/src/org/apache/axis/handlers/soap SOAPService.java
               java/src/org/apache/axis/message MessageElement.java
                        SOAPHeader.java
               java/src/org/apache/axis/utils Admin.java
  Log:
  Fix potential bug in MessageContext by syncing the targetService string and
  the actual serviceHandler member.
  
  Rough in support for per-service type mappings by setting the MessageContext
  TypeMappingRegistry when we set the target service.  Also change Admin
  to parse per-service bean mappings (this is just a P.O.C).
  
  Give AxisFault a String-only constructor for ease-of-use.
  
  Give SOAPHeader a simple constructor for building headers on the fly.
  
  Revision  Changes    Path
  1.19      +7 -1      xml-axis/java/src/org/apache/axis/AxisFault.java
  
  Index: AxisFault.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/AxisFault.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- AxisFault.java	2001/05/03 21:20:13	1.18
  +++ AxisFault.java	2001/05/30 20:00:02	1.19
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -102,6 +102,12 @@
       e.printStackTrace(ps);
       ps.close();
       setFaultString( stream.toString() );
  +  }
  +  
  +  public AxisFault(String message)
  +  {
  +    setFaultCode(Constants.FAULT_SERVER_GENERAL);
  +    setFaultString(message);
     }
   
     public void dump() {
  
  
  
  1.23      +57 -18    xml-axis/java/src/org/apache/axis/MessageContext.java
  
  Index: MessageContext.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/MessageContext.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- MessageContext.java	2001/05/21 21:03:39	1.22
  +++ MessageContext.java	2001/05/30 20:00:03	1.23
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 2001 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -10,7 +10,7 @@
    * are met:
    *
    * 1. Redistributions of source code must retain the above copyright
  - *    notice, this list of conditions and the following disclaimer. 
  + *    notice, this list of conditions and the following disclaimer.
    *
    * 2. Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in
  @@ -18,7 +18,7 @@
    *    distribution.
    *
    * 3. The end-user documentation included with the redistribution,
  - *    if any, must include the following acknowledgment:  
  + *    if any, must include the following acknowledgment:
    *       "This product includes software developed by the
    *        Apache Software Foundation (http://www.apache.org/)."
    *    Alternately, this acknowledgment may appear in the software itself,
  @@ -26,7 +26,7 @@
    *
    * 4. The names "Axis" and "Apache Software Foundation" must
    *    not be used to endorse or promote products derived from this
  - *    software without prior written permission. For written 
  + *    software without prior written permission. For written
    *    permission, please contact apache@apache.org.
    *
    * 5. Products derived from this software may not be called "Apache",
  @@ -61,6 +61,8 @@
   import org.apache.axis.encoding.TypeMappingRegistry;
   import org.apache.axis.encoding.SOAPTypeMappingRegistry;
   import org.apache.axis.encoding.ServiceDescription;
  +import org.apache.axis.registries.HandlerRegistry;
  +import org.apache.axis.handlers.soap.SOAPService;
   
   /**
    * Some more general docs will go here.
  @@ -77,7 +79,7 @@
    *
    *  Actually I think we might just list the keys in the docs and
    *  provide no such constants since they create yet another
  - *  namespace, but we'd have no compile-time checks then. 
  + *  namespace, but we'd have no compile-time checks then.
    *
    *  Whaddya think? - todo by Jacek)
    *
  @@ -110,7 +112,7 @@
       private AxisClassLoader  classLoader ;
   
       /**
  -     * 
  +     *
        */
       private Hashtable bag ;
   
  @@ -123,7 +125,7 @@
        */
       private TypeMappingRegistry mappingRegistry = null;
   
  -    private static final SOAPTypeMappingRegistry soapTMR = 
  +    private static final SOAPTypeMappingRegistry soapTMR =
           new SOAPTypeMappingRegistry();
   
       public void setTypeMappingRegistry(TypeMappingRegistry reg) {
  @@ -154,15 +156,15 @@
       /**
        * Placeholder.
        */
  -    public Message getRequestMessage() { 
  -        return inMessage ; 
  +    public Message getRequestMessage() {
  +        return inMessage ;
       };
   
       /**
        * Placeholder.
        */
  -    public void setRequestMessage(Message inMsg) { 
  -        inMessage = inMsg ; 
  +    public void setRequestMessage(Message inMsg) {
  +        inMessage = inMsg ;
           if (inMessage != null) inMessage.setMessageContext(this);
       };
   
  @@ -174,13 +176,13 @@
       /**
        * Placeholder.
        */
  -    public void setResponseMessage(Message outMsg) { 
  +    public void setResponseMessage(Message outMsg) {
           outMessage = outMsg ;
           if (outMessage != null) outMessage.setMessageContext(this);
       };
   
       public AxisClassLoader getClassLoader() {
  -      if ( classLoader == null ) 
  +      if ( classLoader == null )
           classLoader = AxisClassLoader.getClassLoader(null);
         return( classLoader );
       }
  @@ -198,8 +200,28 @@
         return( targetService );
       }
   
  -    public void setTargetService(String tServ) {
  +    /**
  +     * Set the target service for this message.
  +     *
  +     * This looks up the named service in the registry, and has
  +     * the side effect of setting our TypeMappingRegistry to the
  +     * service's.
  +     *
  +     * @param tServ the name of the target service.
  +     * @exception AxisFault
  +     */
  +    public void setTargetService(String tServ) throws AxisFault {
         targetService = tServ ;
  +      HandlerRegistry sr = (HandlerRegistry)
  +                            getProperty(Constants.SERVICE_REGISTRY);
  +      if (sr == null)
  +	    return;
  +      
  +      Handler service = sr.find(tServ);
  +      if (service == null)
  +        throw new AxisFault("No service named '" + tServ + "' in registry!");
  +      
  +      setServiceHandler(service);
       }
   
       /** ServiceHandler is the handler that is the "service".  This handler
  @@ -209,11 +231,28 @@
       private Handler          serviceHandler ;
   
       public Handler getServiceHandler() {
  +      if ((serviceHandler == null) && (targetService != null)) {
  +        try {
  +          /** This is a bit kludgey for now - what might have happened is
  +           * that someone set the target service name before the registry
  +           * was set, or before the service was registered.  So just to
  +           * make sure, we set it again here and see if that causes the
  +           * serviceHandler to be set correctly.
  +           */
  +          setTargetService(targetService);
  +        } catch (AxisFault f) {
  +        }
  +      }
         return( serviceHandler );
       }
  -
  -    public void setServiceHandler(Handler h) {
  -      serviceHandler = h ;
  +    
  +    public void setServiceHandler(Handler sh)
  +    {
  +      serviceHandler = sh;
  +      if (sh instanceof SOAPService) {
  +        TypeMappingRegistry tmr = ((SOAPService)sh).getTypeMappingRegistry();
  +        setTypeMappingRegistry(tmr);
  +      }
       }
   
       /** Contains an instance of Handler, which is the
  @@ -243,7 +282,7 @@
        */
       public static String PASSWORD            = "user.password";
   
  -    /** Just a util so we don't have to cast the result 
  +    /** Just a util so we don't have to cast the result
        */
       public String getStrProp(String propName) {
         return( (String) getProperty(propName) );
  
  
  
  1.3       +21 -1     xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java
  
  Index: SOAPService.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/handlers/soap/SOAPService.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- SOAPService.java	2001/05/10 22:19:33	1.2
  +++ SOAPService.java	2001/05/30 20:00:05	1.3
  @@ -55,6 +55,7 @@
   package org.apache.axis.handlers.soap;
   
   import org.apache.axis.*;
  +import org.apache.axis.encoding.*;
   import org.apache.axis.utils.Debug;
   import org.apache.axis.transport.http.HTTPConstants;
   import org.apache.axis.registries.* ;
  @@ -70,12 +71,31 @@
   {
       public static final String OPTION_PIVOT = "pivot";
       
  +    /** Service-specific type mappings
  +     * 
  +     * !!! This is just a test for now, these do not get serialized (and thus
  +     * restored) with the registered services.  This should come out of our
  +     * XML storage eventually.
  +     * 
  +     */
  +    private transient TypeMappingRegistry typeMap = new TypeMappingRegistry();
  +    
       /** Standard, no-arg constructor.
        */
       public SOAPService()
       {
       }
       
  +    public TypeMappingRegistry getTypeMappingRegistry()
  +    {
  +        return typeMap;
  +    }
  +    
  +    public void setTypeMappingRegistry(TypeMappingRegistry map)
  +    {
  +        typeMap = map;
  +    }
  +    
       /** Convenience constructor for wrapping SOAP semantics around
        * "service handlers" which actually do work.
        */
  @@ -90,7 +110,7 @@
       {
           Debug.Print( 1, "Enter: SOAPService::invoke" );
           
  -        msgContext.setServiceHandler( this );
  +        //msgContext.setServiceHandler( this );
           
           Handler h = getInputChain() ;
           if ( h != null ) {
  
  
  
  1.21      +1 -0      xml-axis/java/src/org/apache/axis/message/MessageElement.java
  
  Index: MessageElement.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/MessageElement.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- MessageElement.java	2001/05/10 16:25:11	1.20
  +++ MessageElement.java	2001/05/30 20:00:06	1.21
  @@ -147,6 +147,7 @@
       public String getID() { return id; }
       
       public String getName() { return( name ); }
  +    public void setName(String name) { this.name = name; }
       
       public String getPrefix() { return( prefix ); }
       public void setPrefix(String prefix) { this.prefix = prefix; }
  
  
  
  1.17      +6 -0      xml-axis/java/src/org/apache/axis/message/SOAPHeader.java
  
  Index: SOAPHeader.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/message/SOAPHeader.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- SOAPHeader.java	2001/05/03 14:32:22	1.16
  +++ SOAPHeader.java	2001/05/30 20:00:07	1.17
  @@ -87,6 +87,12 @@
   
       public SOAPHeader() {
       }
  +    
  +    public SOAPHeader(String namespace, String localPart)
  +    {
  +        setNamespaceURI(namespace);
  +        setName(localPart);
  +    }
   
       public SOAPHeader(String namespace, String localPart,
                         Attributes attributes, DeserializationContext context) {
  
  
  
  1.32      +66 -50    xml-axis/java/src/org/apache/axis/utils/Admin.java
  
  Index: Admin.java
  ===================================================================
  RCS file: /home/cvs/xml-axis/java/src/org/apache/axis/utils/Admin.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- Admin.java	2001/05/30 14:18:25	1.31
  +++ Admin.java	2001/05/30 20:00:09	1.32
  @@ -79,19 +79,14 @@
   
     private void init() {
       if ( hr == null ) {
  -      if ( onServer )
  -        hr = new DefaultHandlerRegistry(Constants.SERVER_HANDLER_REGISTRY);
  -      else
  -        hr = new DefaultHandlerRegistry(Constants.CLIENT_HANDLER_REGISTRY);
  +      // hr = new SimpleRegistry("handlers.reg");
  +      hr = new DefaultHandlerRegistry("handlers-supp.reg");
         hr.setOnServer( onServer );
         hr.init();
       }
       if ( sr == null ) {
         // sr = new SimpleRegistry("services.reg");
  -      if ( onServer )
  -        sr = new DefaultServiceRegistry(Constants.SERVER_SERVICE_REGISTRY);
  -      else
  -        sr = new DefaultServiceRegistry(Constants.CLIENT_SERVICE_REGISTRY);
  +      sr = new DefaultServiceRegistry("services-supp.reg");
         hr.setOnServer( onServer );
         sr.init();
       }
  @@ -111,6 +106,17 @@
           handler.addOption( name, value );
       }
     }
  +  
  +  private void registerTypeMappings(Element root, SOAPService service)
  +    throws Exception
  +  {
  +    NodeList list = root.getElementsByTagName("bean");
  +    Debug.Print(1, "Registering " + list.getLength() + " service-specific types.");
  +    for (int i = 0; list != null && i < list.getLength(); i++) {
  +      Element el = (Element)list.item(i);
  +      registerTypeMapping(el, service.getTypeMappingRegistry());
  +    }
  +  }
   
     public Document AdminService(MessageContext msgContext, Document xml) 
                     throws AxisFault
  @@ -349,7 +355,7 @@
   
             if ( service == null ) service = new SOAPService();
             else              service.clear();
  -  
  +          
             if ( input != null && !"".equals(input) ) {
               st = new StringTokenizer( input, " \t\n\r\f," );
               c  = null ;
  @@ -388,6 +394,8 @@
               }
             }
             getOptions( elem, service );
  +          registerTypeMappings(elem, service);
  +  
             hr.add( name, service ); // ???
             sr.add( name, service );
           }
  @@ -396,47 +404,8 @@
           // for a bean at the same time.
           else if ( type.equals( "bean" ) ) {
             Debug.Print( 2, "Deploying bean: " + name );
  -
  -          // Resolve class name
  -
  -          Class cls;
  -          try {
  -            cls = Class.forName(name);
  -          } catch (Exception e) {
  -            throw new AxisFault( "Admin.error", e.toString(), null, null);
  -          }
  -
  -          // Resolve qname based on prefix and localpart
  -
  -          String qname = elem.getAttribute( "qname" );
  -          if (qname == null)
  -            throw new AxisFault( "Admin.error", 
  -                                 "Missing qname in bean " + name, null, null);
  -
  -          int pos = qname.indexOf(':'); 
  -          if (pos < 0)
  -            throw new AxisFault( "Admin.error", 
  -                                 "Missing namespace in qname " + qname, 
  -                                 null, null);
  -
  -          String prefix = qname.substring(0, pos);
  -          String localPart = qname.substring(pos+1);
  -          String namespace = XMLUtils.getNamespace(prefix, elem); 
  -          if (namespace == null)
  -            throw new AxisFault( "Admin.error", 
  -                                 "Unknown namespace in qname " + qname, 
  -                                 null, null);
  -
  -          QName qn = new QName(namespace, localPart);
  -
  -          // register both serializers and deserializers for this bean
  -
  -          TypeMappingRegistry map = tmr.getParent();
  -          map.addSerializer(cls, qn, new BeanSerializer(cls));
  -          map.addDeserializerFactory(qn, cls, BeanSerializer.getFactory(cls));
  -          }
  -
  -        else 
  +          registerTypeMapping(elem, tmr.getParent());
  +        } else 
             throw new AxisFault( "Admin.error", 
                                  "Unknown type to " + action + ": " + type,
                                  null, null );
  @@ -453,6 +422,53 @@
       return( doc );
     }
   
  +  private void registerTypeMapping(Element elem, TypeMappingRegistry map)
  +    throws Exception
  +  {
  +    String name = elem.getAttribute("name");
  +    if ((name == null) || name.equals(""))
  +      throw new AxisFault("Server.Admin.error",
  +                          "No name attribute in type mapping",
  +                          null, null);
  +    
  +    // Resolve class name
  +
  +    Class cls;
  +    try {
  +      cls = Class.forName(name);
  +    } catch (Exception e) {
  +      throw new AxisFault( "Admin.error", e.toString(), null, null);
  +    }
  +
  +    // Resolve qname based on prefix and localpart
  +
  +    String qname = elem.getAttribute( "qname" );
  +    if (qname == null)
  +      throw new AxisFault( "Admin.error", 
  +        "Missing qname in bean " + name, null, null);
  +
  +    int pos = qname.indexOf(':'); 
  +    if (pos < 0)
  +      throw new AxisFault( "Admin.error", 
  +        "Missing namespace in qname " + qname, 
  +        null, null);
  +
  +    String prefix = qname.substring(0, pos);
  +    String localPart = qname.substring(pos+1);
  +    String namespace = XMLUtils.getNamespace(prefix, elem); 
  +    if (namespace == null)
  +      throw new AxisFault( "Admin.error", 
  +        "Unknown namespace in qname " + qname, 
  +        null, null);
  +
  +    QName qn = new QName(namespace, localPart);
  +
  +    // register both serializers and deserializers for this bean
  +
  +    map.addSerializer(cls, qn, new BeanSerializer(cls));
  +    map.addDeserializerFactory(qn, cls, BeanSerializer.getFactory(cls));
  +  }
  +  
     public static void main(String args[]) {
       int  i = 0 ;
   
  
  
  

Mime
View raw message