You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by ga...@apache.org on 2004/04/14 19:24:24 UTC

cvs commit: ws-fx/addressing/src/org/apache/axis/message/addressing/handler AddressingHandler.java

gawor       2004/04/14 10:24:24

  Modified:    addressing/src/org/apache/axis/message/addressing
                        EndpointReference.java EndpointReferenceType.java
                        ReferencePropertiesType.java
               addressing/src/org/apache/axis/message/addressing/handler
                        AddressingHandler.java
  Log:
  addressing handler updates: added fault support and reworked passing of entire EPRs. also fixed a few minor bugs
  
  Revision  Changes    Path
  1.6       +4 -2      ws-fx/addressing/src/org/apache/axis/message/addressing/EndpointReference.java
  
  Index: EndpointReference.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/addressing/src/org/apache/axis/message/addressing/EndpointReference.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EndpointReference.java	7 Apr 2004 19:35:05 -0000	1.5
  +++ EndpointReference.java	14 Apr 2004 17:24:24 -0000	1.6
  @@ -145,17 +145,19 @@
           }
   
           list = el.getElementsByTagNameNS(Constants.NS_URI_ADDRESSING,
  -                Constants.REFERENCE_PROPERTIES);
  +                                         Constants.REFERENCE_PROPERTIES);
   
           if (list.getLength() > 0) {
               NodeList children = list.item(0).getChildNodes();
               if (children != null) {
  +                ReferencePropertiesType props = new ReferencePropertiesType();
                   for (int i = 0; i < children.getLength(); i++) {
                       Node n = children.item(i);
                       if (n.getNodeType() == Node.ELEMENT_NODE) {
  -                        getProperties().add((Element) n);
  +                        props.add((Element) n);
                       }
                   }
  +                setProperties(props);
               }
           }
       }
  
  
  
  1.6       +5 -4      ws-fx/addressing/src/org/apache/axis/message/addressing/EndpointReferenceType.java
  
  Index: EndpointReferenceType.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/addressing/src/org/apache/axis/message/addressing/EndpointReferenceType.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EndpointReferenceType.java	7 Apr 2004 19:35:05 -0000	1.5
  +++ EndpointReferenceType.java	14 Apr 2004 17:24:24 -0000	1.6
  @@ -97,14 +97,15 @@
           setPortType(endpoint.getPortType());
           setServiceName(endpoint.getServiceName());
           ReferencePropertiesType properties = endpoint.getProperties();
  -        if (properties != null) {
  +        if (properties != null && properties.size() > 0) {
  +            ReferencePropertiesType props = new ReferencePropertiesType();
               for (int i = 0; i < properties.size(); i++) {
  -                Element elem = (Element) properties.get(i);
  -                this.getProperties().add(elem);
  +                props.add ( properties.get(i) );
               }
  +            setProperties(props);
           }
       }
  -
  +    
       /**
        * Method getAddress
        * 
  
  
  
  1.3       +15 -8     ws-fx/addressing/src/org/apache/axis/message/addressing/ReferencePropertiesType.java
  
  Index: ReferencePropertiesType.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/addressing/src/org/apache/axis/message/addressing/ReferencePropertiesType.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ReferencePropertiesType.java	7 Apr 2004 19:35:05 -0000	1.2
  +++ ReferencePropertiesType.java	14 Apr 2004 17:24:24 -0000	1.3
  @@ -19,12 +19,15 @@
   
   import org.w3c.dom.Element;
   import org.w3c.dom.Node;
  +import org.w3c.dom.Document;
   
   import java.io.Serializable;
   import java.util.Iterator;
   import java.util.LinkedList;
   
   import org.apache.axis.message.MessageElement;
  +import org.apache.axis.components.logger.LogFactory;
  +import org.apache.commons.logging.Log;
   
   /**
    * Java content class for ReferencePropertiesType complex type.
  @@ -46,6 +49,9 @@
    */
   public class ReferencePropertiesType implements Serializable { 
   
  +    private static Log log = 
  +        LogFactory.getLog(ReferencePropertiesType.class.getName());
  +
       private MessageElement [] _any;
   
       /**
  @@ -72,10 +78,10 @@
   
       public void add(Object element) {
           MessageElement value = null;
  -        if (element instanceof Element) {
  -            value = new MessageElement((Element)element);
  -        } else if (element instanceof MessageElement) {
  +        if (element instanceof MessageElement) {
               value = (MessageElement)element;
  +        } else if (element instanceof Element) {
  +            value = new MessageElement((Element)element);
           } else {
               throw new IllegalArgumentException();
           }
  @@ -100,17 +106,18 @@
        * @param parent 
        */
       public void append(Element parent) {
  -        Element refProp =
  -                parent.getOwnerDocument().createElementNS(Constants.NS_URI_ADDRESSING,
  -                        Constants.REFERENCE_PROPERTIES);
  +        Document doc = parent.getOwnerDocument();
  +        Element refProp = doc.createElementNS(Constants.NS_URI_ADDRESSING,
  +                                              Constants.REFERENCE_PROPERTIES);
           MessageElement [] any = get_any();
           if (any != null) {
               try {
                   for (int i=0;i<any.length;i++) {
  -                    refProp.appendChild(any[i].getAsDOM());
  +                    refProp.appendChild(doc.importNode(any[i].getAsDOM(), 
  +                                                       true));
                   }
               } catch (Exception e) {
  -                
  +                log.debug("", e);
               }
           }
           parent.appendChild(refProp);
  
  
  
  1.9       +231 -122  ws-fx/addressing/src/org/apache/axis/message/addressing/handler/AddressingHandler.java
  
  Index: AddressingHandler.java
  ===================================================================
  RCS file: /home/cvs/ws-fx/addressing/src/org/apache/axis/message/addressing/handler/AddressingHandler.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AddressingHandler.java	7 Apr 2004 19:35:05 -0000	1.8
  +++ AddressingHandler.java	14 Apr 2004 17:24:24 -0000	1.9
  @@ -74,21 +74,17 @@
       public AddressingHandler() {
           uuidGen = UUIDGenFactory.getUUIDGen();
       }
  -    
      
       /**
        * Initialize the addressing handler.
        */
  -	public void init()
  -	{
  -		super.init();		
  -		initializeReferencePropertyNames();
  -	}
  -    
  -    
  -
  +    public void init()
  +    {
  +        super.init();		
  +        initializeReferencePropertyNames();
  +    }
   
  -	/**
  +    /**
        * Method invoke
        * 
        * @param msgContext 
  @@ -115,14 +111,103 @@
           }
       }
       
  +    public void onFault(MessageContext msgContext) {
  +        if (msgContext.isClient()) {
  +            return;
  +        }
  +        try {
  +            processFault(msgContext);
  +        } catch (Exception e) {
  +            log.error("Exception in AddressingHandler", e);
  +        }
  +    }
  +
  +    private void processFault(MessageContext msgContext) 
  +        throws Exception {
  +        AddressingHeaders reqHeaders = 
  +            (AddressingHeaders) msgContext.getProperty(
  +                  Constants.ENV_ADDRESSING_REQUEST_HEADERS
  +             );
  +
  +        if (reqHeaders == null) {
  +            // error?
  +            return;
  +        }
  +
  +        AddressingHeaders resHeaders = 
  +            (AddressingHeaders) msgContext.getProperty(
  +                  Constants.ENV_ADDRESSING_RESPONSE_HEADERS
  +            );
  +
  +        if (resHeaders == null) {
  +            resHeaders = new AddressingHeaders();
  +            // set property so other handlers might have a chance to use/modify
  +            msgContext.setProperty(Constants.ENV_ADDRESSING_RESPONSE_HEADERS, 
  +                                   resHeaders);
  +        }
  +
  +        // set From
  +        EndpointReference fromEPR = resHeaders.getFrom();
  +        if (fromEPR == null) {
  +            To toURI = reqHeaders.getTo();
  +            if (toURI != null) {
  +                fromEPR = new EndpointReference(toURI);
  +                fromEPR.setProperties(reqHeaders.getReferenceProperties());
  +                resHeaders.setFrom(fromEPR);
  +            }
  +        }
  +        
  +        // don't set action for faults at this point - 03 spec unclear on that
  +        
  +        MessageID msgID = null;
  +
  +        // process RelatesTo
  +        msgID = reqHeaders.getMessageID();
  +        if (msgID != null) {
  +            resHeaders.addRelatesTo(msgID.toString(), 
  +                                    Constants.QNAME_RESPONSE);
  +        }
  +        
  +        // process MessageID
  +        msgID = new MessageID(new URI("uuid:" + uuidGen.nextUUID()));
  +        resHeaders.setMessageID(msgID);
  +
  +        // now put all headers into soap env.
  +        Message msg = msgContext.getCurrentMessage();
  +        if (msg == null) {
  +            return;
  +        }
  +        
  +        resHeaders.toEnvelope(msg.getSOAPEnvelope());
  +        
  +        // process FaultTo
  +        EndpointReferenceType faultTo = reqHeaders.getFaultTo();
  +        if (faultTo != null) {
  +            Address address = faultTo.getAddress();
  +            if (address != null) {
  +                String uri = address.toString();
  +                if (uri != null) {
  +                    // send the msg to fault to
  +                    forwardMessage(faultTo, msg);
  +                    // Somehow make the response empty, or create a new empty 
  +                    // response
  +                    msgContext.setCurrentMessage(null);
  +                }
  +            }
  +        }
  +    }
  +
       /**
        * Method processClientRequest
        * 
        * @param msgContext 
        */
       void processClientRequest(MessageContext msgContext) 
  -        throws AxisFault, Exception {
  -        AddressingHeaders headers = (AddressingHeaders) msgContext.getProperty(Constants.ENV_ADDRESSING_REQUEST_HEADERS);
  +        throws Exception {
  +        AddressingHeaders headers = 
  +            (AddressingHeaders) msgContext.getProperty(
  +                  Constants.ENV_ADDRESSING_REQUEST_HEADERS
  +            );
           if (headers == null) {
               headers = new AddressingHeaders();
           }
  @@ -149,13 +234,17 @@
        * 
        * @param msgContext 
        */
  -    void processClientResponse(MessageContext msgContext) throws Exception {
  +    void processClientResponse(MessageContext msgContext) 
  +        throws Exception {
           Message msg = msgContext.getResponseMessage();
  -        if (msg != null) {
  -            AddressingHeaders headers = new AddressingHeaders(
  -            	msg.getSOAPEnvelope(), null, true, true, ignoreNonWSAHeaders, refPropQNames);
  -            msgContext.setProperty(Constants.ENV_ADDRESSING_RESPONSE_HEADERS, headers);
  +        if (msg == null) {
  +            return;
           }
  +        AddressingHeaders headers = 
  +            new AddressingHeaders(msg.getSOAPEnvelope(), null, true,
  +                                  true, ignoreNonWSAHeaders, refPropQNames);
  +        msgContext.setProperty(Constants.ENV_ADDRESSING_RESPONSE_HEADERS, 
  +                               headers);
       }
       
       /**
  @@ -164,18 +253,20 @@
        * @param msgContext 
        * @throws Exception 
        */
  -    void processServerRequest(MessageContext msgContext) throws Exception {
  +    void processServerRequest(MessageContext msgContext) 
  +        throws Exception {
           Message msg = msgContext.getRequestMessage();
  -        
  +        if (msg == null) {
  +            return;
  +        }
           AddressingHeaders headers = 
  -            new AddressingHeaders(msg.getSOAPEnvelope(), null, true, true, ignoreNonWSAHeaders, refPropQNames);
  +            new AddressingHeaders(msg.getSOAPEnvelope(), null, true, 
  +                                  true, ignoreNonWSAHeaders, refPropQNames);
           
           msgContext.setProperty(Constants.ENV_ADDRESSING_REQUEST_HEADERS, 
                                  headers);
           
  -        AddressingHeaders resheaders = new AddressingHeaders();
  -        
  -        // process To
  +        // set the target service based on To header
           To toURI = headers.getTo();
           if (toURI != null) {
               String to = toURI.toString();
  @@ -183,132 +274,150 @@
                   // set the target service
                   int i = to.lastIndexOf("/");
                   msgContext.setTargetService(to.substring(i + 1));
  -                // set From
  -                resheaders.setFrom(new EndpointReference(toURI));
               }
           }
  -        
  -        // process ReplyTo
  -        EndpointReferenceType replyTo = headers.getReplyTo();
  -        if (replyTo != null) {
  -            String replyToStr = null;
  -            Address address = replyTo.getAddress();;
  -            if (address != null) {
  -                replyToStr = address.toString();
  -            }
  -            if (replyToStr == null) {
  -                replyToStr = Constants.NS_URI_ANONYMOUS;
  +    }
  +    
  +    /**
  +     * Method processServerResponse
  +     * 
  +     * @param msgContext 
  +     */
  +    void processServerResponse(MessageContext msgContext) 
  +        throws Exception {
  +
  +        AddressingHeaders reqHeaders = 
  +            (AddressingHeaders) msgContext.getProperty(
  +                  Constants.ENV_ADDRESSING_REQUEST_HEADERS
  +             );
  +
  +        if (reqHeaders == null) {
  +            // error?
  +            return;
  +        }
  +
  +        AddressingHeaders resHeaders = 
  +            (AddressingHeaders) msgContext.getProperty(
  +                  Constants.ENV_ADDRESSING_RESPONSE_HEADERS
  +            );
  +
  +        if (resHeaders == null) {
  +            resHeaders = new AddressingHeaders();
  +            // set property so other handlers might have a chance to use/modify
  +            msgContext.setProperty(Constants.ENV_ADDRESSING_RESPONSE_HEADERS, 
  +                                   resHeaders);
  +        }
  +
  +        // set From
  +        EndpointReference fromEPR = resHeaders.getFrom();
  +        if (fromEPR == null) {
  +            To toURI = reqHeaders.getTo();
  +            if (toURI != null) {
  +                fromEPR = new EndpointReference(toURI);
  +                fromEPR.setProperties(reqHeaders.getReferenceProperties());
  +                resHeaders.setFrom(fromEPR);
               }
  -            // set To
  -            resheaders.setTo(new To(replyToStr));
           }
  -        else {
  -            // if no reply-to was set in incoming message
  -            // add a to address that indicates anonymous
  -            resheaders.setTo(new To(Constants.NS_URI_ANONYMOUS));
  +        
  +        // set Action
  +        Action action = resHeaders.getAction();
  +        if (action == null) {
  +            // not set - try request headers
  +            action = reqHeaders.getAction();
  +            if (action != null) {
  +                resHeaders.setAction(new Action(new URI(action.toString() + 
  +                                                        "Response")));
  +            }
           }
           
           MessageID msgID = null;
  -        
  +
           // process RelatesTo
  -        msgID = headers.getMessageID();
  +        msgID = reqHeaders.getMessageID();
           if (msgID != null) {
  -            resheaders.addRelatesTo(msgID.toString(), 
  +            resHeaders.addRelatesTo(msgID.toString(), 
                                       Constants.QNAME_RESPONSE);
           }
           
           // process MessageID
           msgID = new MessageID(new URI("uuid:" + uuidGen.nextUUID()));
  -        resheaders.setMessageID(msgID);
  -        
  -        // process Action
  -        Action action = headers.getAction();
  -        if (action != null) {
  -            resheaders.setAction(new Action(new URI(action.toString() + "Response")));
  +        resHeaders.setMessageID(msgID);
  +
  +        // now put all headers into soap env.
  +        Message msg = msgContext.getResponseMessage();
  +        if (msg == null) {
  +            return;
           }
           
  -        msgContext.setProperty(Constants.ENV_ADDRESSING_RESPONSE_HEADERS, 
  -                               resheaders);
  +        resHeaders.toEnvelope(msg.getSOAPEnvelope());
  +
  +        // process ReplyTo
  +        EndpointReferenceType replyTo = reqHeaders.getReplyTo();
  +        if (replyTo != null) {
  +            Address address = replyTo.getAddress();
  +            if (address != null) {
  +                String uri = address.toString();
  +                if (uri != null && !uri.equals(Constants.NS_URI_ANONYMOUS)) {
  +                    // send the msg to reply to
  +                    forwardMessage(replyTo, msg);
  +                    // Somehow make the response empty, or create a new empty 
  +                    // response
  +                    msgContext.setResponseMessage(null);
  +                }
  +            }
  +        }
       }
       
  +    private void forwardMessage(EndpointReferenceType epr,
  +                                Message msg) 
  +        throws Exception {
  +        Address address = epr.getAddress();
  +        
  +        AddressingHeaders headers = new AddressingHeaders();
  +        headers.setTo(address);
  +        headers.setReferenceProperties(epr.getProperties());
  +        
  +        Call c = new Call(address.toString());
  +        c.setRequestMessage(msg);
  +        c.setProperty(Constants.ENV_ADDRESSING_REQUEST_HEADERS, headers);
  +        c.invoke();
  +    }
  +
       /**
  -     * Method processServerResponse
  -     * 
  -     * @param msgContext 
  +     * Retrieve QNames for reference properties from deployment
  +     * and initialize the refPropQNames list which is the list
  +     * of reference properties that this handler should care
  +     * about.
        */
  -    void processServerResponse(MessageContext msgContext) 
  -        throws AxisFault, Exception {
  -        AddressingHeaders resheaders = (AddressingHeaders) msgContext.getProperty(Constants.ENV_ADDRESSING_RESPONSE_HEADERS);
  -        if (resheaders == null) {
  +    private void initializeReferencePropertyNames() {
  +        // check if the user wants to process all headers, this means
  +        // the user wants to treat non ws-addr headers as reference props
  +        // If this option is not enabled, the non ws-addr headers will not
  +        // be deserialized.
  +        String refPropNames =  (String) getOption("referencePropertyNames");
  +        if (refPropNames == null) {
               return;
           }
  -        Message msg = msgContext.getResponseMessage();
  -        if (msg == null) {
  +		
  +        ignoreNonWSAHeaders = false;
  +
  +        if (refPropNames.equals("*")) {
               return;
           }
  -        
  -        resheaders.toEnvelope(msg.getSOAPEnvelope());
  -        
  -        boolean isResponse = false;
  -        List relates = resheaders.getRelatesTo();
  -        for (int i = 0; (relates != null) && (i < relates.size()); i++) {
  -            RelatesTo rtp = (RelatesTo) relates.get(i);
  -            if (rtp.getType().equals(Constants.QNAME_RESPONSE)) {
  -                isResponse = true;
  +		
  +        refPropQNames = new ArrayList();
  +        StringTokenizer tkn = new StringTokenizer(refPropNames, ",");
  +        while (tkn.hasMoreTokens()) {
  +            String qnameString = tkn.nextToken().trim();
  +            try {
  +                QName qname = QName.valueOf(qnameString);
  +                refPropQNames.add(qname);
               }
  -        }
  -        
  -        // process replyTo by invoking a service
  -        To toURI = resheaders.getTo();
  -        if (toURI != null) {
  -            String to = toURI.toString();
  -            if (to != null && !to.equals(Constants.NS_URI_ANONYMOUS) && 
  -                isResponse) {
  -                // ReplyTo has been specified. Special processing...
  -                Call c = new Call(to);
  -                c.setRequestMessage(msg);
  -                c.invoke();
  -                
  -                // Somehow make the response empty, or create a new empty 
  -                // response
  -                msgContext.setResponseMessage(null);
  +            catch (Exception e) {
  +                // Ignore QNames which were written incorrectly
  +                // if their parsing results in errors
               }
           }
       }
  -    
  -
  -    /**
  -	 * Retrieve QNames for reference properties from deployment
  -	 * and initialize the refPropQNames list which is the list
  -	 * of reference properties that this handler should care
  -	 * about.
  -	 */
  -	private void initializeReferencePropertyNames() {
  -		// check if the user wants to process all headers, this means
  -		// the user wants to treat non ws-addr headers as reference props
  -		// If this option is not enabled, the non ws-addr headers will not
  -		// be deserialized.
  -		String refPropNames =  (String) getOption("referencePropertyNames");
  -		if (refPropNames == null) return;
  -		
  -		ignoreNonWSAHeaders = false;
  -		if (refPropNames.equals("*")) {
  -			return;
  -		}
  -		
  -		refPropQNames = new ArrayList();
  -		StringTokenizer tkn = new StringTokenizer(refPropNames, ",");
  -		while (tkn.hasMoreTokens()) {
  -			String qnameString = tkn.nextToken().trim();
  -			try {
  -                                QName qname = QName.valueOf(qnameString);
  -				refPropQNames.add(qname);
  -			}
  -			catch (Exception e) {
  -				// Ignore QNames which were written incorrectly
  -				// if their parsing results in errors
  -			}
  -		}
  -	}
   
   }